"在地方"在Android的SQLite数据库更新不rawQuery工作 [英] "In place" update in Android SQLite database not working with rawQuery

查看:152
本文介绍了"在地方"在Android的SQLite数据库更新不rawQuery工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在我的Andr​​oid应用程序的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 usual SQLiteDatabase.update(...) it works fine, 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.

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 with execSQL(), not rawQuery().

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 a SELECT in one request, but it is still an UPDATE and a SELECT. Furthermore, SQLite does not support stored procedures, at least when I last looked.

这篇关于"在地方"在Android的SQLite数据库更新不rawQuery工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆