aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-01-22 17:43:56 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-01-22 17:43:56 +0200
commit7761af971a4c51e3d0c8c183d90975c0a2a772ef (patch)
tree4127b45e39ee461d34c8199c0dcc73fba1154d0e
parent33a0d3bd87b17977a2c5aec9c1b19ed81303542a (diff)
Pass precision and scale to Oracle query_param
-rw-r--r--odb/oracle/query.hxx91
-rw-r--r--odb/oracle/query.txx32
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 <typename T>
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 <typename T>
@@ -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 <typename T>
static val_bind<T>
- _val (const T& x)
+ _val (const T& x, unsigned short prec = 0xFFF, short scale = 0xFFF)
{
- return val_bind<T> (x);
+ return val_bind<T> (x, prec, scale);
}
template <typename T>
static ref_bind<T>
- _ref (const T& x)
+ _ref (const T& x, unsigned short prec = 0xFFF, short scale = 0xFFF)
{
- return ref_bind<T> (x);
+ return ref_bind<T> (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<T> v) const
{
+ v.prec = prec_;
+ v.scale = scale_;
+
query q (table_, column_);
q += "=";
q.append<T, ID> (v);
@@ -477,6 +516,9 @@ namespace odb
query
equal (ref_bind<T> r) const
{
+ r.prec = prec_;
+ r.scale = scale_;
+
query q (table_, column_);
q += "=";
q.append<T, ID> (r);
@@ -545,6 +587,9 @@ namespace odb
query
unequal (val_bind<T> v) const
{
+ v.prec = prec_;
+ v.scale = scale_;
+
query q (table_, column_);
q += "!=";
q.append<T, ID> (v);
@@ -562,6 +607,9 @@ namespace odb
query
unequal (ref_bind<T> r) const
{
+ r.prec = prec_;
+ r.scale = scale_;
+
query q (table_, column_);
q += "!=";
q.append<T, ID> (r);
@@ -630,6 +678,9 @@ namespace odb
query
less (val_bind<T> v) const
{
+ v.prec = prec_;
+ v.scale = scale_;
+
query q (table_, column_);
q += "<";
q.append<T, ID> (v);
@@ -647,6 +698,9 @@ namespace odb
query
less (ref_bind<T> r) const
{
+ r.prec = prec_;
+ r.scale = scale_;
+
query q (table_, column_);
q += "<";
q.append<T, ID> (r);
@@ -715,6 +769,9 @@ namespace odb
query
greater (val_bind<T> v) const
{
+ v.prec = prec_;
+ v.scale = scale_;
+
query q (table_, column_);
q += ">";
q.append<T, ID> (v);
@@ -732,6 +789,9 @@ namespace odb
query
greater (ref_bind<T> r) const
{
+ r.prec = prec_;
+ r.scale = scale_;
+
query q (table_, column_);
q += ">";
q.append<T, ID> (r);
@@ -800,6 +860,9 @@ namespace odb
query
less_equal (val_bind<T> v) const
{
+ v.prec = prec_;
+ v.scale = scale_;
+
query q (table_, column_);
q += "<=";
q.append<T, ID> (v);
@@ -817,6 +880,9 @@ namespace odb
query
less_equal (ref_bind<T> r) const
{
+ r.prec = prec_;
+ r.scale = scale_;
+
query q (table_, column_);
q += "<=";
q.append<T, ID> (r);
@@ -885,6 +951,9 @@ namespace odb
query
greater_equal (val_bind<T> v) const
{
+ v.prec = prec_;
+ v.scale = scale_;
+
query q (table_, column_);
q += ">=";
q.append<T, ID> (v);
@@ -902,6 +971,9 @@ namespace odb
query
greater_equal (ref_bind<T> r) const
{
+ r.prec = prec_;
+ r.scale = scale_;
+
query q (table_, column_);
q += ">=";
q.append<T, ID> (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<bool, ID> (val_bind<bool> (true));
+ append<bool, ID> (val_bind<bool> (true, c.prec (), c.scale ()));
}
// query_column
@@ -31,9 +31,9 @@ namespace odb
{
query q (table_, column_);
q += "IN (";
- q.append<T, ID> (val_bind<T> (v1));
+ q.append<T, ID> (val_bind<T> (v1, prec_, scale_));
q += ",";
- q.append<T, ID> (val_bind<T> (v2));
+ q.append<T, ID> (val_bind<T> (v2, prec_, scale_));
q += ")";
return q;
}
@@ -44,11 +44,11 @@ namespace odb
{
query q (table_, column_);
q += "IN (";
- q.append<T, ID> (val_bind<T> (v1));
+ q.append<T, ID> (val_bind<T> (v1, prec_, scale_));
q += ",";
- q.append<T, ID> (val_bind<T> (v2));
+ q.append<T, ID> (val_bind<T> (v2, prec_, scale_));
q += ",";
- q.append<T, ID> (val_bind<T> (v3));
+ q.append<T, ID> (val_bind<T> (v3, prec_, scale_));
q += ")";
return q;
}
@@ -59,13 +59,13 @@ namespace odb
{
query q (table_, column_);
q += "IN (";
- q.append<T, ID> (val_bind<T> (v1));
+ q.append<T, ID> (val_bind<T> (v1, prec_, scale_));
q += ",";
- q.append<T, ID> (val_bind<T> (v2));
+ q.append<T, ID> (val_bind<T> (v2, prec_, scale_));
q += ",";
- q.append<T, ID> (val_bind<T> (v3));
+ q.append<T, ID> (val_bind<T> (v3, prec_, scale_));
q += ",";
- q.append<T, ID> (val_bind<T> (v4));
+ q.append<T, ID> (val_bind<T> (v4, prec_, scale_));
q += ")";
return q;
}
@@ -76,15 +76,15 @@ namespace odb
{
query q (table_, column_);
q += "IN (";
- q.append<T, ID> (val_bind<T> (v1));
+ q.append<T, ID> (val_bind<T> (v1, prec_, scale_));
q += ",";
- q.append<T, ID> (val_bind<T> (v2));
+ q.append<T, ID> (val_bind<T> (v2, prec_, scale_));
q += ",";
- q.append<T, ID> (val_bind<T> (v3));
+ q.append<T, ID> (val_bind<T> (v3, prec_, scale_));
q += ",";
- q.append<T, ID> (val_bind<T> (v4));
+ q.append<T, ID> (val_bind<T> (v4, prec_, scale_));
q += ",";
- q.append<T, ID> (val_bind<T> (v5));
+ q.append<T, ID> (val_bind<T> (v5, prec_, scale_));
q += ")";
return q;
}
@@ -102,7 +102,7 @@ namespace odb
if (i != begin)
q += ",";
- q.append<T, ID> (val_bind<T> (*i));
+ q.append<T, ID> (val_bind<T> (*i, prec_, scale_));
}
q += ")";
return q;