컴파일 할 업데이트 쿼리를 실행하고 있습니다. 그러나 결과를 테스트 할 때 아무런 변화가없는 것 같습니다. 모든 것이 나에게 잘 보이지만 분명히 잘못된 것이 있습니다. 아무도 내가 누락 된 것을 볼 수 있습니까? SQLite를 처음 접했을 때 간단합니다. 감사!SQLite 업데이트 쿼리가 작동하지 않습니다.
public static Boolean updateHealth (int unitVal, int oldValue, int newValue) {
String unit = Integer.toString(unitVal);
String oldVal = Integer.toString(oldValue);
String newVal = Integer.toString(newValue);
System.err.printf("old val: %s, new val: %s\n", oldVal, newVal);
SQLiteDatabase db = myDBOpenHelper.getWritableDatabase();
String where = UNIT_COLUMN + " = " + unit + " AND " + HEALTH_COLUMN + " = " + oldVal;
Cursor cursor = db.query(UNITS_TABLE, new String[] {UNIT_COLUMN}, where, null, null, null, null);
if (cursor != null) {
/* the record doesn't exist, cancel the operation */
return false;
}
ContentValues updatedValues = new ContentValues();
updatedValues.put(HEALTH_COLUMN, newVal);
/* SQL query clauses */
String whereArgs[] = null;
db.update(UNITS_TABLE, updatedValues, where, whereArgs);
return true;
}
이 코드를 실행하면 어떻게됩니까? 무슨 일이 일어날 것으로 예상됩니까? 구체적인 예를 들려 줄 수 있습니까? –
'if (cursor! = null)'이 항상 적용되어야합니다. 'Cursor'는 어떤 경우에는 비어있을 수 있습니다.'cursor.getCount() == 0' – zapl