Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite database updating a row android

I am developing an android app, in which I need update a column in a table based on the a certain where clause.Here is the code below,

public void updatethekeyofweeklycolumn(String profilename, String keystemp) 
{
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();

    values.put(Profile_keysofweekly, keystemp);

    db.update(TABLE_PROFILE_SETTINGS_FOR_WEEKLY, values,Profile_Name_for_weekly +" = "+profilename, null);
}

The above code is working fine with where clause as null, but its throwing a force close with the whereclause is set. Is my Query wrong?

like image 225
Dave Avatar asked Dec 04 '22 09:12

Dave


1 Answers

You need to escape profilename. So you either add the single ' character:

db.update(TABLE_PROFILE_SETTINGS_FOR_WEEKLY, values,Profile_Name_for_weekly +" = '"+ profilename + "'", null);

Or, the option I would follow:

db.update(TABLE_PROFILE_SETTINGS_FOR_WEEKLY, values,Profile_Name_for_weekly +" = ?", new String[] {profilename});
like image 150
gunar Avatar answered Dec 25 '22 18:12

gunar