"在地方"在Android的SQLite数据库更新不rawQuery工作 [英] "In place" update in Android SQLite database not working with rawQuery
问题描述
我要在我的Android应用程序的SQLite数据库上执行的就地升级SQL查询。查询的格式为:
更新表T组列=列+ 1,其中someOtherColumn =安勤
块引用>我试图执行这个查询与
SQLiteDatabase.rawQuery(updateQuery,someOtherColumn =?,新的String {} [安勤])
,但我发现,列不递增。当我运行相同的查询通常的SQLiteDatabase.update(...)
它工作正常,但是这需要我去取旧列值,外面再更新执行更新()
这可能是低效率的,因为它需要一个选择,然后更新。有没有一些方法,我可以用第一个查询更新到位?
感谢。
解决方案
有没有一些方法,我可以用第一个查询更新到位?
块引用>这不是一个查询。这是一个
更新
语句。它不返回结果集。与execSQL使用()
,而不是rawQuery()
。
,但这需要我抓取旧列值,外面更新它,然后,因为它需要一个选择并执行更新()这可能是效率较低的再一个更新
块引用>这是所有SQL数据库的工作方式。现在,那些提供存储过程,也许能够让你做一个
更新
和SELECT
在一个请求,但它的还是的一个更新
和SELECT
。此外,SQLite不支持存储过程,至少在我上次看。I need to execute an "in place" update SQL Query on an SQLite database in my android application. The query is of the form:
update table T set column = column + 1 where someOtherColumn = aValue
I tried executing this query with
SQLiteDatabase.rawQuery(updateQuery, "someOtherColumn = ?", new String{}[aValue])
but I find that the column is not incremented. When I run the same query with the usualSQLiteDatabase.update(...)
it works fine, but this requires me to fetch the old column value, update it outside and then executeupdate()
which is probably less efficient since it requires a select and then an update.Is there some way I can update "in place" by using the first query?
Thanks.
解决方案Is there some way I can update "in place" by using the first query?
That's not a query. It's an
UPDATE
statement. It does not return a result set. Use it withexecSQL()
, notrawQuery()
.but this requires me to fetch the old column value, update it outside and then execute update() which is probably less efficient since it requires a select and then an update
This is the way all SQL databases work. Now, those that offer stored procedures may be able to let you do an
UPDATE
and aSELECT
in one request, but it is still anUPDATE
and aSELECT
. Furthermore, SQLite does not support stored procedures, at least when I last looked.这篇关于"在地方"在Android的SQLite数据库更新不rawQuery工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!