SQLiteException syntax error (code 1):

ChemDev

I am trying to crete a SQLite database in an android application in a SQLiteOpenHelper subclass and I am getting the following error:

.SQLiteException: near "playlist": syntax error (code 1): , while compiling: CREATE playlist(
_id INTEGER PRIMARY KEY,
playlist_name TEXT,
sound_id Integer,
FOREIGN KEY (sound_id) REFERENCES sound(_ID)
);

Here is my relevant code starting with the String constants with the SQL code used to create my databse:

public static final String CREATE_PLAYLIST_TABLE = "CREATE playlist(\n" +
        "   _id INTEGER PRIMARY KEY,\n" +
        "   playlist_name TEXT,\n" +
        "   sound_id Integer,\n" +
        "   FOREIGN KEY (sound_id) REFERENCES sound(_ID)\n" +
        ");";

public static final String CREATE_SOUND_TABLE = "CREATE sound(\n" +
        "   _id INTEGER PRIMARY KEY,\n" +
        "   volume REAL,\n" +
        "   rate REAL,\n" +
        "   FOREIGN KEY (sound_file) REFERENCES sound_file(_ID)\n" +
        ");";

public static final String CREATE_SOUND_FILE_TABLE = "CREATE sound_file(\n" +
        "   _id INTEGER PRIMARY KEY,\n" +
        "   sound_name TEXT,\n" +
        "   is_rate_editing_enabled REAL,\n" +
        "   url TEXT\n" +
        ");";

And here is the onCreate(SQLiteDatabase db) method:

 @Override
public void onCreate(SQLiteDatabase db) {
    Log.d(TAG, "onCreate database called");
    db.execSQL(CREATE_PLAYLIST_TABLE);
    db.execSQL(CREATE_SOUND_FILE_TABLE);
    db.execSQL(CREATE_SOUND_TABLE);
}

Any ideas as far as what is going wrong here?

Phantômaxx

You need to use the keyword TABLE:

"CREATE TABLE playlist (" +
    "_id INTEGER PRIMARY KEY, " +
    "playlist_name TEXT, " +
    "sound_id INTEGER, " +
    "FOREIGN KEY (sound_id) REFERENCES sound(_ID))";

Also for the other 2 tables.

The ; is simply useless.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android - SQLiteException: near "=": syntax error (code 1)

From Dev

SQLiteException: near "CREATE": syntax error (code 1)

From Dev

Android SQLiteException syntax error code 1

From Dev

Android SQLite syntax error SQLiteException (code 1)

From Dev

android.database.sqlite.SQLiteException: near "ON": syntax error (code 1)

From Dev

.SQLiteException: near ",": syntax error (code 1): , while compiling:

From Dev

android.database.sqlite.SQLiteException: near "ON": syntax error (code 1):

From Dev

android.database.sqlite.SQLiteException: near ")": syntax error (code 1)

From Dev

android.database.sqlite.SQLiteException: near "ON": syntax error (code 1)

From Dev

android.database.sqlite.SQLiteException: near "-- " syntax error code 1

From Dev

android.database.sqlite.SQLiteException: near "If": syntax error (code 1)

From Dev

Can't resolve SQLiteException: near "SELECT": syntax error (code 1)

From Dev

android.database.sqlite.SQLiteException: near ";": syntax error (code 1):

From Dev

android.database.sqlite.SQLiteException: near ": syntax error (code 1): , while compiling: android programing error

From Dev

Error: Caused by: android.database.sqlite.SQLiteException: near "add": syntax error (code 1):

From Dev

Experiencing SQLiteException error syntax error (code 1) when attempting to create Database table

From Dev

android.database.sqlite.SQLiteException: near "Group": syntax error (code 1):

From Dev

android.database.sqlite.SQLiteException: near "ORDER": syntax error (code 1): ,

From Dev

android.database.sqlite.SQLiteException: near "where": syntax error (code 1):

From Dev

android.database.sqlite.SQLiteException: near "Standards": syntax error (code 1)

From Dev

SQLiteException: near ";" syntax error (code 1): , while compiling: INSERT INTO SubjectsDB('softskill','no');

From Dev

android.database.sqlite.SQLiteException: near "Foreign": syntax error (code 1):

From Dev

android.database.sqlite.SQLiteException: near "Details": syntax error (code 1):

From Dev

android.database.sqlite.SQLiteException: near "Group": syntax error (code 1):

From Dev

android.database.sqlite.SQLiteException: near "Foreign": syntax error (code 1):

From Dev

I get a message of android.database.sqlite.SQLiteException: near "=": syntax error (code 1):

From Dev

android.database.sqlite.SQLiteException: near "tableplayers": syntax error (code 1)

From Dev

SQLiteException: near "null": syntax error (code 1): , while compiling: create table

From Dev

android.database.sqlite.SQLiteException: near "FROM": syntax error (code 1):

Related Related

  1. 1

    Android - SQLiteException: near "=": syntax error (code 1)

  2. 2

    SQLiteException: near "CREATE": syntax error (code 1)

  3. 3

    Android SQLiteException syntax error code 1

  4. 4

    Android SQLite syntax error SQLiteException (code 1)

  5. 5

    android.database.sqlite.SQLiteException: near "ON": syntax error (code 1)

  6. 6

    .SQLiteException: near ",": syntax error (code 1): , while compiling:

  7. 7

    android.database.sqlite.SQLiteException: near "ON": syntax error (code 1):

  8. 8

    android.database.sqlite.SQLiteException: near ")": syntax error (code 1)

  9. 9

    android.database.sqlite.SQLiteException: near "ON": syntax error (code 1)

  10. 10

    android.database.sqlite.SQLiteException: near "-- " syntax error code 1

  11. 11

    android.database.sqlite.SQLiteException: near "If": syntax error (code 1)

  12. 12

    Can't resolve SQLiteException: near "SELECT": syntax error (code 1)

  13. 13

    android.database.sqlite.SQLiteException: near ";": syntax error (code 1):

  14. 14

    android.database.sqlite.SQLiteException: near ": syntax error (code 1): , while compiling: android programing error

  15. 15

    Error: Caused by: android.database.sqlite.SQLiteException: near "add": syntax error (code 1):

  16. 16

    Experiencing SQLiteException error syntax error (code 1) when attempting to create Database table

  17. 17

    android.database.sqlite.SQLiteException: near "Group": syntax error (code 1):

  18. 18

    android.database.sqlite.SQLiteException: near "ORDER": syntax error (code 1): ,

  19. 19

    android.database.sqlite.SQLiteException: near "where": syntax error (code 1):

  20. 20

    android.database.sqlite.SQLiteException: near "Standards": syntax error (code 1)

  21. 21

    SQLiteException: near ";" syntax error (code 1): , while compiling: INSERT INTO SubjectsDB('softskill','no');

  22. 22

    android.database.sqlite.SQLiteException: near "Foreign": syntax error (code 1):

  23. 23

    android.database.sqlite.SQLiteException: near "Details": syntax error (code 1):

  24. 24

    android.database.sqlite.SQLiteException: near "Group": syntax error (code 1):

  25. 25

    android.database.sqlite.SQLiteException: near "Foreign": syntax error (code 1):

  26. 26

    I get a message of android.database.sqlite.SQLiteException: near "=": syntax error (code 1):

  27. 27

    android.database.sqlite.SQLiteException: near "tableplayers": syntax error (code 1)

  28. 28

    SQLiteException: near "null": syntax error (code 1): , while compiling: create table

  29. 29

    android.database.sqlite.SQLiteException: near "FROM": syntax error (code 1):

HotTag

Archive