diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-02-21 11:07:26 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-02-21 11:09:13 +0200 |
commit | 34d177d03f5020ca0ec4bf9b77e20951ed17ff29 (patch) | |
tree | c13c3e45449ec60229eec91842de73e1db44ae7d /common | |
parent | f06485aab7bb076a2e5a35db50920377de1dc1b9 (diff) |
Add support for pattern matching (SQL LIKE)
Diffstat (limited to 'common')
-rw-r--r-- | common/query/basics/driver.cxx | 32 | ||||
-rw-r--r-- | common/query/basics/test.std | 10 |
2 files changed, 42 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) { diff --git a/common/query/basics/test.std b/common/query/basics/test.std index 0548968..d420dc4 100644 --- a/common/query/basics/test.std +++ b/common/query/basics/test.std @@ -100,3 +100,13 @@ test 016 test 017 test 018 test 019 +test 020 +John Doe 30 married +Joe Squeaky Dirt 31 single +Johansen J Johansen 32 single + +Jane Doe 29 married + + +Jane Doe 29 married + |