Android SQLite Update not working

前端 未结 4 695
野趣味
野趣味 2020-12-11 08:48

I am trying to update one column for any number of rows.

Here is the function:

public void setAwardsSyncComplete(String[] ids) {

    String inArray         


        
相关标签:
4条回答
  • 2020-12-11 09:14

    I think there is a problem on your update..

    You need to loop your array and update each one by one..

        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
    

    Regards

    0 讨论(0)
  • 2020-12-11 09:20

    As you're using transactions, you need to call db.setTransactionSuccessful(); at the end of the try clause. Without this, the update gets rolled back.

    See SQLiteDatabase.beginTransaction

    Hope this helps,

    Phil Lello

    0 讨论(0)
  • 2020-12-11 09:26

    there's no explicit boolean type in sqlite tables? what data type is the COL_SYNED column you are trying to update?

    and you will need to call db.setTransactionSuccussful()

    0 讨论(0)
  • 2020-12-11 09:30

    You need to call db.setTransactionSuccussful() after db.update otherwise any changes will be rolled back when you call endTransaction().

    0 讨论(0)
提交回复
热议问题