aboutsummaryrefslogtreecommitdiff
path: root/odb/pgsql/query.txx
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-07-04 10:11:02 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-07-04 10:11:02 +0200
commit0bf87e33b786fc64ae5bf059205de1fa674ab788 (patch)
treec11e4e5a3e24b4a13b950cc55334d4b3dfcfb064 /odb/pgsql/query.txx
parentbef81b1627c2c31dc22cd2b18920ed8db230a94c (diff)
Add query and result implementation
Diffstat (limited to 'odb/pgsql/query.txx')
-rw-r--r--odb/pgsql/query.txx110
1 files changed, 110 insertions, 0 deletions
diff --git a/odb/pgsql/query.txx b/odb/pgsql/query.txx
new file mode 100644
index 0000000..7d80f2b
--- /dev/null
+++ b/odb/pgsql/query.txx
@@ -0,0 +1,110 @@
+// file : odb/pgsql/query.txx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+namespace odb
+{
+ namespace pgsql
+ {
+ // query
+ //
+
+ template <database_type_id ID>
+ query::
+ query (const query_column<bool, ID>& c)
+ : clause_ (c.name ()), binding_ (0, 0), native_binding_ (0, 0, 0, 0)
+ {
+ // Cannot use IS TRUE here since database type can be a non-
+ // integral type.
+ //
+ clause_ += " = ";
+ append<bool, ID> (val_bind<bool> (true));
+ }
+
+ // query_column
+ //
+ template <typename T, database_type_id ID>
+ query query_column<T, ID>::
+ in (const T& v1, const T& v2) const
+ {
+ query q (name_);
+ q += "IN (";
+ q.append<T, ID> (val_bind<T> (v1));
+ q += ",";
+ q.append<T, ID> (val_bind<T> (v2));
+ q += ")";
+ return q;
+ }
+
+ template <typename T, database_type_id ID>
+ query query_column<T, ID>::
+ in (const T& v1, const T& v2, const T& v3) const
+ {
+ query q (name_);
+ q += "IN (";
+ q.append<T, ID> (val_bind<T> (v1));
+ q += ",";
+ q.append<T, ID> (val_bind<T> (v2));
+ q += ",";
+ q.append<T, ID> (val_bind<T> (v3));
+ q += ")";
+ return q;
+ }
+
+ template <typename T, database_type_id ID>
+ query query_column<T, ID>::
+ in (const T& v1, const T& v2, const T& v3, const T& v4) const
+ {
+ query q (name_);
+ q += "IN (";
+ q.append<T, ID> (val_bind<T> (v1));
+ q += ",";
+ q.append<T, ID> (val_bind<T> (v2));
+ q += ",";
+ q.append<T, ID> (val_bind<T> (v3));
+ q += ",";
+ q.append<T, ID> (val_bind<T> (v4));
+ q += ")";
+ return q;
+ }
+
+ template <typename T, database_type_id ID>
+ query query_column<T, ID>::
+ in (const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) const
+ {
+ query q (name_);
+ q += "IN (";
+ q.append<T, ID> (val_bind<T> (v1));
+ q += ",";
+ q.append<T, ID> (val_bind<T> (v2));
+ q += ",";
+ q.append<T, ID> (val_bind<T> (v3));
+ q += ",";
+ q.append<T, ID> (val_bind<T> (v4));
+ q += ",";
+ q.append<T, ID> (val_bind<T> (v5));
+ q += ")";
+ return q;
+ }
+
+ template <typename T, database_type_id ID>
+ template <typename I>
+ query query_column<T, ID>::
+ in_range (I begin, I end) const
+ {
+ query q (name_);
+ q += "IN (";
+
+ for (I i (begin); i != end; ++i)
+ {
+ if (i != begin)
+ q += ",";
+
+ q.append<T, ID> (val_bind<T> (*i));
+ }
+ q += ")";
+ return q;
+ }
+ }
+}