diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-05-02 18:41:53 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-05-02 18:41:53 +0100 |
commit | c6d40e631d9b6496d44cc03abf1fedf4b46e5aad (patch) | |
tree | db0506f40bc48806f2ea06d6b0b2857802960291 | |
parent | Refactor, more OO, less hacky bind (diff) | |
download | project2-c6d40e631d9b6496d44cc03abf1fedf4b46e5aad.tar.bz2 project2-c6d40e631d9b6496d44cc03abf1fedf4b46e5aad.tar.xz project2-c6d40e631d9b6496d44cc03abf1fedf4b46e5aad.zip |
Add support for RDBMS boolean/bit types
-rw-r--r-- | project2/sql/sqlHandleAsVariableType.cpp | 3 | ||||
-rw-r--r-- | project2/sql/sqlHandleAsVariableType.h | 1 | ||||
-rw-r--r-- | project2/sql/sqlTest.cpp | 3 | ||||
-rw-r--r-- | project2/sql/unittests/mysqlschema.sql | 3 | ||||
-rw-r--r-- | project2/sql/unittests/pqschema.sql | 3 | ||||
-rw-r--r-- | project2/sql/unittests/testCore.cpp | 1 | ||||
-rw-r--r-- | project2/sql/unittests/testCore.h | 1 | ||||
-rw-r--r-- | project2/sql/unittests/testmysql.cpp | 17 | ||||
-rw-r--r-- | project2/sql/unittests/testpq.cpp | 17 |
9 files changed, 33 insertions, 16 deletions
diff --git a/project2/sql/sqlHandleAsVariableType.cpp b/project2/sql/sqlHandleAsVariableType.cpp index 2583df5..ac1ea3b 100644 --- a/project2/sql/sqlHandleAsVariableType.cpp +++ b/project2/sql/sqlHandleAsVariableType.cpp @@ -11,6 +11,9 @@ void HandleAsVariableType::string(const char * c, size_t l) { void HandleAsVariableType::integer(int64_t i) { variable = i; } +void HandleAsVariableType::boolean(bool b) { + variable = b; +} void HandleAsVariableType::floatingpoint(double d) { variable = d; } diff --git a/project2/sql/sqlHandleAsVariableType.h b/project2/sql/sqlHandleAsVariableType.h index 2aa6ccb..d843c4e 100644 --- a/project2/sql/sqlHandleAsVariableType.h +++ b/project2/sql/sqlHandleAsVariableType.h @@ -9,6 +9,7 @@ class HandleAsVariableType : public DB::HandleField { void null(); void string(const char * c, size_t l); void integer(int64_t i); + void boolean(bool i); void floatingpoint(double d); void interval(const boost::posix_time::time_duration & t); void timestamp(const boost::posix_time::ptime & t); diff --git a/project2/sql/sqlTest.cpp b/project2/sql/sqlTest.cpp index 3c41fef..fedc2a0 100644 --- a/project2/sql/sqlTest.cpp +++ b/project2/sql/sqlTest.cpp @@ -50,6 +50,9 @@ class HandleDoCompare : public DB::HandleField { void integer(int64_t val) { doTest(val); } + void boolean(bool val) { + doTest(val); + } void floatingpoint(double val) { doTest(val); } diff --git a/project2/sql/unittests/mysqlschema.sql b/project2/sql/unittests/mysqlschema.sql index 39e63dc..18c0211 100644 --- a/project2/sql/unittests/mysqlschema.sql +++ b/project2/sql/unittests/mysqlschema.sql @@ -2,6 +2,7 @@ CREATE TABLE test( id int, fl numeric(5,2), string varchar(30), + boolean bool, dt timestamp, ts time); -INSERT INTO test VALUES(4, 123.45, 'some text', '2015-04-27 23:06:03', '38:13:12'); +INSERT INTO test VALUES(4, 123.45, 'some text', true, '2015-04-27 23:06:03', '38:13:12'); diff --git a/project2/sql/unittests/pqschema.sql b/project2/sql/unittests/pqschema.sql index a097419..96848eb 100644 --- a/project2/sql/unittests/pqschema.sql +++ b/project2/sql/unittests/pqschema.sql @@ -2,6 +2,7 @@ CREATE TABLE test( id int, fl numeric(5,2), string text, + boolean bool, dt timestamp without time zone, ts interval); -INSERT INTO test VALUES(4, 123.45, 'some text', '2015-04-27 23:06:03', '1 day 14:13:12'); +INSERT INTO test VALUES(4, 123.45, 'some text', true, '2015-04-27 23:06:03', '1 day 14:13:12'); diff --git a/project2/sql/unittests/testCore.cpp b/project2/sql/unittests/testCore.cpp index ce921c2..440d676 100644 --- a/project2/sql/unittests/testCore.cpp +++ b/project2/sql/unittests/testCore.cpp @@ -6,6 +6,7 @@ TestCore::TestCore() : testInt(43), testDouble(3.14), testString("Some C String"), + testBool(false), testDateTime(boost::posix_time::from_time_t(1430530593)), testInterval(boost::posix_time::time_duration(1, 2, 3)) { diff --git a/project2/sql/unittests/testCore.h b/project2/sql/unittests/testCore.h index b807922..2b5be0e 100644 --- a/project2/sql/unittests/testCore.h +++ b/project2/sql/unittests/testCore.h @@ -11,6 +11,7 @@ class TestCore : public CommonObjects { int testInt; double testDouble; std::string testString; + bool testBool; boost::posix_time::ptime testDateTime; boost::posix_time::time_duration testInterval; }; diff --git a/project2/sql/unittests/testmysql.cpp b/project2/sql/unittests/testmysql.cpp index 4debd35..6cbc440 100644 --- a/project2/sql/unittests/testmysql.cpp +++ b/project2/sql/unittests/testmysql.cpp @@ -46,12 +46,13 @@ BOOST_AUTO_TEST_CASE( bindAndSend ) RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("mysqlmock"); auto rw = ds->getWritable(); - auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?, ?, ?)"); + auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?, ?, ?, ?)"); mod->bindParamI(0, testInt); mod->bindParamF(1, testDouble); mod->bindParamS(2, testString); - mod->bindParamT(3, testDateTime); - mod->bindParamT(4, testInterval); + mod->bindParamB(3, testBool); + mod->bindParamT(4, testDateTime); + mod->bindParamT(5, testInterval); mod->execute(); delete mod; ds->commit(); @@ -80,8 +81,9 @@ BOOST_AUTO_TEST_CASE( bindAndSelect ) assertColumnValueHelper(*select, 0, testInt); assertColumnValueHelper(*select, 1, testDouble); assertColumnValueHelper(*select, 2, testString); - assertColumnValueHelper(*select, 3, testDateTime); - assertColumnValueHelper(*select, 4, testInterval); + assertColumnValueHelper(*select, 3, testBool); + assertColumnValueHelper(*select, 4, testDateTime); + assertColumnValueHelper(*select, 5, testInterval); rows += 1; } delete select; @@ -102,8 +104,9 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther ) assertColumnValueHelper(*select, 0, 4); assertColumnValueHelper(*select, 1, 123.45); assertColumnValueHelper(*select, 2, std::string("some text")); - assertColumnValueHelper(*select, 3, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, 0})); - assertColumnValueHelper(*select, 4, boost::posix_time::time_duration(38, 13, 12)); + assertColumnValueHelper(*select, 3, true); + assertColumnValueHelper(*select, 4, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, 0})); + assertColumnValueHelper(*select, 5, boost::posix_time::time_duration(38, 13, 12)); rows += 1; } delete select; diff --git a/project2/sql/unittests/testpq.cpp b/project2/sql/unittests/testpq.cpp index 9d2367e..1d38e8c 100644 --- a/project2/sql/unittests/testpq.cpp +++ b/project2/sql/unittests/testpq.cpp @@ -46,12 +46,13 @@ BOOST_AUTO_TEST_CASE( bindAndSend ) RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("pqmock"); auto rw = ds->getWritable(); - auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?, ?, ?)"); + auto mod = rw->newModifyCommand("INSERT INTO test VALUES(?, ?, ?, ?, ?, ?)"); mod->bindParamI(0, testInt); mod->bindParamF(1, testDouble); mod->bindParamS(2, testString); - mod->bindParamT(3, testDateTime); - mod->bindParamT(4, testInterval); + mod->bindParamB(3, testBool); + mod->bindParamT(4, testDateTime); + mod->bindParamT(5, testInterval); mod->execute(); delete mod; ds->commit(); @@ -80,8 +81,9 @@ BOOST_AUTO_TEST_CASE( bindAndSelect ) assertColumnValueHelper(*select, 0, testInt); assertColumnValueHelper(*select, 1, testDouble); assertColumnValueHelper(*select, 2, testString); - assertColumnValueHelper(*select, 3, testDateTime); - assertColumnValueHelper(*select, 4, testInterval); + assertColumnValueHelper(*select, 3, testBool); + assertColumnValueHelper(*select, 4, testDateTime); + assertColumnValueHelper(*select, 5, testInterval); rows += 1; } delete select; @@ -102,8 +104,9 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther ) assertColumnValueHelper(*select, 0, 4); assertColumnValueHelper(*select, 1, 123.45); assertColumnValueHelper(*select, 2, std::string("some text")); - assertColumnValueHelper(*select, 3, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, 0})); - assertColumnValueHelper(*select, 4, boost::posix_time::time_duration(38, 13, 12)); + assertColumnValueHelper(*select, 3, true); + assertColumnValueHelper(*select, 4, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, 0})); + assertColumnValueHelper(*select, 5, boost::posix_time::time_duration(38, 13, 12)); rows += 1; } delete select; |