[sqlite] shared cache and 'no such table' issue
Hi, I have a multi-threaded program. Each thread opens a connection to the same database file. It runs fine most of the time but sometime I get a 'no such table' error from a SQL select statement. It appears that if one thread close the database connection, it closes all the schema without checking nRef in BtShared. This make other threads receive a 'no such table' error. Do I get it right that schema is also shared together with Btree? When shared cache mode is enabled, does SQLite really share cache within one thread and not between other threads? I don't know much about internal of SQLite. But from looking at the source code, there is only one sqlite3SharedCacheList variable that is shared with every threads. Jay
Re: [sqlite] shared cache and 'no such table' issue
I think I found a bug in sqlite3_close but don't know how to fix it. There is a race condition between sqlite3SchemaFree and sqlite3Init. The problem is if there are two threads with its own connection to the same database file with shared-cache mode enabled. Db.pSchema of both connections point to the same schema. When the first thread is closing the connection and in the middle of sqlite3SchemaFree, where all the hash tables are freed but DB_SchemaLoaded in pSchema->flags is not cleared yet. If the other thread calls to sqlite3LocateTable at this time, it'll return no such table. Because sqlite3Init will see that DB_SchemaLoaded is still set and will not do anything. The only mutex I see involved is db->mutex which not help in this case. Should there be a pSchema->mutex? Does anyone have this same problem? Jay PS. Sorry for the bad English. It's not my native language. - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] shared cache and 'no such table' issue
On Dec 27, 2007 10:15 PM, Dan <[EMAIL PROTECTED]> wrote: > Should be fixed by: > >http://www.sqlite.org/cvstrac/chngview?cn=4643 > > Please post if you find this is not the case (or if you find it is). > It fixes the problem. Thanks a lot for your help. Jay - To unsubscribe, send email to [EMAIL PROTECTED] -