diff options
author | Constantin Michael <constantin@codesynthesis.com> | 2011-10-20 11:03:09 +0200 |
---|---|---|
committer | Constantin Michael <constantin@codesynthesis.com> | 2011-10-21 13:29:10 +0200 |
commit | 5fae6bf3eaf7301b0ecf89783ca6cd4e63acec67 (patch) | |
tree | 6d0b7dd18adefba5fa08d1e060c16ad5b45abe50 | |
parent | 621a91328ba7f552ddcd05f3680184cd56357830 (diff) |
Add character set conversion tests to Oracle types test
-rw-r--r-- | oracle/types/driver.cxx | 72 | ||||
-rw-r--r-- | oracle/types/test.hxx | 41 |
2 files changed, 103 insertions, 10 deletions
diff --git a/oracle/types/driver.cxx b/oracle/types/driver.cxx index aa7a2cf..55918af 100644 --- a/oracle/types/driver.cxx +++ b/oracle/types/driver.cxx @@ -29,7 +29,7 @@ main (int argc, char* argv[]) // Create an Oracle database instance, setting both the client database // and national character set to UTF-8. // - auto_ptr<database> db (create_database (argc, argv, false, 873, 873)); + auto_ptr<database> db (create_database (argc, argv, false)); object o (1); @@ -45,29 +45,62 @@ main (int argc, char* argv[]) o.date_ = date_time (2010, 8, 29, 15, 33, 18); - string short_str (32, 's'); + string vshort_str (8, 's'); + string short_str (13, 's'); string medium_str (104, 'm'); string long_str (1018, 'l'); string vlong_str (15000, 'v'); o.char_ = short_str; o.varchar2_ = medium_str; - o.nchar_ = short_str; - o.nvarchar2_ = medium_str;o.raw_.assign (long_str.data (), long_str.data () + long_str.size ()); - o.blob_.assign (vlong_str.data (), vlong_str.data () + vlong_str.size ()); + o.clob_.assign (vlong_str.data (), vlong_str.data () + vlong_str.size ()); - const char* unicode_str = "a \xD5\x95 \xEA\xAA\xAA \xF2\xAA\xAA\xAA"; + o.nchar_ = vshort_str; + o.nvarchar2_ = medium_str; + o.nclob_.assign (vlong_str.data (), vlong_str.data () + vlong_str.size ()); - o.clob_ = unicode_str; - o.nclob_ = unicode_str; + o.raw_.assign (long_str.data (), long_str.data () + long_str.size ()); + o.blob_.assign (vlong_str.data (), vlong_str.data () + vlong_str.size ()); + // Persist. + // { transaction t (db->begin ()); db->persist (o); t.commit (); } + // Load. + // + { + transaction t (db->begin ()); + auto_ptr<object> o1 (db->load<object> (1)); + t.commit (); + + assert (o == *o1); + } + + // Test character set conversion. // + // const char* unicode_str = "a \xD5\x95 \xEA\xAA\xAA \xF2\xAA\xAA\xAA"; + + // o.char_ = unicode_str; + // o.varchar2_ = unicode_str; + // o.clob_ = unicode_str; + + // o.nchar_ = unicode_str; + // o.nvarchar2_ = unicode_str; + // o.nclob_ = unicode_str; + + // Persist. + // + { + transaction t (db->begin ()); + db->update (o); + t.commit (); + } + + // Load. // { transaction t (db->begin ()); @@ -76,6 +109,29 @@ main (int argc, char* argv[]) assert (o == *o1); } + + // Test 64 bit integers. + // + big_ints bi (true); + bi.id = 1; + + // Persist. + // + { + transaction t (db->begin ()); + db->persist (bi); + t.commit (); + } + + // Load. + // + { + transaction t (db->begin ()); + auto_ptr<big_ints> bi1 (db->load<big_ints> (1)); + t.commit (); + + assert (bi == *bi1); + } } catch (const odb::exception& e) { diff --git a/oracle/types/test.hxx b/oracle/types/test.hxx index 0d9f5f7..d137a1d 100644 --- a/oracle/types/test.hxx +++ b/oracle/types/test.hxx @@ -106,13 +106,13 @@ struct object // String and binary types. // - #pragma db type ("CHAR(32)") + #pragma db type ("CHAR(13)") std::string char_; #pragma db type ("VARCHAR2(512)") std::string varchar2_; - #pragma db type ("NCHAR(32)") + #pragma db type ("NCHAR(8)") std::string nchar_; #pragma db type ("NVARCHAR2(512)") @@ -160,4 +160,41 @@ struct object } }; +#pragma db object +struct big_ints +{ + big_ints (bool init = false) + { + if (init) + { + signed_zero = 0; + signed_min = 0x8000000000000000; // –9223372036854775808 + signed_max = 0x7FFFFFFFFFFFFFFFLL; // 9223372036854775807 + unsigned_zero = 0; + unsigned_max = 0xFFFFFFFFFFFFFFFFULL; + } + } + + #pragma db id + unsigned int id; + + long long signed_zero; + long long signed_min; + long long signed_max; + + unsigned long long unsigned_zero; + unsigned long long unsigned_max; + + bool + operator== (const big_ints& y) const + { + return id == y.id && + signed_zero == y.signed_zero && + signed_min == y.signed_min && + signed_max == y.signed_max && + unsigned_zero == y.unsigned_zero && + unsigned_max == y.unsigned_max; + } +}; + #endif // TEST_HXX |