Sql: Fixed SQL destruction issues

git-svn-id: svn://ultimatepp.org/upp/trunk@14460 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2020-05-13 09:23:28 +00:00
parent a07381ddc1
commit dfe84698ea
2 changed files with 17 additions and 8 deletions

View file

@ -84,6 +84,8 @@ void SqlSession::InstallErrorHandler(bool (*handler)(String error, String stmt,
error_handler = handler;
}
void Detach_SQL();
void SqlSession::SessionClose()
{
if(sql) {
@ -94,6 +96,13 @@ void SqlSession::SessionClose()
sqlr->Cancel();
sqlr.Clear();
}
#ifndef flagNOAPPSQL
if(SQL.IsOpen() && &SQL.GetSession() == this) {
SQL.Cancel();
SQL.Detach();
Detach_SQL();
}
#endif
}
Sql& SqlSession::GetSessionSql()
@ -143,24 +152,28 @@ void SqlSession::PerThread(bool b)
#ifndef NOAPPSQL
void Detach_SQL()
{
if(sPerThread)
sThreadSessionR = sThreadSession = NULL;
else
sGlobalSessionR = sGlobalSession = NULL;
}
void Sql::operator=(SqlSession& s)
{
Mutex::Lock __(sDefs);
if(this == &AppCursor()) {
#ifdef _MULTITHREADED
if(sPerThread)
sThreadSession = &s;
else
#endif
sGlobalSession = &s;
return;
}
if(this == &AppCursorR()) {
#ifdef _MULTITHREADED
if(sPerThread)
sThreadSessionR = &s;
else
#endif
sGlobalSessionR = &s;
return;
}

View file

@ -379,10 +379,6 @@ void Sqlite3Session::Close() {
if (NULL != db) {
SessionClose();
int retval;
#ifndef flagNOAPPSQL
if(SQL.IsOpen() && &SQL.GetSession() == this)
SQL.Cancel();
#endif
retval = sqlite3_close(db);
// If this function fails, that means that some of the
// prepared statements have not been finalized.