views:

84

answers:

2

Hey, I want to increment a column in a sqlite android database. Im doing like this:

public void atualiza(String word){
   this.db.rawQuery("UPDATE words SET count = count + 1 WHERE word= ? ", new String[] {word});     

}

And I call this method on another class like this:

this.dh.atualiza(word); 

But when i pull the database from the emulator and check with the SQLite Database Browser, the field is not incremented. Why?

A: 

You need to start a transaction on the database http://stackoverflow.com/questions/3483123/data-not-inserting-in-sqlite-database-in-android/3486373#3486373

Konstantin Burov
I should point out that when transactions are not specified, SQLite makes its own.
MPelletier
Hmm.. do you know good android docs about that feature? I'd highly appreciate a link.
Konstantin Burov
It's a feature of SQLite, not so much as Android, but here is the official doc: http://sqlite.org/lang_transaction.html : "No changes can be made to the database except within a transaction. Any command that changes the database (basically, any SQL command other than SELECT) will automatically start a transaction if one is not already in effect. Automatically started transactions are committed when the last query finishes."
MPelletier
Its ok. The problem was change from rawQuery to execSQL.Thanks a lot!
psyhclo
+2  A: 

You should really use execSQL for a query that does not return a table: http://stackoverflow.com/questions/3427516/increase-the-value-of-a-record-in-android-sqlite-database/3432777#3432777

MPelletier