获取更新的行从SQLite的在Android中使用计数的原始查询?原始、SQLite、Android

2023-09-05 01:46:16 作者:话不投机半句多

我怎样才能使用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.