mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-29 06:12:18 -06:00
Sql: Refactored SQL 'default app cursor', added per-thread SQL option, added secondary SQLR 'default app cursor'
git-svn-id: svn://ultimatepp.org/upp/trunk@4290 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
97bfa2f508
commit
6aefb7f0b1
14 changed files with 913 additions and 788 deletions
113
uppsrc/Sql/Script.cpp
Normal file
113
uppsrc/Sql/Script.cpp
Normal file
|
|
@ -0,0 +1,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
|
||||
Loading…
Add table
Add a link
Reference in a new issue