aboutsummaryrefslogtreecommitdiff
path: root/common/query/basics/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-02-21 11:07:26 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-02-21 11:09:13 +0200
commit34d177d03f5020ca0ec4bf9b77e20951ed17ff29 (patch)
treec13c3e45449ec60229eec91842de73e1db44ae7d /common/query/basics/driver.cxx
parentf06485aab7bb076a2e5a35db50920377de1dc1b9 (diff)
Add support for pattern matching (SQL LIKE)
Diffstat (limited to 'common/query/basics/driver.cxx')
-rw-r--r--common/query/basics/driver.cxx32
1 files changed, 32 insertions, 0 deletions
diff --git a/common/query/basics/driver.cxx b/common/query/basics/driver.cxx
index a87a0b0..ee8e3b1 100644
--- a/common/query/basics/driver.cxx
+++ b/common/query/basics/driver.cxx
@@ -247,6 +247,9 @@ main (int argc, char* argv[])
db->query<person> (query::first_name.in ("John", "Jane"));
db->query<person> (query::first_name.in_range (names, names_end));
+ db->query<person> (query::first_name.like ("J%"));
+ db->query<person> (query::first_name.like ("J%!%", "!"));
+
// Query operators.
//
db->query<person> (query::age == 30 && query::last_name == "Doe");
@@ -598,6 +601,35 @@ main (int argc, char* argv[])
}
}
#endif
+
+ // Test like.
+ //
+ cout << "test 020" << endl;
+ {
+ transaction t (db->begin ());
+
+ result r (db->query<person> (query::first_name.like ("Jo%")));
+ print (r);
+
+ r = db->query<person> (!query::first_name.like ("Jo%"));
+ print (r);
+
+ r = db->query<person> (query::first_name.like ("Jo!%", "!"));
+ print (r);
+
+ // In Oracle one can only escape special characters (% and _).
+ //
+#if defined(DATABASE_ORACLE)
+ string v ("Ja%");
+#else
+ string v ("!Ja%");
+#endif
+
+ r = db->query<person> (query::first_name.like (query::_ref (v), "!"));
+ print (r);
+
+ t.commit ();
+ }
}
catch (const odb::exception& e)
{