From dfe84698ea3ec5d62d2ea55dfacba45c50fd40f3 Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 13 May 2020 09:23:28 +0000 Subject: [PATCH] Sql: Fixed SQL destruction issues git-svn-id: svn://ultimatepp.org/upp/trunk@14460 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Sql/Session.cpp | 21 +++++++++++++++++---- uppsrc/plugin/sqlite3/Sqlite3upp.cpp | 4 ---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/uppsrc/Sql/Session.cpp b/uppsrc/Sql/Session.cpp index ed188774b..0795716a1 100644 --- a/uppsrc/Sql/Session.cpp +++ b/uppsrc/Sql/Session.cpp @@ -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; } diff --git a/uppsrc/plugin/sqlite3/Sqlite3upp.cpp b/uppsrc/plugin/sqlite3/Sqlite3upp.cpp index fd25b71f5..2c63da489 100644 --- a/uppsrc/plugin/sqlite3/Sqlite3upp.cpp +++ b/uppsrc/plugin/sqlite3/Sqlite3upp.cpp @@ -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.