SQLite update statement. Not updating all the time
This is for use in an android app. The first call works, not the second, and they are called in sequence. No errors. All strings are as should be. The first updates properly, but the second does not update either value.
///DOESN'T WORK
mDbHelper.updateValue(SaveSlot, item, value1,value2,"S");
public void updateValue(String saveslot, String item, String value1, String value2,String cat) {
ContentValues args = new ContentValues();
if (value1 !=null){
args.put(VALUE1, value1);
if (value2 !=null){
args.put(VALUE2, value2);
}}
else if (value2 !=null){
args.put(VALUE2, value2);
}
mDb.update(DATABASE_PUSHERS_TABLE, args, SAVE_SLOT + "=" + saveslot +" AND " + ITEM +" = "+item+" AND category = "+cat, null);
return ;
}
found some error messag开发者_Go百科es...
INFO/dalvikvm(23920): Uncaught exception thrown by finalizer (will be discarded):
INFO/dalvikvm(23920): Ljava/lang/IllegalStateException;: Finalizing cursor android.database.sqlite.SQLiteCursor@43dc3e90 on pushers that has not been deactivated or closed
INFO/dalvikvm(23920): at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596)
INFO/dalvikvm(23920): at dalvik.system.NativeStart.run(Native Method)
INFO/dalvikvm(23920): Uncaught exception thrown by finalizer (will be discarded):
INFO/dalvikvm(23920): Ljava/lang/IllegalStateException;: Finalizing cursor android.database.sqlite.SQLiteCursor@43da38c0 on pushers that has not been deactivated or closed
04-10 01:56:24.091: ERROR/Database(2983): Error updating value1=82 using UPDATE database SET value1=? WHERE save_slot=1 AND item = 98 AND category = S
Putting a single quote around the variables fixed it..
mDb.update(DATABASE_PUSHERS_TABLE, args, SAVE_SLOT + " = '" + saveslot +"' AND " + ITEM +" = '"+item+"' AND category = '"+cat+"'", null);
精彩评论