SQLite - 更新多个表
SQLite - Updating multiple tables
谁能帮我解决查询中的问题?
我正在尝试调用一个函数来更新多个表,这些表在 "col"
列中的值为 "1"
,但它不起作用,
my_function
public long updateNow() {
mDbHelper = new DatabaseHelper(mContext);
mDb = mDbHelper.getWritableDatabase();
int doneClear = 0;
String base_value = "1"; // update all column "col" where value of 1
ContentValues initialValues = new ContentValues();
initialValues.put("col", "0"); // Update all column "col" with 0
doneClear = mDb.update(SQLITE_TABLE_ONE, initialValues, "col=" + base_value, null);
doneClear = mDb.update(SQLITE_TABLE_TWO, initialValues, "col=" + base_value, null);
doneClear = mDb.update(SQLITE_TABLE_THREE, initialValues, "col=" + base_value, null);
doneClear = mDb.update(SQLITE_TABLE_FOUR, initialValues, "col=" + base_value, null);
doneClear = mDb.update(SQLITE_TABLE_FIVE, initialValues, "col=" + base_value, null);
doneClear = mDb.update(SQLITE_TABLE_SIX, initialValues, "col=" + base_value, null);
Log.w(TAG, Integer.toString(doneClear));
return doneClear;
}
此代码无效,我不明白为什么。
col
列中没有任何反应。
无论如何,该代码基于我之前的查询,它运行良好。
working_update_query
public long updates(String recent_value, String _id, String table_name) {
ContentValues initialValues = new ContentValues();
initialValues.put("recent_value", recent_value);
Log.w(TAG, String.valueOf(initialValues) + " WITH ID OF " + _id + " IN TABLE OF " + table_name);
return mDb.update(table_name, initialValues, "_id=" + _id, null);
}
我卡在这里快1个小时了,没弄清楚问题。
谁能帮帮我?
尝试使用通配符适当地注入更新参数,如下所示:
int updateCount = db.update(
TABLE_NAME,
newValues,
"col = ?",
new String[] {String.valueOf(colValue)}
);
如需快速示例,请查看 this tutorial。
谁能帮我解决查询中的问题?
我正在尝试调用一个函数来更新多个表,这些表在 "col"
列中的值为 "1"
,但它不起作用,
my_function
public long updateNow() {
mDbHelper = new DatabaseHelper(mContext);
mDb = mDbHelper.getWritableDatabase();
int doneClear = 0;
String base_value = "1"; // update all column "col" where value of 1
ContentValues initialValues = new ContentValues();
initialValues.put("col", "0"); // Update all column "col" with 0
doneClear = mDb.update(SQLITE_TABLE_ONE, initialValues, "col=" + base_value, null);
doneClear = mDb.update(SQLITE_TABLE_TWO, initialValues, "col=" + base_value, null);
doneClear = mDb.update(SQLITE_TABLE_THREE, initialValues, "col=" + base_value, null);
doneClear = mDb.update(SQLITE_TABLE_FOUR, initialValues, "col=" + base_value, null);
doneClear = mDb.update(SQLITE_TABLE_FIVE, initialValues, "col=" + base_value, null);
doneClear = mDb.update(SQLITE_TABLE_SIX, initialValues, "col=" + base_value, null);
Log.w(TAG, Integer.toString(doneClear));
return doneClear;
}
此代码无效,我不明白为什么。
col
列中没有任何反应。
无论如何,该代码基于我之前的查询,它运行良好。
working_update_query
public long updates(String recent_value, String _id, String table_name) {
ContentValues initialValues = new ContentValues();
initialValues.put("recent_value", recent_value);
Log.w(TAG, String.valueOf(initialValues) + " WITH ID OF " + _id + " IN TABLE OF " + table_name);
return mDb.update(table_name, initialValues, "_id=" + _id, null);
}
我卡在这里快1个小时了,没弄清楚问题。
谁能帮帮我?
尝试使用通配符适当地注入更新参数,如下所示:
int updateCount = db.update(
TABLE_NAME,
newValues,
"col = ?",
new String[] {String.valueOf(colValue)}
);
如需快速示例,请查看 this tutorial。