Android:如何取消/中断/中断挂起的 SQLite 查询?
在我的 Android 应用程序中,用户可以使用导入的数据填充数据库,然后执行预定义的复杂 SQL 查询。对于某些数据模式,查询会花费很长时间(HTC Hero 上需要几分钟甚至更长),而一般使用不会超过 10-15 秒。
有什么方法可以取消 Android 上待处理的 SQLite 查询吗?超时也很好,不需要部分结果。我正在 AsyncTask.doInBackground()
中执行查询,
我知道最好的方法是优化查询或更改应用程序逻辑,但在这种情况下,结果无论如何都取决于用户知识,所以我想帮助那些输入麻烦的模式。
In my Android application user can fill database with imported data, then perform predefined, complex SQL query. With some data pattern, query will take very long (minutes and more on HTC Hero), while common usage will not exceed 10-15 seconds.
Is there any way to cancel pending SQLite query on Android? Timeout would be as good as well, partial results are not required. I'm performing query within AsyncTask.doInBackground()
I know best way is optimize query or change app logic, but in this case results depends on user knowledge anyway, so I'd like to help those who enter troublesome pattern.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您无法取消挂起的 SQL 查询。它是在 SQLite 引擎中完成的。 SQLite 有本地方法来中断查询,但在 java 接口中无法访问。
最好的办法是提高查询性能。
阅读此内容:http://www.sqlite.org/cvstrac/wiki?p=PerformanceTuning< /a>
您可以通过限制行数将长时间运行的查询划分为更小的查询。那么取消以块的形式执行的查询会更容易。
You can't cancel pending sql query. It's done in SQLite engine. SQLite has native methods to interrupt query, but it's not accessible in java interface.
The best would be to improve query performance.
Read this: http://www.sqlite.org/cvstrac/wiki?p=PerformanceTuning
You can divide long running queries to smaller by limiting row number. Then it would be easier to cancel query that is performed in chunks.
ASyncTask 支持取消,并且该标志应取消所有操作,包括您的 SQL 查询。
ASyncTask supports cancellation and the flag should cancel all, including your SQL Query.
SQLite提供了中断方法:
http://www.sqlite.org/c3ref/interrupt.html
我不是当然,你知道在 Android 中如何称呼它。
SQLite provides a intrerupt method:
http://www.sqlite.org/c3ref/interrupt.html
I'm not sure how you would call that in Android though.
您可以使用
android.os.CancellationSignal
取消在 sqlite 上运行的查询,该信号可以传递给android.database.sqlite.SQLiteDatabase
的某些方法代码>You can cancel running queries on sqlite by using
android.os.CancellationSignal
which can be passed to some of the methods ofandroid.database.sqlite.SQLiteDatabase