I'd better do it this way:

       int rc = sqlite3_close(db);
       if ( rc == SQLITE_BUSY)
       {
           // shouldn't happen in a good written application but let's handle it
           sqlite3_stmt * stmt;
           while ((stmt = sqlite3_next_stmt(db, NULL)) != NULL) {
               sqlite3_finalize(stmt);
           }
           rc = sqlite3_close(db);
           if (rc != SQLITE_OK) {
               // throw this application away as it messes with CSQLiteDB object
               // in another thread while closing it here
               ... // Your choice of how to deal with fatal error
           }
       }


Pavel

On Tue, Jun 22, 2010 at 6:18 PM, Sam Carleton
<scarle...@miltonstreet.com> wrote:
> On Tue, Jun 22, 2010 at 10:13 AM, Pavel Ivanov <paiva...@gmail.com> wrote:
>
>> > No, I did not.  I am not storing any blobs right now, but...  Is the busy
>> > handler going to kick in?  I know the busy handler is not the sole answer
>> to
>> > the problem, but it does seem to catch most of my SQLITE_BUSY issues
>> since
>> > all data is pretty small.
>>
>> No, this SQLITE_BUSY result is not related to database locking and so
>> busy handler is not called. You can force connection closing in case
>> of SQLITE_BUSY result by forcible finalizing of all statements. Use
>> http://www.sqlite.org/c3ref/next_stmt.html for iterating all
>> statements and sqlite3_finalize on each of them. After that
>> sqlite3_close should complete successfully.
>>
>
> Pavel,
>
> So would you agree with this as a solution to deal with the close being
> busy:
>
> void CSQLiteDB::Close()
> {
>    if(m_db)
>    {
>        sqlite3 *db = m_db;
>        m_db = NULL;
>        int rc = sqlite3_close(db);
>
>        while( rc == SQLITE_BUSY)
>        {
>            // set rc to something that will exit the while loop
>            rc = SQLITE_OK;
>            sqlite3_stmt * stmt = sqlite3_next_stmt(db, NULL);
>
>            if(stmt != NULL)
>            {
>                rc = sqlite3_finalize(stmt);
>                if(rc == SQLITE_OK)
>                {
>                    rc = sqlite3_close(db);
>                }
>            }
>        }
>    }
> }
>
> Sam
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to