标签 SQLite 下的文章

在多线程中同时访问 SQLite 数据库,使用 sqlite3_stepsqlite3_prepare 和其他的函数可能引发 SQLITE_BUSYSQLITE_LOCKED 错误。SQLITE_BUSY 通常意味着 sqlite 需要一个锁,但是一定时间内无法获得。 SQLITE_BUSYSQLITE_LOCKED 最大的区别是:

  • SQLITE_LOCKED: if you get this from a sqlite3_step statement, you MUST call sqlite3_reset on the statement handle. You should only get this on the first call to sqlite3_step, so once reset is called you can actually "retry" your sqlite3_step call. On other operations, it's the same as SQLITE_BUSY
  • SQLITE_BUSY : There is no need to call sqlite3_reset, just retry your operation after waiting a bit for the lock to be released.

- 阅读剩余部分 -