diff --git a/uppsrc/OleDB/OleDB.cpp b/uppsrc/OleDB/OleDB.cpp index d9dc9a546..b19153aa8 100644 --- a/uppsrc/OleDB/OleDB.cpp +++ b/uppsrc/OleDB/OleDB.cpp @@ -1141,7 +1141,8 @@ Array OleDBSession::EnumProviders() OleDBSession dummy; One conn = new OleDBConnection(&dummy); conn->Execute(rowset); - Sql cursor(-conn); + Sql0 cursor; + Attach(cursor, -conn); int cname = -1, cdesc = -1, cguid = -1; for(int i = 0; i < cursor.GetColumns(); i++) { String ci = cursor.GetColumnInfo(i).name; @@ -1351,7 +1352,8 @@ Vector OleDBSession::EnumDatabases() OleVerify(srowset->GetRowset(NULL, DBSCHEMA_CATALOGS, 0, NULL, trowset.GetIID(), 0, NULL, trowset.SetUnk())); One conn = new OleDBConnection(this); conn->Execute(trowset); - Sql cursor(-conn); + Sql0 cursor; + Attach(cursor, -conn); int ccat = -1; for(int i = 0; i < cursor.GetColumns(); i++) { String n = cursor.GetColumnInfo(i).name; @@ -1376,7 +1378,8 @@ Vector OleDBSession::EnumTables(String database) OleVerify(srowset->GetRowset(NULL, DBSCHEMA_TABLES, 1, restrictions, trowset.GetIID(), 0, NULL, trowset.SetUnk())); One conn = new OleDBConnection(this); conn->Execute(trowset); - Sql cursor(-conn); + Sql0 cursor; + Attach(cursor, -conn); int cname = -1; int cschema = -1; int ctype = -1; @@ -1418,7 +1421,8 @@ Vector OleDBSession::EnumViews(String database) OleVerify(srowset->GetRowset(NULL, DBSCHEMA_TABLES, 1, restrictions, trowset.GetIID(), 0, NULL, trowset.SetUnk())); One conn = new OleDBConnection(this); conn->Execute(trowset); - Sql cursor(-conn); + Sql0 cursor; + Attach(cursor, -conn); int cname = -1; int cschema = -1; int ctype = -1; @@ -1476,7 +1480,8 @@ Vector OleDBSession::EnumPrimaryKey(String database, String table) trowset.GetIID(), 0, NULL, trowset.SetUnk())); One conn = new OleDBConnection(this); conn->Execute(trowset); - Sql cursor(-conn); + Sql0 cursor; + Attach(cursor, -conn); int cname = -1; int cord = -1; Vector ordinal; diff --git a/uppsrc/Sql/Session.cpp b/uppsrc/Sql/Session.cpp index 685deca30..689285d1a 100644 --- a/uppsrc/Sql/Session.cpp +++ b/uppsrc/Sql/Session.cpp @@ -1,185 +1,190 @@ -#include "Sql.h" - -NAMESPACE_UPP - -SqlSession::SqlSession() -{ - trace = NULL; - traceslow = INT_MAX / 4; - logerrors = false; - usrlog = false; - tracetime = false; - dialect = 255; - errorcode_number = Null; - errorclass = Sql::ERROR_UNSPECIFIED; - error_handler = NULL; - throwonerror = false; -} - -SqlSession::~SqlSession() -{ -} - -void SqlSession::Begin() { NEVER(); } -void SqlSession::Commit() { NEVER(); } -void SqlSession::Rollback() { NEVER(); } -String SqlSession::Savepoint() { NEVER(); return Null; } -void SqlSession::RollbackTo(const String&) { NEVER(); } -bool SqlSession::IsOpen() const { return false; } -int SqlSession::GetTransactionLevel() const { return 0; } -RunScript SqlSession::GetRunScript() const { return NULL; } -SqlConnection *SqlSession::CreateConnection() { return NULL; } -Vector SqlSession::EnumUsers() { return Vector(); } -Vector SqlSession::EnumDatabases() { return Vector(); } -Vector SqlSession::EnumTables(String database) { return Vector(); } -Vector SqlSession::EnumViews(String database) { return Vector(); } -Vector SqlSession::EnumSequences(String database) { return Vector(); } -Vector SqlSession::EnumPrimaryKey(String database, String table) { return Vector(); } -Vector SqlSession::EnumReservedWords() { return Vector(); } -String SqlSession::EnumRowID(String database, String table) { return Null; } - -Vector SqlSession::EnumColumns(String database, String table) -{ - Sql cursor(*this); - Vector info; - SqlBool none; - none.SetFalse(); - String full_name = database; - if(!IsNull(database)) - full_name << '.'; - full_name << table; - if(cursor.Execute(Select(SqlAll()).From(SqlSet(SqlId(full_name))).Where(none))) { - info.SetCount(cursor.GetColumns()); - for(int i = 0; i < info.GetCount(); i++) - info[i] = cursor.GetColumnInfo(i); - } - return info; -} - -void SqlSession::SetError(String error, String stmt, int code, const char *scode, Sql::ERRORCLASS clss) { - if(error_handler && (*error_handler)(error, stmt, code, scode, clss)) - return; - if(GetTransactionLevel() && errorstatement.GetCount()) - return; - lasterror = error; - errorstatement = stmt; - errorcode_number = code; - errorcode_string = scode; - errorclass = clss; - String err; - err << "ERROR " << error << "(" << code << "): " << stmt << '\n'; - if(logerrors) - BugLog() << err; - if(GetTrace()) - *GetTrace() << err; -} - -void SqlSession::InstallErrorHandler(bool (*handler)(String error, String stmt, int code, const char *scode, Sql::ERRORCLASS clss)) -{ - error_handler = handler; -} - -void SqlSession::SessionClose() -{ - if(sql) { - sql->Cancel(); - sql.Clear(); - } - if(sqlr) { - sqlr->Cancel(); - sqlr.Clear(); - } -} - -Sql& SqlSession::GetSessionSql() -{ - if(!sql) - sql = new Sql(*this); - return *sql; -} - -Sql& SqlSession::GetSessionSqlR() -{ - if(!sqlr) - sqlr = new Sql(*this); - return *sqlr; -} - -void SqlSession::ClearError() -{ - lasterror.Clear(); - errorstatement.Clear(); - errorcode_number = Null; - errorcode_string = Null; - errorclass = Sql::ERROR_UNSPECIFIED; -} - -StaticMutex sDefs; -static SqlSession *sGlobalSession; -static SqlSession *sGlobalSessionR; -#ifdef _MULTITHREADED -thread__ SqlSession *sThreadSession; -thread__ SqlSession *sThreadSessionR; -#endif - -void Sql::operator=(SqlSession& s) -{ - Mutex::Lock __(sDefs); - if(this == &AppCursor()) { - #ifdef _MULTITHREADED - sThreadSession = &s; - if(!sGlobalSession) - #endif - sGlobalSession = &s; - return; - } - if(this == &AppCursorR()) { - #ifdef _MULTITHREADED - sThreadSessionR = &s; - if(!sGlobalSessionR) - #endif - sGlobalSessionR = &s; - return; - } - NEVER(); -} - -Sql& AppCursor() -{ -#ifdef _MULTITHREADED - if(sThreadSession) - return sThreadSession->GetSessionSql(); -#endif - if(sGlobalSession) - return sGlobalSession->GetSessionSql(); - static Sql *empty; - ONCELOCK { - static Sql0 h; - empty = &h; - } - return *empty; -} - -Sql& AppCursorR() -{ -#ifdef _MULTITHREADED - if(sThreadSessionR) - return sThreadSessionR->GetSessionSqlR(); -#endif - if(sGlobalSessionR) - return sGlobalSessionR->GetSessionSqlR(); -#ifdef _MULTITHREADED - if(sThreadSession) - return sThreadSession->GetSessionSqlR(); -#endif - if(sGlobalSession) - return sGlobalSession->GetSessionSqlR(); - static Sql *empty; - ONCELOCK { - static Sql0 h; - empty = &h; - } - return *empty; -} - -END_UPP_NAMESPACE +#include "Sql.h" + +NAMESPACE_UPP + +void SqlSession::Attach(Sql& sql, SqlConnection *con) +{ + sql.Attach(con); // Duck tape to fix OleDB +} + +SqlSession::SqlSession() +{ + trace = NULL; + traceslow = INT_MAX / 4; + logerrors = false; + usrlog = false; + tracetime = false; + dialect = 255; + errorcode_number = Null; + errorclass = Sql::ERROR_UNSPECIFIED; + error_handler = NULL; + throwonerror = false; +} + +SqlSession::~SqlSession() +{ +} + +void SqlSession::Begin() { NEVER(); } +void SqlSession::Commit() { NEVER(); } +void SqlSession::Rollback() { NEVER(); } +String SqlSession::Savepoint() { NEVER(); return Null; } +void SqlSession::RollbackTo(const String&) { NEVER(); } +bool SqlSession::IsOpen() const { return false; } +int SqlSession::GetTransactionLevel() const { return 0; } +RunScript SqlSession::GetRunScript() const { return NULL; } +SqlConnection *SqlSession::CreateConnection() { return NULL; } +Vector SqlSession::EnumUsers() { return Vector(); } +Vector SqlSession::EnumDatabases() { return Vector(); } +Vector SqlSession::EnumTables(String database) { return Vector(); } +Vector SqlSession::EnumViews(String database) { return Vector(); } +Vector SqlSession::EnumSequences(String database) { return Vector(); } +Vector SqlSession::EnumPrimaryKey(String database, String table) { return Vector(); } +Vector SqlSession::EnumReservedWords() { return Vector(); } +String SqlSession::EnumRowID(String database, String table) { return Null; } + +Vector SqlSession::EnumColumns(String database, String table) +{ + Sql cursor(*this); + Vector info; + SqlBool none; + none.SetFalse(); + String full_name = database; + if(!IsNull(database)) + full_name << '.'; + full_name << table; + if(cursor.Execute(Select(SqlAll()).From(SqlSet(SqlId(full_name))).Where(none))) { + info.SetCount(cursor.GetColumns()); + for(int i = 0; i < info.GetCount(); i++) + info[i] = cursor.GetColumnInfo(i); + } + return info; +} + +void SqlSession::SetError(String error, String stmt, int code, const char *scode, Sql::ERRORCLASS clss) { + if(error_handler && (*error_handler)(error, stmt, code, scode, clss)) + return; + if(GetTransactionLevel() && errorstatement.GetCount()) + return; + lasterror = error; + errorstatement = stmt; + errorcode_number = code; + errorcode_string = scode; + errorclass = clss; + String err; + err << "ERROR " << error << "(" << code << "): " << stmt << '\n'; + if(logerrors) + BugLog() << err; + if(GetTrace()) + *GetTrace() << err; +} + +void SqlSession::InstallErrorHandler(bool (*handler)(String error, String stmt, int code, const char *scode, Sql::ERRORCLASS clss)) +{ + error_handler = handler; +} + +void SqlSession::SessionClose() +{ + if(sql) { + sql->Cancel(); + sql.Clear(); + } + if(sqlr) { + sqlr->Cancel(); + sqlr.Clear(); + } +} + +Sql& SqlSession::GetSessionSql() +{ + if(!sql) + sql = new Sql(*this); + return *sql; +} + +Sql& SqlSession::GetSessionSqlR() +{ + if(!sqlr) + sqlr = new Sql(*this); + return *sqlr; +} + +void SqlSession::ClearError() +{ + lasterror.Clear(); + errorstatement.Clear(); + errorcode_number = Null; + errorcode_string = Null; + errorclass = Sql::ERROR_UNSPECIFIED; +} + +StaticMutex sDefs; +static SqlSession *sGlobalSession; +static SqlSession *sGlobalSessionR; +#ifdef _MULTITHREADED +thread__ SqlSession *sThreadSession; +thread__ SqlSession *sThreadSessionR; +#endif + +void Sql::operator=(SqlSession& s) +{ + Mutex::Lock __(sDefs); + if(this == &AppCursor()) { + #ifdef _MULTITHREADED + sThreadSession = &s; + if(!sGlobalSession) + #endif + sGlobalSession = &s; + return; + } + if(this == &AppCursorR()) { + #ifdef _MULTITHREADED + sThreadSessionR = &s; + if(!sGlobalSessionR) + #endif + sGlobalSessionR = &s; + return; + } + NEVER(); +} + +Sql& AppCursor() +{ +#ifdef _MULTITHREADED + if(sThreadSession) + return sThreadSession->GetSessionSql(); +#endif + if(sGlobalSession) + return sGlobalSession->GetSessionSql(); + static Sql *empty; + ONCELOCK { + static Sql0 h; + empty = &h; + } + return *empty; +} + +Sql& AppCursorR() +{ +#ifdef _MULTITHREADED + if(sThreadSessionR) + return sThreadSessionR->GetSessionSqlR(); +#endif + if(sGlobalSessionR) + return sGlobalSessionR->GetSessionSqlR(); +#ifdef _MULTITHREADED + if(sThreadSession) + return sThreadSession->GetSessionSqlR(); +#endif + if(sGlobalSession) + return sGlobalSession->GetSessionSqlR(); + static Sql *empty; + ONCELOCK { + static Sql0 h; + empty = &h; + } + return *empty; +} + +END_UPP_NAMESPACE diff --git a/uppsrc/Sql/Sql.cpp b/uppsrc/Sql/Sql.cpp index 79b4889c7..90bc2682c 100644 --- a/uppsrc/Sql/Sql.cpp +++ b/uppsrc/Sql/Sql.cpp @@ -610,7 +610,7 @@ bool Sql::IsOpen() { return cn && GetSession().Is void SqlConnection::Attach(Sql& sql, SqlConnection *con) { - sql.Attach(con); + sql.Attach(con); // Duck tape to fix Oci8 } #ifndef NOAPPSQL diff --git a/uppsrc/Sql/Sqls.h b/uppsrc/Sql/Sqls.h index 407065249..979f1fe30 100644 --- a/uppsrc/Sql/Sqls.h +++ b/uppsrc/Sql/Sqls.h @@ -322,6 +322,8 @@ protected: void SessionClose(); + static void Attach(Sql& sql, SqlConnection *con); + public: virtual void Begin(); virtual void Commit(); diff --git a/uppsrc/SqlCommander/init b/uppsrc/SqlCommander/init index 68f8c165a..c5b11d34d 100644 --- a/uppsrc/SqlCommander/init +++ b/uppsrc/SqlCommander/init @@ -3,7 +3,7 @@ #include "SqlCtrl/init" #include "Oracle/init" #include "OleDB/init" -#include "MySql/init" #include "plugin\sqlite3/init" #include "PostgreSQL/init" +#include "MySql/init" #endif