Unable to update multiple rows in Sqlite database update command in android

I ran into a problem here. I am trying to bulk update my table, trying to update multiple rows in a database. The update is simple. I just need to set the column value to 1, which is actually used as a flag in the application. Therefore, I want to set the value to 1 and in the where clause I give an array of strings of all identifiers where I want to set it. But the problem is that it gives me "android.database.sqlite.SQLiteException: binding index or column out of range:". However, when a single value is provided either as a string or a string array, the update works fine.

here is the request

db.update( tableName, cv, Z_ID + "=?", items ); 

where the elements are of type String []

kindly tell me what i'm missing?

considers

Fahad Ali Sheikh

+4
source share
1 answer

This will not work, I believe, based on one line that you gave.

If we look at the signature of the method call:

 update(String table, ContentValues values, String whereClause, String[] whereArgs) 

So:

 ContentValues cv=new ContentValues(); cv.put(colName, new Integer(1)); String[] items = new String []{String.valueOf(Z_ID)} db.update( tableName, cv, Z_ID + "=?", items ); 

You code looks something like this?

Your array of elements should match the where clause. Another example would look something like this:

 ContentValues cv=new ContentValues(); cv.put(salesColName, new Integer(4534)); String whereClause = "band=? and album=?"; String whereArgs = new String [] { "U2", "Joshua Tree" }; db.update( tableName, cv, whereClause , whereArgs); 
+4
source

Source: https://habr.com/ru/post/1333765/


All Articles