From 06712594f44e8300570103c05f54d686dfc4fb53 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Wed, 26 Oct 2011 15:37:32 +0200 Subject: Add BLOB comparison and null predicate test cases to query test --- common/query/driver.cxx | 44 +++++++++++++++++++++-- common/query/test.hxx | 35 +++++++++++++++---- common/query/test.std | 93 ++++++++++++++++++++++++++----------------------- 3 files changed, 119 insertions(+), 53 deletions(-) (limited to 'common') diff --git a/common/query/driver.cxx b/common/query/driver.cxx index bc8fd1d..1d19860 100644 --- a/common/query/driver.cxx +++ b/common/query/driver.cxx @@ -13,6 +13,7 @@ #include #include +#include // DATABASE_XXX #include #include "test.hxx" @@ -35,9 +36,16 @@ print (result& r) const char* names[] = { "John", "Jane", "Joe" }; const char** names_end = names + sizeof (names)/sizeof (names[0]); +const char* key_data[] = { "\x23\x03\x15", "\x13\x13\x54", "\x08\x62\x35" }; + int main (int argc, char* argv[]) { + vector + key1 (key_data[0], key_data[0] + 3), + key2 (key_data[1], key_data[1] + 3), + key3 (key_data[2], key_data[2] + 3); + try { auto_ptr db (create_database (argc, argv)); @@ -48,9 +56,9 @@ main (int argc, char* argv[]) // // { - person p1 (1, "John", "Doe", 30, true); - person p2 (2, "Jane", "Doe", 29, true); - person p3 (3, "Joe", "Dirt", 31, false); + person p1 (1, "John", "Doe", 30, true, key1); + person p2 (2, "Jane", "Doe", 29, true, key2); + person p3 (3, "Joe", "Dirt", 31, false, key3); p3.middle_name_.reset (new string ("Squeaky")); person p4 (4, "Johansen", "Johansen", 32, false); p4.middle_name_.reset (new string ("J")); @@ -416,6 +424,36 @@ main (int argc, char* argv[]) t.commit (); } + // Test BLOB column operations. + // + cout << "test 016" << endl; + { + transaction t (db->begin ()); + + result r; + +#ifndef DATABASE_ORACLE + // == + // + r = db->query (query::public_key == key2); + + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->public_key_ == key2); +#endif + + // is_null + // + r = db->query (query::public_key.is_null ()); + print (r); + + // is_not_null + // + r = db->query (query::public_key.is_not_null ()); + print (r); + + t.commit (); + } } catch (const odb::exception& e) { diff --git a/common/query/test.hxx b/common/query/test.hxx index 74f5f73..db09f32 100644 --- a/common/query/test.hxx +++ b/common/query/test.hxx @@ -7,12 +7,17 @@ #define TEST_HXX #include +#include #include #include #include +#include + #include // DATABASE_XXX +typedef odb::nullable > nullable_vector; + #pragma db object struct person { @@ -20,12 +25,14 @@ struct person const std::string& fn, const std::string& ln, unsigned short age, - bool married) + bool married, + const nullable_vector& public_key = nullable_vector ()) : id_ (id), first_name_ (fn), last_name_ (ln), age_ (age), - married_ (married) + married_ (married), + public_key_ (public_key) { } @@ -38,11 +45,8 @@ struct person #pragma db column ("first") std::string first_name_; -#ifndef DATABASE_ORACLE - #pragma db column ("middle") type ("TEXT") null -#else - #pragma db column ("middle") type ("CLOB") null -#endif + + #pragma db column ("middle") null std::auto_ptr middle_name_; #pragma db column ("last") @@ -50,6 +54,13 @@ struct person unsigned short age_; bool married_; + +#ifdef DATABASE_PGSQL + #pragma db column ("key") type ("BYTEA") null +#else + #pragma db column ("key") type ("BLOB") null +#endif + nullable_vector public_key_; }; inline std::ostream& @@ -63,6 +74,16 @@ operator<< (std::ostream& os, const person& p) os << ' ' << p.last_name_ << ' ' << p.age_ << (p.married_ ? " married" : " single"); + if (p.public_key_ && p.public_key_->size () > 0) + { + os << ' '; + + for (std::size_t i (0), e (p.public_key_->size () - 1); i < e; ++i) + os << (unsigned int)(*p.public_key_)[i] << '-'; + + os << (unsigned int)p.public_key_->back (); + } + return os; } diff --git a/common/query/test.std b/common/query/test.std index 978282a..f351eab 100644 --- a/common/query/test.std +++ b/common/query/test.std @@ -1,7 +1,7 @@ test 001 -John Doe 30 married -Jane Doe 29 married -Joe Squeaky Dirt 31 single +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 +Joe Squeaky Dirt 31 single 8-98-53 Johansen J Johansen 32 single test 002 Jane Doe 29 married @@ -10,89 +10,96 @@ Joe Squeaky Dirt 31 single Johansen J Johansen 32 single test 003 -John Doe 30 married +John Doe 30 married 35-3-21 test 004 -John Doe 30 married +John Doe 30 married 35-3-21 test 005 -John Doe 30 married +John Doe 30 married 35-3-21 -Joe Squeaky Dirt 31 single +Joe Squeaky Dirt 31 single 8-98-53 test 006 -John Doe 30 married -Jane Doe 29 married +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 -Joe Squeaky Dirt 31 single +Joe Squeaky Dirt 31 single 8-98-53 Johansen J Johansen 32 single test 007 -John Doe 30 married -Jane Doe 29 married +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 -Joe Squeaky Dirt 31 single +Joe Squeaky Dirt 31 single 8-98-53 Johansen J Johansen 32 single test 008 -John Doe 30 married -Jane Doe 29 married +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 -Joe Squeaky Dirt 31 single +Joe Squeaky Dirt 31 single 8-98-53 -John Doe 30 married -Jane Doe 29 married +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 test 009 -John Doe 30 married -Jane Doe 29 married +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 -Joe Squeaky Dirt 31 single +Joe Squeaky Dirt 31 single 8-98-53 Johansen J Johansen 32 single -John Doe 30 married -Jane Doe 29 married +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 -Joe Squeaky Dirt 31 single +Joe Squeaky Dirt 31 single 8-98-53 Johansen J Johansen 32 single -John Doe 30 married -Jane Doe 29 married +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 -Joe Squeaky Dirt 31 single +Joe Squeaky Dirt 31 single 8-98-53 Johansen J Johansen 32 single test 010 -Jane Doe 29 married +Jane Doe 29 married 19-19-84 -John Doe 30 married -Jane Doe 29 married -Joe Squeaky Dirt 31 single +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 +Joe Squeaky Dirt 31 single 8-98-53 -Jane Doe 29 married +Jane Doe 29 married 19-19-84 -Joe Squeaky Dirt 31 single +Joe Squeaky Dirt 31 single 8-98-53 Johansen J Johansen 32 single -Jane Doe 29 married -John Doe 30 married +Jane Doe 29 married 19-19-84 +John Doe 30 married 35-3-21 test 011 -John Doe 30 married -Jane Doe 29 married +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 -John Doe 30 married -Jane Doe 29 married -Joe Squeaky Dirt 31 single +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 +Joe Squeaky Dirt 31 single 8-98-53 test 012 Johansen J Johansen 32 single test 013 -Joe Squeaky Dirt 31 single +Joe Squeaky Dirt 31 single 8-98-53 test 014 test 015 -John Doe 30 married -Jane Doe 29 married +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 + +test 016 +Johansen J Johansen 32 single + +John Doe 30 married 35-3-21 +Jane Doe 29 married 19-19-84 +Joe Squeaky Dirt 31 single 8-98-53 -- cgit v1.1