Hi,

Newbie to SQLite, so maybe my question will seems trivial.

I want to manage the SQLITE_BUSY error like this: If it fails, sleep X
ms then try the command Y times. I found 2 ways to do it:

----- First is to manage a loop like:

tryIt = X;

do
{
        err = sqlite3_exec(...)
} while (err == SQLITE_BUSY && tryIt-- && sleep(Y))

-- Alternative (??)

sqlite3_busy_timeout(sqlite3*, Y);
tryIt = X;

do
{
        err = sqlite3_exec(...)
} while (err == SQLITE_BUSY && tryIt--)


----- The second is to set a busy callback

sqlite3_busy_handler(sqlite3*, foo, void*)

And in 
int foo(void*,int count)
{
        if (count > X)
                return 0;

        sleep(Y);
        return 1;
}

-----

The second solution seems better to me, because we don't have to manage
a loop for each function that can return SQLITE_BUSY (like exec, step or
even close).

In a lot of example, the first solution is often use. Is there any
issues with the second one?

Any advise ?

Thanks.


Reply via email to