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
#include "Sql.h"

NAMESPACE_UPP

bool StdStatementExecutor::Execute(const String& stmt)
{
cursor.Execute(stmt);
return true;
}

#ifndef NOAPPSQL
struct SQLStatementExecutorClass : StatementExecutor {
virtual bool Execute(const String& stmt) { SQL.Execute(stmt); return true; }
};

StatementExecutor& SQLStatementExecutor() {
return Single<SQLStatementExecutorClass>();
}
#endif

bool SqlPerformScript(SqlSession& session, Stream& script,
Gate2<int, int> progress_canceled, bool stoponerror)
{
String stmt;
int level = 0;
bool ok = true;
while(!script.IsEof()) {
int c = script.Term();
if(IsAlpha(c)) {
String id;
while(IsAlpha(script.Term())) {
c = script.Get();
stmt.Cat(c);
id.Cat(ToUpper(c));
}
if(id == "BEGIN")
level++;
if(id == "END")
level--;
}
else
if(c == '\'') {
stmt.Cat(c);
script.Get();
for(;;) {
c = script.Get();
if(c < 0) {
ok = false;
if(stoponerror)
return false;
break;
}
stmt.Cat(c);
if(c == '\'')
break;
}
}
else
if(c == ';' && level == 0) {
Sql sql(session);
session.ClearError();
int q = 0;
while(stmt[q] == '\r' || stmt[q] == '\n')
q++;
stmt = stmt.Mid(q);
if(!sql.Execute(stmt)) {
ok = false;
if(stoponerror)
break;
}
stmt.Clear();
script.Get();
}
else {
if(c == '(')
level++;
if(c == ')')
level--;
if(c != '\r') {
if(session.GetDialect() == ORACLE && c == '\n')
stmt.Cat('\r');
stmt.Cat(c);
}
script.Get();
}
}
return ok;
}

bool SqlPerformScript(SqlSession& session, const String& script,
Gate2<int, int> progress_canceled, bool stoponerror)
{
StringStream ss(script);
return SqlPerformScript(session, ss, progress_canceled, stoponerror);
}

#ifndef NOAPPSQL

bool SqlPerformScript(Stream& script,
Gate2<int, int> progress_canceled, bool stoponerror)
{
return SqlPerformScript(SQL.GetSession(), script, progress_canceled, stoponerror);
}

bool SqlPerformScript(const String& script,
Gate2<int, int> progress_canceled, bool stoponerror)
{
return SqlPerformScript(SQL.GetSession(), script, progress_canceled, stoponerror);
}

#endif

END_UPP_NAMESPACE

Change log

r4290 by cxl on Dec 10, 2011   Diff
Sql: Refactored SQL 'default app cursor',
added per-thread SQL option, added
secondary SQLR 'default app cursor'
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 2274 bytes, 113 lines
Powered by Google Project Hosting