Today i have assigned to a requirement, in which a file should be continuously monitored by a process, if suppose that file is being modified i have to store the current line NO of the file in one table and a new texts that added to that file into an another table that's it. so i write a file watcher class which does what was told as a requirement it could monitor and update the two tables with the line number and the newly added text respectively,later during testing my app i have just closed the file watcher process and added some new text to the file then start the file watcher again there comes the creepy problem, during updating the new line number my update statement gives result code=5 that said it means SQLITE_BUSY how come it is possible i just have a single update statement.There is no race condition or whatever that bother concurrency is not present in my code. it especially happens when i ran my app second time at the first time the update statements works smoothly whenever the file get modified, can anyone help me get rid of this freaking behaviour
please see my below code the update stmnt is to update line NO and the insert stmnt is for inserting newly added text
rc = sqlite3_open("test.db", &db);
cout<<"rc"<<rc;--------------------------0
if(rc>0){
onej.EJ_Log("ERROR OPRNNING DB");
}else{
-
sql= "UPDATE LAST_UPDATE_LINE SET Line_Number="
+quotesql(ss.str())+" where ID=1;";--5 after restarting the app
rc=sqlite3_exec(db, sql.c_str(), callback, 0, &zErrMsg);
if(rc>0)
{
cout<<"iam in ";
onej.EJ_Log("ERROR INSERTING LINE");
}
else{
sql="INSERT INTO EJ (EJ,UPDATE_TIME) VALUES (?,?);";
rc = sqlite3_prepare(db,sql.c_str(), sql.size(), &stmt, &pzTest);
if(rc==SQLITE_OK)
{
sqlite3_bind_text(stmt, 1,text.c_str(),text.size(), 0);
sqlite3_bind_text(stmt, 2,time.c_str(), time.size(), 0);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
}
else
{
onej.EJ_Log("ERROR INSERTING EJ");
}
}
sqlite3_close(db);
}
Aucun commentaire:
Enregistrer un commentaire