Inside an onClick()
event, I am trying to increment a counter value by 1 in my CARDNUM column within a SQLite database table (TOTALCOUNT) using the INSERT INTO command.
The error occurs when trying to run:
db.execSQL(INCREMENT_COUNT2);
Android Studio gives the following error message
"SQLiteException: near "cardnum": syntax error (code 1): , while compiling: INSERT INTO totalcount(cardnum) VALUES cardnum+1"
What am I missing here?
Is there a better way to achieve the increment upon INSERTion?
DatabaseHelper.java file:
// Increment the counter in the TOTALCOUNT Table in the database.
public void insertIntoTableTOTALCOUNT() {
// Get a reference to a writable DB
SQLiteDatabase db = this.getWritableDatabase();
db.beginTransaction();
db.execSQL(INCREMENT_COUNT1);
db.execSQL(INCREMENT_COUNT2);
db.setTransactionSuccessful();
db.endTransaction();
if(db.isOpen())
db.close();
}
// Set the counter to a default value of zero.
public static final String INCREMENT_COUNT1 = " INSERT OR IGNORE INTO " + TABLE_NAME_TOTALCOUNT +
"(" + COLUMN_NAME_CARDNUM+")" + " VALUES (0)";
// Increment the Cardnum count by +1 for each onClick.
public static final String INCREMENT_COUNT2 = "INSERT INTO " + TABLE_NAME_TOTALCOUNT + "(" + COLUMN_NAME_CARDNUM+") VALUES " + COLUMN_NAME_CARDNUM +"+1";