我想用以下查询更新我的表的一个列:
update TABLE set COLUMN_NAME= COLUMN_NAME+1;
如果可能的话使用
update(String table, ContentValues values, String whereClause, String[] whereArgs)
android中sqliteddatabase类中的方法这可能吗?
Thanks in advance
虽然这是有点迟了,我只是添加一个例子,工作…
SQLite version 3.7.9 2011-11-01 00:52:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table test1(a int primary key, b int);
sqlite> begin transaction;
sqlite> insert into test1(a,b) values (1,4);
sqlite> insert into test1(a,b) values (2,5);
sqlite> insert into test1(a,b) values (3,4);
sqlite> commit;
sqlite> select * from test1;
1|4
2|5
3|4
sqlite> update test1 set b=b+1;
sqlite> select * from test1;
1|5
2|6
3|5
sqlite> update test1 set b=b+10;
sqlite> select * from test1;
1|15
2|16
3|15
sqlite>
使用execSQL可能会有一些运气。下面是我解决类似问题的方法:
db.beginTransaction();
try {
//do update stuff, including execSQL()
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
参见https://stackoverflow.com/a/5575277/6027