我想使用以下查询更新我的表格列之一:
update TABLE set COLUMN_NAME= COLUMN_NAME+1;
使用if posible
update(String table, ContentValues values, String whereClause, String[] whereArgs)
android中SQLiteDatabase类中的方法 那可能吗?
提前致谢
答案 0 :(得分:0)
虽然这有点过期,但我只是添加一个有效的例子......
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>
答案 1 :(得分:0)
你可能对execSQL有好运。以下是我为解决类似问题所做的工作:
db.beginTransaction();
try {
//do update stuff, including execSQL()
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}