Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

david.david

macrumors newbie
Original poster
Nov 12, 2008
9
0
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) ?
 

david.david

macrumors newbie
Original poster
Nov 12, 2008
9
0
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...
 

david.david

macrumors newbie
Original poster
Nov 12, 2008
9
0
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

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
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

macrumors newbie
Original poster
Nov 12, 2008
9
0
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) ?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.