【问题标题】:Flutter SQLite Syntax Error near TEXT decimal pointFlutter SQLite 语法错误靠近 TEXT 小数点
【发布时间】:2021-10-29 19:16:21
【问题描述】:

我似乎无法弄清楚这个语法错误是什么,我已经为 mac 和图像字段尝试了 TEXT 和 BLOB,但似乎没有任何效果。请帮忙!

customQuery("CREATE TABLE Profile ("
    "mac TEXT,"
    "image TEXT,"
    "name TEXT,"
    "age INT,"
    "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});");
           },

&这是错误

    E/SQLiteLog( 4520): (1) near ".0": syntax error in "INSERT Into Profile (mac,image,name,age,nationality,profession,about) VALUES (0.0.0.0.0.0,/data/user/0/com.test.fltestar/cache/scaled_image_picker3315305739073272987.jpg,test,35,test
E/flutter ( 4520): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: DatabaseException(near ".0": syntax error (code 1 SQLITE_ERROR): , while compiling: 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_picker3315305739073272987.jpg,test,35,test,test,test);) 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_picker3315305739073272987.jpg,test,35,test,test,test);' args []

【问题讨论】:

    标签: android ios flutter sqlite


    【解决方案1】:

    事实上,INSERT 语法是错误的。 这是您的实际语法:

    INSERT Into Profile (mac,image,name,age,nationality,profession,about) VALUES (0.0.0.0.0.0,/data/user/0/com.test.fltestar/cache/scaled_image_picker3315305739073272987.jpg,test,35,test,test,test);
    

    但这些值并不是所有 TEXT 字段的值都表示为 TEXT。应该是这样的:

    INSERT Into Profile (mac,image,name,age,nationality,profession,about) VALUES ('0.0.0.0.0.0','/data/user/0/com.test.fltestar/cache/scaled_image_picker3315305739073272987.jpg','test',35,'test','test','test');
    

    另外,我建议您使用 moor 之类的库,这对您有很大帮助。

    【讨论】:

    • 非常感谢@Gregorio!那是一个愚蠢的错误。但现在我得到这个错误: E/SQLiteLog(4520): (20) statement aborts at 5: E/SQLiteQuery(4520): exception: datatype mismatch (code 20 SQLITE_MISMATCH);查询: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_picker3315305739073272987.jpg' ,'test','35','test','test','test');
    • 35 值应该是一个整数,但您在此版本的查询中将其称为字符串。只需将其切换回整数即可。
    • 又犯了一个愚蠢的错误,但是,在将年龄列的数据类型更改为 TEXT 后,我仍然得到数据类型不匹配,反之亦然。你还能看到什么?仅供参考(平台版本和图像是字符串)
    猜你喜欢
    • 1970-01-01
    • 2021-04-22
    • 2020-04-07
    • 2017-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    相关资源
    最近更新 更多