From 7761af971a4c51e3d0c8c183d90975c0a2a772ef Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 22 Jan 2012 17:43:56 +0200 Subject: Pass precision and scale to Oracle query_param --- odb/oracle/query.hxx | 91 +++++++++++++++++++++++++++++++++++++++++++++++----- odb/oracle/query.txx | 32 +++++++++--------- 2 files changed, 99 insertions(+), 24 deletions(-) diff --git a/odb/oracle/query.hxx b/odb/oracle/query.hxx index 726086e..5257d24 100644 --- a/odb/oracle/query.hxx +++ b/odb/oracle/query.hxx @@ -27,14 +27,29 @@ namespace odb { namespace oracle { + // For both precision and scale 0 is a valid value. Furthermore, + // scale can be negative. To indicate that these values are not + // specified, we will use 0xFFF which is out of range for both + // precision (0 to 4000) and scale (-84 to 127). Note also that + // string size (stored in precision) is always in bytes. If a + // national string size is specified as a number of characters + // and not bytes, then this will be a conservative estimate (4 + // bytes per character). + // template class val_bind { public: explicit - val_bind (const T& v): val (v) {} + val_bind (const T& v, unsigned short p = 0xFFF, short s = 0xFFF) + : val (v), prec (p), scale (s) + { + } const T& val; + + unsigned short prec; + short scale; }; template @@ -42,9 +57,15 @@ namespace odb { public: explicit - ref_bind (const T& r): ref (r) {} + ref_bind (const T& r, unsigned short p = 0xFFF, short s = 0xFFF) + : ref (r), prec (p), scale (s) + { + } const T& ref; + + unsigned short prec; + short scale; }; struct LIBODB_ORACLE_EXPORT query_param: details::shared_base @@ -194,16 +215,16 @@ namespace odb public: template static val_bind - _val (const T& x) + _val (const T& x, unsigned short prec = 0xFFF, short scale = 0xFFF) { - return val_bind (x); + return val_bind (x, prec, scale); } template static ref_bind - _ref (const T& x) + _ref (const T& x, unsigned short prec = 0xFFF, short scale = 0xFFF) { - return ref_bind (x); + return ref_bind (x, prec, scale); } public: @@ -393,8 +414,11 @@ namespace odb { // Note that we keep shalow copies of the table and column names. // - query_column (const char* table, const char* column) - : table_ (table), column_ (column) + query_column (const char* table, + const char* column, + unsigned short prec = 0xFFF, + short scale = 0xFFF) + : table_ (table), column_ (column), prec_ (prec), scale_ (scale) { } @@ -410,6 +434,18 @@ namespace odb return column_; } + unsigned short + prec () const + { + return prec_; + } + + short + scale () const + { + return scale_; + } + // is_null, is_not_null // public: @@ -460,6 +496,9 @@ namespace odb query equal (val_bind v) const { + v.prec = prec_; + v.scale = scale_; + query q (table_, column_); q += "="; q.append (v); @@ -477,6 +516,9 @@ namespace odb query equal (ref_bind r) const { + r.prec = prec_; + r.scale = scale_; + query q (table_, column_); q += "="; q.append (r); @@ -545,6 +587,9 @@ namespace odb query unequal (val_bind v) const { + v.prec = prec_; + v.scale = scale_; + query q (table_, column_); q += "!="; q.append (v); @@ -562,6 +607,9 @@ namespace odb query unequal (ref_bind r) const { + r.prec = prec_; + r.scale = scale_; + query q (table_, column_); q += "!="; q.append (r); @@ -630,6 +678,9 @@ namespace odb query less (val_bind v) const { + v.prec = prec_; + v.scale = scale_; + query q (table_, column_); q += "<"; q.append (v); @@ -647,6 +698,9 @@ namespace odb query less (ref_bind r) const { + r.prec = prec_; + r.scale = scale_; + query q (table_, column_); q += "<"; q.append (r); @@ -715,6 +769,9 @@ namespace odb query greater (val_bind v) const { + v.prec = prec_; + v.scale = scale_; + query q (table_, column_); q += ">"; q.append (v); @@ -732,6 +789,9 @@ namespace odb query greater (ref_bind r) const { + r.prec = prec_; + r.scale = scale_; + query q (table_, column_); q += ">"; q.append (r); @@ -800,6 +860,9 @@ namespace odb query less_equal (val_bind v) const { + v.prec = prec_; + v.scale = scale_; + query q (table_, column_); q += "<="; q.append (v); @@ -817,6 +880,9 @@ namespace odb query less_equal (ref_bind r) const { + r.prec = prec_; + r.scale = scale_; + query q (table_, column_); q += "<="; q.append (r); @@ -885,6 +951,9 @@ namespace odb query greater_equal (val_bind v) const { + v.prec = prec_; + v.scale = scale_; + query q (table_, column_); q += ">="; q.append (v); @@ -902,6 +971,9 @@ namespace odb query greater_equal (ref_bind r) const { + r.prec = prec_; + r.scale = scale_; + query q (table_, column_); q += ">="; q.append (r); @@ -1048,6 +1120,9 @@ namespace odb private: const char* table_; const char* column_; + + unsigned short prec_; + short scale_; }; // diff --git a/odb/oracle/query.txx b/odb/oracle/query.txx index b8bd3c5..68a950b 100644 --- a/odb/oracle/query.txx +++ b/odb/oracle/query.txx @@ -20,7 +20,7 @@ namespace odb // append (c.table (), c.column ()); append ("="); - append (val_bind (true)); + append (val_bind (true, c.prec (), c.scale ())); } // query_column @@ -31,9 +31,9 @@ namespace odb { query q (table_, column_); q += "IN ("; - q.append (val_bind (v1)); + q.append (val_bind (v1, prec_, scale_)); q += ","; - q.append (val_bind (v2)); + q.append (val_bind (v2, prec_, scale_)); q += ")"; return q; } @@ -44,11 +44,11 @@ namespace odb { query q (table_, column_); q += "IN ("; - q.append (val_bind (v1)); + q.append (val_bind (v1, prec_, scale_)); q += ","; - q.append (val_bind (v2)); + q.append (val_bind (v2, prec_, scale_)); q += ","; - q.append (val_bind (v3)); + q.append (val_bind (v3, prec_, scale_)); q += ")"; return q; } @@ -59,13 +59,13 @@ namespace odb { query q (table_, column_); q += "IN ("; - q.append (val_bind (v1)); + q.append (val_bind (v1, prec_, scale_)); q += ","; - q.append (val_bind (v2)); + q.append (val_bind (v2, prec_, scale_)); q += ","; - q.append (val_bind (v3)); + q.append (val_bind (v3, prec_, scale_)); q += ","; - q.append (val_bind (v4)); + q.append (val_bind (v4, prec_, scale_)); q += ")"; return q; } @@ -76,15 +76,15 @@ namespace odb { query q (table_, column_); q += "IN ("; - q.append (val_bind (v1)); + q.append (val_bind (v1, prec_, scale_)); q += ","; - q.append (val_bind (v2)); + q.append (val_bind (v2, prec_, scale_)); q += ","; - q.append (val_bind (v3)); + q.append (val_bind (v3, prec_, scale_)); q += ","; - q.append (val_bind (v4)); + q.append (val_bind (v4, prec_, scale_)); q += ","; - q.append (val_bind (v5)); + q.append (val_bind (v5, prec_, scale_)); q += ")"; return q; } @@ -102,7 +102,7 @@ namespace odb if (i != begin) q += ","; - q.append (val_bind (*i)); + q.append (val_bind (*i, prec_, scale_)); } q += ")"; return q; -- cgit v1.1