这是我通过android检索并同时更新我的数据库的代码:
public String returnQuestion(SQLiteDatabase db, int difficultyLevel) {
ContentValues contentValues = new ContentValues();
contentValues.put("repeat", "1");
String whereArgs[] = new String[1];
String[] selectionArgs = new String[1];
selectionArgs[0] = Integer.toString(difficultyLevel);
Cursor cursor = db.rawQuery("SELECT _id, question FROM table1 WHERE difficulty_level LIKE ? ", selectionArgs);
cursor.moveToFirst();
if(cursor.getCount() !=0)
{
int i = cursor.getColumnIndex("question");
String result = cursor.getString(i);
int j = cursor.getColumnIndex("_id");
String id = cursor.getString(j);
whereArgs[0] = id;
if( db.update("table1", contentValues, "_id = ?", whereArgs) == 1)
return result;
else
return id;
}
else return "Not found !";
}
代码工作正常,我得到字符串结果我调用函数。但是,当我在运行我的应用程序后打开数据库时,重复字段为空。 (早些时候它是空的。)关于这个的任何线索?我正在使用reigndesign.com
中的数据库代码