Reputation: 11
I am working on a school project which involves SQLite3.
I've created a bunch of functions for my DatabaseManager
class which all work quite good.
Now, after adding a function with a DELETE statement, sqlite3_step()
returns SQLITE_BUSY
and the sqlite3_errmsg()
says "Database is locked".
Before opening this function I have already called sqlite3_finalize()
and sqlite3_close()
.
int errorcode;
sqlite3 *db;
//sql statement
std::string statement = "DELETE FROM tbl_follower WHERE flw_ID = " + std::to_string(row);
sqlite3_stmt *binStatement;
errorcode = sqlite3_open(m_filePath.c_str(), &db);
if (errorcode != SQLITE_OK)
std::cerr << sqlite3_errmsg(db) << std::endl;
errorcode = sqlite3_prepare_v2(db, statement.c_str(), statement.size(), &binStatement, NULL);
if(errorcode != SQLITE_OK)
std::cerr << sqlite3_errmsg(db) << std::endl;
errorcode = sqlite3_step(binStatement);
if (errorcode == SQLITE_DONE)
{
sqlite3_finalize(binStatement);
sqlite3_close(db);
}
else
{
//error
std::cerr << sqlite3_errmsg(db) << std::endl;
sqlite3_finalize(binStatement);
sqlite3_close(db);
}
I am pretty sure the issue is somewhere in this code because I have already checked all of my other functions for mistakes (which all work without giving an error). My SQL statement is also correct.
Upvotes: 0
Views: 628
Reputation: 180020
"Database is locked" means that there is some other active transaction.
You probably forgot to finalize a statement in some other part of the program.
Upvotes: 0