From 8f796ba6400e65143ac49b895e46a7a26de7992b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 11 Aug 2023 01:40:49 +0100 Subject: Misc tidy up in db module --- slicer/db/sqlBinder.h | 2 -- slicer/db/sqlCommon.cpp | 10 +++++----- slicer/db/sqlCommon.h | 10 +++++----- slicer/db/sqlInsertSerializer.cpp | 2 -- slicer/db/sqlInsertSerializer.h | 10 ++-------- slicer/db/sqlSource.cpp | 33 +++++++++++++++++---------------- slicer/db/sqlSource.h | 4 +--- slicer/db/sqlTablePatchSerializer.cpp | 2 -- 8 files changed, 30 insertions(+), 43 deletions(-) diff --git a/slicer/db/sqlBinder.h b/slicer/db/sqlBinder.h index 71f23ea..a4a9a93 100644 --- a/slicer/db/sqlBinder.h +++ b/slicer/db/sqlBinder.h @@ -34,8 +34,6 @@ namespace Slicer { DB::Command & command; const unsigned int idx; }; - - typedef std::shared_ptr SqlBinderPtr; } #endif diff --git a/slicer/db/sqlCommon.cpp b/slicer/db/sqlCommon.cpp index 21fb9e5..0516f45 100644 --- a/slicer/db/sqlCommon.cpp +++ b/slicer/db/sqlCommon.cpp @@ -11,31 +11,31 @@ namespace Slicer { constexpr std::string_view md_global_ignore {"ignore"}; bool - isPKey(const HookCommon * h) + isPKey(const HookCommon * h) noexcept { return h->GetMetadata().flagSet(md_pkey) && isBind(h); } bool - isAuto(const HookCommon * h) + isAuto(const HookCommon * h) noexcept { return h->GetMetadata().flagSet(md_auto) && isBind(h); } bool - isNotAuto(const HookCommon * h) + isNotAuto(const HookCommon * h) noexcept { return h->GetMetadata().flagNotSet(md_auto) && isBind(h); } bool - isBind(const HookCommon * h) + isBind(const HookCommon * h) noexcept { return h->GetMetadata().flagNotSet(md_global_ignore) && h->GetMetadata().flagNotSet(md_ignore); } bool - isValue(const HookCommon * h) + isValue(const HookCommon * h) noexcept { return h->GetMetadata().flagNotSet(md_auto) && h->GetMetadata().flagNotSet(md_pkey) && isBind(h); } diff --git a/slicer/db/sqlCommon.h b/slicer/db/sqlCommon.h index acabc51..16cefac 100644 --- a/slicer/db/sqlCommon.h +++ b/slicer/db/sqlCommon.h @@ -4,11 +4,11 @@ namespace Slicer { class HookCommon; - bool isPKey(const HookCommon *); - bool isAuto(const HookCommon *); - bool isNotAuto(const HookCommon *); - bool isBind(const HookCommon *); - bool isValue(const HookCommon *); + [[nodiscard]] bool isPKey(const HookCommon *) noexcept; + [[nodiscard]] bool isAuto(const HookCommon *) noexcept; + [[nodiscard]] bool isNotAuto(const HookCommon *) noexcept; + [[nodiscard]] bool isBind(const HookCommon *) noexcept; + [[nodiscard]] bool isValue(const HookCommon *) noexcept; } #endif diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp index ff30c7c..c99df57 100644 --- a/slicer/db/sqlInsertSerializer.cpp +++ b/slicer/db/sqlInsertSerializer.cpp @@ -15,8 +15,6 @@ #include namespace Slicer { - using namespace std::placeholders; - SqlInsertSerializer::SqlInsertSerializer(DB::Connection * const c, std::string t) : connection(c), tableName(std::move(t)) { diff --git a/slicer/db/sqlInsertSerializer.h b/slicer/db/sqlInsertSerializer.h index f9f4fdf..36ecac3 100644 --- a/slicer/db/sqlInsertSerializer.h +++ b/slicer/db/sqlInsertSerializer.h @@ -36,10 +36,7 @@ namespace Slicer { class DLL_PUBLIC SqlAutoIdInsertSerializer : public SqlInsertSerializer { public: - template - explicit SqlAutoIdInsertSerializer(P &&... p) : SqlInsertSerializer(std::forward

(p)...) - { - } + using SqlInsertSerializer::SqlInsertSerializer; protected: void createInsertField(unsigned int & fieldNo, std::ostream & insert, const std::string & name, @@ -50,10 +47,7 @@ namespace Slicer { class DLL_PUBLIC SqlFetchIdInsertSerializer : public SqlAutoIdInsertSerializer { public: - template - explicit SqlFetchIdInsertSerializer(P &&... p) : SqlAutoIdInsertSerializer(std::forward

(p)...) - { - } + using SqlAutoIdInsertSerializer::SqlAutoIdInsertSerializer; protected: void bindObjectAndExecute(ModelPartParam, DB::ModifyCommand *) const override; diff --git a/slicer/db/sqlSource.cpp b/slicer/db/sqlSource.cpp index 41b9c1c..ed14b3a 100644 --- a/slicer/db/sqlSource.cpp +++ b/slicer/db/sqlSource.cpp @@ -7,6 +7,17 @@ namespace Slicer { SqlSource::SqlSource(const DB::Column & c) : column(c) { } + namespace { + template + void + numericSet(const DB::Column & column, T & b) + { + C cb {}; + column >> cb; + b = boost::numeric_cast(cb); + } + } + bool SqlSource::isNull() const { @@ -34,47 +45,37 @@ namespace Slicer { void SqlSource::set(Ice::Byte & b) const { - int64_t cb; - column >> cb; - b = boost::numeric_cast(cb); + numericSet(column, b); } void SqlSource::set(Ice::Short & b) const { - int64_t cb; - column >> cb; - b = boost::numeric_cast(cb); + numericSet(column, b); } void SqlSource::set(Ice::Int & b) const { - int64_t cb; - column >> cb; - b = boost::numeric_cast(cb); + numericSet(column, b); } void SqlSource::set(Ice::Long & b) const { - int64_t cb; - column >> cb; - b = boost::numeric_cast(cb); + numericSet(column, b); } void SqlSource::set(Ice::Float & b) const { - double cb; - column >> cb; - b = boost::numeric_cast(cb); + numericSet(column, b); } void SqlSource::set(Ice::Double & b) const { - column >> b; + numericSet(column, b); } void diff --git a/slicer/db/sqlSource.h b/slicer/db/sqlSource.h index 70a0122..78d9909 100644 --- a/slicer/db/sqlSource.h +++ b/slicer/db/sqlSource.h @@ -23,7 +23,7 @@ namespace Slicer { public: explicit SqlSource(const DB::Column & c); - bool isNull() const; + [[nodiscard]] 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; @@ -38,8 +38,6 @@ namespace Slicer { private: const DB::Column & column; }; - - typedef std::shared_ptr SqlSourcePtr; } #endif diff --git a/slicer/db/sqlTablePatchSerializer.cpp b/slicer/db/sqlTablePatchSerializer.cpp index 69acb16..da5b0b2 100644 --- a/slicer/db/sqlTablePatchSerializer.cpp +++ b/slicer/db/sqlTablePatchSerializer.cpp @@ -37,8 +37,6 @@ namespace Slicer { if (isPKey(h)) { tablePatch.pk.insert(name); } - }); - mp->OnEachChild([this](const auto & name, const auto &, const auto & h) { if (isBind(h)) { tablePatch.cols.insert(name); } -- cgit v1.2.3