[英]Android SQLite Update not working
我正在嘗試為任意數量的行更新一列。
這是功能:
public void setAwardsSyncComplete(String[] ids) {
String inArray = StringUtils.separateCommas(ids);
db.beginTransaction();
try {
ContentValues contentValues = new ContentValues();
contentValues.put(COL_SYNCED, true);
int rowsAffected = db.update(TABLE, contentValues, COL_ID + " IN (" + inArray + ")", null);
} catch (Exception e) {
DebugLog.e("Error in transaction", e.toString());
} finally {
db.endTransaction();
}
}
奇怪的是rowsAffected正確返回(即rowsAffected> 0),但列值保持為null 。
我在這里忽略了一些非常簡單的事情
謝謝。
在使用事務時,需要調用db.setTransactionSuccessful(); 在try子句的末尾。 如果沒有這個,更新將回滾。
請參見SQLiteDatabase.beginTransaction
希望這可以幫助,
Phil Lello
你需要調用db.setTransactionSuccussful()
后db.update
否則任何更改都將回滾,當你調用endTransaction()
。
在sqlite表中沒有明確的布爾類型? 您要更新的COL_SYNED列是什么數據類型?
你需要調用db.setTransactionSuccussful()
我認為您的更新存在問題..
你需要循環你的數組並逐個更新每個數組..
private int _rowsAffected;
foreach (var a in inArray)
{
_rowsAffected= db.update(TABLE, contentValues, COL_ID + " = (" + a +")", null);
}
db.Commit();
db.setTransactionSuccussful();
if(_rowsAffected > 0)
//Success
問候
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.