造成原因:android.database.sqlite.SQLiteException:在“设备”附近:语法错误(代码1):

时间:2019-03-17 15:54:38

标签: android sqlite syntax

当尝试编译时,我在SQLITE中有5个表,上面写着“语法错误”,但是我在代码中找不到任何语法错误。

这是我的代码

override fun onCreate(db: SQLiteDatabase?) {
        var ClothTable = "CREATE TABLE $Cloth (_id INTEGER PRIMARY KEY AUTOINCREMENT,Description TEXT ,IMAGE BLOB)"
        var DairyTable = "CREATE TABLE $Dairy (_id INTEGER PRIMARY KEY AUTOINCREMENT,Description TEXT ,IMAGE BLOB)"
        var EATable = "CREATE TABLE $ElectricalAppliances (_id INTEGER PRIMARY KEY AUTOINCREMENT,Description TEXT ,IMAGE BLOB)"
        var FoodTable = "CREATE TABLE $Food (_id INTEGER PRIMARY KEY AUTOINCREMENT,Description TEXT ,IMAGE BLOB)"
        var VegetableTable = "CREATE TABLE $vegetable (_id INTEGER PRIMARY KEY AUTOINCREMENT,Description TEXT ,IMAGE BLOB)"

        db?.execSQL(ClothTable)
        db?.execSQL(DairyTable)
        db?.execSQL(EATable)
        db?.execSQL(FoodTable)
        db?.execSQL(VegetableTable)


    }

错误是:

Caused by: android.database.sqlite.SQLiteException: near "Appliances": syntax error (code 1): , while compiling: CREATE TABLE Electrical Appliances (_id INTEGER PRIMARY KEY AUTOINCREMENT,Description STRING ,IMAGE BLOB)

1 个答案:

答案 0 :(得分:2)

我想您已经像这样声明了变量ElectricalAppliances:

val ElectricalAppliances = "Electrical Appliances"

作为表名,但不允许使用空格。
更改为:

val ElectricalAppliances = "[Electrical Appliances]"

名称必须用方括号[]或反引号`(ASCII代码096)包围。