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);
}
}
}
}
}
{
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);
}
}
}
}
}
关闭SQLite数据库连接
本文介绍了一个关闭SQLite数据库连接的方法,通过循环处理SQLite_BUSY错误来确保所有事务和准备语句正确结束,最终安全关闭数据库。
2089

被折叠的 条评论
为什么被折叠?



