在 INSERT 上使用正确的数据类型 Flutter SQLite 数据类型不匹配

Posted

技术标签:

【中文标题】在 INSERT 上使用正确的数据类型 Flutter SQLite 数据类型不匹配【英文标题】:Flutter SQLite Datatype mismatch on INSERT with the correct datatypes 【发布时间】:2021-10-31 13:35:48 【问题描述】:

无论我如何尝试,我都会不断收到此错误

E/SQLiteLog( 9445): (20) statement aborts at 5: [INSERT Into Profile (mac,image,name,age,nationality,profession,about) VALUES ('0.0.0.0.0.0','/data/user/0/com.shades.flidar/cache/scaled_image_picker5826102720138113893.jpg','test','35',
E/SQLiteQuery( 9445): exception: datatype mismatch (code 20 SQLITE_MISMATCH); query: INSERT Into Profile (mac,image,name,age,nationality,profession,about) VALUES ('0.0.0.0.0.0','/data/user/0/com.test.test/cache/scaled_image_picker5826102720138113893.jpg','test','35','test','test','test');
E/flutter ( 9445): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: DatabaseException(datatype mismatch (code 20 SQLITE_MISMATCH)) sql 'INSERT Into Profile (mac,image,name,age,nationality,profession,about) VALUES ('0.0.0.0.0.0','/data/user/0/com.test.test/cache/scaled_image_picker5826102720138113893.jpg','test','35','test','test','test');' args []

这是代码:

customQuery("CREATE TABLE Profile ("
"mac TEXT,"
"image TEXT,"
"name TEXT,"
"age TEXT,"
"nationality TEXT,"
"profession TEXT,"
"about TEXT"
")");

onPressed: () 
    profile.add(Profile(
        mac: _platformVersion,
        image: imagePath,
        name: nameController.text,
        age: ageController.text,
        nationality: nationalityController.text,
        profession: professionController.text,
        about: aboutController.text));

    DBProvider.db.customQuery("INSERT Into Profile (mac,image,name,age,nationality,profession,about)"
        " VALUES ('$profile[0].mac','$profile[0].image',"
        "'$profile[0].name','$profile[0].age','$profile[0].nationality',"
        "'$profile[0].profession','$profile[0].about');");
       ,

我真的不知道为什么,请帮忙! 谢谢!

【问题讨论】:

【参考方案1】:

profile[0].age 应该返回一个字符串数据类型。

【讨论】:

谢谢,它确实返回一个字符串值

以上是关于在 INSERT 上使用正确的数据类型 Flutter SQLite 数据类型不匹配的主要内容,如果未能解决你的问题,请参考以下文章

FlutterDart数据类型之num

Insert into Select 没有正确插入相同的数据顺序

正确的 INSERT .. ON DUPLICATE KEY 语法?

SpringBoot Date类型插入数据库始终比正确时间早一天问题解决办法

MySQL INSERT 在同一张表上使用带有 COUNT() 的子查询

扩展 mysqli_result 在 INSERT 类型的查询上抛出错误