summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-04-09 12:36:47 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2018-04-09 12:36:47 +0100
commitbd5f4b71bc8a9e391aa557bacc1f95a10ad476f3 (patch)
tree9ac749ef6efd27e73937ef2c50359d6e801548b1
parentTidy up build process of internal libSlice (diff)
downloadslicer-bd5f4b71bc8a9e391aa557bacc1f95a10ad476f3.tar.bz2
slicer-bd5f4b71bc8a9e391aa557bacc1f95a10ad476f3.tar.xz
slicer-bd5f4b71bc8a9e391aa557bacc1f95a10ad476f3.zip
C++17
Updates DB code inline with C++17 libdbpp.
-rw-r--r--slicer/db/Jamfile.jam2
-rw-r--r--slicer/db/sqlInsertSerializer.cpp12
-rw-r--r--slicer/db/sqlInsertSerializer.h8
-rw-r--r--slicer/db/sqlSelectDeserializer.cpp30
-rw-r--r--slicer/db/sqlSelectDeserializer.h4
-rw-r--r--slicer/db/sqlTablePatchSerializer.cpp2
-rw-r--r--slicer/db/sqlTablePatchSerializer.h4
-rw-r--r--slicer/db/sqlUpdateSerializer.cpp8
-rw-r--r--slicer/db/sqlUpdateSerializer.h8
-rw-r--r--slicer/db/testInsert.cpp59
-rw-r--r--slicer/db/testPatch.cpp15
-rw-r--r--slicer/db/testSelect.cpp153
-rw-r--r--slicer/db/testUpdate.cpp45
13 files changed, 168 insertions, 182 deletions
diff --git a/slicer/db/Jamfile.jam b/slicer/db/Jamfile.jam
index cf5cca8..8efce48 100644
--- a/slicer/db/Jamfile.jam
+++ b/slicer/db/Jamfile.jam
@@ -36,6 +36,8 @@ lib testCommon :
<slicerbin>../tool//slicer
<implicit-dependency>../test//types
<library>../test//types
+ : :
+ <library>adhocutil
;
run testSelect.cpp
diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp
index e7f702b..9d1da32 100644
--- a/slicer/db/sqlInsertSerializer.cpp
+++ b/slicer/db/sqlInsertSerializer.cpp
@@ -10,7 +10,7 @@
#include <boost/bind.hpp>
namespace Slicer {
- SqlInsertSerializer::SqlInsertSerializer(DB::Connection * const c, const std::string & t) :
+ SqlInsertSerializer::SqlInsertSerializer(DB::ConnectionPtr const c, const std::string & t) :
connection(c),
tableName(t)
{
@@ -41,7 +41,7 @@ namespace Slicer {
void
SqlInsertSerializer::SerializeSequence(Slicer::ModelPartPtr mp) const
{
- ModifyPtr ins = createInsert(mp->GetContainedModelPart());
+ auto ins = createInsert(mp->GetContainedModelPart());
mp->OnEachChild([&ins, this](const std::string &, ModelPartPtr cmp, const HookCommon *) {
bindObjectAndExecute(cmp, ins.get());
});
@@ -57,7 +57,7 @@ namespace Slicer {
class IdSave : public Slicer::ValueSource {
public:
- IdSave(DB::Connection * const c) :
+ IdSave(const DB::ConnectionPtr & c) :
connection(c)
{
}
@@ -79,7 +79,7 @@ namespace Slicer {
NumType(Ice::Double);
private:
- DB::Connection * const connection;
+ const DB::ConnectionPtr & connection;
};
void
@@ -112,7 +112,7 @@ namespace Slicer {
}
}
- SqlInsertSerializer::ModifyPtr
+ DB::ModifyCommandPtr
SqlInsertSerializer::createInsert(Slicer::ModelPartPtr mp) const
{
AdHoc::Buffer insert;
@@ -124,7 +124,7 @@ namespace Slicer {
insert.append("?, ");
}
insert.append("?)");
- return ModifyPtr(connection->newModifyCommand(insert));
+ return connection->modify(insert);
}
void
diff --git a/slicer/db/sqlInsertSerializer.h b/slicer/db/sqlInsertSerializer.h
index a693301..9c99f80 100644
--- a/slicer/db/sqlInsertSerializer.h
+++ b/slicer/db/sqlInsertSerializer.h
@@ -9,21 +9,19 @@
namespace Slicer {
class DLL_PUBLIC SqlInsertSerializer : public Slicer::Serializer {
public:
- typedef boost::shared_ptr<DB::ModifyCommand> ModifyPtr;
-
- SqlInsertSerializer(DB::Connection * const, const std::string & tableName);
+ SqlInsertSerializer(DB::ConnectionPtr const, const std::string & tableName);
virtual void Serialize(Slicer::ModelPartForRootPtr) override;
protected:
void SerializeObject(Slicer::ModelPartPtr) const;
void SerializeSequence(Slicer::ModelPartPtr) const;
- ModifyPtr createInsert(Slicer::ModelPartPtr) const;
+ DB::ModifyCommandPtr createInsert(Slicer::ModelPartPtr) const;
virtual void createInsertField(int & fieldNo, AdHoc::Buffer & insert, const std::string & name, const HookCommon * h) const;
virtual void bindObjectAndExecute(Slicer::ModelPartPtr, DB::ModifyCommand *) const;
virtual void bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand *, Slicer::ModelPartPtr, const HookCommon *) const;
- DB::Connection * const connection;
+ DB::ConnectionPtr const connection;
const std::string tableName;
};
diff --git a/slicer/db/sqlSelectDeserializer.cpp b/slicer/db/sqlSelectDeserializer.cpp
index 3516265..5b226ce 100644
--- a/slicer/db/sqlSelectDeserializer.cpp
+++ b/slicer/db/sqlSelectDeserializer.cpp
@@ -4,7 +4,7 @@
#include <common.h>
namespace Slicer {
- SqlSelectDeserializer::SqlSelectDeserializer(DB::SelectCommand & c, IceUtil::Optional<std::string> tc) :
+ SqlSelectDeserializer::SqlSelectDeserializer(DB::SelectCommandPtr c, IceUtil::Optional<std::string> tc) :
cmd(c),
typeIdColName(tc)
{
@@ -13,10 +13,10 @@ namespace Slicer {
void
SqlSelectDeserializer::Deserialize(Slicer::ModelPartForRootPtr mp)
{
- cmd.execute();
- columnCount = cmd.columnCount();
+ cmd->execute();
+ columnCount = cmd->columnCount();
if (typeIdColName) {
- typeIdColIdx = cmd.getOrdinal(*typeIdColName);
+ typeIdColIdx = cmd->getOrdinal(*typeIdColName);
}
switch (mp->GetType()) {
case Slicer::mpt_Sequence:
@@ -36,19 +36,19 @@ namespace Slicer {
void
SqlSelectDeserializer::DeserializeSimple(Slicer::ModelPartPtr mp)
{
- if (!cmd.fetch()) {
+ if (!cmd->fetch()) {
if (!mp->IsOptional()) {
throw NoRowsReturned();
}
return;
}
- if (!cmd[0].isNull()) {
+ if (!(*cmd)[0].isNull()) {
auto fmp = mp->GetAnonChild();
fmp->Create();
- fmp->SetValue(SqlSource(cmd[0]));
+ fmp->SetValue(SqlSource((*cmd)[0]));
fmp->Complete();
}
- if (cmd.fetch()) {
+ if (cmd->fetch()) {
throw TooManyRowsReturned();
}
}
@@ -57,7 +57,7 @@ namespace Slicer {
SqlSelectDeserializer::DeserializeSequence(Slicer::ModelPartPtr mp)
{
mp = mp->GetAnonChild();
- while (cmd.fetch()) {
+ while (cmd->fetch()) {
DeserializeRow(mp);
}
}
@@ -65,15 +65,15 @@ namespace Slicer {
void
SqlSelectDeserializer::DeserializeObject(Slicer::ModelPartPtr mp)
{
- if (!cmd.fetch()) {
+ if (!cmd->fetch()) {
if (!mp->IsOptional()) {
throw NoRowsReturned();
}
return;
}
DeserializeRow(mp);
- if (cmd.fetch()) {
- while (cmd.fetch()) ;
+ if (cmd->fetch()) {
+ while (cmd->fetch()) ;
throw TooManyRowsReturned();
}
}
@@ -88,12 +88,12 @@ namespace Slicer {
{
if (typeIdColIdx) {
std::string subclass;
- cmd[*typeIdColIdx] >> subclass;
+ (*cmd)[*typeIdColIdx] >> subclass;
rmp = rmp->GetSubclassModelPart(subclass);
}
rmp->Create();
for (auto col = 0u; col < columnCount; col += 1) {
- const DB::Column & c = cmd[col];
+ const DB::Column & c = (*cmd)[col];
if (!c.isNull()) {
auto fmpr = rmp->GetChildRef(c.name, NULL, false);
if (fmpr) {
@@ -110,7 +110,7 @@ namespace Slicer {
case Slicer::mpt_Simple:
{
rmp->Create();
- const DB::Column & c = cmd[0];
+ const DB::Column & c = (*cmd)[0];
if (!c.isNull()) {
rmp->SetValue(SqlSource(c));
}
diff --git a/slicer/db/sqlSelectDeserializer.h b/slicer/db/sqlSelectDeserializer.h
index 782283e..72403ee 100644
--- a/slicer/db/sqlSelectDeserializer.h
+++ b/slicer/db/sqlSelectDeserializer.h
@@ -8,7 +8,7 @@
namespace Slicer {
class DLL_PUBLIC SqlSelectDeserializer : public Slicer::Deserializer {
public:
- SqlSelectDeserializer(DB::SelectCommand &, IceUtil::Optional<std::string> typeIdCol = IceUtil::Optional<std::string>());
+ SqlSelectDeserializer(DB::SelectCommandPtr, IceUtil::Optional<std::string> typeIdCol = IceUtil::Optional<std::string>());
virtual void Deserialize(Slicer::ModelPartForRootPtr) override;
@@ -18,7 +18,7 @@ namespace Slicer {
void DLL_PRIVATE DeserializeSequence(Slicer::ModelPartPtr);
void DLL_PRIVATE DeserializeRow(Slicer::ModelPartPtr);
- DB::SelectCommand & cmd;
+ DB::SelectCommandPtr cmd;
unsigned int columnCount;
IceUtil::Optional<std::string> typeIdColName;
IceUtil::Optional<unsigned int> typeIdColIdx;
diff --git a/slicer/db/sqlTablePatchSerializer.cpp b/slicer/db/sqlTablePatchSerializer.cpp
index da4b7f4..ed293ca 100644
--- a/slicer/db/sqlTablePatchSerializer.cpp
+++ b/slicer/db/sqlTablePatchSerializer.cpp
@@ -8,7 +8,7 @@
namespace Slicer {
AdHocFormatter(ttname, "slicer_tmp_%?");
- SqlTablePatchSerializer::SqlTablePatchSerializer(DB::Connection * db, DB::TablePatch & tp) :
+ SqlTablePatchSerializer::SqlTablePatchSerializer(DB::ConnectionPtr db, DB::TablePatch & tp) :
db(db),
tablePatch(tp)
{
diff --git a/slicer/db/sqlTablePatchSerializer.h b/slicer/db/sqlTablePatchSerializer.h
index 9aad96c..41fb89d 100644
--- a/slicer/db/sqlTablePatchSerializer.h
+++ b/slicer/db/sqlTablePatchSerializer.h
@@ -7,7 +7,7 @@
namespace Slicer {
class DLL_PUBLIC SqlTablePatchSerializer : public Slicer::Serializer {
public:
- SqlTablePatchSerializer(DB::Connection *, DB::TablePatch &);
+ SqlTablePatchSerializer(DB::ConnectionPtr, DB::TablePatch &);
~SqlTablePatchSerializer();
virtual void Serialize(Slicer::ModelPartForRootPtr) override;
@@ -16,7 +16,7 @@ namespace Slicer {
void createTemporaryTable();
void dropTemporaryTable();
- DB::Connection * db;
+ DB::ConnectionPtr db;
DB::TablePatch & tablePatch;
};
}
diff --git a/slicer/db/sqlUpdateSerializer.cpp b/slicer/db/sqlUpdateSerializer.cpp
index 0c20b12..6cd0360 100644
--- a/slicer/db/sqlUpdateSerializer.cpp
+++ b/slicer/db/sqlUpdateSerializer.cpp
@@ -9,7 +9,7 @@
#include <boost/bind.hpp>
namespace Slicer {
- SqlUpdateSerializer::SqlUpdateSerializer(DB::Connection * const c, const std::string & t) :
+ SqlUpdateSerializer::SqlUpdateSerializer(DB::ConnectionPtr const c, const std::string & t) :
connection(c),
tableName(t)
{
@@ -40,7 +40,7 @@ namespace Slicer {
void
SqlUpdateSerializer::SerializeSequence(Slicer::ModelPartPtr mp) const
{
- ModifyPtr ins = createUpdate(mp->GetContainedModelPart());
+ auto ins = createUpdate(mp->GetContainedModelPart());
mp->OnEachChild([&ins, this](const std::string &, ModelPartPtr cmp, const HookCommon *) {
bindObjectAndExecute(cmp, ins.get());
});
@@ -68,7 +68,7 @@ namespace Slicer {
}
}
- SqlUpdateSerializer::ModifyPtr
+ DB::ModifyCommandPtr
SqlUpdateSerializer::createUpdate(Slicer::ModelPartPtr mp) const
{
AdHoc::Buffer update;
@@ -92,7 +92,7 @@ namespace Slicer {
update.appendbf("%s = ?", name);
}
});
- return ModifyPtr(connection->newModifyCommand(update));
+ return connection->modify(update);
}
}
diff --git a/slicer/db/sqlUpdateSerializer.h b/slicer/db/sqlUpdateSerializer.h
index c31a192..fe6f4bc 100644
--- a/slicer/db/sqlUpdateSerializer.h
+++ b/slicer/db/sqlUpdateSerializer.h
@@ -8,19 +8,17 @@
namespace Slicer {
class DLL_PUBLIC SqlUpdateSerializer : public Slicer::Serializer {
public:
- typedef boost::shared_ptr<DB::ModifyCommand> ModifyPtr;
-
- SqlUpdateSerializer(DB::Connection * const, const std::string & tableName);
+ SqlUpdateSerializer(DB::ConnectionPtr const, const std::string & tableName);
virtual void Serialize(Slicer::ModelPartForRootPtr) override;
protected:
void SerializeObject(Slicer::ModelPartPtr) const;
void SerializeSequence(Slicer::ModelPartPtr) const;
- ModifyPtr createUpdate(Slicer::ModelPartPtr) const;
+ DB::ModifyCommandPtr createUpdate(Slicer::ModelPartPtr) const;
static void bindObjectAndExecute(Slicer::ModelPartPtr, DB::ModifyCommand *);
- DB::Connection * const connection;
+ DB::ConnectionPtr const connection;
const std::string tableName;
};
}
diff --git a/slicer/db/testInsert.cpp b/slicer/db/testInsert.cpp
index 1c9542f..01a6246 100644
--- a/slicer/db/testInsert.cpp
+++ b/slicer/db/testInsert.cpp
@@ -25,9 +25,9 @@ namespace std {
}
}
-class StandardMockDatabase : public PQ::Mock {
+class StandardMockDatabase : public DB::PluginMock<PQ::Mock> {
public:
- StandardMockDatabase() : PQ::Mock("user=postgres dbname=postgres", "pqmock", {
+ StandardMockDatabase() : DB::PluginMock<PQ::Mock>("user=postgres dbname=postgres", "pqmock", {
rootDir.parent_path() / "db" / "slicer.sql" })
{
}
@@ -35,16 +35,13 @@ class StandardMockDatabase : public PQ::Mock {
BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
-typedef boost::shared_ptr<DB::Connection> DBPtr;
-typedef boost::shared_ptr<DB::SelectCommand> SelectPtr;
-
BOOST_AUTO_TEST_CASE( insert_builtins )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestModule::BuiltInsPtr bi = std::make_shared<TestModule::BuiltIns>(true, 4, 16, 64, 128, 1.2, 3.4, "text");
- Slicer::SerializeAny<Slicer::SqlInsertSerializer>(bi, db.get(), "builtins");
- auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM builtins"));
- auto bi2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInsPtr>(*sel);
+ Slicer::SerializeAny<Slicer::SqlInsertSerializer>(bi, db, "builtins");
+ auto sel = db->select("SELECT * FROM builtins");
+ auto bi2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInsPtr>(sel);
BOOST_REQUIRE_EQUAL(bi->mbool, bi2->mbool);
BOOST_REQUIRE_EQUAL(bi->mbyte, bi2->mbyte);
BOOST_REQUIRE_EQUAL(bi->mshort, bi2->mshort);
@@ -57,14 +54,14 @@ BOOST_AUTO_TEST_CASE( insert_builtins )
BOOST_AUTO_TEST_CASE( insert_seq_builtins )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestModule::BuiltInSeq bis = {
std::make_shared<TestModule::BuiltIns>(true, 5, 17, 65, 129, 2.3, 4.5, "more text"),
std::make_shared<TestModule::BuiltIns>(true, 6, 18, 66, 130, 3.4, 5.6, "even more text")
};
- Slicer::SerializeAny<Slicer::SqlInsertSerializer>(bis, db.get(), "builtins");
- auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM builtins ORDER BY mint"));
- auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(*sel);
+ Slicer::SerializeAny<Slicer::SqlInsertSerializer>(bis, db, "builtins");
+ auto sel = db->select("SELECT * FROM builtins ORDER BY mint");
+ auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(sel);
BOOST_REQUIRE_EQUAL(3, bis2.size());
BOOST_REQUIRE_EQUAL(bis.back()->mbool, bis2.back()->mbool);
BOOST_REQUIRE_EQUAL(bis.back()->mbyte, bis2.back()->mbyte);
@@ -78,14 +75,14 @@ BOOST_AUTO_TEST_CASE( insert_seq_builtins )
BOOST_AUTO_TEST_CASE( autoinsert_seq_builtins )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestModule::BuiltInSeq bis = {
std::make_shared<TestModule::BuiltIns>(true, 5, 17, 0, 129, 2.3, 4.5, "more text"),
std::make_shared<TestModule::BuiltIns>(true, 6, 18, 0, 130, 3.4, 5.6, "even more text")
};
- Slicer::SerializeAny<Slicer::SqlAutoIdInsertSerializer>(bis, db.get(), "builtins");
- auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM builtins WHERE mint IN (1, 2) ORDER BY mint"));
- auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(*sel);
+ Slicer::SerializeAny<Slicer::SqlAutoIdInsertSerializer>(bis, db, "builtins");
+ auto sel = db->select("SELECT * FROM builtins WHERE mint IN (1, 2) ORDER BY mint");
+ auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(sel);
BOOST_REQUIRE_EQUAL(2, bis2.size());
BOOST_REQUIRE_EQUAL(bis.front()->mint, 0);
BOOST_REQUIRE_EQUAL(bis.back()->mint, 0);
@@ -102,14 +99,14 @@ BOOST_AUTO_TEST_CASE( autoinsert_seq_builtins )
BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtins )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestModule::BuiltInSeq bis = {
std::make_shared<TestModule::BuiltIns>(true, 5, 17, 0, 129, 2.3, 4.5, "more text"),
std::make_shared<TestModule::BuiltIns>(true, 6, 18, 0, 130, 3.4, 5.6, "even more text")
};
- Slicer::SerializeAny<Slicer::SqlFetchIdInsertSerializer>(bis, db.get(), "builtins");
- auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM builtins WHERE mint IN (3, 4) ORDER BY mint"));
- auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(*sel);
+ Slicer::SerializeAny<Slicer::SqlFetchIdInsertSerializer>(bis, db, "builtins");
+ auto sel = db->select("SELECT * FROM builtins WHERE mint IN (3, 4) ORDER BY mint");
+ auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(sel);
BOOST_REQUIRE_EQUAL(2, bis2.size());
BOOST_REQUIRE_EQUAL(bis.front()->mint, 3);
BOOST_REQUIRE_EQUAL(bis.back()->mint, 4);
@@ -126,14 +123,14 @@ BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtins )
BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtinsWithNulls )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestDatabase::BuiltInSeq bis = {
std::make_shared<TestDatabase::BuiltIns>(true, IceUtil::None, 17, 0, 129, 2.3, 4.5, "more text"s),
std::make_shared<TestDatabase::BuiltIns>(true, 6, 18, 0, 130, 3.4, IceUtil::None, "even more text"s)
};
- Slicer::SerializeAny<Slicer::SqlFetchIdInsertSerializer>(bis, db.get(), "builtins");
- auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM builtins WHERE mint IN (5, 6) ORDER BY mint"));
- auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(*sel);
+ Slicer::SerializeAny<Slicer::SqlFetchIdInsertSerializer>(bis, db, "builtins");
+ auto sel = db->select("SELECT * FROM builtins WHERE mint IN (5, 6) ORDER BY mint");
+ auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(sel);
BOOST_REQUIRE_EQUAL(2, bis2.size());
BOOST_REQUIRE_EQUAL(bis.front()->mint, 5);
BOOST_REQUIRE_EQUAL(bis.back()->mint, 6);
@@ -150,15 +147,15 @@ BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtinsWithNulls )
BOOST_AUTO_TEST_CASE( insert_converted )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestDatabase::SpecificTypesPtr st = std::make_shared<TestDatabase::SpecificTypes>(
TestModule::DateTime {2015, 10, 16, 19, 12, 34},
TestModule::IsoDate {2015, 10, 16},
std::make_shared<TestDatabase::Timespan>(1, 2, 3, 4)
);
- Slicer::SerializeAny<Slicer::SqlInsertSerializer>(st, db.get(), "converted");
- auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM converted"));
- auto st2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::SpecificTypesPtr>(*sel);
+ Slicer::SerializeAny<Slicer::SqlInsertSerializer>(st, db, "converted");
+ auto sel = db->select("SELECT * FROM converted");
+ auto st2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::SpecificTypesPtr>(sel);
BOOST_REQUIRE_EQUAL(st->date, st2->date);
BOOST_REQUIRE_EQUAL(st->dt, st2->dt);
BOOST_REQUIRE_EQUAL(st->ts->days, st2->ts->days);
@@ -169,8 +166,8 @@ BOOST_AUTO_TEST_CASE( insert_converted )
BOOST_AUTO_TEST_CASE( insert_unsupportedModel )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestModule::ClassMap cm;
- BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::SqlInsertSerializer>(cm, db.get(), "converted"), Slicer::UnsupportedModelType);
+ BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::SqlInsertSerializer>(cm, db, "converted"), Slicer::UnsupportedModelType);
}
diff --git a/slicer/db/testPatch.cpp b/slicer/db/testPatch.cpp
index 012f2f5..ef94823 100644
--- a/slicer/db/testPatch.cpp
+++ b/slicer/db/testPatch.cpp
@@ -17,9 +17,9 @@ BOOST_TEST_DONT_PRINT_LOG_VALUE(TestDatabase::Timespan);
BOOST_TEST_DONT_PRINT_LOG_VALUE(DB::PrimaryKey);
// LCOV_EXCL_STOP
-class StandardMockDatabase : public PQ::Mock {
+class StandardMockDatabase : public DB::PluginMock<PQ::Mock> {
public:
- StandardMockDatabase() : PQ::Mock("user=postgres dbname=postgres", "pqmock", {
+ StandardMockDatabase() : DB::PluginMock<PQ::Mock>("user=postgres dbname=postgres", "pqmock", {
rootDir.parent_path() / "db" / "slicer.sql" })
{
}
@@ -27,22 +27,19 @@ class StandardMockDatabase : public PQ::Mock {
BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
-typedef boost::shared_ptr<DB::Connection> DBPtr;
-typedef boost::shared_ptr<DB::SelectCommand> SelectPtr;
-
BOOST_AUTO_TEST_CASE( insert_builtins )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestModule::BuiltInSeq bis = {
TestModule::BuiltInsPtr(new TestModule::BuiltIns(true, 5, 17, 0, 129, 2.3, 4.5, "more text")),
TestModule::BuiltInsPtr(new TestModule::BuiltIns(true, 6, 18, 0, 130, 3.4, 5.6, "even more text"))
};
DB::TablePatch tp;
- DB::TransactionScope tx(db.get());
+ DB::TransactionScope tx(db);
tp.dest = "builtins";
- Slicer::SerializeAny<Slicer::SqlTablePatchSerializer>(bis, db.get(), tp);
+ Slicer::SerializeAny<Slicer::SqlTablePatchSerializer>(bis, db, tp);
auto cmd = db->select("SELECT COUNT(*) FROM builtins");
- auto c = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, int>(*cmd);
+ auto c = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, int>(cmd);
BOOST_REQUIRE_EQUAL(2, c);
BOOST_REQUIRE_EQUAL(2, tp.pk.size());
DB::PrimaryKey pk = {"mint", "mlong"};
diff --git a/slicer/db/testSelect.cpp b/slicer/db/testSelect.cpp
index e1c2068..9ea9139 100644
--- a/slicer/db/testSelect.cpp
+++ b/slicer/db/testSelect.cpp
@@ -12,9 +12,9 @@
using namespace std::literals;
-class StandardMockDatabase : public PQ::Mock {
+class StandardMockDatabase : public DB::PluginMock<PQ::Mock> {
public:
- StandardMockDatabase() : PQ::Mock("user=postgres dbname=postgres", "pqmock", {
+ StandardMockDatabase() : DB::PluginMock<PQ::Mock>("user=postgres dbname=postgres", "pqmock", {
rootDir.parent_path() / "db" / "slicer.sql" })
{
}
@@ -22,61 +22,58 @@ class StandardMockDatabase : public PQ::Mock {
BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
-typedef boost::shared_ptr<DB::Connection> DBPtr;
-typedef boost::shared_ptr<DB::SelectCommand> SelectPtr;
-
BOOST_AUTO_TEST_CASE( select_simple_int )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT MAX(id) FROM test"));
- auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::Int>(*sel);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT MAX(id) FROM test");
+ auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::Int>(sel);
BOOST_REQUIRE_EQUAL(4, bi);
}
BOOST_AUTO_TEST_CASE( select_simple_double )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT MAX(fl) FROM test"));
- auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::Double>(*sel);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT MAX(fl) FROM test");
+ auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::Double>(sel);
BOOST_REQUIRE_CLOSE(1234.1234, bi, 0.0001);
}
BOOST_AUTO_TEST_CASE( select_simple_string )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT MAX(string) FROM test"));
- auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, std::string>(*sel);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT MAX(string) FROM test");
+ auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, std::string>(sel);
BOOST_REQUIRE_EQUAL("text two", bi);
}
BOOST_AUTO_TEST_CASE( select_simple_true )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT true"));
- auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, bool>(*sel);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT true");
+ auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, bool>(sel);
BOOST_REQUIRE_EQUAL(true, bi);
}
BOOST_AUTO_TEST_CASE( select_simple_false )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT NOT(true)"));
- auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, bool>(*sel);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT NOT(true)");
+ auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, bool>(sel);
BOOST_REQUIRE_EQUAL(false, bi);
}
BOOST_AUTO_TEST_CASE( select_single )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand(
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select(
"SELECT boolean mbool, \
id mbyte, id mshort, id mint, id mlong, \
fl mdouble, fl mfloat, \
string mstring \
FROM test \
ORDER BY id \
- LIMIT 1"));
- auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInsPtr>(*sel);
+ LIMIT 1");
+ auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInsPtr>(sel);
BOOST_REQUIRE(bi);
BOOST_REQUIRE_EQUAL(true, bi->mbool);
BOOST_REQUIRE_EQUAL(1, bi->mbyte);
@@ -90,12 +87,12 @@ BOOST_AUTO_TEST_CASE( select_single )
BOOST_AUTO_TEST_CASE( select_inherit_single )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand(
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select(
"SELECT id a, '::TestModule::D' || CAST(id AS TEXT) tc, 200 b, 300 c, 400 d \
FROM test \
- WHERE id = 2"));
- auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BasePtr>(*sel, "tc"s);
+ WHERE id = 2");
+ auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BasePtr>(sel, "tc"s);
BOOST_REQUIRE(bi);
auto d2 = std::dynamic_pointer_cast<TestModule::D2>(bi);
BOOST_REQUIRE(d2);
@@ -105,12 +102,12 @@ BOOST_AUTO_TEST_CASE( select_inherit_single )
BOOST_AUTO_TEST_CASE( select_simple_sequence )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand(
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select(
"SELECT string \
FROM test \
- ORDER BY id DESC"));
- auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::SimpleSeq>(*sel);
+ ORDER BY id DESC");
+ auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::SimpleSeq>(sel);
BOOST_REQUIRE_EQUAL(4, bi.size());
BOOST_REQUIRE_EQUAL("text four", bi[0]);
BOOST_REQUIRE_EQUAL("text three", bi[1]);
@@ -120,13 +117,13 @@ BOOST_AUTO_TEST_CASE( select_simple_sequence )
BOOST_AUTO_TEST_CASE( select_inherit_sequence )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand(
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select(
"SELECT id a, '::TestModule::D' || CAST(id AS TEXT) tc, 200 b, 300 c, 400 d \
FROM test \
WHERE id < 4 \
- ORDER BY id DESC"));
- auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BaseSeq>(*sel, "tc"s);
+ ORDER BY id DESC");
+ auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BaseSeq>(sel, "tc"s);
BOOST_REQUIRE_EQUAL(3, bi.size());
auto d3 = std::dynamic_pointer_cast<TestModule::D3>(bi[0]);
auto d2 = std::dynamic_pointer_cast<TestModule::D2>(bi[1]);
@@ -145,12 +142,12 @@ BOOST_AUTO_TEST_CASE( select_inherit_sequence )
BOOST_AUTO_TEST_CASE( select_inherit_datetime )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand(
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select(
"SELECT dt, to_char(dt, 'YYYY-MM-DD') date, ts \
FROM test \
- WHERE id = 3"));
- TestDatabase::SpecificTypesPtr bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::SpecificTypesPtr>(*sel);
+ WHERE id = 3");
+ TestDatabase::SpecificTypesPtr bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::SpecificTypesPtr>(sel);
BOOST_REQUIRE_EQUAL(2015, bi->dt.year);
BOOST_REQUIRE_EQUAL(3, bi->dt.month);
BOOST_REQUIRE_EQUAL(27, bi->dt.day);
@@ -175,101 +172,101 @@ BoostThrowWrapperHelper(P && ... p)
BOOST_AUTO_TEST_CASE( select_unsupportedModel )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT id FROM test"));
- BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::ClassMap>(*sel), Slicer::UnsupportedModelType);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT id FROM test");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::ClassMap>(sel), Slicer::UnsupportedModelType);
}
BOOST_AUTO_TEST_CASE( select_tooManyRowsSimple )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT id FROM test"));
- BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(*sel), Slicer::TooManyRowsReturned);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT id FROM test");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(sel), Slicer::TooManyRowsReturned);
}
BOOST_AUTO_TEST_CASE( select_noRowsSimple )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT id FROM test WHERE false"));
- BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(*sel), Slicer::NoRowsReturned);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT id FROM test WHERE false");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(sel), Slicer::NoRowsReturned);
}
BOOST_AUTO_TEST_CASE( select_noRowsSimpleOptional )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT id FROM test WHERE false"));
- auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, IceUtil::Optional<Ice::Int>>(*sel);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT id FROM test WHERE false");
+ auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, IceUtil::Optional<Ice::Int>>(sel);
BOOST_REQUIRE(!v);
}
BOOST_AUTO_TEST_CASE( select_tooManyRowsSimpleOptional )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT id FROM test"));
- BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<IceUtil::Optional<Ice::Int>>(*sel), Slicer::TooManyRowsReturned);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT id FROM test");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<IceUtil::Optional<Ice::Int>>(sel), Slicer::TooManyRowsReturned);
}
BOOST_AUTO_TEST_CASE( select_simpleOptional )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT MAX(id) FROM test"));
- auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, IceUtil::Optional<Ice::Int>>(*sel);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT MAX(id) FROM test");
+ auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, IceUtil::Optional<Ice::Int>>(sel);
BOOST_REQUIRE(v);
BOOST_REQUIRE_EQUAL(4, *v);
}
BOOST_AUTO_TEST_CASE( select_noRowsComplexOptional )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand(
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select(
"SELECT boolean mbool, \
id mbyte, id mshort, id mint, id mlong, \
fl mdouble, fl mfloat, \
string mstring \
FROM test \
- WHERE false"));
- auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, IceUtil::Optional<TestModule::BuiltInsPtr>>(*sel);
+ WHERE false");
+ auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, IceUtil::Optional<TestModule::BuiltInsPtr>>(sel);
BOOST_REQUIRE(!v);
}
BOOST_AUTO_TEST_CASE( select_tooManyRowsComplex )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT id FROM test"));
- BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::BuiltInsPtr>(*sel), Slicer::TooManyRowsReturned);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT id FROM test");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::BuiltInsPtr>(sel), Slicer::TooManyRowsReturned);
}
BOOST_AUTO_TEST_CASE( select_noRowsComplex )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT id FROM test WHERE false"));
- BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::BuiltInsPtr>(*sel), Slicer::NoRowsReturned);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT id FROM test WHERE false");
+ BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::BuiltInsPtr>(sel), Slicer::NoRowsReturned);
}
BOOST_AUTO_TEST_CASE( select_emptySequence )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT id FROM test WHERE false"));
- auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BaseSeq>(*sel);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT id FROM test WHERE false");
+ auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BaseSeq>(sel);
BOOST_REQUIRE_EQUAL(0, bi.size());
}
BOOST_AUTO_TEST_CASE( select_null )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
db->execute("INSERT INTO test(id) VALUES(NULL)");
- auto sel = SelectPtr(db->newSelectCommand("SELECT id optSimple FROM test WHERE id IS NULL"));
- auto oi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::OptionalsPtr>(*sel);
+ auto sel = db->select("SELECT id optSimple FROM test WHERE id IS NULL");
+ auto oi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::OptionalsPtr>(sel);
BOOST_REQUIRE(!oi->optSimple);
- sel = SelectPtr(db->newSelectCommand("SELECT MAX(id) optSimple FROM test WHERE id IS NOT NULL"));
- oi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::OptionalsPtr>(*sel);
+ sel = db->select("SELECT MAX(id) optSimple FROM test WHERE id IS NOT NULL");
+ oi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::OptionalsPtr>(sel);
BOOST_REQUIRE(oi->optSimple);
BOOST_REQUIRE_EQUAL(*oi->optSimple, 4);
- sel = SelectPtr(db->newSelectCommand("SELECT MAX(id) FROM test WHERE false"));
- auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, IceUtil::Optional<Ice::Int>>(*sel);
+ sel = db->select("SELECT MAX(id) FROM test WHERE false");
+ auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, IceUtil::Optional<Ice::Int>>(sel);
BOOST_REQUIRE(!v);
}
diff --git a/slicer/db/testUpdate.cpp b/slicer/db/testUpdate.cpp
index f97a3f5..c33e645 100644
--- a/slicer/db/testUpdate.cpp
+++ b/slicer/db/testUpdate.cpp
@@ -14,9 +14,9 @@
using namespace std::literals;
-class StandardMockDatabase : public PQ::Mock {
+class StandardMockDatabase : public DB::PluginMock<PQ::Mock> {
public:
- StandardMockDatabase() : PQ::Mock("user=postgres dbname=postgres", "pqmock", {
+ StandardMockDatabase() : DB::PluginMock<PQ::Mock>("user=postgres dbname=postgres", "pqmock", {
rootDir.parent_path() / "db" / "slicer.sql" })
{
}
@@ -24,29 +24,26 @@ class StandardMockDatabase : public PQ::Mock {
BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
-typedef boost::shared_ptr<DB::Connection> DBPtr;
-typedef boost::shared_ptr<DB::SelectCommand> SelectPtr;
-
BOOST_AUTO_TEST_CASE( update_builtinsNotFound )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestModule::BuiltInsPtr ubi = std::make_shared<TestModule::BuiltIns>(false, 5, 17, 64, 129, -1.2, -1.4, "string");
- BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(ubi, db.get(), "builtins"), Slicer::NoRowsFound);
+ BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(ubi, db, "builtins"), Slicer::NoRowsFound);
}
BOOST_AUTO_TEST_CASE( update_builtins )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestModule::BuiltInsPtr bi1 = std::make_shared<TestModule::BuiltIns>(true, 4, 16, 64, 128, 1.2, 3.4, "text1");
TestModule::BuiltInsPtr bi2 = std::make_shared<TestModule::BuiltIns>(true, 3, 15, 63, 127, 5.2, 5.4, "text2");
- Slicer::SerializeAny<Slicer::SqlInsertSerializer>(bi1, db.get(), "builtins");
- Slicer::SerializeAny<Slicer::SqlInsertSerializer>(bi2, db.get(), "builtins");
+ Slicer::SerializeAny<Slicer::SqlInsertSerializer>(bi1, db, "builtins");
+ Slicer::SerializeAny<Slicer::SqlInsertSerializer>(bi2, db, "builtins");
TestModule::BuiltInsPtr ubi = std::make_shared<TestModule::BuiltIns>(false, 5, 17, 64, 128, -1.2, -1.4, "string");
- Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(ubi, db.get(), "builtins");
+ Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(ubi, db, "builtins");
- auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM builtins ORDER BY mint DESC"));
- auto bis = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(*sel);
+ auto sel = db->select("SELECT * FROM builtins ORDER BY mint DESC");
+ auto bis = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(sel);
BOOST_REQUIRE_EQUAL(2, bis.size());
BOOST_REQUIRE_EQUAL(bis.front()->mbool, ubi->mbool);
BOOST_REQUIRE_EQUAL(bis.front()->mbyte, ubi->mbyte);
@@ -68,15 +65,15 @@ BOOST_AUTO_TEST_CASE( update_builtins )
BOOST_AUTO_TEST_CASE( update_builtins_seq )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestModule::BuiltInSeq ubis {
TestModule::BuiltInsPtr(std::make_shared<TestModule::BuiltIns>(false, 5, 17, 64, 128, -1.2, -1.4, "string")),
TestModule::BuiltInsPtr(std::make_shared<TestModule::BuiltIns>(false, 5, 21, 63, 127, -4.2, -5.4, "string updated"))
};
- Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(ubis, db.get(), "builtins");
+ Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(ubis, db, "builtins");
- auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM builtins ORDER BY mint"));
- auto ubis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(*sel);
+ auto sel = db->select("SELECT * FROM builtins ORDER BY mint");
+ auto ubis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(sel);
BOOST_REQUIRE_EQUAL(2, ubis2.size());
BOOST_REQUIRE_EQUAL(ubis.front()->mbool, ubis2.back()->mbool);
BOOST_REQUIRE_EQUAL(ubis.front()->mbyte, ubis2.back()->mbyte);
@@ -98,9 +95,9 @@ BOOST_AUTO_TEST_CASE( update_builtins_seq )
BOOST_AUTO_TEST_CASE( update_withNulls )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
- auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM builtins ORDER BY mint"));
- auto bis = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(*sel);
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
+ auto sel = db->select("SELECT * FROM builtins ORDER BY mint");
+ auto bis = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(sel);
BOOST_REQUIRE_EQUAL(2, bis.size());
BOOST_REQUIRE_EQUAL("string updated", *bis[0]->mstring);
BOOST_REQUIRE_EQUAL("string", *bis[1]->mstring);
@@ -111,8 +108,8 @@ BOOST_AUTO_TEST_CASE( update_withNulls )
bis[0]->mshort = IceUtil::Optional<Ice::Short>();
bis[1]->mdouble = IceUtil::Optional<Ice::Double>();
BOOST_TEST_CHECKPOINT("Do update");
- Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(bis, db.get(), "builtins");
- auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(*sel);
+ Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(bis, db, "builtins");
+ auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(sel);
BOOST_REQUIRE(bis2[0]->mstring);
BOOST_REQUIRE(!bis2[1]->mstring);
BOOST_REQUIRE(bis2[0]->mbyte);
@@ -123,8 +120,8 @@ BOOST_AUTO_TEST_CASE( update_withNulls )
BOOST_AUTO_TEST_CASE( update_unsupportedModel )
{
- auto db = DBPtr(DB::MockDatabase::openConnectionTo("pqmock"));
+ auto db = DB::MockDatabase::openConnectionTo("pqmock");
TestModule::ClassMap cm;
- BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(cm, db.get(), "converted"), Slicer::UnsupportedModelType);
+ BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(cm, db, "converted"), Slicer::UnsupportedModelType);
}