OleDB: fixed for private Connection in Sql

git-svn-id: svn://ultimatepp.org/upp/trunk@4353 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-12-28 19:33:38 +00:00
parent 0b7b0f5af4
commit 5f0b18e7ae
5 changed files with 204 additions and 192 deletions

View file

@ -1141,7 +1141,8 @@ Array<OleDBSession::Provider> OleDBSession::EnumProviders()
OleDBSession dummy; OleDBSession dummy;
One<OleDBConnection> conn = new OleDBConnection(&dummy); One<OleDBConnection> conn = new OleDBConnection(&dummy);
conn->Execute(rowset); conn->Execute(rowset);
Sql cursor(-conn); Sql0 cursor;
Attach(cursor, -conn);
int cname = -1, cdesc = -1, cguid = -1; int cname = -1, cdesc = -1, cguid = -1;
for(int i = 0; i < cursor.GetColumns(); i++) { for(int i = 0; i < cursor.GetColumns(); i++) {
String ci = cursor.GetColumnInfo(i).name; String ci = cursor.GetColumnInfo(i).name;
@ -1351,7 +1352,8 @@ Vector<String> OleDBSession::EnumDatabases()
OleVerify(srowset->GetRowset(NULL, DBSCHEMA_CATALOGS, 0, NULL, trowset.GetIID(), 0, NULL, trowset.SetUnk())); OleVerify(srowset->GetRowset(NULL, DBSCHEMA_CATALOGS, 0, NULL, trowset.GetIID(), 0, NULL, trowset.SetUnk()));
One<OleDBConnection> conn = new OleDBConnection(this); One<OleDBConnection> conn = new OleDBConnection(this);
conn->Execute(trowset); conn->Execute(trowset);
Sql cursor(-conn); Sql0 cursor;
Attach(cursor, -conn);
int ccat = -1; int ccat = -1;
for(int i = 0; i < cursor.GetColumns(); i++) { for(int i = 0; i < cursor.GetColumns(); i++) {
String n = cursor.GetColumnInfo(i).name; String n = cursor.GetColumnInfo(i).name;
@ -1376,7 +1378,8 @@ Vector<String> OleDBSession::EnumTables(String database)
OleVerify(srowset->GetRowset(NULL, DBSCHEMA_TABLES, 1, restrictions, trowset.GetIID(), 0, NULL, trowset.SetUnk())); OleVerify(srowset->GetRowset(NULL, DBSCHEMA_TABLES, 1, restrictions, trowset.GetIID(), 0, NULL, trowset.SetUnk()));
One<OleDBConnection> conn = new OleDBConnection(this); One<OleDBConnection> conn = new OleDBConnection(this);
conn->Execute(trowset); conn->Execute(trowset);
Sql cursor(-conn); Sql0 cursor;
Attach(cursor, -conn);
int cname = -1; int cname = -1;
int cschema = -1; int cschema = -1;
int ctype = -1; int ctype = -1;
@ -1418,7 +1421,8 @@ Vector<String> OleDBSession::EnumViews(String database)
OleVerify(srowset->GetRowset(NULL, DBSCHEMA_TABLES, 1, restrictions, trowset.GetIID(), 0, NULL, trowset.SetUnk())); OleVerify(srowset->GetRowset(NULL, DBSCHEMA_TABLES, 1, restrictions, trowset.GetIID(), 0, NULL, trowset.SetUnk()));
One<OleDBConnection> conn = new OleDBConnection(this); One<OleDBConnection> conn = new OleDBConnection(this);
conn->Execute(trowset); conn->Execute(trowset);
Sql cursor(-conn); Sql0 cursor;
Attach(cursor, -conn);
int cname = -1; int cname = -1;
int cschema = -1; int cschema = -1;
int ctype = -1; int ctype = -1;
@ -1476,7 +1480,8 @@ Vector<String> OleDBSession::EnumPrimaryKey(String database, String table)
trowset.GetIID(), 0, NULL, trowset.SetUnk())); trowset.GetIID(), 0, NULL, trowset.SetUnk()));
One<OleDBConnection> conn = new OleDBConnection(this); One<OleDBConnection> conn = new OleDBConnection(this);
conn->Execute(trowset); conn->Execute(trowset);
Sql cursor(-conn); Sql0 cursor;
Attach(cursor, -conn);
int cname = -1; int cname = -1;
int cord = -1; int cord = -1;
Vector<int> ordinal; Vector<int> ordinal;

View file

@ -1,185 +1,190 @@
#include "Sql.h" #include "Sql.h"
NAMESPACE_UPP NAMESPACE_UPP
SqlSession::SqlSession() void SqlSession::Attach(Sql& sql, SqlConnection *con)
{ {
trace = NULL; sql.Attach(con); // Duck tape to fix OleDB
traceslow = INT_MAX / 4; }
logerrors = false;
usrlog = false; SqlSession::SqlSession()
tracetime = false; {
dialect = 255; trace = NULL;
errorcode_number = Null; traceslow = INT_MAX / 4;
errorclass = Sql::ERROR_UNSPECIFIED; logerrors = false;
error_handler = NULL; usrlog = false;
throwonerror = false; tracetime = false;
} dialect = 255;
errorcode_number = Null;
SqlSession::~SqlSession() errorclass = Sql::ERROR_UNSPECIFIED;
{ error_handler = NULL;
} throwonerror = false;
}
void SqlSession::Begin() { NEVER(); }
void SqlSession::Commit() { NEVER(); } SqlSession::~SqlSession()
void SqlSession::Rollback() { NEVER(); } {
String SqlSession::Savepoint() { NEVER(); return Null; } }
void SqlSession::RollbackTo(const String&) { NEVER(); }
bool SqlSession::IsOpen() const { return false; } void SqlSession::Begin() { NEVER(); }
int SqlSession::GetTransactionLevel() const { return 0; } void SqlSession::Commit() { NEVER(); }
RunScript SqlSession::GetRunScript() const { return NULL; } void SqlSession::Rollback() { NEVER(); }
SqlConnection *SqlSession::CreateConnection() { return NULL; } String SqlSession::Savepoint() { NEVER(); return Null; }
Vector<String> SqlSession::EnumUsers() { return Vector<String>(); } void SqlSession::RollbackTo(const String&) { NEVER(); }
Vector<String> SqlSession::EnumDatabases() { return Vector<String>(); } bool SqlSession::IsOpen() const { return false; }
Vector<String> SqlSession::EnumTables(String database) { return Vector<String>(); } int SqlSession::GetTransactionLevel() const { return 0; }
Vector<String> SqlSession::EnumViews(String database) { return Vector<String>(); } RunScript SqlSession::GetRunScript() const { return NULL; }
Vector<String> SqlSession::EnumSequences(String database) { return Vector<String>(); } SqlConnection *SqlSession::CreateConnection() { return NULL; }
Vector<String> SqlSession::EnumPrimaryKey(String database, String table) { return Vector<String>(); } Vector<String> SqlSession::EnumUsers() { return Vector<String>(); }
Vector<String> SqlSession::EnumReservedWords() { return Vector<String>(); } Vector<String> SqlSession::EnumDatabases() { return Vector<String>(); }
String SqlSession::EnumRowID(String database, String table) { return Null; } Vector<String> SqlSession::EnumTables(String database) { return Vector<String>(); }
Vector<String> SqlSession::EnumViews(String database) { return Vector<String>(); }
Vector<SqlColumnInfo> SqlSession::EnumColumns(String database, String table) Vector<String> SqlSession::EnumSequences(String database) { return Vector<String>(); }
{ Vector<String> SqlSession::EnumPrimaryKey(String database, String table) { return Vector<String>(); }
Sql cursor(*this); Vector<String> SqlSession::EnumReservedWords() { return Vector<String>(); }
Vector<SqlColumnInfo> info; String SqlSession::EnumRowID(String database, String table) { return Null; }
SqlBool none;
none.SetFalse(); Vector<SqlColumnInfo> SqlSession::EnumColumns(String database, String table)
String full_name = database; {
if(!IsNull(database)) Sql cursor(*this);
full_name << '.'; Vector<SqlColumnInfo> info;
full_name << table; SqlBool none;
if(cursor.Execute(Select(SqlAll()).From(SqlSet(SqlId(full_name))).Where(none))) { none.SetFalse();
info.SetCount(cursor.GetColumns()); String full_name = database;
for(int i = 0; i < info.GetCount(); i++) if(!IsNull(database))
info[i] = cursor.GetColumnInfo(i); full_name << '.';
} full_name << table;
return info; if(cursor.Execute(Select(SqlAll()).From(SqlSet(SqlId(full_name))).Where(none))) {
} info.SetCount(cursor.GetColumns());
for(int i = 0; i < info.GetCount(); i++)
void SqlSession::SetError(String error, String stmt, int code, const char *scode, Sql::ERRORCLASS clss) { info[i] = cursor.GetColumnInfo(i);
if(error_handler && (*error_handler)(error, stmt, code, scode, clss)) }
return; return info;
if(GetTransactionLevel() && errorstatement.GetCount()) }
return;
lasterror = error; void SqlSession::SetError(String error, String stmt, int code, const char *scode, Sql::ERRORCLASS clss) {
errorstatement = stmt; if(error_handler && (*error_handler)(error, stmt, code, scode, clss))
errorcode_number = code; return;
errorcode_string = scode; if(GetTransactionLevel() && errorstatement.GetCount())
errorclass = clss; return;
String err; lasterror = error;
err << "ERROR " << error << "(" << code << "): " << stmt << '\n'; errorstatement = stmt;
if(logerrors) errorcode_number = code;
BugLog() << err; errorcode_string = scode;
if(GetTrace()) errorclass = clss;
*GetTrace() << err; String err;
} err << "ERROR " << error << "(" << code << "): " << stmt << '\n';
if(logerrors)
void SqlSession::InstallErrorHandler(bool (*handler)(String error, String stmt, int code, const char *scode, Sql::ERRORCLASS clss)) BugLog() << err;
{ if(GetTrace())
error_handler = handler; *GetTrace() << err;
} }
void SqlSession::SessionClose() void SqlSession::InstallErrorHandler(bool (*handler)(String error, String stmt, int code, const char *scode, Sql::ERRORCLASS clss))
{ {
if(sql) { error_handler = handler;
sql->Cancel(); }
sql.Clear();
} void SqlSession::SessionClose()
if(sqlr) { {
sqlr->Cancel(); if(sql) {
sqlr.Clear(); sql->Cancel();
} sql.Clear();
} }
if(sqlr) {
Sql& SqlSession::GetSessionSql() sqlr->Cancel();
{ sqlr.Clear();
if(!sql) }
sql = new Sql(*this); }
return *sql;
} Sql& SqlSession::GetSessionSql()
{
Sql& SqlSession::GetSessionSqlR() if(!sql)
{ sql = new Sql(*this);
if(!sqlr) return *sql;
sqlr = new Sql(*this); }
return *sqlr;
} Sql& SqlSession::GetSessionSqlR()
{
void SqlSession::ClearError() if(!sqlr)
{ sqlr = new Sql(*this);
lasterror.Clear(); return *sqlr;
errorstatement.Clear(); }
errorcode_number = Null;
errorcode_string = Null; void SqlSession::ClearError()
errorclass = Sql::ERROR_UNSPECIFIED; {
} lasterror.Clear();
errorstatement.Clear();
StaticMutex sDefs; errorcode_number = Null;
static SqlSession *sGlobalSession; errorcode_string = Null;
static SqlSession *sGlobalSessionR; errorclass = Sql::ERROR_UNSPECIFIED;
#ifdef _MULTITHREADED }
thread__ SqlSession *sThreadSession;
thread__ SqlSession *sThreadSessionR; StaticMutex sDefs;
#endif static SqlSession *sGlobalSession;
static SqlSession *sGlobalSessionR;
void Sql::operator=(SqlSession& s) #ifdef _MULTITHREADED
{ thread__ SqlSession *sThreadSession;
Mutex::Lock __(sDefs); thread__ SqlSession *sThreadSessionR;
if(this == &AppCursor()) { #endif
#ifdef _MULTITHREADED
sThreadSession = &s; void Sql::operator=(SqlSession& s)
if(!sGlobalSession) {
#endif Mutex::Lock __(sDefs);
sGlobalSession = &s; if(this == &AppCursor()) {
return; #ifdef _MULTITHREADED
} sThreadSession = &s;
if(this == &AppCursorR()) { if(!sGlobalSession)
#ifdef _MULTITHREADED #endif
sThreadSessionR = &s; sGlobalSession = &s;
if(!sGlobalSessionR) return;
#endif }
sGlobalSessionR = &s; if(this == &AppCursorR()) {
return; #ifdef _MULTITHREADED
} sThreadSessionR = &s;
NEVER(); if(!sGlobalSessionR)
} #endif
sGlobalSessionR = &s;
Sql& AppCursor() return;
{ }
#ifdef _MULTITHREADED NEVER();
if(sThreadSession) }
return sThreadSession->GetSessionSql();
#endif Sql& AppCursor()
if(sGlobalSession) {
return sGlobalSession->GetSessionSql(); #ifdef _MULTITHREADED
static Sql *empty; if(sThreadSession)
ONCELOCK { return sThreadSession->GetSessionSql();
static Sql0 h; #endif
empty = &h; if(sGlobalSession)
} return sGlobalSession->GetSessionSql();
return *empty; static Sql *empty;
} ONCELOCK {
static Sql0 h;
Sql& AppCursorR() empty = &h;
{ }
#ifdef _MULTITHREADED return *empty;
if(sThreadSessionR) }
return sThreadSessionR->GetSessionSqlR();
#endif Sql& AppCursorR()
if(sGlobalSessionR) {
return sGlobalSessionR->GetSessionSqlR(); #ifdef _MULTITHREADED
#ifdef _MULTITHREADED if(sThreadSessionR)
if(sThreadSession) return sThreadSessionR->GetSessionSqlR();
return sThreadSession->GetSessionSqlR(); #endif
#endif if(sGlobalSessionR)
if(sGlobalSession) return sGlobalSessionR->GetSessionSqlR();
return sGlobalSession->GetSessionSqlR(); #ifdef _MULTITHREADED
static Sql *empty; if(sThreadSession)
ONCELOCK { return sThreadSession->GetSessionSqlR();
static Sql0 h; #endif
empty = &h; if(sGlobalSession)
} return sGlobalSession->GetSessionSqlR();
return *empty; static Sql *empty;
} ONCELOCK {
static Sql0 h;
END_UPP_NAMESPACE empty = &h;
}
return *empty;
}
END_UPP_NAMESPACE

View file

@ -610,7 +610,7 @@ bool Sql::IsOpen() { return cn && GetSession().Is
void SqlConnection::Attach(Sql& sql, SqlConnection *con) void SqlConnection::Attach(Sql& sql, SqlConnection *con)
{ {
sql.Attach(con); sql.Attach(con); // Duck tape to fix Oci8
} }
#ifndef NOAPPSQL #ifndef NOAPPSQL

View file

@ -322,6 +322,8 @@ protected:
void SessionClose(); void SessionClose();
static void Attach(Sql& sql, SqlConnection *con);
public: public:
virtual void Begin(); virtual void Begin();
virtual void Commit(); virtual void Commit();

View file

@ -3,7 +3,7 @@
#include "SqlCtrl/init" #include "SqlCtrl/init"
#include "Oracle/init" #include "Oracle/init"
#include "OleDB/init" #include "OleDB/init"
#include "MySql/init"
#include "plugin\sqlite3/init" #include "plugin\sqlite3/init"
#include "PostgreSQL/init" #include "PostgreSQL/init"
#include "MySql/init"
#endif #endif