I?m very excited that I re-produce the SQLITE_BUSY code in a simple demo. Here is my test code,
void showResultCode(int resultCode) { if (resultCode!=SQLITE_DONEresultCode!=SQLITE_OKresultCode!=SQLITE_ROW) { NSLog(@"unexperted result %d", resultCode); } } void SQLiteLog(void* userInfo, int ret, const char* msg) { NSLog(@"ret=%d, msg=%s", ret, msg); } void write(const char* path) { int code = SQLITE_OK; sqlite3* handle; showResultCode(sqlite3_open(path, handle)); sqlite3_exec(handle, "PRAGMA journal_mode=WAL", nullptr, nullptr, nullptr); sqlite3_exec(handle, "create table test(id integer);", nullptr, nullptr, nullptr); sqlite3_stmt* stmt = nullptr; showResultCode(sqlite3_exec(handle, "BEGIN IMMEDIATE", nullptr, nullptr, nullptr)); for (int i = 0; i 2; i++) { showResultCode(sqlite3_prepare(handle, [NSString stringWithFormat:@"insert into test values(%d);", i].UTF8String, -1, stmt, nullptr)); showResultCode(sqlite3_step(stmt)); } showResultCode(sqlite3_exec(handle, "COMMIT", nullptr, nullptr, nullptr)); showResultCode(sqlite3_finalize(stmt)); showResultCode(sqlite3_close(handle)); } int main(int argc, char * argv[]) { sqlite3_config(SQLITE_CONFIG_LOG, SQLiteLog, NULL); const char* path = "/Users/sanhuazhang/Desktop/test.db"; write(path); return 1; } The console result is ?unexperted result 5?, which indicates SQLITE_BUSY. It happens at code?sqlite3_close?.one of the strange things is that?SQLiteLog? print nothing. AndYou can see that I only write some data using transaction. How could SQLITE_BUSY happened while sqlite.org said that?The SQLITE_BUSY result code indicates that the database file could not be written (or in some cases read) because of concurrent activity by some other database connection.?. So, as a conclusion, I confuse that why the result code of?sqlite3_close" is SQLITE_BUSY and is it possible that SQLITE_BUSY returned by other function in this situation(single process,single thread,single connection). ???? ???:sanhua.zhsanhua.zh at foxmail.com ???:sqlite-userssqlite-users at mailinglists.sqlite.org ????:2015?12?14?(??)?17:21 ??:[sqlite] Why SQLITE_BUSY? I queue all my db operation into one thread with single sqlite conn. neither multi-thread nor multi-process operation happened.But some SQLITE_BUSY error code still be catched. I can not re-produce this error code indeveloping environment,because it happen in alow probability. I only catch this error report online. So how did it happen? I guess that, when WAL reach the checkpoint, sqlite will write the data back to original db file in background thread. So writing will be busy at this time. But I?m not sure. I hope that you will not stint your criticism _______________________________________________ sqlite-users mailing list sqlite-users at mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users