I would like to write with several processes in a SQLite database. Here is my c++ code:
stringstream sstream << "BEGIN;" << query << "COMMIT;";
sqlite3_busy_timeout(databasePtr, 60000); // set timeout if sql busy
if((result = sqlite3_exec(databasePtr, (sstream.str()).c_str(), NULL, NULL, NULL)) != SQLITE_OK){
/** ERROR or SQLITE_BUSY **/
}
sqlite3_busy_timeout(databasePtr, 0); // reset sql_busy handler
I thought that the sqlite3_busy_timeout leads to success. But I've checked the results and found that not all data is written to the database. Where is my mistake?
Does someone knows how often sqlite3_exec is called when the sqlite3_busy_timeout is set to 60000 (ms)? Or is there only one call after 60000 (ms) if the first try returns with SQLITE_BUSY?
I've tried to fix the problem with the following code. But it looks like there is only one active process all the time. The other processes will not finished...
do{
if((result = sqlite3_exec(databasePtr, (sstream.str()).c_str(), NULL, NULL, NULL)) != SQLITE_OK){
if(result == SQLITE_BUSY){
sleep(60000); // sleep 10 sec
}else{
/** ERROR **/
}
}
}while(result == SQLITE_BUSY);