diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-25 17:28:38 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-25 17:28:38 +0300 |
commit | d9f372d7b1bc1abbff5fdf9735118290cd024d5e (patch) | |
tree | 49bc3160ea184e19cd5cb6a7404dee42311c0fd7 /libodb-pgsql/odb/pgsql/query.txx | |
parent | 55e14d8f9697adeeb05fcd23cf8f19c33452bb56 (diff) |
Turn libodb-pgsql repository into package for muti-package repositorylibodb-pgsql
Diffstat (limited to 'libodb-pgsql/odb/pgsql/query.txx')
-rw-r--r-- | libodb-pgsql/odb/pgsql/query.txx | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/libodb-pgsql/odb/pgsql/query.txx b/libodb-pgsql/odb/pgsql/query.txx new file mode 100644 index 0000000..44dae30 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/query.txx @@ -0,0 +1,168 @@ +// file : odb/pgsql/query.txx +// license : GNU GPL v2; see accompanying LICENSE file + +namespace odb +{ + namespace pgsql + { + // + // query_base + // + + template <database_type_id ID> + query_base:: + query_base (const query_column<bool, ID>& c) + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + // Cannot use IS TRUE here since database type can be a non- + // integral type. + // + append (c.table (), c.column ()); + append ("="); + append<bool, ID> (val_bind<bool> (true), c.conversion ()); + } + + // + // query_column + // + + // in + // + template <typename T, database_type_id ID> + query_base query_column<T, ID>:: + in (decayed_type v1, decayed_type v2) const + { + query_base q (table_, column_); + q += "IN ("; + q.append<T, ID> (val_bind<T> (v1), conversion_); + q += ","; + q.append<T, ID> (val_bind<T> (v2), conversion_); + q += ")"; + return q; + } + + template <typename T, database_type_id ID> + query_base query_column<T, ID>:: + in (decayed_type v1, decayed_type v2, decayed_type v3) const + { + query_base q (table_, column_); + q += "IN ("; + q.append<T, ID> (val_bind<T> (v1), conversion_); + q += ","; + q.append<T, ID> (val_bind<T> (v2), conversion_); + q += ","; + q.append<T, ID> (val_bind<T> (v3), conversion_); + q += ")"; + return q; + } + + template <typename T, database_type_id ID> + query_base query_column<T, ID>:: + in (decayed_type v1, decayed_type v2, decayed_type v3, + decayed_type v4) const + { + query_base q (table_, column_); + q += "IN ("; + q.append<T, ID> (val_bind<T> (v1), conversion_); + q += ","; + q.append<T, ID> (val_bind<T> (v2), conversion_); + q += ","; + q.append<T, ID> (val_bind<T> (v3), conversion_); + q += ","; + q.append<T, ID> (val_bind<T> (v4), conversion_); + q += ")"; + return q; + } + + template <typename T, database_type_id ID> + query_base query_column<T, ID>:: + in (decayed_type v1, decayed_type v2, decayed_type v3, decayed_type v4, + decayed_type v5) const + { + query_base q (table_, column_); + q += "IN ("; + q.append<T, ID> (val_bind<T> (v1), conversion_); + q += ","; + q.append<T, ID> (val_bind<T> (v2), conversion_); + q += ","; + q.append<T, ID> (val_bind<T> (v3), conversion_); + q += ","; + q.append<T, ID> (val_bind<T> (v4), conversion_); + q += ","; + q.append<T, ID> (val_bind<T> (v5), conversion_); + q += ")"; + return q; + } + + template <typename T, database_type_id ID> + template <typename I> + query_base query_column<T, ID>:: + in_range (I begin, I end) const + { + if (begin != end) + { + query_base q (table_, column_); + q += "IN ("; + + for (I i (begin); i != end; ++i) + { + if (i != begin) + q += ","; + + q.append<T, ID> (val_bind<T> (*i), conversion_); + } + + q += ")"; + return q; + } + else + return query_base (false); + } + + // like + // + template <typename T, database_type_id ID> + query_base query_column<T, ID>:: + like (val_bind<T> p) const + { + query_base q (table_, column_); + q += "LIKE"; + q.append<T, ID> (p, conversion_); + return q; + } + + template <typename T, database_type_id ID> + query_base query_column<T, ID>:: + like (ref_bind<T> p) const + { + query_base q (table_, column_); + q += "LIKE"; + q.append<T, ID> (p, conversion_); + return q; + } + + template <typename T, database_type_id ID> + query_base query_column<T, ID>:: + like (val_bind<T> p, decayed_type e) const + { + query_base q (table_, column_); + q += "LIKE"; + q.append<T, ID> (p, conversion_); + q += "ESCAPE"; + q.append<T, ID> (val_bind<T> (e), conversion_); + return q; + } + + template <typename T, database_type_id ID> + query_base query_column<T, ID>:: + like (ref_bind<T> p, decayed_type e) const + { + query_base q (table_, column_); + q += "LIKE"; + q.append<T, ID> (p, conversion_); + q += "ESCAPE"; + q.append<T, ID> (val_bind<T> (e), conversion_); + return q; + } + } +} |