Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I get the error "SQLiteLog﹕ (1) near "order": syntax error" when I attempt to create a new database?

Tags:

android

sqlite

Here is the code that constructs my query that is called by execSQL() later in my code.

    public static final String TABLE_NAME = "active";
    public static final String COLUMN_NAME_ORDER = "order";
    public static final String COLUMN_NAME_TITLE = "title";
    public static final String COLUMN_NAME_CONTENTS = "contents";

    //SQL Queries

    public static final String TEXT_TYPE = " TEXT";
    public static final String COMMA = ",";
    public static final String SQL_CREATE_TABLE_ACTIVE =
            "CREATE TABLE " + ActiveTasks.TABLE_NAME + " (" +
                    ActiveTasks._ID + " INTEGER PRIMARY KEY AUTOINCREMENT" + COMMA +
                    ActiveTasks.COLUMN_NAME_ORDER + TEXT_TYPE + COMMA +
                    ActiveTasks.COLUMN_NAME_TITLE + TEXT_TYPE + COMMA +
                    ActiveTasks.COLUMN_NAME_CONTENTS + TEXT_TYPE +
                    " );";

And here is the execSQL statment:

@Override
public void onCreate(SQLiteDatabase db) {
    Log.v(LOG_TAG, DataContract.ActiveTasks.SQL_CREATE_TABLE_ACTIVE);
    db.execSQL(DataContract.ActiveTasks.SQL_CREATE_TABLE_ACTIVE);

}

When the onCreate method is called, I get the following in my log.

925  16102-16119/xxxxxxxx V/ActiveDatabaseHelper﹕ CREATE TABLE active (_id INTEGER     PRIMARY KEY AUTOINCREMENT,order TEXT,title TEXT,contents TEXT );
 16102-16119/xxxxxxxx E/SQLiteLog﹕ (1) near "order": syntax error

I do not believe I have overlooked anything, and if that is true, what could I be doing wrong? Also, I have confirmed that the problem is located in the Oncreate method.

Thanks in advance, - Sam. And Yes, I have viewed multiple SO questions and answers describing the same problem I am having. They do not help my situation.

like image 758
Sam Avatar asked Dec 04 '25 12:12

Sam


1 Answers

Order is Sql keyword. you should use it with in quotes. Refer Here for more info.

like image 129
MathanG Avatar answered Dec 07 '25 16:12

MathanG