3

What am I missing? Something with a "," but I seem to be looking in the wrong place. This is my code:

private static final String DATABASE_CREATE =
        "CREATE TABLE if not exists " + SQLITE_TABLE + " (" +
                KEY_ROWID + " integer PRIMARY KEY autoincrement," +
                KEY_CURSUS + "," +
                KEY_ONDERDEEL + "," +
                KEY_GAME + "," +
                KEY_TIJD + "," +
                KEY_WEB + "," +
                KEY_CHECK + "," +
                " UNIQUE (" + KEY_ROWID +"));";

And this is the error I get:

 Caused by: android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: CREATE TABLE if not exists Games_getset (_id integer PRIMARY KEY autoincrement,cursus,onderdeel,game,tijd,web,check, UNIQUE (_id));
1

3 Answers 3

9

Rename or quote the check column since check is a keyword in SQL.

For example:

private static final String DATABASE_CREATE =
    "CREATE TABLE if not exists " + SQLITE_TABLE + " (" +
            KEY_ROWID + " integer PRIMARY KEY autoincrement," +
            KEY_CURSUS + "," +
            KEY_ONDERDEEL + "," +
            KEY_GAME + "," +
            KEY_TIJD + "," +
            KEY_WEB + "," +
            + "`" + KEY_CHECK + "`," +
            " UNIQUE (" + KEY_ROWID +"));";
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks laalto (and CRUSADER)!
I made the same mistake by naming a column as 'cast'. I realized the mistake after reading your answer. Thanks
Same problem for me except my column name was 'group'
-1

You need to add data type for the columns you are defining for your table. You have added integer dataType for KEY_ROWID but forgot to add dataTypes for the rest..

.........KEY_ROWID + " integer PRIMARY KEY autoincrement," +
                KEY_CURSUS + " text," +
                KEY_ONDERDEEL + " text," + ........
and so on...

1 Comment

This isn't the issue - it's all right to have columns with just the name specified. The problem is using a reserved word check as a column name which confuses the SQL parser.
-1

Try deleting "IF NOT EXIST" in the create table command, SQLite in android version 4.0.4 give me this error, and not in 4.4.2

Luck.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.