Response time limit in SQLite

Is there way to limit response time on SQLite?

I have SQL request, which executes from 0 to 10 seconds depends on device performance. This SQL is OPTIONAL. If request takes more than 3 sec, it should be terminated. I would prefer do not run this SQL if I could know apriori that it takes more than 3 sec.


Use the sqlite3_progress_handler interface to register a callback function.

As @JeremyP suggested, you can pass in a a pointer to NSDate, or something else storing time as context to compare against. If it reaches above a certain threshold then return a non-zero value from the callback registered with this function to terminate the operation.

int progressHandler(void *context) {
    NSDate *start = (NSDate *)context;
    NSTimeInterval wait = -[start timeIntervalSinceNow];

    if (wait > 3.0) {
        return 1;
    } else {
        return 0;

The second argument to this function is how often your callback should be invoked. This value is in # of jump opcodes executed and will vary by machine. For context, on my Macbook, it processes around 20 million opcodes every second. A decent number for your use-case might be 10K-100K.

sqlite3_progress_handler(db, 100000, &progressHandler, (void *)someDate);

Need Your Help

Is there a common way for C# and unmanaged native C++ to determine installed CLR versions?

c# c++ .net clr clr-hosting

As the title says: Is there a common way in C# and especially unmanaged native C++ to determine installed CLR versions? This means not just checking whether the Framework is installed according thi...

How to avoid argument name collision in R snow/ snowfall package, sfSapply?

r parallel-processing raster r-raster

I'm trying to use the snow and snowfall packages, specifically the sfSapply() function to extract data from multiple raster files. It looks something like this: