1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

sqlite doesn't support concurrent insertion to difff. tables ?

Discussion in 'iPhone/iPad Programming' started by david.david, Nov 12, 2008.

  1. macrumors newbie

    #1
    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) ?
     
  2. macrumors member

    #2
    yes, I found the same thing. I had to do all of my updates
    From within one thread
     
  3. macrumors newbie

    #3
    the problem fixed when I use seperate sqlite3 instance ..

    thanks for the response..
    david.
     
  4. macrumors newbie

    #4
    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...
     
  5. macrumors 6502a

    #5
    Presumably one thread is locking the DB, preventing the other from accessing it.
     
  6. macrumors newbie

    #6
    simultaneously inserting to different table not to the same table..Then why the db needs a lock ?

    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..
     
  7. macrumors 6502a

    #7
    Different table, presumably same DB. SQLite locks the whole DB for any writes, see http://www.sqlite.org/faq.html#q5 for more info.

    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?
     
  8. macrumors newbie

    #8
    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) ?
     

Share This Page