mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
SqlBinary changed to work as SqlCompile type -> it now should work in PGSQL too
git-svn-id: svn://ultimatepp.org/upp/trunk@1232 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
b4fa5709a8
commit
951d74e221
5 changed files with 64 additions and 7 deletions
|
|
@ -539,7 +539,7 @@ String HexString(const byte *s, int count, int sep)
|
|||
|
||||
String HexString(const String& s, int sep)
|
||||
{
|
||||
return HexString(s, s.GetCount(), sep);
|
||||
return HexString(~s, s.GetCount(), sep);
|
||||
}
|
||||
|
||||
String NormalizeSpaces(const char *s)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ String Encode64(const String& s);
|
|||
String Decode64(const String& s);
|
||||
|
||||
String HexString(const byte *s, int count, int sep = INT_MAX);
|
||||
inline String HexString(const char *s, int count, int sep = INT_MAX) { return HexString((byte *)s, count, sep); }
|
||||
inline String HexString(const void *s, int count, int sep = INT_MAX) { return HexString((byte *)s, count, sep); }
|
||||
String HexString(const String& s, int sep = INT_MAX);
|
||||
|
||||
#ifdef PLATFORM_WINCE
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ enum {
|
|||
SQLC_DATE,
|
||||
SQLC_TIME,
|
||||
SQLC_STRING,
|
||||
SQLC_BINARY,
|
||||
};
|
||||
|
||||
template <class T>
|
||||
|
|
@ -124,6 +125,39 @@ void SqlCompile(const char *&s, StringBuffer *r, byte dialect)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case SQLC_BINARY: {
|
||||
int l;
|
||||
ReadSqlValue(l, s);
|
||||
if(r) {
|
||||
switch(dialect) {
|
||||
case PGSQL: {
|
||||
*r << "\'";
|
||||
const char *e = s + l;
|
||||
while(s < e) {
|
||||
byte c = *s++;
|
||||
if(c < 32 || c > 126 || c == 39 || c == 92) {
|
||||
*r << '\\\\';
|
||||
r->Cat(((c >> 6) & 3) + '0');
|
||||
r->Cat(((c >> 3) & 7) + '0');
|
||||
r->Cat((c & 7) + '0');
|
||||
}
|
||||
}
|
||||
*r << "\'::bytea";
|
||||
}
|
||||
case MSSQL:
|
||||
*r << "0x" << HexString(s, l);
|
||||
break;
|
||||
case SQLITE3:
|
||||
case MY_SQL:
|
||||
*r << "X";
|
||||
default:
|
||||
*r << "\'" << HexString(s, l) << "\'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
s += l;
|
||||
break;
|
||||
}
|
||||
case SQLC_STRING: {
|
||||
int l;
|
||||
ReadSqlValue(l, s);
|
||||
|
|
@ -190,15 +224,20 @@ String SqlFormat(int64 x)
|
|||
return FormatInt64(x);
|
||||
}
|
||||
|
||||
String SqlFormat(const char *s, int l)
|
||||
String SqlFormat0(const char *s, int l, int code)
|
||||
{
|
||||
StringBuffer b(1 + sizeof(int) + l);
|
||||
b[0] = SQLC_STRING;
|
||||
b[0] = code;
|
||||
memcpy(~b + 1, &l, sizeof(int));
|
||||
memcpy(~b + 1 + sizeof(int), s, l);
|
||||
return b;
|
||||
}
|
||||
|
||||
String SqlFormat(const char *s, int l)
|
||||
{
|
||||
return SqlFormat0(s, l, SQLC_STRING);
|
||||
}
|
||||
|
||||
String SqlFormat(const char *s)
|
||||
{
|
||||
return SqlFormat(s, strlen(s));
|
||||
|
|
@ -209,6 +248,16 @@ String SqlFormat(const String& x)
|
|||
return SqlFormat(x, x.GetLength());
|
||||
}
|
||||
|
||||
String SqlFormatBinary(const char *s, int l)
|
||||
{
|
||||
return SqlFormat0(s, l, SQLC_BINARY);
|
||||
}
|
||||
|
||||
String SqlFormatBinary(const String& x)
|
||||
{
|
||||
return SqlFormatBinary(x, x.GetLength());
|
||||
}
|
||||
|
||||
String SqlFormat(Date x)
|
||||
{
|
||||
return MakeSqlValue(SQLC_DATE, x);
|
||||
|
|
|
|||
|
|
@ -406,12 +406,16 @@ SqlVal OuterJoin(SqlCol col)
|
|||
return SqlCol(~col + "(+)");
|
||||
}
|
||||
|
||||
SqlVal SqlBinary(const char *s, int l)
|
||||
{
|
||||
SqlVal x;
|
||||
x.SetHigh(SqlFormatBinary(s, l));
|
||||
return x;
|
||||
}
|
||||
|
||||
SqlVal SqlBinary(const String& data)
|
||||
{
|
||||
String x = SqlCase(MSSQL, "0x")(MY_SQL, "x\'")(SQLITE3, "X\'")("\'");
|
||||
x << HexString(data)
|
||||
<< SqlCase(MSSQL, "")("\'");
|
||||
return SqlVal(x, SqlS::HIGH);
|
||||
return SqlBinary(~data, data.GetCount());
|
||||
}
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ String SqlFormat(const String& x);
|
|||
String SqlFormat(Date x);
|
||||
String SqlFormat(Time x);
|
||||
String SqlFormat(const Value& x);
|
||||
String SqlFormatBinary(const char *s, int l);
|
||||
String SqlFormatBinary(const String& x);
|
||||
|
||||
class SqlCol : Moveable<SqlCol> {
|
||||
String name;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue