Re: [sqlite] Multiple threads sharing one DB

2011-01-27 Thread Richard Hipp
On Wed, Jan 26, 2011 at 10:56 AM, Ian Hardingham  wrote:

> Hey guys.
>
> I am under the impression that there is no concurrent access to a single
> SQLite DB.  Ie if thread A is performing a query, and thread B trys to
> query, it will block until thread A is finished, no matter the query.
>
> 1.  Is this correct?
>

It is true if A and B are attempting to share the same database connection.
 Access to the database connection is protected by a mutex.


>
> 2.  Are there any fairly general workarounds of any kind?
>

Use a separate database connection for each thread.  Or better:  Use
processes instead of threads, as threads are evil.


>
> Thanks,
> Ian
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



-- 
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Multiple threads sharing one DB

2011-01-27 Thread Ian Hardingham
Hey guys.

I am under the impression that there is no concurrent access to a single 
SQLite DB.  Ie if thread A is performing a query, and thread B trys to 
query, it will block until thread A is finished, no matter the query.

1.  Is this correct?

2.  Are there any fairly general workarounds of any kind?

Thanks,
Ian
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Multiple threads sharing one DB

2011-01-26 Thread Navaneeth.K.N
On Wed, Jan 26, 2011 at 10:24 PM, Ian Hardingham  wrote:
> Many thanks Eric.
>
> Does a write on Table A block a read/write on Table B?

AFAIK, it does. The lock is acquired on the whole file and not on tables.

-- 
-n
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Multiple threads sharing one DB

2011-01-26 Thread Simon Slavin

On 26 Jan 2011, at 4:54pm, Ian Hardingham wrote:

> Does a write on Table A block a read/write on Table B?

SQLite only has one locking thing: it locks the entire database.  So under 
conditions where table A would be locked, all tables would be locked in the 
same way.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Multiple threads sharing one DB

2011-01-26 Thread Ian Hardingham
Many thanks Eric.
  
Does a write on Table A block a read/write on Table B?


On 26/01/2011 16:18, Eric Smith wrote:
>
>
> On Wed, Jan 26, 2011 at 11:02 AM, Ian Hardingham  > wrote:
>
> Hey guys.
>
> I am under the impression that there is no concurrent access to a
> single
> SQLite DB.  Ie if thread A is performing a query, and thread B trys to
> query, it will block until thread A is finished, no matter the query.
>
> 1.  Is this correct?
>
>
> Certainly not!  By default, an arbitrary number of readers can execute 
> queries concurrently.  But writers block readers and other writers.
>
> Under the "WAL" journaling mode you can have readers executing 
> concurrently with a writer.  See 
> http://www.sqlite.org/wal.html#concurrency for details on that.
>
> SQLite isn't the king of concurrency by any stretch, but it does much 
> better than at-most-one-querier-at-a-time.
>
> Eric
>
> --
> Eric A. Smith
>
> Dad said, "To fish you must be patient."  Since Dad is not patient,
> and since he was catching no fish, I figured he must be right.
> -- Paige Smith, age 14
>

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Multiple threads sharing one DB

2011-01-26 Thread Eric Smith
On Wed, Jan 26, 2011 at 11:02 AM, Ian Hardingham  wrote:

> Hey guys.
>
> I am under the impression that there is no concurrent access to a single
> SQLite DB.  Ie if thread A is performing a query, and thread B trys to
> query, it will block until thread A is finished, no matter the query.
>
> 1.  Is this correct?
>

Certainly not!  By default, an arbitrary number of readers can execute
queries concurrently.  But writers block readers and other writers.

Under the "WAL" journaling mode you can have readers executing concurrently
with a writer.  See http://www.sqlite.org/wal.html#concurrency for details
on that.

SQLite isn't the king of concurrency by any stretch, but it does much better
than at-most-one-querier-at-a-time.

Eric

--
Eric A. Smith

Dad said, "To fish you must be patient."  Since Dad is not patient,
and since he was catching no fish, I figured he must be right.
-- Paige Smith, age 14
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Multiple threads sharing one DB

2011-01-26 Thread Ian Hardingham
Hey guys.

I am under the impression that there is no concurrent access to a single 
SQLite DB.  Ie if thread A is performing a query, and thread B trys to 
query, it will block until thread A is finished, no matter the query.

1.  Is this correct?

2.  Are there any fairly general workarounds of any kind?

Thanks,
Ian
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users