我怎样才能使用SQLite中的更新
语句更新Android中的行数?
How can I get the number of rows updated using an update
statement in SQLite in Android?
请注意,我需要使用某种类型的原始SQL语句的执行,而不是做 ContentValues
任何东西,因为我需要一个动态查询。因此,我不能利用 SQLiteDatabase.update()
方法。例如,我在运行像
Note that I need to use some type of raw execute of a SQL statement, rather than do anything with ContentValues
because I need a dynamic query. Thus I can't make use of the SQLiteDatabase.update()
method. For example, I'm running something like
UPDATE my_table
SET field_name = field_name + 1
返回void,例如我知道的方法 SQLiteDatabase.execSQL()
。 SQLiteDatabase.rawQuery()
返回光标
,但光标具有零行,其计数始终为-1。
The methods I know of return void, e.g. SQLiteDatabase.execSQL()
. SQLiteDatabase.rawQuery()
returns a Cursor
, but the cursor has zero rows and its count is always -1.
您可以做任何你想要的方式你的插入,然后做一个选择和使用的 的变化()
函数返回受影响的行数。
You could do your insert whichever way you want, and then do a select and use the changes()
function to return the number of affected rows.