dimanche 29 novembre 2015

CREATE table query syntax error in SQLite android

I'm programming an android application that is using sqlite database and now I'm facing syntax error in executing the create query of update table:

 // Logcat tag
private static final String LOG = "DatabaseHelper";

// Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "budget";

// Table Names
private static final String TABLE_CATEGORY = "category";
private static final String TABLE_UPDATE = "update";
private static final String TABLE_CATEGORY_UPDATE = "category_update";

// Common column names
private static final String KEY_ID = "id";

// Category Table - column nmaes
private static final String KEY_TYPE = "TYPE";


// Update Table - column names
private static final String KEY_MONEY = "money";
private static final String KEY_LOCATION = "location";
private static final String IMAGE_PATH = "image_path";
// CATEGORY_UPDATE Table - column names
private static final String KEY_CATEGORY_ID = "category_id";
private static final String KEY_UPDATE_ID = "update_id";


// Table Create Statements
// Category table create statement
private static final String CREATE_TABLE_CATEGORY = "CREATE TABLE if not exists "
        + TABLE_CATEGORY + "(" + KEY_ID + " INTEGER PRIMARY KEY autoincrement," + KEY_TYPE
        + " TEXT"+ ");";

// Update table create statement
private static final String CREATE_TABLE_UPDATE = "CREATE TABLE if not exists " + TABLE_UPDATE
        + "(" + KEY_ID + " INTEGER PRIMARY KEY autoincrement," + KEY_MONEY + " INTEGER,"
        + KEY_LOCATION + " TEXT," + IMAGE_PATH +" TEXT);";

// CATEGORY_UPDATE table create statement
private static final String CREATE_TABLE_CATEGORY_UPDATE = "CREATE TABLE if not exists "
        + TABLE_CATEGORY_UPDATE + "(" + KEY_ID + " INTEGER PRIMARY KEY autoincrement,"
        + KEY_CATEGORY_ID + " INTEGER," + KEY_UPDATE_ID + " INTEGER );";

all of the create queries are ordered as followed:

@Override
public void onCreate(SQLiteDatabase db) {

    // creating required tables
    db.execSQL(CREATE_TABLE_CATEGORY_UPDATE);
    db.execSQL(CREATE_TABLE_CATEGORY);
    db.execSQL(CREATE_TABLE_UPDATE);

}

and I am only receiving a syntax error in create update table here is the printed error:

11-30 01:59:20.841 24880-24880/com.example.hassanalmusajjen.tba E/SQLiteLog: (1) near "update": syntax error
11-30 01:59:20.845 24880-24880/com.example.hassanalmusajjen.tba W/System.err: android.database.sqlite.SQLiteException: near "update": syntax error (code 1): , while compiling: CREATE TABLE if not exists update(id INTEGER PRIMARY KEY,money INTEGER,location TEXT,image_path TEXT);
11-30 01:59:20.846 24880-24880/com.example.hassanalmusajjen.tba W/System.err:     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-30 01:59:20.846 24880-24880/com.example.hassanalmusajjen.tba W/System.err:     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
11-30 01:59:20.846 24880-24880/com.example.hassanalmusajjen.tba W/System.err:     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
11-30 01:59:20.846 24880-24880/com.example.hassanalmusajjen.tba W/System.err:     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588
11-30 01:59:20.846 24880-24880/com.example.hassanalmusajjen.tba W/System.err:     at com.example.hassanalmusajjen.tba.localDB.DatabaseHelper.onCreate(DatabaseHelper.java:77)

Aucun commentaire:

Enregistrer un commentaire