I'm getting information about items from the web and I want my app to check if certain rows exist. If they do exist then the app should update those rows, otherwise it should create new rows:
try {
mDb.execSQL("UPDATE ["
+ ParseReciverAddList.tableName
+ "] SET purchased = " + pCheck
+ " WHERE id =" + (thisId));
mDb.execSQL("UPDATE ["
+ ParseReciverAddList.tableName
+ "] SET name = '" + (PName)
+ "' WHERE id =" + (thisId));
mDb.execSQL("UPDATE ["
+ ParseReciverAddList.tableName
+ "] SET quantity = '" + (pQuantity)
+ "' WHERE id =" + (thisId));
Log.d("p", "e");
} catch (Exception e) {
Log.d("p", "ne");
mDb.execSQL("INSERT INTO ["+ParseReciverAddList.tableName+"] VALUES ("+thisId+","+pCheck+", '"+PName+"','"+pQuantity+"');");
}
I figure I'll try to update it and if it throws Exception
then it means the rows don't exist and it will create it.
However, I'm running into a problem: even if the row doesn't exist it doesn't throw Exception
. Any ideas as to why it's not triggering the catch
clause when the rows already exist?