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});
}

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
I'm not sure but you can attempt to use the method rawQuery() with the sql statement from your question. See this link developer.android.com/reference/android/database/sqlite/…, java.lang.String[]). Otherwise you would need to do a query followed by an update.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.