I am trying to create a database table for Android. MY error message is the following.
08-02 10:16:50.075: E/AndroidRuntime(29093): Caused by:
android.database.sqlite.SQLiteException: near "index": syntax error (code 1): , while
compiling: CREATE TABLE featured_kluster (_id INTEGER PRIMARY KEY AUTOINCREMENT, index
TEXT, term TEXT)
What is wrong with my sql query?
public interface TableKluster extends BaseColumns {
public String table = "featured_kluster";
public String index = "index";
public String term = "term";
public String CREATE = "CREATE TABLE " + table + " ("
+ _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ index + " TEXT, "
+ term + " TEXT)";
}
I don't know what is wrong with the index field..
Index is an SQL keyword; replace it and it should work.
You cannot use an unquoted reserved keyword as an identifier. Ideally do what ClaireG suggests (use a non-keyword identifier), if that's not an option you can use one of the keyword escape mechanisms offered by SQLite
MS style using []
CREATE TABLE [table] (
MySQL style using backticks/grave accents
CREATE TABLE `table` (
ANSI style using double quotes
CREATE TABLE "table" (
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With