sqlite3_close 返回 SQLITE_BUSY 的解决方案

来源:互联网 发布:电脑故障检测软件 编辑:程序博客网 时间:2024/05/22 04:46
void CSQLiteDB::Close()
{
    if(m_db)
    {
        sqlite3 *db = m_db;
        m_db = NULL;
        int rc = sqlite3_close(db);

        while( rc == SQLITE_BUSY)
        {
            // set rc to something that will exit the while loop
            rc = SQLITE_OK;
            sqlite3_stmt * stmt = sqlite3_next_stmt(db, NULL);

            if(stmt != NULL)
            {
                rc = sqlite3_finalize(stmt);
                if(rc == SQLITE_OK)
                {
                    rc = sqlite3_close(db);
                }
            }
        }
    }
}