From 0bf87e33b786fc64ae5bf059205de1fa674ab788 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Mon, 4 Jul 2011 10:11:02 +0200 Subject: Add query and result implementation --- odb/pgsql/query.txx | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 odb/pgsql/query.txx (limited to 'odb/pgsql/query.txx') 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 +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +namespace odb +{ + namespace pgsql + { + // query + // + + template + query:: + query (const query_column& 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 (val_bind (true)); + } + + // query_column + // + template + query query_column:: + in (const T& v1, const T& v2) const + { + query q (name_); + q += "IN ("; + q.append (val_bind (v1)); + q += ","; + q.append (val_bind (v2)); + q += ")"; + return q; + } + + template + query query_column:: + in (const T& v1, const T& v2, const T& v3) const + { + query q (name_); + q += "IN ("; + q.append (val_bind (v1)); + q += ","; + q.append (val_bind (v2)); + q += ","; + q.append (val_bind (v3)); + q += ")"; + return q; + } + + template + query query_column:: + in (const T& v1, const T& v2, const T& v3, const T& v4) const + { + query q (name_); + q += "IN ("; + q.append (val_bind (v1)); + q += ","; + q.append (val_bind (v2)); + q += ","; + q.append (val_bind (v3)); + q += ","; + q.append (val_bind (v4)); + q += ")"; + return q; + } + + template + query query_column:: + in (const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) const + { + query q (name_); + q += "IN ("; + q.append (val_bind (v1)); + q += ","; + q.append (val_bind (v2)); + q += ","; + q.append (val_bind (v3)); + q += ","; + q.append (val_bind (v4)); + q += ","; + q.append (val_bind (v5)); + q += ")"; + return q; + } + + template + template + query query_column:: + 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 (val_bind (*i)); + } + q += ")"; + return q; + } + } +} -- cgit v1.1