aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-02-21 11:07:24 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-02-21 13:39:18 +0200
commit4962329eecb716bc2b99810ec1ac4214606fc1e8 (patch)
treeccb9a2eef35b27f5b9fb5dd152c345eafb5cb04b
parent4fa9af2045dee259949c89cc6e0fa93adc326869 (diff)
Add support for pattern matching (SQL LIKE)
-rw-r--r--odb/query-dynamic.cxx2
-rw-r--r--odb/query-dynamic.hxx43
-rw-r--r--odb/query-dynamic.txx50
3 files changed, 95 insertions, 0 deletions
diff --git a/odb/query-dynamic.cxx b/odb/query-dynamic.cxx
index 4050c90..81959ea 100644
--- a/odb/query-dynamic.cxx
+++ b/odb/query-dynamic.cxx
@@ -100,6 +100,8 @@ namespace odb
case clause_part::op_null:
case clause_part::op_not_null:
case clause_part::op_in:
+ case clause_part::op_like:
+ case clause_part::op_like_escape:
break;
}
}
diff --git a/odb/query-dynamic.hxx b/odb/query-dynamic.hxx
index a2779b1..132e0c0 100644
--- a/odb/query-dynamic.hxx
+++ b/odb/query-dynamic.hxx
@@ -135,6 +135,8 @@ namespace odb
op_not_null, // is_not_null ()
op_in, // in(), data is the number of arguments
+ op_like, // like(pattern)
+ op_like_escape, // like(pattern, escape)
op_eq, // ==
op_ne, // !=
@@ -415,6 +417,47 @@ namespace odb
query_base
in_range (I begin, I end) const;
+ // like
+ //
+ public:
+ query_base
+ like (const T& pattern) const
+ {
+ return like (val_bind<T> (pattern));
+ }
+
+ query_base
+ like (val_bind<T> pattern) const;
+
+ template <typename T2>
+ query_base
+ like (val_bind<T2> pattern) const
+ {
+ return like (val_bind<T> (T (pattern.val)));
+ }
+
+ query_base
+ like (ref_bind<T> pattern) const;
+
+ query_base
+ like (const T& pattern, const T& escape) const
+ {
+ return like (val_bind<T> (pattern), escape);
+ }
+
+ query_base
+ like (val_bind<T> pattern, const T& escape) const;
+
+ template <typename T2>
+ query_base
+ like (val_bind<T2> pattern, const T& escape) const
+ {
+ return like (val_bind<T> (T (pattern.val)), escape);
+ }
+
+ query_base
+ like (ref_bind<T> pattern, const T& escape) const;
+
// ==
//
public:
diff --git a/odb/query-dynamic.txx b/odb/query-dynamic.txx
index 521ab86..95bddf3 100644
--- a/odb/query-dynamic.txx
+++ b/odb/query-dynamic.txx
@@ -4,8 +4,10 @@
namespace odb
{
+ //
// query_base
//
+
template <typename T>
void query_base::
append_val (const T& val, const native_column_info* c)
@@ -21,8 +23,12 @@ namespace odb
p.data = reinterpret_cast<std::size_t> (qp);
}
+ //
// query_column
//
+
+ // in
+ //
template <typename T>
query_base query_column<T>::
in (const T& v1, const T& v2) const
@@ -87,4 +93,48 @@ namespace odb
q.append (query_base::clause_part::op_in, n);
return q;
}
+
+ // like
+ //
+ template <typename T>
+ query_base query_column<T>::
+ like (val_bind<T> p) const
+ {
+ query_base q (native_info);
+ q.append_val (p.val, native_info);
+ q.append (query_base::clause_part::op_like, 0);
+ return q;
+ }
+
+ template <typename T>
+ query_base query_column<T>::
+ like (ref_bind<T> p) const
+ {
+ query_base q (native_info);
+ q.append_ref (p.ptr (), native_info);
+ q.append (query_base::clause_part::op_like, 0);
+ return q;
+ }
+
+ template <typename T>
+ query_base query_column<T>::
+ like (val_bind<T> p, const T& e) const
+ {
+ query_base q (native_info);
+ q.append_val (p.val, native_info);
+ q.append_val (e, native_info);
+ q.append (query_base::clause_part::op_like_escape, 0);
+ return q;
+ }
+
+ template <typename T>
+ query_base query_column<T>::
+ like (ref_bind<T> p, const T& e) const
+ {
+ query_base q (native_info);
+ q.append_ref (p.ptr (), native_info);
+ q.append_val (e, native_info);
+ q.append (query_base::clause_part::op_like_escape, 0);
+ return q;
+ }
}