mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
Sql: SplitSqlSet (+ fix of SqlBinary compilation)
git-svn-id: svn://ultimatepp.org/upp/trunk@7858 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
a959657382
commit
67e889d96e
2 changed files with 34 additions and 7 deletions
|
|
@ -53,9 +53,11 @@ String SqlId::Quoted() const
|
||||||
return id.ToString();
|
return id.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqlCompile(const char *&s, StringBuffer *r, byte dialect)
|
void SqlCompile(const char *&s, StringBuffer *r, byte dialect, Vector<SqlVal> *split)
|
||||||
{
|
{
|
||||||
char quote = dialect == MY_SQL ? '`' : '\"';
|
char quote = dialect == MY_SQL ? '`' : '\"';
|
||||||
|
const char *b = s;
|
||||||
|
int lvl = 0;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
int c = *s++;
|
int c = *s++;
|
||||||
switch(c) {
|
switch(c) {
|
||||||
|
|
@ -121,16 +123,16 @@ void SqlCompile(const char *&s, StringBuffer *r, byte dialect)
|
||||||
for(;;) {
|
for(;;) {
|
||||||
c = *s++;
|
c = *s++;
|
||||||
if(c & dialect) {
|
if(c & dialect) {
|
||||||
SqlCompile(s, er, dialect);
|
SqlCompile(s, er, dialect, NULL);
|
||||||
er = NULL;
|
er = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
SqlCompile(s, NULL, dialect);
|
SqlCompile(s, NULL, dialect, NULL);
|
||||||
if(*s == '\0')
|
if(*s == '\0')
|
||||||
return;
|
return;
|
||||||
c = *s++;
|
c = *s++;
|
||||||
if(c == SQLC_ELSE) {
|
if(c == SQLC_ELSE) {
|
||||||
SqlCompile(s, er, dialect);
|
SqlCompile(s, er, dialect, NULL);
|
||||||
ASSERT(*s == SQLC_ENDIF);
|
ASSERT(*s == SQLC_ENDIF);
|
||||||
s++;
|
s++;
|
||||||
break;
|
break;
|
||||||
|
|
@ -139,8 +141,8 @@ void SqlCompile(const char *&s, StringBuffer *r, byte dialect)
|
||||||
break;
|
break;
|
||||||
ASSERT(c == SQLC_ELSEIF);
|
ASSERT(c == SQLC_ELSEIF);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case SQLC_DATE: {
|
case SQLC_DATE: {
|
||||||
LTIMING("SqlCompile DATE");
|
LTIMING("SqlCompile DATE");
|
||||||
Date x;
|
Date x;
|
||||||
|
|
@ -234,6 +236,8 @@ void SqlCompile(const char *&s, StringBuffer *r, byte dialect)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
s += l;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SQLC_STRING: {
|
case SQLC_STRING: {
|
||||||
|
|
@ -289,7 +293,20 @@ void SqlCompile(const char *&s, StringBuffer *r, byte dialect)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if(c >= 0 && c < 32) {
|
bool end = c >= 0 && c < 32;
|
||||||
|
if(split) {
|
||||||
|
if(c == '(')
|
||||||
|
lvl++;
|
||||||
|
if(c == ')')
|
||||||
|
lvl--;
|
||||||
|
if((c == ',' && lvl == 0 || end) && s - 1 > b) {
|
||||||
|
while(*b == ' ')
|
||||||
|
b++;
|
||||||
|
split->Add(SqlVal(String(b, s - 1), SqlS::HIGH));
|
||||||
|
b = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(end) {
|
||||||
s--;
|
s--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -309,7 +326,7 @@ String SqlCompile(byte dialect, const String& s)
|
||||||
StringBuffer b;
|
StringBuffer b;
|
||||||
b.Reserve(s.GetLength() + 100);
|
b.Reserve(s.GetLength() + 100);
|
||||||
const char *q = s;
|
const char *q = s;
|
||||||
SqlCompile(q, &b, dialect);
|
SqlCompile(q, &b, dialect, NULL);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -318,6 +335,14 @@ String SqlCompile(const String& s)
|
||||||
return SqlCompile(SQL.GetDialect(), s);
|
return SqlCompile(SQL.GetDialect(), s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector<SqlVal> SplitSqlSet(const SqlSet& set)
|
||||||
|
{
|
||||||
|
const char *s = ~set;
|
||||||
|
Vector<SqlVal> r;
|
||||||
|
SqlCompile(s, NULL, ORACLE, &r);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
String SqlFormat(int x)
|
String SqlFormat(int x)
|
||||||
{
|
{
|
||||||
if(IsNull(x)) return "NULL";
|
if(IsNull(x)) return "NULL";
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,8 @@ public:
|
||||||
String SqlCompile(byte dialect, const String& s);
|
String SqlCompile(byte dialect, const String& s);
|
||||||
String SqlCompile(const String& s);
|
String SqlCompile(const String& s);
|
||||||
|
|
||||||
|
Vector<SqlVal> SplitSqlSet(const SqlSet& set);
|
||||||
|
|
||||||
String SqlFormat(int x);
|
String SqlFormat(int x);
|
||||||
String SqlFormat(double x);
|
String SqlFormat(double x);
|
||||||
String SqlFormat(int64 x);
|
String SqlFormat(int64 x);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue