8

Possible Duplicate:
SQLite in Android How to update a specific row

Is it possible to update database for one column using where statment And this was my table structure and i need to update "messagestatus" column using "id".

db.execSQL("CREATE TABLE IF NOT EXISTS autosms(id INTEGER PRIMARY KEY AUTOINCREMENT ,phonenumber VARCHAR(15) ,message VARCHAR(5000) , year VARCHAR(10) , month VARCHAR(10) , date VARCHAR(10) , hour VARCHAR(10) , minute VARCHAR(10) , messagestatus VARCHAR(10))");

I tried with this, but with out Success theres an warning "No such column Send"

public void update(int id)
{
        String s = "Send";
        db= SQLiteDatabase.openDatabase("data/data/com.example.schduled_messages/SMS_Schdule_Sample.db", null, SQLiteDatabase.CREATE_IF_NECESSARY);
        db.execSQL("UPDATE autosms SET messagestatus="+s+" WHERE id="+id+""); 
    }

Thanks in Advance..

Community
  • 1
  • 1
Vishnu
  • 349
  • 3
  • 8
  • 16

2 Answers2

18

String values must be enclosed in quotes:

"UPDATE autosms SET messagestatus='"+s+"' WHERE id="+id+""

I've added a quote here '"+s+"'

Without it, here is how your string expands:

"UPDATE autosms SET messagestatus=Send WHERE id=1234

SQLite will try to find a column called Send and set messagestatus to its' value.

Simon
  • 14,407
  • 8
  • 46
  • 61
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

R World
  • 766
  • 9
  • 26