0

So, i want to update field name from account table. I function below this function. but when i test it, it is not work correctly. sqlite3_step always return SQLITE_BUSY I do a test and i got database is locked message. What should i do?

int c_accountdata::name_set(std::string input)
{
if (input.length() > 20)
{
    return -1;
}

sqlite3_bind_text(stmt_name_exist, 1, input.c_str(), -1, NULL);
if (sqlite3_step(stmt_name_exist) == SQLITE_ROW)
{
    sqlite3_reset(stmt_name_exist);
    return 0;
}
sqlite3_reset(stmt_name_exist);


sqlite3_bind_text(stmt_name_update, 0, input.c_str(), -1, NULL);
sqlite3_bind_text(stmt_name_update, 1, input.c_str(), -1, NULL);

int ret = sqlite3_step(stmt_name_update);

sqlite3_reset(stmt_name_update);

sampgdk::logprintf("%d", ret);

return 1;
}
  • Means the database is locked, some other connection has taken exclusive write control. Any idea who did that? Where that lock may have been taken? – Luke Jun 26 '15 at 03:36
  • See the answer here, perhaps: http://stackoverflow.com/questions/8559623/sqlite-busy-the-database-file-is-locked-database-is-locked-in-wicket – Luke Jun 26 '15 at 03:37

1 Answers1

1

"Database locked" message is displayed usually when some other process is accessing it (for DELETE or UPDATE operations). See Locking mechanism details here: http://www.sqlite.org/lockingv3.html If you have admin/root access of database; And If you are using MySQL, You can possibly try

mysql> SHOW FULL PROCESSLIST;

This will show you a list of all current processes, their SQL query and state. Now usually if a single query is causing many others to lock then it should be easy to identify. The affected queries will have a status of Locked and the offending query will be sitting out by itself, possibly waiting for something intensive, like a temporary table.

If it's not obvious then you will have to use your powers of SQL deduction to determine which piece of offending SQL may be the cause of your woes.

stack_d_code
  • 1,196
  • 2
  • 12
  • 19