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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot mate ;) I would have spent ages finding that out.

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.