SqlRaw support in OleDB

git-svn-id: svn://ultimatepp.org/upp/trunk@661 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2008-11-21 20:09:31 +00:00
parent 660ce4fe91
commit de2191b220
8 changed files with 73 additions and 6 deletions

View file

@ -338,6 +338,11 @@ void DisplayCtrl::SetData(const Value& v)
Refresh();
}
Value DisplayCtrl::GetData() const
{
return pr.GetValue();
}
void DisplayCtrl::SetDisplay(const Display& d)
{
pr.SetDisplay(d);

View file

@ -101,6 +101,7 @@ public:
virtual void Paint(Draw& w);
virtual Size GetMinSize() const;
virtual void SetData(const Value& v);
virtual Value GetData() const;
private:
PaintRect pr;

View file

@ -502,6 +502,16 @@ void OleDBConnection::SetParam(int i, const Value& r)
par.bindproc = &DBInDouble;
}
break;
case SQLRAW_V:
l = String(SqlRaw(r)).GetLength();
if(par.vtype != SQLRAW_V || par.alloc < l) {
ClearArgs();
par.vtype = SQLRAW_V;
par.alloc = max(2 * l, 32);
par.bindproc = &DBInString;
}
break;
case STRING_V:
l = String(r).GetLength();
@ -522,7 +532,7 @@ void OleDBConnection::SetParam(int i, const Value& r)
par.bindproc = &DBInWString;
}
break;
case DATE_V:
case TIME_V:
if(par.vtype != TIME_V) {
@ -799,6 +809,16 @@ void OleDBConnection::SyncArgs()
rowbytes += 8;
break;
case SQLRAW_V:
cb->wType = DBTYPE_BYTES;
cb->dwPart = DBPART_STATUS | DBPART_VALUE | DBPART_LENGTH;
cb->cbMaxLen = par.alloc + 1;
cb->obValue = rowbytes;
rowbytes = (rowbytes + par.alloc + 1 + 3) & -4;
cb->obLength = rowbytes;
rowbytes += sizeof(DBLENGTH);
break;
case STRING_V:
cb->wType = DBTYPE_STR;
cb->dwPart = DBPART_STATUS | DBPART_VALUE | DBPART_LENGTH;

View file

@ -28,6 +28,9 @@
#define STRING_(x, n) COLUMN_(OleDBTextType(n), String, x, n, 0)
#define STRING_ARRAY_(x, n, items) COLUMN_ARRAY_(OleDBTextType(n), String, x, n, 0, items)
#define LONGRAW(x) COLUMN("varbinary(max)", String, x, 0, 0)
#define LONGRAW_(x) COLUMN_("varbinary(max)", String, x, 0, 0)
#define PRIMARY_KEY INLINE_ATTRIBUTE("primary key")
#define KEY INLINE_ATTRIBUTE("key")
#define NOT_NULL INLINE_ATTRIBUTE("not null")

View file

@ -51,7 +51,7 @@ int OidToType(Oid oid)
case PGSQL_TIMESTAMPZOID:
return TIME_V;
case PGSQL_BYTEAOID:
return BYTEA_V;
return SQLRAW_V;
}
return STRING_V;
}
@ -357,7 +357,7 @@ void PostgreSQLConnection::SetParam(int i, const Value& r)
p = "NULL";
else
switch(r.GetType()) {
case BYTEA_V: {
case SQLRAW_V: {
String raw = SqlRaw(r);
size_t rl;
unsigned char *s = PQescapeByteaConn(conn, (const byte *)~raw, raw.GetLength(), &rl);

View file

@ -14,8 +14,6 @@ NAMESPACE_UPP
// Postgre -> Value types
// Bytea_v values are stored as bytea data, but recived as string type
const int BYTEA_V = 34;
const char *PostgreSQLReadString(const char *s, String& stmt);
bool PostgreSQLPerformScript(const String& text,

View file

@ -17,7 +17,9 @@ public:
void SetSessionError(const SqlSession& session);
};
class SqlRaw : public String, AssignValueTypeNo<SqlRaw, 34> {
enum { SQLRAW_V = 34 };
class SqlRaw : public String, AssignValueTypeNo<SqlRaw, SQLRAW_V> {
public:
operator Value() const { return RawValue<SqlRaw>(*this); }
SqlRaw(const Value& q)

View file

@ -0,0 +1,38 @@
topic "class SqlRaw : public String, private AssignValueTypeNo<SqlRaw, SQLRAW_V> ";
[2 $$0,0#00000000000000000000000000000000:Default]
[l288;i1120;a17;O9;~~~.1408;2 $$1,0#10431211400427159095818037425705:param]
[a83;*R6 $$2,5#31310162474203024125188417583966:caption]
[H4;b83;*4 $$3,5#07864147445237544204411237157677:title]
[i288;O9;C2 $$4,6#40027414424643823182269349404212:item]
[b42;a42;2 $$5,5#45413000475342174754091244180557:text]
[l288;b17;a17;2 $$6,6#27521748481378242620020725143825:desc]
[l321;C@5;1 $$7,7#20902679421464641399138805415013:code]
[b2503;2 $$8,0#65142375456100023862071332075487:separator]
[*@(0.0.255)2 $$9,0#83433469410354161042741608181528:base]
[C2 $$10,0#37138531426314131251341829483380:class]
[l288;a17;*1 $$11,11#70004532496200323422659154056402:requirement]
[i417;b42;a42;O9;~~~.416;2 $$12,12#10566046415157235020018451313112:tparam]
[b167;C2 $$13,13#92430459443460461911108080531343:item1]
[i288;a42;O9;C2 $$14,14#77422149456609303542238260500223:item2]
[*@2$(0.128.128)2 $$15,15#34511555403152284025741354420178:NewsDate]
[l321;*C$7;2 $$16,16#03451589433145915344929335295360:result]
[l321;b83;a83;*C$7;2 $$17,17#07531550463529505371228428965313:result`-line]
[l160;*C+117 $$18,5#88603949442205825958800053222425:package`-title]
[2 $$19,0#53580023442335529039900623488521:gap]
[C2 $$20,20#70211524482531209251820423858195:class`-nested]
[b50;2 $$21,21#03324558446220344731010354752573:Par]
[i448;a25;kKO9; $$22,0#37138531426314131252341829483380:structitem]
[0 $$23,0#96390100711032703541132217272105:end]
[{_}%EN-US
[s22;:SqlRaw`:`:class:%- [@(0.0.255) class]_[* SqlRaw]_:_[@(0.0.255) public]_[*@3 String],
[@(0.0.255) private]_[*@3 AssignValueTypeNo][@(0.0.255) <][* SqlRaw],
SQLRAW`_V[@(0.0.255) >]_&]
[s6; This type represents a string with binary data. It is required
because otherwise Sql interface would be unable to tell which
sql statement parameters should be treated as regular texts and
which parameters are raw binary data (to be stored into raw binary
data columns).&]
[s6; Note that only input parameters `- values in Insert/Update statements
`- can be SqlRaw. When fetching data from database, normal String
values are returned for binary columns.&]
[s0; ]