1

I am getting an exception, and I just can't figure out why it is being thrown. The exception appeared when I added the Table Messages. Please give it a look, and see if there is a blunder I have missed. Thanks in advance.

Exception:

 Caused by: android.database.sqlite.SQLiteException: near "From": syntax error (code 1): , while compiling: CREATE TABLE Messages (UniqueId TEXT PRIMARY KEY,From TEXT,To TEXT,Subject TEXT,Body TEXT,HandledOn TEXT,IsRead INTEGER,CreatedOn TEXT,UpdatedOn TEXT,DeletedOn TEXT);

Statement which causes the exception, in SQLiteOpenHelper:

@Override
public void onCreate(android.database.sqlite.SQLiteDatabase db) {
    String CREATE_MESSAGES_TABLE =
            "CREATE TABLE " + TABLE_MESSAGES + "("
                    + COLUMN_UNIQUEID + " TEXT PRIMARY KEY,"
                    + COLUMN_FROM + " TEXT,"
                    + COLUMN_TO + " TEXT,"
                    + COLUMN_SUBJECT + " TEXT,"
                    + COLUMN_BODY + " TEXT,"
                    + COLUMN_HANDLEDON + " TEXT,"
                    + COLUMN_ISREAD + " INTEGER,"
                    + COLUMN_CREATEDON + " TEXT,"
                    + COLUMN_UPDATEDON + " TEXT,"
                    + COLUMN_DELETEDON + " TEXT"
                    + ");";

    String CREATE_CONTACTS_TABLE =
            "CREATE TABLE " + TABLE_CONTACTS + "("
                    + COLUMN_UNIQUEID + " TEXT PRIMARY KEY,"
                    + COLUMN_NAME + " TEXT,"
                    + COLUMN_EMAIL + " TEXT,"
                    + COLUMN_CREATEDON + " TEXT,"
                    + COLUMN_UPDATEDON + " TEXT,"
                    + COLUMN_DELETEDON + " TEXT"
                    + ");";

    db.execSQL(CREATE_MESSAGES_TABLE);
    db.execSQL(CREATE_CONTACTS_TABLE);
}

1 Answer 1

3

You are using protected keywords like "from" and "to" as table names, which is not allowed in SQLite:

https://www.sqlite.org/lang_keywords.html

1
  • Thanks alot mate ;) I would have spent ages finding that out.
    – Hoffmann
    Jan 30, 2014 at 12:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.