Reputation: 73
I have 5 tables in SQLITE when I try to compile it says "Syntax error" But I can't find any syntax error in the code.
Here is my Code
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)
}
Error is :
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)
Upvotes: 0
Views: 57
Reputation: 164099
I guess you have declared the variable ElectricalAppliances like this:
val ElectricalAppliances = "Electrical Appliances"
as a table name but the space is not allowed.
Change it to:
val ElectricalAppliances = "[Electrical Appliances]"
The name must be surrounded with square brackets [ ] or backticks ` (ascii code 096).
Upvotes: 2