SQLite Exception - Create Table

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);
}

Answers


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


Need Your Help

Get Yii CgridView's dataprovider in jquery

jquery yii cgridview

I'm trying to get all data from yii cgridview, I need to get the dataprovider of cgridview in jquery ajax.

Styled cross-platform native widgets and windows

c user-interface cross-platform

I'm looking for a reasonably cross-platform way to render windows and widgets and style them the way I want without losing the ability to interface with the OS-preferred ways of doing things like