开发者

what is the update statement pattern in android SQLite to add a value the field?

my code is as follows, but it seems not working.

public void update(int mixId, long startPos, int count) {
    SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
 开发者_JAVA技巧   db.execSQL("update downloadedFragement set downloadedLength=downloadedLength+? where mixId=? and startPos=?", 
            new Object[]{count, mixId, startPos});
}


From the doc on the execSQL() method:

Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.

You should use the update() method instead


I had a similar problem and solved it by surrounding it with:

db.beginTransaction();
try {
    //do stuff, including execSQL()
    db.setTransactionSuccessful();
} finally {
    db.endTransaction();
}

See also https://stackoverflow.com/a/5575277/6027

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜