0

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

public void update(int mixId, long startPos, int count) {
    SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
    db.execSQL("update downloadedFragement set downloadedLength=downloadedLength+? where mixId=? and startPos=?", 
            new Object[]{count, mixId, startPos});
}
demongolem
  • 9,474
  • 36
  • 90
  • 105
David
  • 2,691
  • 7
  • 38
  • 50

2 Answers2

0

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

Community
  • 1
  • 1
parkerfath
  • 1,648
  • 1
  • 12
  • 18
0

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

Noel
  • 7,350
  • 1
  • 36
  • 26
  • Yes, it is right to use the update() method, but it seems not easy to add a value to the original value using update method. – David Jun 15 '11 at 01:58
  • I'm not sure but you can attempt to use the method rawQuery() with the sql statement from your question. See this link http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery(java.lang.String, java.lang.String[]). Otherwise you would need to do a query followed by an update. – Noel Jun 15 '11 at 02:20