diff options
-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 + |