summaryrefslogtreecommitdiff
path: root/slicer/db
diff options
context:
space:
mode:
Diffstat (limited to 'slicer/db')
-rw-r--r--slicer/db/Jamfile.jam7
-rw-r--r--slicer/db/sqlBinder.cpp7
-rw-r--r--slicer/db/sqlBinder.h44
-rw-r--r--slicer/db/sqlCommon.cpp40
-rw-r--r--slicer/db/sqlCommon.h3
-rw-r--r--slicer/db/sqlInsertSerializer.cpp102
-rw-r--r--slicer/db/sqlInsertSerializer.h61
-rw-r--r--slicer/db/sqlSelectDeserializer.cpp69
-rw-r--r--slicer/db/sqlSelectDeserializer.h27
-rw-r--r--slicer/db/sqlSource.cpp6
-rw-r--r--slicer/db/sqlSource.h43
-rw-r--r--slicer/db/sqlTablePatchSerializer.cpp16
-rw-r--r--slicer/db/sqlTablePatchSerializer.h17
-rw-r--r--slicer/db/sqlUpdateSerializer.cpp32
-rw-r--r--slicer/db/sqlUpdateSerializer.h23
-rw-r--r--slicer/db/testConversions.cpp8
-rw-r--r--slicer/db/testInsert.cpp65
-rw-r--r--slicer/db/testMockCommon.cpp11
-rw-r--r--slicer/db/testMockCommon.h13
-rw-r--r--slicer/db/testPatch.cpp23
-rw-r--r--slicer/db/testSelect.cpp87
-rw-r--r--slicer/db/testUpdate.cpp34
22 files changed, 361 insertions, 377 deletions
diff --git a/slicer/db/Jamfile.jam b/slicer/db/Jamfile.jam
index fcfa4d3..7a5de7e 100644
--- a/slicer/db/Jamfile.jam
+++ b/slicer/db/Jamfile.jam
@@ -39,7 +39,6 @@ lib testCommon :
:
<dependency>../tool//slicer
<slicer>pure
- <slicerbin>../tool//slicer
<implicit-dependency>../test//types
<library>../test//types
<library>../test//common
@@ -48,6 +47,12 @@ lib testCommon :
<library>..//adhocutil
<library>dbicetypes
<implicit-dependency>dbicetypes
+ <toolset>gcc:<dependency>../tool//slicer/<toolset>gcc
+ <toolset>clang:<dependency>../tool//slicer/<toolset>clang
+ <toolset>tidy:<dependency>../tool//slicer/<toolset>gcc
+ <toolset>gcc:<slicerbin>../tool//slicer/<toolset>gcc
+ <toolset>clang:<slicerbin>../tool//slicer/<toolset>clang
+ <toolset>tidy:<slicerbin>../tool//slicer/<toolset>gcc
: :
<library>..//adhocutil
<library>dbicetypes
diff --git a/slicer/db/sqlBinder.cpp b/slicer/db/sqlBinder.cpp
index 6969749..8245217 100644
--- a/slicer/db/sqlBinder.cpp
+++ b/slicer/db/sqlBinder.cpp
@@ -1,11 +1,7 @@
#include "sqlBinder.h"
namespace Slicer {
- SqlBinder::SqlBinder(DB::Command & c, unsigned int i) :
- command(c),
- idx(i)
- {
- }
+ SqlBinder::SqlBinder(DB::Command & c, unsigned int i) : command(c), idx(i) { }
void
SqlBinder::get(const boost::posix_time::ptime & b) const
@@ -67,4 +63,3 @@ namespace Slicer {
command.bindParamS(idx, b);
}
}
-
diff --git a/slicer/db/sqlBinder.h b/slicer/db/sqlBinder.h
index f7a0be6..8c1ce80 100644
--- a/slicer/db/sqlBinder.h
+++ b/slicer/db/sqlBinder.h
@@ -1,36 +1,34 @@
#ifndef SLICER_DB_SQLBINDER_H
#define SLICER_DB_SQLBINDER_H
-#include <slicer/modelParts.h>
-#include <command.h>
#include <boost/date_time/posix_time/ptime.hpp>
+#include <command.h>
+#include <slicer/modelParts.h>
namespace Slicer {
- class SqlBinder : public Slicer::ValueTarget,
- public Slicer::TValueTarget<boost::posix_time::time_duration>,
- public Slicer::TValueTarget<boost::posix_time::ptime>
- {
- public:
- SqlBinder(DB::Command & c, unsigned int idx);
+ class SqlBinder :
+ public Slicer::ValueTarget,
+ public Slicer::TValueTarget<boost::posix_time::time_duration>,
+ public Slicer::TValueTarget<boost::posix_time::ptime> {
+ public:
+ SqlBinder(DB::Command & c, unsigned int idx);
- void get(const boost::posix_time::ptime & b) const override;
- void get(const boost::posix_time::time_duration & b) const override;
- void get(const bool & b) const override;
- void get(const Ice::Byte & b) const override;
- void get(const Ice::Short & b) const override;
- void get(const Ice::Int & b) const override;
- void get(const Ice::Long & b) const override;
- void get(const Ice::Float & b) const override;
- void get(const Ice::Double & b) const override;
- void get(const std::string & b) const override;
+ void get(const boost::posix_time::ptime & b) const override;
+ void get(const boost::posix_time::time_duration & b) const override;
+ void get(const bool & b) const override;
+ void get(const Ice::Byte & b) const override;
+ void get(const Ice::Short & b) const override;
+ void get(const Ice::Int & b) const override;
+ void get(const Ice::Long & b) const override;
+ void get(const Ice::Float & b) const override;
+ void get(const Ice::Double & b) const override;
+ void get(const std::string & b) const override;
- private:
- DB::Command & command;
- const unsigned int idx;
+ private:
+ DB::Command & command;
+ const unsigned int idx;
};
typedef std::shared_ptr<SqlBinder> SqlBinderPtr;
}
#endif
-
-
diff --git a/slicer/db/sqlCommon.cpp b/slicer/db/sqlCommon.cpp
index 193285e..ecce6cc 100644
--- a/slicer/db/sqlCommon.cpp
+++ b/slicer/db/sqlCommon.cpp
@@ -1,7 +1,7 @@
-#include <sqlExceptions.h>
-#include <compileTimeFormatter.h>
#include "sqlCommon.h"
+#include <compileTimeFormatter.h>
#include <metadata.h>
+#include <sqlExceptions.h>
namespace Slicer {
const std::string md_pkey = "db:pkey";
@@ -9,53 +9,61 @@ namespace Slicer {
const std::string md_ignore = "db:ignore";
const std::string md_global_ignore = "ignore";
- bool isPKey(const HookCommon * h)
+ bool
+ isPKey(const HookCommon * h)
{
return metaDataFlagSet(h->GetMetadata(), md_pkey) && isBind(h);
}
- bool isAuto(const HookCommon * h)
+ bool
+ isAuto(const HookCommon * h)
{
return metaDataFlagSet(h->GetMetadata(), md_auto) && isBind(h);
}
- bool isNotAuto(const HookCommon * h)
+ bool
+ isNotAuto(const HookCommon * h)
{
return metaDataFlagNotSet(h->GetMetadata(), md_auto) && isBind(h);
}
- bool isBind(const HookCommon * h)
+ bool
+ isBind(const HookCommon * h)
{
- return metaDataFlagNotSet(h->GetMetadata(), md_global_ignore) &&
- metaDataFlagNotSet(h->GetMetadata(), md_ignore);
+ return metaDataFlagNotSet(h->GetMetadata(), md_global_ignore)
+ && metaDataFlagNotSet(h->GetMetadata(), md_ignore);
}
- bool isValue(const HookCommon * h)
+ bool
+ isValue(const HookCommon * h)
{
- return metaDataFlagNotSet(h->GetMetadata(), md_auto) &&
- metaDataFlagNotSet(h->GetMetadata(), md_pkey) && isBind(h);
+ return metaDataFlagNotSet(h->GetMetadata(), md_auto) && metaDataFlagNotSet(h->GetMetadata(), md_pkey)
+ && isBind(h);
}
- void TooManyRowsReturned::ice_print(std::ostream & s) const
+ void
+ TooManyRowsReturned::ice_print(std::ostream & s) const
{
s << "Too many rows returned";
}
- void NoRowsReturned::ice_print(std::ostream & s) const
+ void
+ NoRowsReturned::ice_print(std::ostream & s) const
{
s << "No rows returned";
}
- void NoRowsFound::ice_print(std::ostream & s) const
+ void
+ NoRowsFound::ice_print(std::ostream & s) const
{
s << "No rows found";
}
AdHocFormatter(UnsuitableIdFieldTypeMsg, "Unsuitable id field type [%?]");
- void UnsuitableIdFieldType::ice_print(std::ostream & s) const
+ void
+ UnsuitableIdFieldType::ice_print(std::ostream & s) const
{
UnsuitableIdFieldTypeMsg::write(s, type);
}
}
-
diff --git a/slicer/db/sqlCommon.h b/slicer/db/sqlCommon.h
index 954800a..32afd87 100644
--- a/slicer/db/sqlCommon.h
+++ b/slicer/db/sqlCommon.h
@@ -1,8 +1,8 @@
#ifndef SLICER_DB_SQLCOMMON_H
#define SLICER_DB_SQLCOMMON_H
-#include <string>
#include <modelParts.h>
+#include <string>
namespace Slicer {
bool isPKey(const HookCommon *);
@@ -13,4 +13,3 @@ namespace Slicer {
}
#endif
-
diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp
index dde8f1f..4061b17 100644
--- a/slicer/db/sqlInsertSerializer.cpp
+++ b/slicer/db/sqlInsertSerializer.cpp
@@ -1,20 +1,20 @@
-#include "sqlInsertSerializer.h"
-#include <common.h>
-#include <sqlExceptions.h>
#include "sqlBinder.h"
#include "sqlCommon.h"
+#include "sqlInsertSerializer.h"
+#include <boost/numeric/conversion/cast.hpp>
+#include <common.h>
#include <compileTimeFormatter.h>
+#include <functional>
#include <modifycommand.h>
#include <slicer/metadata.h>
-#include <boost/numeric/conversion/cast.hpp>
-#include <functional>
+#include <sqlExceptions.h>
+#include <type_traits>
namespace Slicer {
using namespace std::placeholders;
SqlInsertSerializer::SqlInsertSerializer(DB::Connection * const c, std::string t) :
- connection(c),
- tableName(std::move(t))
+ connection(c), tableName(std::move(t))
{
}
@@ -22,11 +22,15 @@ namespace Slicer {
SqlInsertSerializer::Serialize(Slicer::ModelPartForRootPtr mp)
{
switch (mp->GetType()) {
- case Slicer::mpt_Sequence:
- mp->OnEachChild(std::bind(&SqlInsertSerializer::SerializeSequence, this, _2));
+ case Slicer::ModelPartType::Sequence:
+ mp->OnEachChild([this](auto &&, auto && PH2, auto &&) {
+ SerializeSequence(PH2);
+ });
return;
- case Slicer::mpt_Complex:
- mp->OnEachChild(std::bind(&SqlInsertSerializer::SerializeObject, this, _2));
+ case Slicer::ModelPartType::Complex:
+ mp->OnEachChild([this](auto &&, auto && PH2, auto &&) {
+ SerializeObject(PH2);
+ });
return;
default:
throw UnsupportedModelType();
@@ -45,45 +49,52 @@ namespace Slicer {
{
auto ins = createInsert(mp->GetContainedModelPart());
mp->OnEachChild([&ins, this](const std::string &, const ModelPartPtr & cmp, const HookCommon *) {
- bindObjectAndExecute(cmp, ins.get());
- });
+ bindObjectAndExecute(cmp, ins.get());
+ });
}
void
SqlInsertSerializer::bindObjectAndExecute(const Slicer::ModelPartPtr & cmp, DB::ModifyCommand * ins) const
{
int paramNo = 0;
- cmp->OnEachChild(std::bind(&SqlInsertSerializer::bindObjectAndExecuteField, this, std::ref(paramNo), ins, _2, _3));
+ cmp->OnEachChild([this, &paramNo, ins](auto &&, auto && PH2, auto && PH3) {
+ bindObjectAndExecuteField(paramNo, ins, PH2, PH3);
+ });
ins->execute();
}
class IdSave : public Slicer::ValueSource {
- public:
- explicit IdSave(DB::Connection * const c) :
- connection(c)
- {
- }
-
-#define NonNumType(T) \
- /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
- void set(T &) const override { throw UnsuitableIdFieldType(#T); }
+ public:
+ explicit IdSave(DB::Connection * const c) : connection(c) { }
#define NumType(T) \
- /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
- void set(T & v) const override { v = boost::numeric_cast<T>(connection->insertId()); }
-
- NonNumType(bool);
- NonNumType(std::string);
-
- NumType(Ice::Byte);
- NumType(Ice::Short);
- NumType(Ice::Int);
- NumType(Ice::Long);
- NumType(Ice::Float);
- NumType(Ice::Double);
+ void set(T & v) const override \
+ { \
+ doSet(v, #T); \
+ }
- private:
- DB::Connection * const connection;
+ NumType(bool);
+ NumType(std::string);
+ NumType(Ice::Byte);
+ NumType(Ice::Short);
+ NumType(Ice::Int);
+ NumType(Ice::Long);
+ NumType(Ice::Float);
+ NumType(Ice::Double);
+
+ private:
+ DB::Connection * const connection;
+ template<typename T>
+ inline void
+ doSet([[maybe_unused]] T & v, [[maybe_unused]] const char * Tname) const
+ {
+ if constexpr (std::is_integral_v<T>) {
+ v = boost::numeric_cast<T>(connection->insertId());
+ }
+ else {
+ throw UnsuitableIdFieldType(Tname);
+ }
+ }
};
void
@@ -98,7 +109,8 @@ namespace Slicer {
}
void
- SqlInsertSerializer::bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand * ins, const Slicer::ModelPartPtr & cmp, const HookCommon * h) const
+ SqlInsertSerializer::bindObjectAndExecuteField(
+ int & paramNo, DB::ModifyCommand * ins, const Slicer::ModelPartPtr & cmp, const HookCommon * h) const
{
if (isBind(h)) {
if (!cmp->GetValue(SqlBinder(*ins, paramNo))) {
@@ -109,7 +121,8 @@ namespace Slicer {
}
void
- SqlAutoIdInsertSerializer::bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand * ins, const Slicer::ModelPartPtr & cmp, const HookCommon * h) const
+ SqlAutoIdInsertSerializer::bindObjectAndExecuteField(
+ int & paramNo, DB::ModifyCommand * ins, const Slicer::ModelPartPtr & cmp, const HookCommon * h) const
{
if (isNotAuto(h)) {
SqlInsertSerializer::bindObjectAndExecuteField(paramNo, ins, cmp, h);
@@ -123,7 +136,9 @@ namespace Slicer {
std::stringstream insert;
"INSERT INTO %?("_fmt(insert, tableName);
int fieldNo = 0;
- mp->OnEachChild(std::bind(&SqlInsertSerializer::createInsertField, this, std::ref(fieldNo), std::ref(insert), _1, _3));
+ mp->OnEachChild([this, &fieldNo, &insert](auto && PH1, auto &&, auto && PH3) {
+ createInsertField(fieldNo, insert, PH1, PH3);
+ });
insert << ") VALUES (";
for (; fieldNo > 1; --fieldNo) {
insert << "?, ";
@@ -133,7 +148,8 @@ namespace Slicer {
}
void
- SqlInsertSerializer::createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const
+ SqlInsertSerializer::createInsertField(
+ int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const
{
if (isBind(h)) {
if (fieldNo++) {
@@ -144,7 +160,8 @@ namespace Slicer {
}
void
- SqlAutoIdInsertSerializer::createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const
+ SqlAutoIdInsertSerializer::createInsertField(
+ int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const
{
if (isNotAuto(h)) {
if (fieldNo++) {
@@ -154,4 +171,3 @@ namespace Slicer {
}
}
}
-
diff --git a/slicer/db/sqlInsertSerializer.h b/slicer/db/sqlInsertSerializer.h
index 175706f..6150d66 100644
--- a/slicer/db/sqlInsertSerializer.h
+++ b/slicer/db/sqlInsertSerializer.h
@@ -1,49 +1,50 @@
#ifndef SLICER_DB_SQLINSERTSERIALIZER_H
#define SLICER_DB_SQLINSERTSERIALIZER_H
-#include <slicer/serializer.h>
#include <connection.h>
-#include <visibility.h>
#include <ostream>
+#include <slicer/serializer.h>
+#include <visibility.h>
namespace Slicer {
class DLL_PUBLIC SqlInsertSerializer : public Slicer::Serializer {
- public:
- SqlInsertSerializer(DB::Connection * const, std::string tableName);
-
- void Serialize(Slicer::ModelPartForRootPtr) override;
-
- protected:
- void SerializeObject(const Slicer::ModelPartPtr &) const;
- void SerializeSequence(const Slicer::ModelPartPtr &) const;
- DB::ModifyCommandPtr createInsert(const Slicer::ModelPartPtr &) const;
- virtual void createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const;
- virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const;
- virtual void bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const;
-
- DB::Connection * const connection;
- const std::string tableName;
+ public:
+ SqlInsertSerializer(DB::Connection * const, std::string tableName);
+
+ void Serialize(Slicer::ModelPartForRootPtr) override;
+
+ protected:
+ void SerializeObject(const Slicer::ModelPartPtr &) const;
+ void SerializeSequence(const Slicer::ModelPartPtr &) const;
+ DB::ModifyCommandPtr createInsert(const Slicer::ModelPartPtr &) const;
+ virtual void createInsertField(
+ int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const;
+ virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const;
+ virtual void bindObjectAndExecuteField(
+ int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const;
+
+ DB::Connection * const connection;
+ const std::string tableName;
};
class DLL_PUBLIC SqlAutoIdInsertSerializer : public SqlInsertSerializer {
- public:
- template <typename ... P>
- SqlAutoIdInsertSerializer(const P & ... p) : SqlInsertSerializer(p...) { }
-
- protected:
- virtual void createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const;
- virtual void bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const;
+ public:
+ template<typename... P> SqlAutoIdInsertSerializer(const P &... p) : SqlInsertSerializer(p...) { }
+
+ protected:
+ virtual void createInsertField(
+ int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const;
+ virtual void bindObjectAndExecuteField(
+ int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const;
};
class DLL_PUBLIC SqlFetchIdInsertSerializer : public SqlAutoIdInsertSerializer {
- public:
- template <typename ... P>
- SqlFetchIdInsertSerializer(const P & ... p) : SqlAutoIdInsertSerializer(p...) { }
+ public:
+ template<typename... P> SqlFetchIdInsertSerializer(const P &... p) : SqlAutoIdInsertSerializer(p...) { }
- protected:
- virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const;
+ protected:
+ virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const;
};
}
#endif
-
diff --git a/slicer/db/sqlSelectDeserializer.cpp b/slicer/db/sqlSelectDeserializer.cpp
index ff16c43..8982958 100644
--- a/slicer/db/sqlSelectDeserializer.cpp
+++ b/slicer/db/sqlSelectDeserializer.cpp
@@ -1,13 +1,11 @@
#include "sqlSelectDeserializer.h"
#include "sqlSource.h"
-#include <sqlExceptions.h>
#include <common.h>
+#include <sqlExceptions.h>
namespace Slicer {
SqlSelectDeserializer::SqlSelectDeserializer(DB::SelectCommand * c, Ice::optional<std::string> tc) :
- cmd(c),
- columnCount(0),
- typeIdColName(std::move(tc))
+ cmd(c), columnCount(0), typeIdColName(std::move(tc))
{
}
@@ -20,13 +18,13 @@ namespace Slicer {
typeIdColIdx = cmd->getOrdinal(*typeIdColName);
}
switch (mp->GetType()) {
- case Slicer::mpt_Sequence:
+ case Slicer::ModelPartType::Sequence:
DeserializeSequence(mp);
return;
- case Slicer::mpt_Complex:
+ case Slicer::ModelPartType::Complex:
DeserializeObject(mp);
return;
- case Slicer::mpt_Simple:
+ case Slicer::ModelPartType::Simple:
DeserializeSimple(mp);
return;
default:
@@ -74,7 +72,7 @@ namespace Slicer {
}
DeserializeRow(mp);
if (cmd->fetch()) {
- while (cmd->fetch()) {}
+ while (cmd->fetch()) { }
throw TooManyRowsReturned();
}
}
@@ -85,43 +83,38 @@ namespace Slicer {
auto rmp = mp->GetAnonChild();
if (rmp) {
switch (rmp->GetType()) {
- case Slicer::mpt_Complex:
- {
- if (typeIdColIdx) {
- std::string subclass;
- (*cmd)[*typeIdColIdx] >> subclass;
- rmp = rmp->GetSubclassModelPart(subclass);
- }
- rmp->Create();
- for (auto col = 0U; col < columnCount; col += 1) {
- const DB::Column & c = (*cmd)[col];
- if (!c.isNull()) {
- auto fmpr = rmp->GetChildRef(c.name, nullptr, false);
- if (fmpr) {
- auto fmp = fmpr.Child();
- fmp->Create();
- fmp->SetValue(SqlSource(c));
- fmp->Complete();
- }
- }
- }
- rmp->Complete();
+ case Slicer::ModelPartType::Complex: {
+ if (typeIdColIdx) {
+ std::string subclass;
+ (*cmd)[*typeIdColIdx] >> subclass;
+ rmp = rmp->GetSubclassModelPart(subclass);
}
- break;
- case Slicer::mpt_Simple:
- {
- rmp->Create();
- const DB::Column & c = (*cmd)[0];
+ rmp->Create();
+ for (auto col = 0U; col < columnCount; col += 1) {
+ const DB::Column & c = (*cmd)[col];
if (!c.isNull()) {
- rmp->SetValue(SqlSource(c));
+ auto fmpr = rmp->GetChildRef(c.name, nullptr, false);
+ if (fmpr) {
+ auto fmp = fmpr.Child();
+ fmp->Create();
+ fmp->SetValue(SqlSource(c));
+ fmp->Complete();
+ }
}
- rmp->Complete();
}
- break;
+ rmp->Complete();
+ } break;
+ case Slicer::ModelPartType::Simple: {
+ rmp->Create();
+ const DB::Column & c = (*cmd)[0];
+ if (!c.isNull()) {
+ rmp->SetValue(SqlSource(c));
+ }
+ rmp->Complete();
+ } break;
default:
throw UnsupportedModelType();
}
}
}
}
-
diff --git a/slicer/db/sqlSelectDeserializer.h b/slicer/db/sqlSelectDeserializer.h
index e9afd1d..5f34ef4 100644
--- a/slicer/db/sqlSelectDeserializer.h
+++ b/slicer/db/sqlSelectDeserializer.h
@@ -1,29 +1,28 @@
#ifndef SLICER_DB_SQLSELECTDESERIALIZER_H
#define SLICER_DB_SQLSELECTDESERIALIZER_H
-#include <slicer/serializer.h>
#include <selectcommand.h>
+#include <slicer/serializer.h>
#include <visibility.h>
namespace Slicer {
class DLL_PUBLIC SqlSelectDeserializer : public Slicer::Deserializer {
- public:
- SqlSelectDeserializer(DB::SelectCommand *, Ice::optional<std::string> typeIdCol = Ice::optional<std::string>());
+ public:
+ SqlSelectDeserializer(DB::SelectCommand *, Ice::optional<std::string> typeIdCol = Ice::optional<std::string>());
- void Deserialize(Slicer::ModelPartForRootPtr) override;
+ void Deserialize(Slicer::ModelPartForRootPtr) override;
- protected:
- void DLL_PRIVATE DeserializeSimple(const Slicer::ModelPartPtr &);
- void DLL_PRIVATE DeserializeObject(const Slicer::ModelPartPtr &);
- void DLL_PRIVATE DeserializeSequence(const Slicer::ModelPartPtr &);
- void DLL_PRIVATE DeserializeRow(const Slicer::ModelPartPtr &);
+ protected:
+ void DLL_PRIVATE DeserializeSimple(const Slicer::ModelPartPtr &);
+ void DLL_PRIVATE DeserializeObject(const Slicer::ModelPartPtr &);
+ void DLL_PRIVATE DeserializeSequence(const Slicer::ModelPartPtr &);
+ void DLL_PRIVATE DeserializeRow(const Slicer::ModelPartPtr &);
- DB::SelectCommand * cmd;
- unsigned int columnCount;
- Ice::optional<std::string> typeIdColName;
- Ice::optional<unsigned int> typeIdColIdx;
+ DB::SelectCommand * cmd;
+ unsigned int columnCount;
+ Ice::optional<std::string> typeIdColName;
+ Ice::optional<unsigned int> typeIdColIdx;
};
}
#endif
-
diff --git a/slicer/db/sqlSource.cpp b/slicer/db/sqlSource.cpp
index eeea99c..84964f2 100644
--- a/slicer/db/sqlSource.cpp
+++ b/slicer/db/sqlSource.cpp
@@ -2,10 +2,7 @@
#include <boost/numeric/conversion/cast.hpp>
namespace Slicer {
- SqlSource::SqlSource(const DB::Column & c) :
- column(c)
- {
- }
+ SqlSource::SqlSource(const DB::Column & c) : column(c) { }
bool
SqlSource::isNull() const
@@ -83,4 +80,3 @@ namespace Slicer {
column >> b;
}
}
-
diff --git a/slicer/db/sqlSource.h b/slicer/db/sqlSource.h
index 99ffabb..548f35e 100644
--- a/slicer/db/sqlSource.h
+++ b/slicer/db/sqlSource.h
@@ -1,35 +1,34 @@
#ifndef SLICER_DB_SQLSOURCE_H
#define SLICER_DB_SQLSOURCE_H
-#include <slicer/modelParts.h>
-#include <column.h>
#include <boost/date_time/posix_time/ptime.hpp>
+#include <column.h>
+#include <slicer/modelParts.h>
namespace Slicer {
- class SqlSource : public Slicer::ValueSource,
- public Slicer::TValueSource<boost::posix_time::time_duration>,
- public Slicer::TValueSource<boost::posix_time::ptime>
- {
- public:
- SqlSource(const DB::Column & c);
+ class SqlSource :
+ public Slicer::ValueSource,
+ public Slicer::TValueSource<boost::posix_time::time_duration>,
+ public Slicer::TValueSource<boost::posix_time::ptime> {
+ public:
+ SqlSource(const DB::Column & c);
- bool isNull() const;
- void set(boost::posix_time::ptime & b) const override;
- void set(boost::posix_time::time_duration & b) const override;
- void set(bool & b) const override;
- void set(Ice::Byte & b) const override;
- void set(Ice::Short & b) const override;
- void set(Ice::Int & b) const override;
- void set(Ice::Long & b) const override;
- void set(Ice::Float & b) const override;
- void set(Ice::Double & b) const override;
- void set(std::string & b) const override;
+ bool isNull() const;
+ void set(boost::posix_time::ptime & b) const override;
+ void set(boost::posix_time::time_duration & b) const override;
+ void set(bool & b) const override;
+ void set(Ice::Byte & b) const override;
+ void set(Ice::Short & b) const override;
+ void set(Ice::Int & b) const override;
+ void set(Ice::Long & b) const override;
+ void set(Ice::Float & b) const override;
+ void set(Ice::Double & b) const override;
+ void set(std::string & b) const override;
- private:
- const DB::Column & column;
+ private:
+ const DB::Column & column;
};
typedef std::shared_ptr<SqlSource> SqlSourcePtr;
}
#endif
-
diff --git a/slicer/db/sqlTablePatchSerializer.cpp b/slicer/db/sqlTablePatchSerializer.cpp
index ec5b59b..7c29be5 100644
--- a/slicer/db/sqlTablePatchSerializer.cpp
+++ b/slicer/db/sqlTablePatchSerializer.cpp
@@ -1,16 +1,15 @@
-#include "sqlTablePatchSerializer.h"
-#include "sqlInsertSerializer.h"
#include "sqlCommon.h"
-#include <slicer/metadata.h>
+#include "sqlInsertSerializer.h"
+#include "sqlTablePatchSerializer.h"
#include <compileTimeFormatter.h>
-#include <scopeExit.h>
#include <functional>
+#include <scopeExit.h>
+#include <slicer/metadata.h>
namespace Slicer {
AdHocFormatter(ttname, "slicer_tmp_%?");
SqlTablePatchSerializer::SqlTablePatchSerializer(DB::Connection * const db, DB::TablePatch & tp) :
- db(db),
- tablePatch(tp)
+ db(db), tablePatch(tp)
{
tablePatch.src = ttname::get(this);
}
@@ -22,7 +21,9 @@ namespace Slicer {
tablePatch.cols.clear();
createTemporaryTable();
- AdHoc::ScopeExit tidy(std::bind(&SqlTablePatchSerializer::dropTemporaryTable, this));
+ AdHoc::ScopeExit tidy([this] {
+ dropTemporaryTable();
+ });
SqlInsertSerializer ins(db, tablePatch.src);
ins.Serialize(mpr);
@@ -56,4 +57,3 @@ namespace Slicer {
db->execute(dropTmpTable::get(tablePatch.src));
}
}
-
diff --git a/slicer/db/sqlTablePatchSerializer.h b/slicer/db/sqlTablePatchSerializer.h
index 00ea328..9a82f85 100644
--- a/slicer/db/sqlTablePatchSerializer.h
+++ b/slicer/db/sqlTablePatchSerializer.h
@@ -6,19 +6,18 @@
namespace Slicer {
class DLL_PUBLIC SqlTablePatchSerializer : public Slicer::Serializer {
- public:
- SqlTablePatchSerializer(DB::Connection * const, DB::TablePatch &);
+ public:
+ SqlTablePatchSerializer(DB::Connection * const, DB::TablePatch &);
- void Serialize(Slicer::ModelPartForRootPtr) override;
+ void Serialize(Slicer::ModelPartForRootPtr) override;
- private:
- void createTemporaryTable();
- void dropTemporaryTable();
+ private:
+ void createTemporaryTable();
+ void dropTemporaryTable();
- DB::Connection * const db;
- DB::TablePatch & tablePatch;
+ DB::Connection * const db;
+ DB::TablePatch & tablePatch;
};
}
#endif
-
diff --git a/slicer/db/sqlUpdateSerializer.cpp b/slicer/db/sqlUpdateSerializer.cpp
index 64ff1a0..29d9da7 100644
--- a/slicer/db/sqlUpdateSerializer.cpp
+++ b/slicer/db/sqlUpdateSerializer.cpp
@@ -1,19 +1,18 @@
-#include "sqlUpdateSerializer.h"
-#include <sqlExceptions.h>
-#include <common.h>
#include "sqlBinder.h"
#include "sqlCommon.h"
+#include "sqlUpdateSerializer.h"
+#include <common.h>
#include <compileTimeFormatter.h>
+#include <functional>
#include <modifycommand.h>
#include <slicer/metadata.h>
-#include <functional>
+#include <sqlExceptions.h>
namespace Slicer {
using namespace std::placeholders;
SqlUpdateSerializer::SqlUpdateSerializer(DB::Connection * const c, std::string t) :
- connection(c),
- tableName(std::move(t))
+ connection(c), tableName(std::move(t))
{
}
@@ -21,11 +20,15 @@ namespace Slicer {
SqlUpdateSerializer::Serialize(Slicer::ModelPartForRootPtr mp)
{
switch (mp->GetType()) {
- case Slicer::mpt_Sequence:
- mp->OnEachChild(std::bind(&SqlUpdateSerializer::SerializeSequence, this, _2));
+ case Slicer::ModelPartType::Sequence:
+ mp->OnEachChild([this](auto &&, auto && PH2, auto &&) {
+ SerializeSequence(PH2);
+ });
return;
- case Slicer::mpt_Complex:
- mp->OnEachChild(std::bind(&SqlUpdateSerializer::SerializeObject, this, _2));
+ case Slicer::ModelPartType::Complex:
+ mp->OnEachChild([this](auto &&, auto && PH2, auto &&) {
+ SerializeObject(PH2);
+ });
return;
default:
throw UnsupportedModelType();
@@ -44,8 +47,8 @@ namespace Slicer {
{
auto ins = createUpdate(mp->GetContainedModelPart());
mp->OnEachChild([&ins](const std::string &, const ModelPartPtr & cmp, const HookCommon *) {
- bindObjectAndExecute(cmp, ins.get());
- });
+ bindObjectAndExecute(cmp, ins.get());
+ });
}
void
@@ -77,7 +80,7 @@ namespace Slicer {
std::stringstream update;
"UPDATE %? SET "_fmt(update, tableName);
int fieldNo = 0;
- mp->OnEachChild([&update, &fieldNo]( const std::string & name, const ModelPartPtr &, const HookCommon * h) {
+ mp->OnEachChild([&update, &fieldNo](const std::string & name, const ModelPartPtr &, const HookCommon * h) {
if (isValue(h)) {
if (fieldNo++) {
update << ", ";
@@ -87,7 +90,7 @@ namespace Slicer {
});
update << " WHERE ";
fieldNo = 0;
- mp->OnEachChild([&update, &fieldNo]( const std::string & name, const ModelPartPtr &, const HookCommon * h) {
+ mp->OnEachChild([&update, &fieldNo](const std::string & name, const ModelPartPtr &, const HookCommon * h) {
if (isPKey(h)) {
if (fieldNo++) {
update << " AND ";
@@ -98,4 +101,3 @@ namespace Slicer {
return connection->modify(update.str());
}
}
-
diff --git a/slicer/db/sqlUpdateSerializer.h b/slicer/db/sqlUpdateSerializer.h
index a3462f8..e82015b 100644
--- a/slicer/db/sqlUpdateSerializer.h
+++ b/slicer/db/sqlUpdateSerializer.h
@@ -1,27 +1,26 @@
#ifndef SLICER_DB_SQLUPDATESERIALIZER_H
#define SLICER_DB_SQLUPDATESERIALIZER_H
-#include <slicer/serializer.h>
#include <connection.h>
+#include <slicer/serializer.h>
#include <visibility.h>
namespace Slicer {
class DLL_PUBLIC SqlUpdateSerializer : public Slicer::Serializer {
- public:
- SqlUpdateSerializer(DB::Connection * const, std::string tableName);
+ public:
+ SqlUpdateSerializer(DB::Connection * const, std::string tableName);
- void Serialize(Slicer::ModelPartForRootPtr) override;
+ void Serialize(Slicer::ModelPartForRootPtr) override;
- protected:
- void SerializeObject(const Slicer::ModelPartPtr &) const;
- void SerializeSequence(const Slicer::ModelPartPtr &) const;
- DB::ModifyCommandPtr createUpdate(const Slicer::ModelPartPtr &) const;
- static void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *);
+ protected:
+ void SerializeObject(const Slicer::ModelPartPtr &) const;
+ void SerializeSequence(const Slicer::ModelPartPtr &) const;
+ DB::ModifyCommandPtr createUpdate(const Slicer::ModelPartPtr &) const;
+ static void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *);
- DB::Connection * const connection;
- const std::string tableName;
+ DB::Connection * const connection;
+ const std::string tableName;
};
}
#endif
-
diff --git a/slicer/db/testConversions.cpp b/slicer/db/testConversions.cpp
index d19f309..68de17a 100644
--- a/slicer/db/testConversions.cpp
+++ b/slicer/db/testConversions.cpp
@@ -1,16 +1,17 @@
-#include <testModels.h>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/numeric/conversion/cast.hpp>
+#include <testModels.h>
#include <visibility.h>
-#define SHORT(x) boost::numeric_cast< ::Ice::Short , int64_t >(x)
+#define SHORT(x) boost::numeric_cast<::Ice::Short, int64_t>(x)
namespace Slicer {
DLL_PUBLIC
::TestDatabase::TimespanPtr
timedurationToTimespan(const boost::posix_time::time_duration & td)
{
- return std::make_shared<::TestDatabase::Timespan>(SHORT(td.hours() / 24), SHORT(td.hours() % 24), SHORT(td.minutes()), SHORT(td.seconds()));
+ return std::make_shared<::TestDatabase::Timespan>(
+ SHORT(td.hours() / 24), SHORT(td.hours() % 24), SHORT(td.minutes()), SHORT(td.seconds()));
}
DLL_PUBLIC
@@ -20,4 +21,3 @@ namespace Slicer {
return boost::posix_time::time_duration((ts->days * 24) + ts->hours, ts->minutes, ts->seconds);
}
}
-
diff --git a/slicer/db/testInsert.cpp b/slicer/db/testInsert.cpp
index 3724679..6bc6acd 100644
--- a/slicer/db/testInsert.cpp
+++ b/slicer/db/testInsert.cpp
@@ -1,13 +1,13 @@
#define BOOST_TEST_MODULE db_insert
-#include <boost/test/unit_test.hpp>
-#include <boost/date_time/posix_time/posix_time_io.hpp>
-#include "testMockCommon.h"
-#include <slicer/slicer.h>
#include "sqlInsertSerializer.h"
#include "sqlSelectDeserializer.h"
-#include <types.h>
+#include "testMockCommon.h"
+#include <boost/date_time/posix_time/posix_time_io.hpp>
+#include <boost/test/unit_test.hpp>
#include <common.h>
+#include <slicer/slicer.h>
#include <testModels.h>
+#include <types.h>
using namespace std::literals;
@@ -19,16 +19,18 @@ BOOST_TEST_DONT_PRINT_LOG_VALUE(TestDatabase::Timespan);
namespace std {
template<typename T>
- ostream & operator<<(ostream & s, const Ice::optional<T> &) {
+ ostream &
+ operator<<(ostream & s, const Ice::optional<T> &)
+ {
return s;
}
}
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+BOOST_GLOBAL_FIXTURE(StandardMockDatabase);
BOOST_FIXTURE_TEST_SUITE(db, ConnectionFixture);
-BOOST_AUTO_TEST_CASE( insert_builtins )
+BOOST_AUTO_TEST_CASE(insert_builtins)
{
TestModule::BuiltInsPtr bi = std::make_shared<TestModule::BuiltIns>(true, 4, 16, 64, 128, 1.2, 3.4, "text");
Slicer::SerializeAny<Slicer::SqlInsertSerializer>(bi, db, "builtins");
@@ -44,12 +46,10 @@ BOOST_AUTO_TEST_CASE( insert_builtins )
BOOST_REQUIRE_EQUAL(bi->mstring, bi2->mstring);
}
-BOOST_AUTO_TEST_CASE( insert_seq_builtins )
+BOOST_AUTO_TEST_CASE(insert_seq_builtins)
{
- 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")
- };
+ 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, "builtins");
auto sel = db->select("SELECT * FROM builtins ORDER BY mint");
auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(sel.get());
@@ -64,12 +64,10 @@ BOOST_AUTO_TEST_CASE( insert_seq_builtins )
BOOST_REQUIRE_EQUAL(bis.back()->mstring, bis2.back()->mstring);
}
-BOOST_AUTO_TEST_CASE( autoinsert_seq_builtins )
+BOOST_AUTO_TEST_CASE(autoinsert_seq_builtins)
{
- 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")
- };
+ 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, "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.get());
@@ -87,12 +85,10 @@ BOOST_AUTO_TEST_CASE( autoinsert_seq_builtins )
BOOST_REQUIRE_EQUAL(bis.back()->mstring, bis2.back()->mstring);
}
-BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtins )
+BOOST_AUTO_TEST_CASE(fetchinsert_seq_builtins)
{
- 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")
- };
+ 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, "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.get());
@@ -110,12 +106,11 @@ BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtins )
BOOST_REQUIRE_EQUAL(bis.back()->mstring, bis2.back()->mstring);
}
-BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtinsWithNulls )
+BOOST_AUTO_TEST_CASE(fetchinsert_seq_builtinsWithNulls)
{
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)
- };
+ 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, "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.get());
@@ -133,13 +128,11 @@ BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtinsWithNulls )
BOOST_REQUIRE_EQUAL(bis.back()->mstring, bis2.back()->mstring);
}
-BOOST_AUTO_TEST_CASE( insert_converted )
+BOOST_AUTO_TEST_CASE(insert_converted)
{
- 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)
- );
+ 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, "converted");
auto sel = db->select("SELECT * FROM converted");
auto st2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::SpecificTypesPtr>(sel.get());
@@ -151,11 +144,11 @@ BOOST_AUTO_TEST_CASE( insert_converted )
BOOST_REQUIRE_EQUAL(st->ts->seconds, st2->ts->seconds);
}
-BOOST_AUTO_TEST_CASE( insert_unsupportedModel )
+BOOST_AUTO_TEST_CASE(insert_unsupportedModel)
{
TestModule::ClassMap cm;
- BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::SqlInsertSerializer>(cm, db, "converted"), Slicer::UnsupportedModelType);
+ BOOST_REQUIRE_THROW(
+ Slicer::SerializeAny<Slicer::SqlInsertSerializer>(cm, db, "converted"), Slicer::UnsupportedModelType);
}
BOOST_AUTO_TEST_SUITE_END();
-
diff --git a/slicer/db/testMockCommon.cpp b/slicer/db/testMockCommon.cpp
index ed18563..0d8c2c9 100644
--- a/slicer/db/testMockCommon.cpp
+++ b/slicer/db/testMockCommon.cpp
@@ -2,15 +2,8 @@
#include <definedDirs.h>
StandardMockDatabase::StandardMockDatabase() :
-DB::PluginMock<PQ::Mock>("pqmock", {
- rootDir.parent_path() / "db" / "slicer.sql" },
- "user=postgres dbname=postgres")
-{
-}
-
-ConnectionFixture::ConnectionFixture() :
- _db(DB::MockDatabase::openConnectionTo("pqmock")),
- db(_db.get())
+ DB::PluginMock<PQ::Mock>("pqmock", {rootDir.parent_path() / "db" / "slicer.sql"}, "user=postgres dbname=postgres")
{
}
+ConnectionFixture::ConnectionFixture() : _db(DB::MockDatabase::openConnectionTo("pqmock")), db(_db.get()) { }
diff --git a/slicer/db/testMockCommon.h b/slicer/db/testMockCommon.h
index bd9b11f..c775ae0 100644
--- a/slicer/db/testMockCommon.h
+++ b/slicer/db/testMockCommon.h
@@ -6,17 +6,16 @@
#include <visibility.h>
class DLL_PUBLIC StandardMockDatabase : public DB::PluginMock<PQ::Mock> {
- public:
- StandardMockDatabase();
+public:
+ StandardMockDatabase();
};
class DLL_PUBLIC ConnectionFixture {
- public:
- ConnectionFixture();
+public:
+ ConnectionFixture();
- DB::ConnectionPtr _db;
- DB::Connection * const db;
+ DB::ConnectionPtr _db;
+ DB::Connection * const db;
};
#endif
-
diff --git a/slicer/db/testPatch.cpp b/slicer/db/testPatch.cpp
index 2af60b4..70068e2 100644
--- a/slicer/db/testPatch.cpp
+++ b/slicer/db/testPatch.cpp
@@ -1,13 +1,13 @@
#define BOOST_TEST_MODULE db_patch
-#include <boost/test/unit_test.hpp>
-#include <boost/date_time/posix_time/posix_time_io.hpp>
-#include "testMockCommon.h"
-#include <slicer/slicer.h>
-#include "sqlTablePatchSerializer.h"
#include "sqlSelectDeserializer.h"
-#include <types.h>
+#include "sqlTablePatchSerializer.h"
+#include "testMockCommon.h"
+#include <boost/date_time/posix_time/posix_time_io.hpp>
+#include <boost/test/unit_test.hpp>
#include <common.h>
+#include <slicer/slicer.h>
#include <testModels.h>
+#include <types.h>
// LCOV_EXCL_START
BOOST_TEST_DONT_PRINT_LOG_VALUE(TestModule::DateTime);
@@ -16,16 +16,14 @@ BOOST_TEST_DONT_PRINT_LOG_VALUE(TestDatabase::Timespan);
BOOST_TEST_DONT_PRINT_LOG_VALUE(DB::PrimaryKey);
// LCOV_EXCL_STOP
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+BOOST_GLOBAL_FIXTURE(StandardMockDatabase);
BOOST_FIXTURE_TEST_SUITE(db, ConnectionFixture);
-BOOST_AUTO_TEST_CASE( insert_builtins )
+BOOST_AUTO_TEST_CASE(insert_builtins)
{
- 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")
- };
+ 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")};
DB::TablePatch tp;
DB::TransactionScope tx(*db);
tp.dest = "builtins";
@@ -42,4 +40,3 @@ BOOST_AUTO_TEST_CASE( insert_builtins )
}
BOOST_AUTO_TEST_SUITE_END();
-
diff --git a/slicer/db/testSelect.cpp b/slicer/db/testSelect.cpp
index ce7821c..0e765f2 100644
--- a/slicer/db/testSelect.cpp
+++ b/slicer/db/testSelect.cpp
@@ -1,59 +1,58 @@
#define BOOST_TEST_MODULE db_select
-#include <boost/test/unit_test.hpp>
-#include <boost/date_time/posix_time/posix_time_io.hpp>
-#include "testMockCommon.h"
-#include <slicer/slicer.h>
#include "sqlSelectDeserializer.h"
-#include <types.h>
+#include "testMockCommon.h"
+#include <boost/date_time/posix_time/posix_time_io.hpp>
+#include <boost/test/unit_test.hpp>
#include <common.h>
-#include <testModels.h>
+#include <slicer/slicer.h>
#include <sqlExceptions.h>
+#include <testModels.h>
+#include <types.h>
using namespace std::literals;
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+BOOST_GLOBAL_FIXTURE(StandardMockDatabase);
BOOST_FIXTURE_TEST_SUITE(db, ConnectionFixture);
-BOOST_AUTO_TEST_CASE( select_simple_int )
+BOOST_AUTO_TEST_CASE(select_simple_int)
{
auto sel = db->select("SELECT MAX(id) FROM test");
auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::Int>(sel.get());
BOOST_REQUIRE_EQUAL(4, bi);
}
-BOOST_AUTO_TEST_CASE( select_simple_double )
+BOOST_AUTO_TEST_CASE(select_simple_double)
{
auto sel = db->select("SELECT MAX(fl) FROM test");
auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::Double>(sel.get());
BOOST_REQUIRE_CLOSE(1234.1234, bi, 0.0001);
}
-BOOST_AUTO_TEST_CASE( select_simple_string )
+BOOST_AUTO_TEST_CASE(select_simple_string)
{
auto sel = db->select("SELECT MAX(string) FROM test");
auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, std::string>(sel.get());
BOOST_REQUIRE_EQUAL("text two", bi);
}
-BOOST_AUTO_TEST_CASE( select_simple_true )
+BOOST_AUTO_TEST_CASE(select_simple_true)
{
auto sel = db->select("SELECT true");
auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, bool>(sel.get());
BOOST_REQUIRE_EQUAL(true, bi);
}
-BOOST_AUTO_TEST_CASE( select_simple_false )
+BOOST_AUTO_TEST_CASE(select_simple_false)
{
auto sel = db->select("SELECT NOT(true)");
auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, bool>(sel.get());
BOOST_REQUIRE_EQUAL(false, bi);
}
-BOOST_AUTO_TEST_CASE( select_single )
+BOOST_AUTO_TEST_CASE(select_single)
{
- auto sel = db->select(
- "SELECT boolean mbool, \
+ auto sel = db->select("SELECT boolean mbool, \
id mbyte, id mshort, id mint, id mlong, \
fl mdouble, fl mfloat, \
string mstring \
@@ -72,10 +71,9 @@ BOOST_AUTO_TEST_CASE( select_single )
BOOST_REQUIRE_EQUAL("text one", bi->mstring);
}
-BOOST_AUTO_TEST_CASE( select_inherit_single )
+BOOST_AUTO_TEST_CASE(select_inherit_single)
{
- auto sel = db->select(
- "SELECT id a, '::TestModule::D' || CAST(id AS TEXT) tc, 200 b, 300 c, 400 d \
+ 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.get(), "tc"s);
@@ -86,10 +84,9 @@ BOOST_AUTO_TEST_CASE( select_inherit_single )
BOOST_REQUIRE_EQUAL(300, d2->c);
}
-BOOST_AUTO_TEST_CASE( select_simple_sequence )
+BOOST_AUTO_TEST_CASE(select_simple_sequence)
{
- auto sel = db->select(
- "SELECT string \
+ auto sel = db->select("SELECT string \
FROM test \
ORDER BY id DESC");
auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::SimpleSeq>(sel.get());
@@ -100,10 +97,9 @@ BOOST_AUTO_TEST_CASE( select_simple_sequence )
BOOST_REQUIRE_EQUAL("text one", bi[3]);
}
-BOOST_AUTO_TEST_CASE( select_inherit_sequence )
+BOOST_AUTO_TEST_CASE(select_inherit_sequence)
{
- auto sel = db->select(
- "SELECT id a, '::TestModule::D' || CAST(id AS TEXT) tc, 200 b, 300 c, 400 d \
+ 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");
@@ -124,13 +120,13 @@ BOOST_AUTO_TEST_CASE( select_inherit_sequence )
BOOST_REQUIRE_EQUAL(200, d1->b);
}
-BOOST_AUTO_TEST_CASE( select_inherit_datetime )
+BOOST_AUTO_TEST_CASE(select_inherit_datetime)
{
- auto sel = db->select(
- "SELECT dt, to_char(dt, 'YYYY-MM-DD') date, ts \
+ 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.get());
+ TestDatabase::SpecificTypesPtr bi
+ = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::SpecificTypesPtr>(sel.get());
BOOST_REQUIRE_EQUAL(2015, bi->dt.year);
BOOST_REQUIRE_EQUAL(3, bi->dt.month);
BOOST_REQUIRE_EQUAL(27, bi->dt.day);
@@ -146,45 +142,45 @@ BOOST_AUTO_TEST_CASE( select_inherit_datetime )
BOOST_REQUIRE_EQUAL(12, bi->ts->seconds);
}
-template <typename T, typename ... P>
+template<typename T, typename... P>
T
-BoostThrowWrapperHelper(P && ... p)
+BoostThrowWrapperHelper(P &&... p)
{
return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, T>(p...);
}
-BOOST_AUTO_TEST_CASE( select_unsupportedModel )
+BOOST_AUTO_TEST_CASE(select_unsupportedModel)
{
auto sel = db->select("SELECT id FROM test");
BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::ClassMap>(sel.get()), Slicer::UnsupportedModelType);
}
-BOOST_AUTO_TEST_CASE( select_tooManyRowsSimple )
+BOOST_AUTO_TEST_CASE(select_tooManyRowsSimple)
{
auto sel = db->select("SELECT id FROM test");
BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(sel.get()), Slicer::TooManyRowsReturned);
}
-BOOST_AUTO_TEST_CASE( select_noRowsSimple )
+BOOST_AUTO_TEST_CASE(select_noRowsSimple)
{
auto sel = db->select("SELECT id FROM test WHERE false");
BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(sel.get()), Slicer::NoRowsReturned);
}
-BOOST_AUTO_TEST_CASE( select_noRowsSimpleOptional )
+BOOST_AUTO_TEST_CASE(select_noRowsSimpleOptional)
{
auto sel = db->select("SELECT id FROM test WHERE false");
auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::optional<Ice::Int>>(sel.get());
BOOST_REQUIRE(!v);
}
-BOOST_AUTO_TEST_CASE( select_tooManyRowsSimpleOptional )
+BOOST_AUTO_TEST_CASE(select_tooManyRowsSimpleOptional)
{
auto sel = db->select("SELECT id FROM test");
BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::optional<Ice::Int>>(sel.get()), Slicer::TooManyRowsReturned);
}
-BOOST_AUTO_TEST_CASE( select_simpleOptional )
+BOOST_AUTO_TEST_CASE(select_simpleOptional)
{
auto sel = db->select("SELECT MAX(id) FROM test");
auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::optional<Ice::Int>>(sel.get());
@@ -192,10 +188,9 @@ BOOST_AUTO_TEST_CASE( select_simpleOptional )
BOOST_REQUIRE_EQUAL(4, *v);
}
-BOOST_AUTO_TEST_CASE( select_noRowsComplexOptional )
+BOOST_AUTO_TEST_CASE(select_noRowsComplexOptional)
{
- auto sel = db->select(
- "SELECT boolean mbool, \
+ auto sel = db->select("SELECT boolean mbool, \
id mbyte, id mshort, id mint, id mlong, \
fl mdouble, fl mfloat, \
string mstring \
@@ -205,26 +200,26 @@ BOOST_AUTO_TEST_CASE( select_noRowsComplexOptional )
BOOST_REQUIRE(!v);
}
-BOOST_AUTO_TEST_CASE( select_tooManyRowsComplex )
+BOOST_AUTO_TEST_CASE(select_tooManyRowsComplex)
{
auto sel = db->select("SELECT id FROM test");
BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::BuiltInsPtr>(sel.get()), Slicer::TooManyRowsReturned);
}
-BOOST_AUTO_TEST_CASE( select_noRowsComplex )
+BOOST_AUTO_TEST_CASE(select_noRowsComplex)
{
auto sel = db->select("SELECT id FROM test WHERE false");
BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::BuiltInsPtr>(sel.get()), Slicer::NoRowsReturned);
}
-BOOST_AUTO_TEST_CASE( select_emptySequence )
+BOOST_AUTO_TEST_CASE(select_emptySequence)
{
auto sel = db->select("SELECT id FROM test WHERE false");
auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BaseSeq>(sel.get());
BOOST_REQUIRE_EQUAL(0, bi.size());
}
-BOOST_AUTO_TEST_CASE( select_null )
+BOOST_AUTO_TEST_CASE(select_null)
{
db->execute("INSERT INTO test(id) VALUES(NULL)");
@@ -242,12 +237,12 @@ BOOST_AUTO_TEST_CASE( select_null )
BOOST_REQUIRE(!v);
}
-BOOST_AUTO_TEST_CASE( bulkSelectTest )
+BOOST_AUTO_TEST_CASE(bulkSelectTest)
{
- auto sel = db->select(R"SQL(select s mint, cast(s as numeric(7,1)) mdouble, cast(s as text) mstring, s % 2 = 0 mbool from generate_series(1, 10000) s)SQL");
+ auto sel = db->select(
+ R"SQL(select s mint, cast(s as numeric(7,1)) mdouble, cast(s as text) mstring, s % 2 = 0 mbool from generate_series(1, 10000) s)SQL");
auto vec = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(sel.get());
BOOST_REQUIRE_EQUAL(10000, vec.size());
}
BOOST_AUTO_TEST_SUITE_END();
-
diff --git a/slicer/db/testUpdate.cpp b/slicer/db/testUpdate.cpp
index 48ea903..7dbcba3 100644
--- a/slicer/db/testUpdate.cpp
+++ b/slicer/db/testUpdate.cpp
@@ -1,29 +1,29 @@
#define BOOST_TEST_MODULE db_update
-#include <boost/test/unit_test.hpp>
-#include <boost/date_time/posix_time/posix_time_io.hpp>
-#include "testMockCommon.h"
-#include <slicer/slicer.h>
#include "sqlInsertSerializer.h"
#include "sqlSelectDeserializer.h"
#include "sqlUpdateSerializer.h"
-#include <types.h>
+#include "testMockCommon.h"
+#include <boost/date_time/posix_time/posix_time_io.hpp>
+#include <boost/test/unit_test.hpp>
#include <common.h>
-#include <testModels.h>
+#include <slicer/slicer.h>
#include <sqlExceptions.h>
+#include <testModels.h>
+#include <types.h>
using namespace std::literals;
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+BOOST_GLOBAL_FIXTURE(StandardMockDatabase);
BOOST_FIXTURE_TEST_SUITE(db, ConnectionFixture);
-BOOST_AUTO_TEST_CASE( update_builtinsNotFound )
+BOOST_AUTO_TEST_CASE(update_builtinsNotFound)
{
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, "builtins"), Slicer::NoRowsFound);
}
-BOOST_AUTO_TEST_CASE( update_builtins )
+BOOST_AUTO_TEST_CASE(update_builtins)
{
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");
@@ -54,12 +54,10 @@ BOOST_AUTO_TEST_CASE( update_builtins )
BOOST_REQUIRE_EQUAL(bis.back()->mstring, bi2->mstring);
}
-BOOST_AUTO_TEST_CASE( update_builtins_seq )
+BOOST_AUTO_TEST_CASE(update_builtins_seq)
{
- 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"))
- };
+ TestModule::BuiltInSeq ubis {std::make_shared<TestModule::BuiltIns>(false, 5, 17, 64, 128, -1.2, -1.4, "string"),
+ std::make_shared<TestModule::BuiltIns>(false, 5, 21, 63, 127, -4.2, -5.4, "string updated")};
Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(ubis, db, "builtins");
auto sel = db->select("SELECT * FROM builtins ORDER BY mint");
@@ -83,7 +81,7 @@ BOOST_AUTO_TEST_CASE( update_builtins_seq )
BOOST_REQUIRE_EQUAL(ubis.back()->mstring, ubis2.front()->mstring);
}
-BOOST_AUTO_TEST_CASE( update_withNulls )
+BOOST_AUTO_TEST_CASE(update_withNulls)
{
auto sel = db->select("SELECT * FROM builtins ORDER BY mint");
auto bis = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(sel.get());
@@ -107,11 +105,11 @@ BOOST_AUTO_TEST_CASE( update_withNulls )
BOOST_REQUIRE(bis2[1]->mfloat);
}
-BOOST_AUTO_TEST_CASE( update_unsupportedModel )
+BOOST_AUTO_TEST_CASE(update_unsupportedModel)
{
TestModule::ClassMap cm;
- BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(cm, db, "converted"), Slicer::UnsupportedModelType);
+ BOOST_REQUIRE_THROW(
+ Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(cm, db, "converted"), Slicer::UnsupportedModelType);
}
BOOST_AUTO_TEST_SUITE_END();
-