mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
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:
parent
dc088d6015
commit
31c717a2ed
5 changed files with 204 additions and 192 deletions
|
|
@ -1141,7 +1141,8 @@ Array<OleDBSession::Provider> OleDBSession::EnumProviders()
|
|||
OleDBSession dummy;
|
||||
One<OleDBConnection> 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<String> OleDBSession::EnumDatabases()
|
|||
OleVerify(srowset->GetRowset(NULL, DBSCHEMA_CATALOGS, 0, NULL, trowset.GetIID(), 0, NULL, trowset.SetUnk()));
|
||||
One<OleDBConnection> 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<String> OleDBSession::EnumTables(String database)
|
|||
OleVerify(srowset->GetRowset(NULL, DBSCHEMA_TABLES, 1, restrictions, trowset.GetIID(), 0, NULL, trowset.SetUnk()));
|
||||
One<OleDBConnection> 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<String> OleDBSession::EnumViews(String database)
|
|||
OleVerify(srowset->GetRowset(NULL, DBSCHEMA_TABLES, 1, restrictions, trowset.GetIID(), 0, NULL, trowset.SetUnk()));
|
||||
One<OleDBConnection> 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<String> OleDBSession::EnumPrimaryKey(String database, String table)
|
|||
trowset.GetIID(), 0, NULL, trowset.SetUnk()));
|
||||
One<OleDBConnection> conn = new OleDBConnection(this);
|
||||
conn->Execute(trowset);
|
||||
Sql cursor(-conn);
|
||||
Sql0 cursor;
|
||||
Attach(cursor, -conn);
|
||||
int cname = -1;
|
||||
int cord = -1;
|
||||
Vector<int> ordinal;
|
||||
|
|
|
|||
|
|
@ -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<String> SqlSession::EnumUsers() { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumDatabases() { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumTables(String database) { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumViews(String database) { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumSequences(String database) { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumPrimaryKey(String database, String table) { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumReservedWords() { return Vector<String>(); }
|
||||
String SqlSession::EnumRowID(String database, String table) { return Null; }
|
||||
|
||||
Vector<SqlColumnInfo> SqlSession::EnumColumns(String database, String table)
|
||||
{
|
||||
Sql cursor(*this);
|
||||
Vector<SqlColumnInfo> 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<String> SqlSession::EnumUsers() { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumDatabases() { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumTables(String database) { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumViews(String database) { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumSequences(String database) { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumPrimaryKey(String database, String table) { return Vector<String>(); }
|
||||
Vector<String> SqlSession::EnumReservedWords() { return Vector<String>(); }
|
||||
String SqlSession::EnumRowID(String database, String table) { return Null; }
|
||||
|
||||
Vector<SqlColumnInfo> SqlSession::EnumColumns(String database, String table)
|
||||
{
|
||||
Sql cursor(*this);
|
||||
Vector<SqlColumnInfo> 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -322,6 +322,8 @@ protected:
|
|||
|
||||
void SessionClose();
|
||||
|
||||
static void Attach(Sql& sql, SqlConnection *con);
|
||||
|
||||
public:
|
||||
virtual void Begin();
|
||||
virtual void Commit();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue