I try to increase the开发者_如何学Go value of an integer key in a row in my table. However, nothing really seems to happen.
db.rawQuery("UPDATE table SET key = key + 1 WHERE name=?", new String[] {name});
However, this code works fine (just sets the key to a hard-coded value):
ContentValues values = new ContentValues();
values.put("key", 2);
db.update("table", values, "name=?", new String[] {name});
Also tried '?' instead of just ?, but it resulted just in a run-time error.
From http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html:
public Cursor rawQuery (String sql, String[] selectionArgs)
Runs the provided SQL and returns a Cursor over the result set. Returns a Cursor object, which is positioned before the first entry
compared to:
public void execSQL (String sql, Object[] bindArgs)
Execute a single SQL statement that is not a query. For example, CREATE TABLE
, DELETE
, INSERT
, etc.
In other words, SQL queries which return a table are to be run with rawQuery
, and those that do not return tables are to be run with execSQL
.
精彩评论