PDA

View Full Version : sqlite doesn't support concurrent insertion to difff. tables ?




david.david
Nov 12, 2008, 07:44 AM
hi,

I am inserting data in to two tables table1 and table2.

for that created two methods one for insert data into table1 and the other is used to insert data into table2
If I call these two methods one by one then it is successfully inserting..

If I call the first method using thread (NSThread detachNewThreadSelector...) and the other calling by next instruction , then error occured

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error: failed to prepare statement with message 'library routine called out of sequence'.'

I am using same sqlite3 instance for both method..

let me know whats the issue ?

or doesn't sqlite support simultaneous insertion (inserting diff. tables) ?



beachdog
Nov 12, 2008, 06:13 PM
yes, I found the same thing. I had to do all of my updates
From within one thread

david.david
Nov 13, 2008, 01:28 AM
I am using same sqlite3 instance for both method..

the problem fixed when I use seperate sqlite3 instance ..

thanks for the response..
david.

david.david
Nov 13, 2008, 04:07 AM
ooops !!!

its my mistake I check w/o using thread..

Still I am getting error even I am using separate sqlite3 instance.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error: failed to dehydrate with message 'database is locked'.'

hope that anyone can help me this...

jnic
Nov 13, 2008, 04:21 AM
Presumably one thread is locking the DB, preventing the other from accessing it.

david.david
Nov 13, 2008, 04:29 AM
simultaneously inserting to different table not to the same table..Then why the db needs a lock ?

Presumably one thread is locking the DB, preventing the other from accessing it.

in what way I can resolve this..


//I think it is not a good idea if we synchronize all my insert statements. isnt it ?.. I am looking for another good solution..

jnic
Nov 13, 2008, 04:41 AM
Different table, presumably same DB. SQLite locks the whole DB for any writes, see http://www.sqlite.org/faq.html#q5 for more info.

I think it is not a good idea if we synchronize all my insert statements. isnt it ?.. I am looking for another good solution..

Seems like the best solution, unless someone can suggest something better? SQLite is fast enough that making writes synchronous shouldn't affect the speed of your app greatly.

Maybe you could describe what you're trying to achieve to see if there's a different way of going about it?

david.david
Nov 13, 2008, 05:32 AM
hi,
thanks for the link..and the information.

@synchronised :)
I decided to use a same lock for all create, insert, update and delete statements.

Please let me know if any other solution..

another question .
First I was using same sqlite3 instance across all files and close it when application quits. Now I declared separate instance in each file then only I can close immediatly just before release the object
Is there any problem if I use multiple connection for same db at same time.(because I am using threads) ?