SqlPerformScript (intended to replace all those ugly ODBCPerformScript etc..)

git-svn-id: svn://ultimatepp.org/upp/trunk@1233 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-05-25 09:37:24 +00:00
parent 951d74e221
commit d2f4e3a995
2 changed files with 84 additions and 0 deletions

View file

@ -304,6 +304,81 @@ void SqlStatement::Force() const {
Value SqlStatement::Fetch() const {
return Fetch(SQL);
}
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();
if(!sql.Execute(stmt)) {
ok = false;
if(stoponerror)
break;
}
stmt.Clear();
script.Get();
}
else
stmt.Cat(script.Get());
}
return ok;
}
bool SqlPerformScript(Stream& script,
Gate2<int, int> progress_canceled, bool stoponerror)
{
SqlPerformScript(SQL.GetSession(), script, progress_canceled, stoponerror);
}
bool SqlPerformScript(SqlSession& session, const String& script,
Gate2<int, int> progress_canceled, bool stoponerror)
{
StringStream ss(s);
return SqlPerformScript(session, ss, progress_canceled, stoponerror);
}
bool SqlPerformScript(const String& script,
Gate2<int, int> progress_canceled, bool stoponerror)
{
SqlPerformScript(SQL.GetSession(), script, progress_canceled, stoponerror);
}
#endif
END_UPP_NAMESPACE

View file

@ -355,6 +355,15 @@ public:
class OciConnection;
bool SqlPerformScript(SqlSession& session, Stream& script,
Gate2<int, int> progress_canceled = false, bool stoponerror = false);
bool SqlPerformScript(Stream& script,
Gate2<int, int> progress_canceled = false, bool stoponerror = false);
bool SqlPerformScript(SqlSession& session, const String& script,
Gate2<int, int> progress_canceled = false, bool stoponerror = false);
bool SqlPerformScript(const String& script,
Gate2<int, int> progress_canceled = false, bool stoponerror = false);
struct StdStatementExecutor : StatementExecutor {
StdStatementExecutor(SqlSession& session) : cursor(session) {}
virtual bool Execute(const String& stmt);