Reputation: 26094
I'm trying to execute this statement in onUpgrade
method of database helper but I'm getting an error:
database.execSQL("CREATE TABLE VEHICLE_HOURS(ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
"MINUTES INTEGER, VEHICLE VARCHAR(255), ORDER INTEGER);");
ERROR
Caused by: android.database.sqlite.SQLiteException: near "ORDER": syntax error (code 1): , while compiling: CREATE TABLE VEHICLE_HOURS(ID INTEGER PRIMARY KEY AUTOINCREMENT, MINUTES INTEGER, VEHICLE VARCHAR(255), ORDER INTEGER);
Thanks.
Upvotes: 1
Views: 3837
Reputation: 34322
ORDER
is a reserved word in SQL. You could of course suppress that error by taking the name into quotes, like:
database.execSQL("CREATE TABLE VEHICLE_HOURS(ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
"MINUTES INTEGER, VEHICLE VARCHAR(255), \"ORDER\" INTEGER);");
but better just pick another column name, then nobody (including your future self) will hate you while maintaining this code.
Upvotes: 3