oh, sorry, I make this mistake.

Another question is that if ?sqlite3_prepare? fail, do I need to 
?sqlite3_finalize? the stmt. Here is the sample code,


int ret = sqlite3_prepare(handle, ?some sql?, stmt, ?);
if (ret==SQLITE_OK) {
//step
sqlite3_finalize(stmt);
}else {
//log error
//should I finalize stmt here?
//sqlite3_finalize(stmt);
}




????
???:Hick Gunterhick at scigames.at
???:'SQLite mailing list'sqlite-users at mailinglists.sqlite.org
????:2015?12?15?(??)?17:42
??:Re: [sqlite] ??? Why SQLITE_BUSY?


It looks like you have unfinalized statements in your transaction. You are 
preparing statements inside the loop, but finalizing only 1 (the last) 
statement. And attempting to commit even before finalizing only the last 
statement. So sqlite3_close() is complaining about improper call sequence, not 
interference from any other process/thread. -----Urspr?ngliche Nachricht----- 
Von: sqlite-users-bounces at mailinglists.sqlite.org 
[mailto:sqlite-users-bounces at mailinglists.sqlite.org] Im Auftrag von 
sanhua.zh Gesendet: Dienstag, 15. Dezember 2015 10:27 An: SQLite mailing list 
Betreff: [sqlite] ??? Why SQLITE_BUSY? 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 
_______________________________________________ sqlite-users mailing list 
sqlite-users at mailinglists.sqlite.org 
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users 
___________________________________________ Gunter Hick Software Engineer 
Scientific Games International GmbH FN 157284 a, HG Wien Klitschgasse 2-4, 
A-1130 Vienna, Austria Tel: +43 1 80100 0 E-Mail: hick at scigames.at This 
communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your 
cooperation. _______________________________________________ sqlite-users 
mailing list sqlite-users at mailinglists.sqlite.org 
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to