Hi, > > > > Maybe many others have asked this question, so I will say sorry if > > that's true. > > I have a program which uses threads, when writing to (sometime even > > reading > > from) SQLite, I always got the error of database is locked. > > I think since SQLite is a file db, so it get locked easily by multi- > > threads or multi-processes. > > But is there a way to resolve this problem instead of switching > > database to another one? > > > > Thanks. > >I used to have similar problems and solved it by following advice >I got on this list, which is to start the transaction with: >BEGIN IMMEDIATE; >any time the database will be written to (ie an insert, update, >delete, etc). > >That, along with looping on sqlite3_prepare_v2 and sqlite3_step any >time you get SQLITE_BUSY, virtually solved the issue for me.
Don't forget to wrap _whole_ read-modify-write transactions inside the BEGIN IMMEDIATE; .. COMMIT; block, not only the write parts. You may also want to set sqlite3_busy_timeout to a reasonable value avoiding most if not all SQLITE_BUSY conditions. What is "reasonable" all depends on how long the slowest system-wide transaction is likely to take. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users