0

Where is the Problem? I want to create a Table with the following SQL Statement. But i get an Exception near "delete".

 android.database.sqlite.SQLiteException: near "delete": syntax error (code 1):   , while compiling: CREATE TABLE data_base_stuff( _id INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT,color TEXT,priority TEXT,created_date TEXT,delete INTEGER)

        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
        at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
        at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674)
        at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)

This is the Exception

private static final String TEXT_TYP = " TEXT";
private static final String COMMA = ",";
private static final String INTEGER_TYP = " INTEGER";

private static final String SQL_CREATE_TABLE_DATABASE_STUFF = "CREATE TABLE "
        + CheckListColumns.TABLE_NAME + "( "
        + CheckListColumns._ID + INTEGER_TYP + " PRIMARY KEY AUTOINCREMENT,"
        + CheckListColumns.COLUMN_NAME_TITLE + TEXT_TYP + COMMA
        + CheckListColumns.COLUMN_NAME_COLOR + TEXT_TYP + COMMA
        + CheckListColumns.COLUMN_NAME_PRIORITY + TEXT_TYP + COMMA
        + CheckListColumns.COLUMN_NAME_CREATED_DATE + TEXT_TYP + COMMA
        + CheckListColumns.COLUMN_NAME_DELETE + INTEGER_TYP + ")";

End this is my Code

Muhammed Misir
  • 400
  • 9
  • 22

1 Answers1

1

delete is a keyword, and is interpreted as is, not as a column name. In order to keep that name, you need to surround it with backticks as explained here

Community
  • 1
  • 1
Francis Toth
  • 1,595
  • 1
  • 11
  • 23