Re: [sqlite] shared cache and 'no such table' issue

2007-12-27 Thread Pathompong Puengrostham
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]
-



Re: [sqlite] shared cache and 'no such table' issue

2007-12-27 Thread Dan


On Dec 27, 2007, at 5:51 PM, Pathompong Puengrostham wrote:


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?


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).

Dan.


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] shared cache and 'no such table' issue

2007-12-27 Thread Pathompong Puengrostham
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

2007-12-26 Thread Darío Mariani
I found that the sqlite3_open call is not thread safe even if you open
different files in separate connections. Cannot tell you about
sqlite3_close but may be the same problem.
Darío

On Dec 26, 2007 6:40 AM, Pathompong Puengrostham <[EMAIL PROTECTED]> wrote:
> 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
>

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] shared cache and 'no such table' issue

2007-12-26 Thread Pathompong Puengrostham
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