From de2191b220bfb4602487ff3bf773530a6df05e28 Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 21 Nov 2008 20:09:31 +0000 Subject: [PATCH] SqlRaw support in OleDB git-svn-id: svn://ultimatepp.org/upp/trunk@661 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlLib/Static.cpp | 5 ++++ uppsrc/CtrlLib/StaticCtrl.h | 1 + uppsrc/OleDB/OleDB.cpp | 22 ++++++++++++++++- uppsrc/OleDB/OleDBSchema.h | 3 +++ uppsrc/PostgreSQL/PostgreSQL.cpp | 4 +-- uppsrc/PostgreSQL/PostgreSQL.h | 2 -- uppsrc/Sql/Sqls.h | 4 ++- uppsrc/Sql/src.tpp/SqlRaw$en-us.tpp | 38 +++++++++++++++++++++++++++++ 8 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 uppsrc/Sql/src.tpp/SqlRaw$en-us.tpp diff --git a/uppsrc/CtrlLib/Static.cpp b/uppsrc/CtrlLib/Static.cpp index 92c817069..faea4e0b8 100644 --- a/uppsrc/CtrlLib/Static.cpp +++ b/uppsrc/CtrlLib/Static.cpp @@ -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); diff --git a/uppsrc/CtrlLib/StaticCtrl.h b/uppsrc/CtrlLib/StaticCtrl.h index a66d8f9c2..2364bf2dd 100644 --- a/uppsrc/CtrlLib/StaticCtrl.h +++ b/uppsrc/CtrlLib/StaticCtrl.h @@ -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; diff --git a/uppsrc/OleDB/OleDB.cpp b/uppsrc/OleDB/OleDB.cpp index 855132991..925faff3a 100644 --- a/uppsrc/OleDB/OleDB.cpp +++ b/uppsrc/OleDB/OleDB.cpp @@ -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; diff --git a/uppsrc/OleDB/OleDBSchema.h b/uppsrc/OleDB/OleDBSchema.h index 1b73040d2..8c57548e6 100644 --- a/uppsrc/OleDB/OleDBSchema.h +++ b/uppsrc/OleDB/OleDBSchema.h @@ -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") diff --git a/uppsrc/PostgreSQL/PostgreSQL.cpp b/uppsrc/PostgreSQL/PostgreSQL.cpp index b50250b6a..5fa67891f 100644 --- a/uppsrc/PostgreSQL/PostgreSQL.cpp +++ b/uppsrc/PostgreSQL/PostgreSQL.cpp @@ -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); diff --git a/uppsrc/PostgreSQL/PostgreSQL.h b/uppsrc/PostgreSQL/PostgreSQL.h index 71571217e..469abf5bc 100644 --- a/uppsrc/PostgreSQL/PostgreSQL.h +++ b/uppsrc/PostgreSQL/PostgreSQL.h @@ -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, diff --git a/uppsrc/Sql/Sqls.h b/uppsrc/Sql/Sqls.h index 63f98b2bf..d47f28626 100644 --- a/uppsrc/Sql/Sqls.h +++ b/uppsrc/Sql/Sqls.h @@ -17,7 +17,9 @@ public: void SetSessionError(const SqlSession& session); }; -class SqlRaw : public String, AssignValueTypeNo { +enum { SQLRAW_V = 34 }; + +class SqlRaw : public String, AssignValueTypeNo { public: operator Value() const { return RawValue(*this); } SqlRaw(const Value& q) diff --git a/uppsrc/Sql/src.tpp/SqlRaw$en-us.tpp b/uppsrc/Sql/src.tpp/SqlRaw$en-us.tpp new file mode 100644 index 000000000..3d7031ecc --- /dev/null +++ b/uppsrc/Sql/src.tpp/SqlRaw$en-us.tpp @@ -0,0 +1,38 @@ +topic "class SqlRaw : public String, private AssignValueTypeNo "; +[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; ] \ No newline at end of file