Android: how to cancel / abort / abort SQLite query?

In my Android application, the user can populate the database with imported data, and then execute a predefined complex SQL query. With some data template, the request will take a very long time (minutes or more on HTC Hero), while normal use will not exceed 10-15 seconds.

Is there a way to cancel a pending SQLite query on Android? A timeout will also be good, partial results are not required. I execute the request inAsyncTask.doInBackground()

I know that the best way is to optimize the query or change the application logic, but in this case, the results still depend on user knowledge, so I would like to help those who introduce an unpleasant template.

+3
source share
4 answers

You cannot cancel a pending sql query. This is done in the SQLite engine. SQLite has its own methods for interrupting a query, but it is not available in the java interface.

Best would be to improve query performance.
Read this: http://www.sqlite.org/cvstrac/wiki?p=PerformanceTuning

You can split long queries into smaller ones by limiting the line number. Then it would be easier to cancel the request, which is executed in pieces.

+2
source

ASyncTask supports cancellation, and the flag should cancel everything, including your SQL query.

ASyncTask.cancel(boolean mayInterruptIfRunning)
0
source

SQLite intrerupt: http://www.sqlite.org/c3ref/interrupt.html

, Android.

0
source

You can cancel the sqlite query using a android.os.CancellationSignalmethod that can be passed to some of the methodsandroid.database.sqlite.SQLiteDatabase

0
source

Source: https://habr.com/ru/post/1759154/


All Articles