I made a simple C++ program with sqlite3, it's composed by several function in which in each function I open the database at the begin, and i close it ad the end. I didn't realize why, but I'm sure, that there is a function that keep the database locked and don't allow other function to work propertly (I'm always able to read data from DB, but not to write on it by using UPDATE instruction in sql). The function that lock the database is this one:
void connect_user(const std::string& user) {
sqlite3* db = database_open("UTENTE.db");
char* err;
std::string query = "UPDATE UTENTE SET Online=1 WHERE Username='" + user + "';";
try {
int res = sqlite3_exec(db, query.c_str(), NULL, NULL, &err);
database_close(db);
if (res != SQLITE_OK)
std::cout << "Error during update: " << err << std::endl;
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
}
In main:
1 2 3 4 5 6 7
int main(){
....
if ( find_user('JoeDoe') )
connect_user('JoeDoe');
....
}
I get this output: Error during update: database table is locked: UTENTE The strange thing is that I'm using a simple singleThread application, so I shouldn't have any cuncurrency problem.