Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is my sqlite query wrong?

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..

like image 985
user2062024 Avatar asked Aug 15 '26 06:08

user2062024


2 Answers

Index is an SQL keyword; replace it and it should work.

like image 115
ClaireG Avatar answered Aug 17 '26 20:08

ClaireG


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" (
like image 27
fvu Avatar answered Aug 17 '26 19:08

fvu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!