My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#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
static bool sPerThread;

thread__ SqlSession *sThreadSession;
thread__ SqlSession *sThreadSessionR;

void Sql::PerThread(bool b)
{
sPerThread = b;
}

void SqlSession::PerThread(bool b)
{
sPerThread = b;
}
#endif

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;
}
NEVER();
}

Sql& AppCursor()
{
#ifdef _MULTITHREADED
if(sPerThread) {
if(sThreadSession)
return sThreadSession->GetSessionSql();
}
else
#endif
if(sGlobalSession)
return sGlobalSession->GetSessionSql();
static Sql *empty;
ONCELOCK {
static Sql0 h;
empty = &h;
}
return *empty;
}

Sql& AppCursorR()
{
#ifdef _MULTITHREADED
if(sPerThread) {
if(sThreadSessionR)
return sThreadSessionR->GetSessionSqlR();
}
else
#endif
if(sGlobalSessionR)
return sGlobalSessionR->GetSessionSqlR();
#ifdef _MULTITHREADED
if(sPerThread) {
if(sThreadSession)
return sThreadSession->GetSessionSqlR();
}
else
#endif
if(sGlobalSession)
return sGlobalSession->GetSessionSqlR();
static Sql *empty;
ONCELOCK {
static Sql0 h;
empty = &h;
}
return *empty;
}

END_UPP_NAMESPACE

Change log

r4631 by cxl on Feb 28, 2012   Diff
Sql: Sql/SqlSession::PerThread
Go to: 
Project members, sign in to write a code review

Older revisions

r4353 by cxl on Dec 28, 2011   Diff
OleDB: fixed for private Connection in
Sql
r4331 by cxl on Dec 19, 2011   Diff
Sql: SqlSession::ThrowOnError
r4305 by cxl on Dec 15, 2011   Diff
Sql: Sql0 (without session)
All revisions of this file

File info

Size: 5379 bytes, 215 lines
Powered by Google Project Hosting