0

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)
2
  • 2
    problem is update which is a keyword in SQLITE but trying to use it as Table name Commented Nov 30, 2015 at 7:19
  • you are not use "update" key word for table name change table name and try to resolve your problem Commented Nov 30, 2015 at 7:25

1 Answer 1

3

UPDATE, or in your case update, is a reserved keyword in SQLite. Choose a different name for your table.

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

2 Comments

oh my god how could I forget this, yea you're right it's a keyword =_=,Thank you so much
@HassanAli No problem. If this solution fixed your problem, please use the checkmark underneath the downvote button to mark it as the accepted solution. If you'd like to read more about accepting an answer, read this

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.