From 72e0fba3aec8b0b4a4a6d1d2fe964ccd32db29a1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 28 Mar 2020 17:57:10 +0000 Subject: Modernize and tidy --- Jamroot.jam | 1 + libdbpp/column.h | 8 ++++--- libdbpp/command.h | 39 +++++++++++++++++--------------- libdbpp/command_fwd.h | 12 +++++----- libdbpp/connection.cpp | 27 +++++++++------------- libdbpp/connection.h | 43 ++++++++++++++++-------------------- libdbpp/connectionPool.h | 2 +- libdbpp/connection_fwd.h | 4 ++-- libdbpp/dbTypes.cpp | 6 ----- libdbpp/dbTypes.h | 12 +++++----- libdbpp/error.h | 4 ++-- libdbpp/mockDatabase.h | 21 +++++++++--------- libdbpp/modifycommand.h | 2 +- libdbpp/selectcommand.h | 36 +++++++++++++++++------------- libdbpp/selectcommandUtil.impl.h | 6 ++--- libdbpp/sqlWriter.h | 8 +++++-- libdbpp/tablepatch.cpp | 11 --------- libdbpp/tablepatch.h | 29 +++++++++++------------- libdbpp/testCore.cpp | 4 ---- libdbpp/testCore.h | 6 ++--- libdbpp/unittests/libdbpp-mysql | 2 +- libdbpp/unittests/libdbpp-odbc | 2 +- libdbpp/unittests/libdbpp-postgresql | 2 +- libdbpp/unittests/libdbpp-sqlite | 2 +- libdbpp/unittests/testConnection.cpp | 4 +++- libdbpp/unittests/testMock.cpp | 6 ++--- libdbpp/unittests/testUtils.cpp | 19 ++++++++-------- 27 files changed, 149 insertions(+), 169 deletions(-) diff --git a/Jamroot.jam b/Jamroot.jam index 824be0e..9177f1e 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -25,6 +25,7 @@ project tidy:misc-* tidy:modernize-* tidy:modernize-use-trailing-return-type + tidy:misc-non-private-member-variables-in-classes tidy:hicpp-* tidy:performance-* ; diff --git a/libdbpp/column.h b/libdbpp/column.h index 1e7441e..ecb1e41 100644 --- a/libdbpp/column.h +++ b/libdbpp/column.h @@ -9,6 +9,7 @@ #include #include "dbTypes.h" #include "error.h" +#include namespace DB { /// Abstract class for something that can handle field data. See Column::apply. @@ -39,6 +40,8 @@ namespace DB { /// Creates a new column with the given name and ordinal. Column(const Glib::ustring &, unsigned int); virtual ~Column() = 0; + /// Standard special members + SPECIAL_MEMBERS_MOVE_RO(Column); /// Test if the current value is null. [[nodiscard]] virtual bool isNull() const = 0; @@ -60,7 +63,7 @@ namespace DB { public: /// Create an extrator given a target variable. - Extract(T & t) : target(t) { } + explicit Extract(T & t) : target(t) { } void floatingpoint(double v) override { (*this)(v); } void integer(int64_t v) override { (*this)(v); } @@ -84,7 +87,6 @@ namespace DB { inline void operator()(const D & v) { - if constexpr (is_optional::is_arithmetic == std::is_arithmetic::value) { if constexpr (std::is_assignable::value) { target = v; @@ -115,7 +117,7 @@ namespace DB { /// This column's name. const std::string name; }; - typedef std::unique_ptr ColumnPtr; + using ColumnPtr = std::unique_ptr; } #endif diff --git a/libdbpp/command.h b/libdbpp/command.h index 8e06a7c..f080121 100644 --- a/libdbpp/command.h +++ b/libdbpp/command.h @@ -11,6 +11,7 @@ #include #include "dbTypes.h" #include "error.h" +#include namespace DB { /// Exception thrown when binding a parameter of type the connector doesn't support. @@ -26,8 +27,10 @@ namespace DB { public: CommandOptions() = default; /// Constructor which populates the hash value only. - CommandOptions(std::size_t hash, const CommandOptionsMap & = CommandOptionsMap()); + explicit CommandOptions(std::size_t hash, const CommandOptionsMap & = CommandOptionsMap()); virtual ~CommandOptions() = default; + /// Standard special members + SPECIAL_MEMBERS_DEFAULT(CommandOptions); /// An (optional) hash of the SQL statement. std::optional hash; @@ -55,9 +58,12 @@ namespace DB { class DLL_PUBLIC Command { public: /// Creates a new command from the given SQL. - Command(std::string sql); + explicit Command(std::string sql); virtual ~Command() = 0; + /// Standard special members + SPECIAL_MEMBERS_COPY_RO(Command); + /// Bind an integer to parameter i. virtual void bindParamI(unsigned int i, int val) = 0; /// Bind an integer to parameter i. @@ -107,10 +113,8 @@ namespace DB { template inline void bindParam(unsigned int i, const O & o) { - if constexpr (std::is_null_pointer::value) { - bindNull(i); - } - else if constexpr (std::is_same::value) { + if constexpr (std::is_null_pointer::value || + std::is_same::value) { bindNull(i); } else if constexpr (std::is_same::value) { @@ -119,10 +123,8 @@ namespace DB { else if constexpr (std::is_floating_point::value) { bindParamF(i, o); } - else if constexpr (std::is_same::value) { - bindParamT(i, o); - } - else if constexpr (std::is_same::value) { + else if constexpr (std::is_same::value || + std::is_same::value) { bindParamT(i, o); } else if constexpr (std::is_same::value) { @@ -131,7 +133,8 @@ namespace DB { else if constexpr (std::is_integral::value && !std::is_pointer::value) { bindParamI(i, o); } - else if constexpr (std::is_convertible::value && std::is_pointer::value) { + else if constexpr (std::is_convertible::value && + std::is_pointer::value) { if (o) { bindParamS(i, o); } @@ -139,10 +142,9 @@ namespace DB { bindNull(i); } } - else if constexpr (std::is_same::value) { - bindParamS(i, o); - } - else if constexpr (std::is_convertible::value) { + else if constexpr (std::is_same::value || + std::is_convertible::value) { + // NOLINTNEXTLINE(hicpp-no-array-decay) bindParamS(i, o); } else if constexpr (std::is_constructible::value) { @@ -162,8 +164,8 @@ namespace DB { template \ inline auto \ func(unsigned int i, const O & o) -> typename std::enable_if< \ - std::is_constructible::value \ - && !std::is_void::value \ + std::is_constructible_v \ + && !std::is_void_v \ >::type\ { \ bool nn(o); \ @@ -175,6 +177,7 @@ namespace DB { /// @cond OPTWRAPPER(bindParamI); OPTWRAPPER(bindParamF); + // NOLINTNEXTLINE(hicpp-no-array-decay) OPTWRAPPER(bindParamS); OPTWRAPPER(bindParamB); OPTWRAPPER(bindParamT); @@ -185,7 +188,7 @@ namespace DB { /// Bind a (possibly null) c-string to parameter i. void bindParamS(unsigned int, char * const); }; - typedef AdHoc::Factory CommandOptionsFactory; + using CommandOptionsFactory = AdHoc::Factory; } #endif diff --git a/libdbpp/command_fwd.h b/libdbpp/command_fwd.h index d2fed7e..6547705 100644 --- a/libdbpp/command_fwd.h +++ b/libdbpp/command_fwd.h @@ -6,16 +6,16 @@ #include namespace DB { - typedef std::map> CommandOptionsMap; + using CommandOptionsMap = std::map>; class CommandOptions; - typedef std::shared_ptr CommandOptionsPtr; - typedef std::shared_ptr CommandOptionsCPtr; + using CommandOptionsPtr = std::shared_ptr; + using CommandOptionsCPtr = std::shared_ptr; class Command; - typedef std::shared_ptr CommandPtr; + using CommandPtr = std::shared_ptr; class ModifyCommand; - typedef std::shared_ptr ModifyCommandPtr; + using ModifyCommandPtr = std::shared_ptr; class SelectCommand; - typedef std::shared_ptr SelectCommandPtr; + using SelectCommandPtr = std::shared_ptr; } diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp index 42044f9..cc70af6 100644 --- a/libdbpp/connection.cpp +++ b/libdbpp/connection.cpp @@ -18,13 +18,6 @@ DB::TransactionStillOpen::message() const noexcept return "A transaction is still open."; } -DB::Connection::Connection() : - txOpenDepth(0) -{ -} - -DB::Connection::~Connection() = default; - void DB::Connection::execute(const std::string & sql, const CommandOptionsCPtr & opts) { @@ -188,25 +181,25 @@ DB::TransactionRequired::message() const noexcept } DB::TransactionScope::TransactionScope(DB::Connection & c) : - conn(c) + conn(&c) { - conn.beginTx(); + conn->beginTx(); } // It is acceptable for a commit to fail // NOLINTNEXTLINE(bugprone-exception-escape) -DB::TransactionScope::~TransactionScope() +DB::TransactionScope::~TransactionScope() noexcept { - if (std::uncaught_exceptions()) { - try { - conn.rollbackTx(); + try { + if (std::uncaught_exceptions()) { + conn->rollbackTx(); } - catch (...) { - // Nothing we can do here + else { + conn->commitTx(); } } - else { - conn.commitTx(); + catch (...) { + // Nothing we can do here } } diff --git a/libdbpp/connection.h b/libdbpp/connection.h index c7efce4..b58a536 100644 --- a/libdbpp/connection.h +++ b/libdbpp/connection.h @@ -2,6 +2,7 @@ #define DB_CONNECTION_H #include "connection_fwd.h" +#include "command_fwd.h" #include #include #include @@ -11,20 +12,13 @@ #include #include #include "error.h" +#include namespace AdHoc { class Buffer; } namespace DB { - class Command; - class CommandOptions; - typedef std::shared_ptr CommandOptionsPtr; - typedef std::shared_ptr CommandOptionsCPtr; - class SelectCommand; - typedef std::shared_ptr SelectCommandPtr; - class ModifyCommand; - typedef std::shared_ptr ModifyCommandPtr; class TablePatch; enum BulkDeleteStyle { @@ -38,11 +32,11 @@ namespace DB { BulkUpdateUsingJoin = 2, }; - typedef std::string TableName; - typedef std::string ColumnName; - typedef std::set ColumnNames; - typedef ColumnNames PrimaryKey; - typedef PrimaryKey::const_iterator PKI; + using TableName = std::string; + using ColumnName = std::string; + using ColumnNames = std::set; + using PrimaryKey = ColumnNames; + using PKI = PrimaryKey::const_iterator; /// Result of a table patch operation. struct PatchResult { @@ -91,7 +85,9 @@ namespace DB { /// Base class for connections to a database. class DLL_PUBLIC Connection : public std::enable_shared_from_this { public: - virtual ~Connection(); + virtual ~Connection() = default; + /// Standard special members + SPECIAL_MEMBERS_DEFAULT_MOVE_NO_COPY(Connection); /// Perform final checks before closing. void finish() const; @@ -151,7 +147,7 @@ namespace DB { protected: /// Create a new connection. - Connection(); + Connection() = default; /// Internal begin transaction. virtual void beginTxInt() = 0; @@ -168,25 +164,24 @@ namespace DB { virtual unsigned int patchInserts(TablePatch * tp); private: - unsigned int txOpenDepth; + unsigned int txOpenDepth { 0 }; }; /// Helper class for beginning/committing/rolling back transactions in accordance with scope and exceptions. class DLL_PUBLIC TransactionScope { public: /// Create a new helper and associated transaction on the given connection. - TransactionScope(Connection &); - ~TransactionScope(); + explicit TransactionScope(Connection &); + ~TransactionScope() noexcept; + /// Standard special members + SPECIAL_MEMBERS_DEFAULT_MOVE_NO_COPY(TransactionScope); private: - TransactionScope(const TransactionScope &) = delete; - void operator=(const TransactionScope &) = delete; - - Connection & conn; + Connection * conn; }; - typedef AdHoc::Factory ConnectionFactory; - typedef std::shared_ptr ConnectionFactoryCPtr; + using ConnectionFactory = AdHoc::Factory; + using ConnectionFactoryCPtr = std::shared_ptr; } #endif diff --git a/libdbpp/connectionPool.h b/libdbpp/connectionPool.h index e03b6c8..1955f21 100644 --- a/libdbpp/connectionPool.h +++ b/libdbpp/connectionPool.h @@ -41,7 +41,7 @@ namespace DB { const std::string connectionString; }; - typedef std::shared_ptr ConnectionPoolPtr; + using ConnectionPoolPtr = std::shared_ptr; } #endif diff --git a/libdbpp/connection_fwd.h b/libdbpp/connection_fwd.h index 616c6b8..c8f9e73 100644 --- a/libdbpp/connection_fwd.h +++ b/libdbpp/connection_fwd.h @@ -5,8 +5,8 @@ namespace DB { class Connection; - typedef std::shared_ptr ConnectionPtr; - typedef std::shared_ptr ConnectionCPtr; + using ConnectionPtr = std::shared_ptr; + using ConnectionCPtr = std::shared_ptr; } #endif diff --git a/libdbpp/dbTypes.cpp b/libdbpp/dbTypes.cpp index 66e514a..6dd8605 100644 --- a/libdbpp/dbTypes.cpp +++ b/libdbpp/dbTypes.cpp @@ -1,12 +1,6 @@ #include "dbTypes.h" #include -DB::Blob::Blob() : - data(nullptr), - len(0) -{ -} - DB::Blob::Blob(const void * d, size_t l) : data(d), len(l) diff --git a/libdbpp/dbTypes.h b/libdbpp/dbTypes.h index 3055974..7f6dc5e 100644 --- a/libdbpp/dbTypes.h +++ b/libdbpp/dbTypes.h @@ -2,7 +2,7 @@ #define DB_TYPES_H #include -#include +#include #include namespace DB { @@ -10,19 +10,19 @@ namespace DB { class DLL_PUBLIC Blob { public: /// Construct a default blob pointing to no data. - Blob(); + Blob() = default; /// Construct a reference using C-style pointer and length. Blob(const void * data, size_t len); /// Construct a reference using C++ template pointer to an object. template - Blob(const T * t) : + explicit Blob(const T * t) : data(t), len(sizeof(T)) { } /// Construct a reference using C++ vector pointer to a collection of objects. template - Blob(const std::vector & v) : + explicit Blob(const std::vector & v) : data(&v.front()), len(sizeof(T) * v.size()) { @@ -32,9 +32,9 @@ namespace DB { bool operator==(const DB::Blob b) const; /// The beginning of the binary data. - const void * data; + const void * data { nullptr }; /// The length of the binary data. - size_t len; + size_t len { 0 }; }; } diff --git a/libdbpp/error.h b/libdbpp/error.h index 7c36281..6c162f9 100644 --- a/libdbpp/error.h +++ b/libdbpp/error.h @@ -1,7 +1,7 @@ #ifndef DB_ERROR_H #define DB_ERROR_H -#include +#include #include #include @@ -36,7 +36,7 @@ namespace DB { class DLL_PUBLIC UnexpectedNullValue : public AdHoc::Exception { public: /// Create a new UnexpectedNullValue given the source type name. - UnexpectedNullValue(const char * const from); + explicit UnexpectedNullValue(const char * const from); private: std::string message() const noexcept override; diff --git a/libdbpp/mockDatabase.h b/libdbpp/mockDatabase.h index bf02c4a..5435933 100644 --- a/libdbpp/mockDatabase.h +++ b/libdbpp/mockDatabase.h @@ -12,14 +12,11 @@ namespace DB { /// MockDatabase creates, registers and destroys a database suitable for unit testing. class DLL_PUBLIC MockDatabase : public AdHoc::AbstractPluginImplementation { public: - /// Creates and registers a new database. - virtual ~MockDatabase() = default; - /// Open a connection to this database instance. - virtual ConnectionPtr openConnection() const = 0; + [[nodiscard]] virtual ConnectionPtr openConnection() const = 0; /// Open a connection to a named mock database. - static ConnectionPtr openConnectionTo(const std::string &); + [[nodiscard]] static ConnectionPtr openConnectionTo(const std::string &); protected: /// Implementation specific method to create a new database. @@ -44,14 +41,13 @@ class DLL_PUBLIC MockServerDatabase : public MockDatabase { /// @param name the prefix to use when creating databases. /// @param type the database type. MockServerDatabase(const std::string & masterdb, const std::string & name, const std::string & type); - virtual ~MockServerDatabase() = default; /// Get the database instance name on the server. - const std::string & databaseName() const; + [[nodiscard]] const std::string & databaseName() const; protected: - virtual void CreateNewDatabase() const override; - virtual void DropDatabase() const override; + void CreateNewDatabase() const override; + void DropDatabase() const override; /// Connection to the master database. DB::ConnectionPtr master; @@ -77,8 +73,11 @@ class PluginMock { { AdHoc::PluginManager::getDefault()->remove(mockName); } + /// Standard special members + SPECIAL_MEMBERS_MOVE_RO(PluginMock); + /// Get the name of the mock database. - const std::string & databaseName() const + [[nodiscard]] const std::string & databaseName() const { return std::dynamic_pointer_cast(AdHoc::PluginManager::getDefault()->get(mockName)->implementation())->databaseName(); } @@ -87,7 +86,7 @@ class PluginMock { const std::string mockName; }; -typedef AdHoc::Factory &> MockDatabaseFactory; +using MockDatabaseFactory = AdHoc::Factory &>; } #endif diff --git a/libdbpp/modifycommand.h b/libdbpp/modifycommand.h index b948479..16ed142 100644 --- a/libdbpp/modifycommand.h +++ b/libdbpp/modifycommand.h @@ -14,7 +14,7 @@ namespace DB { class DLL_PUBLIC ModifyCommand : public virtual Command { public: /// Creates a new command from the given SQL. - ModifyCommand(const std::string & sql); + explicit ModifyCommand(const std::string & sql); /// Execute the command and return effected row count virtual unsigned int execute(bool allowNoChange = true) = 0; diff --git a/libdbpp/selectcommand.h b/libdbpp/selectcommand.h index 871b332..a0fecc0 100644 --- a/libdbpp/selectcommand.h +++ b/libdbpp/selectcommand.h @@ -21,7 +21,7 @@ namespace DB { /// @cond class DLL_PUBLIC RowBase { public: - RowBase(SelectCommand *); + explicit RowBase(SelectCommand *); /// Get a column reference by index. const Column & operator[](unsigned int col) const; @@ -35,20 +35,23 @@ namespace DB { template class Row : public RowBase { public: - Row(SelectCommand *); + explicit Row(SelectCommand *); + + template + using FieldType = typename std::tuple_element>::type; /// Get value of column C in current row. template - typename std::tuple_element>::type value() const DEPRECATE ; + [[nodiscard]] FieldType value() const DEPRECATE ; template - typename std::tuple_element>::type get() const; + [[nodiscard]] FieldType get() const; }; template class RowRangeIterator { public: - RowRangeIterator(SelectCommand *); + explicit RowRangeIterator(SelectCommand *); bool operator!=(const RowRangeIterator &) const; void operator++(); @@ -62,7 +65,7 @@ namespace DB { template class RowRange { public: - RowRange(SelectCommand *); + explicit RowRange(SelectCommand *); RowRangeIterator begin() const; RowRangeIterator end() const; @@ -77,7 +80,7 @@ namespace DB { public: /// New ColumnIndexOutOfRange exception /// @param n Index requested - ColumnIndexOutOfRange(unsigned int n); + explicit ColumnIndexOutOfRange(unsigned int n); /// Index requested const unsigned int colNo; @@ -91,7 +94,7 @@ namespace DB { public: /// New ColumnDoesNotExist exception /// @param n Name requested - ColumnDoesNotExist(Glib::ustring n); + explicit ColumnDoesNotExist(Glib::ustring n); /// Name requested const Glib::ustring colName; @@ -104,21 +107,24 @@ namespace DB { class DLL_PUBLIC SelectCommand : public virtual Command { public: /// Creates a new command from the given SQL. - SelectCommand(const std::string & sql); - ~SelectCommand(); + explicit SelectCommand(const std::string & sql); + ~SelectCommand() override; + + /// Standard special members + SPECIAL_MEMBERS_MOVE_RO(SelectCommand); /// Fetch the next row from the result set. Returns false when no further rows are availabile. virtual bool fetch() = 0; /// Execute the statement, but don't fetch the first row. virtual void execute() = 0; /// Get a column reference by index. - const Column & operator[](unsigned int col) const; + [[nodiscard]] const Column & operator[](unsigned int col) const; /// Get a column reference by name. - const Column & operator[](const Glib::ustring &) const; + [[nodiscard]] const Column & operator[](const Glib::ustring &) const; /// Get the number of columns in the result set. - unsigned int columnCount() const; + [[nodiscard]] unsigned int columnCount() const; /// Get the index of a column by name. - unsigned int getOrdinal(const Glib::ustring &) const; + [[nodiscard]] unsigned int getOrdinal(const Glib::ustring &) const; /// Push each row through a function accepting one value per column template> void forEachRow(const Func & func); @@ -143,7 +149,7 @@ namespace std { static constexpr auto value = sizeof...(Fn); }; template struct tuple_element> { - typedef typename std::tuple_element>::type type; + using type = typename std::tuple_element>::type; }; /// @endcond } diff --git a/libdbpp/selectcommandUtil.impl.h b/libdbpp/selectcommandUtil.impl.h index a6d17ca..b8f62e5 100644 --- a/libdbpp/selectcommandUtil.impl.h +++ b/libdbpp/selectcommandUtil.impl.h @@ -91,16 +91,16 @@ namespace DB { template template - inline typename std::tuple_element>::type Row::value() const + inline typename Row::template FieldType Row::value() const { return get(); } template template - inline typename std::tuple_element>::type Row::get() const + inline typename Row::template FieldType Row::get() const { - typename std::tuple_element>::type a; + FieldType a; sel->operator[](C) >> a; return a; } diff --git a/libdbpp/sqlWriter.h b/libdbpp/sqlWriter.h index 45c84a9..dbb35aa 100644 --- a/libdbpp/sqlWriter.h +++ b/libdbpp/sqlWriter.h @@ -3,6 +3,7 @@ #include #include +#include namespace DB { class Command; @@ -10,7 +11,10 @@ namespace DB { /// Base class of dynamic SQL constructors. class DLL_PUBLIC SqlWriter { public: + SqlWriter() = default; virtual ~SqlWriter() = default; + /// Standd special memeber + SPECIAL_MEMBERS_DEFAULT(SqlWriter); /// Append your SQL to the buffer. /// @param buffer The buffer virtual void writeSql(AdHoc::Buffer & buffer) = 0; @@ -25,10 +29,10 @@ namespace DB { public: /// Construct with the SQL to write. /// @param sql The SQL to write. - StaticSqlWriter(std::string sql); + explicit StaticSqlWriter(std::string sql); /// Append the SQL to the buffer. /// @param buffer The buffer - void writeSql(AdHoc::Buffer & buffer); + void writeSql(AdHoc::Buffer & buffer) override; /// The SQL to write. std::string sql; diff --git a/libdbpp/tablepatch.cpp b/libdbpp/tablepatch.cpp index 8623848..1a57bbc 100644 --- a/libdbpp/tablepatch.cpp +++ b/libdbpp/tablepatch.cpp @@ -7,17 +7,6 @@ #include #include -DB::TablePatch::TablePatch() : - srcExpr(nullptr), - insteadOfDelete(nullptr), - where(nullptr), - order(nullptr), - doDeletes(true), - doUpdates(true), - doInserts(true) -{ -} - DB::PatchResult DB::Connection::patchTable(TablePatch * tp) { diff --git a/libdbpp/tablepatch.h b/libdbpp/tablepatch.h index f942401..46521dc 100644 --- a/libdbpp/tablepatch.h +++ b/libdbpp/tablepatch.h @@ -15,21 +15,18 @@ namespace DB { /// Table patch settings. class DLL_PUBLIC TablePatch { private: - typedef std::string TableName; - typedef std::string ColumnName; - typedef std::set ColumnNames; - typedef ColumnNames PrimaryKey; - typedef PrimaryKey::const_iterator PKI; - typedef std::function AuditFunction; + using TableName = std::string; + using ColumnName = std::string; + using ColumnNames = std::set; + using PrimaryKey = ColumnNames; + using PKI = PrimaryKey::const_iterator; + using AuditFunction = std::function; public: - /// Default constructor - TablePatch(); - /// Source table name. TableName src; /// Source expression. - SqlWriter * srcExpr; + SqlWriter * srcExpr { nullptr }; /// Destination table name. TableName dest; /// Columns comprising the [effective] primary key. @@ -37,17 +34,17 @@ namespace DB { /// Columns to be updated in the path. ColumnNames cols; /// An optional SQL writer to replace the default delete operation. - SqlWriter * insteadOfDelete; + SqlWriter * insteadOfDelete { nullptr }; /// An optional SQL writer to append a where clause. - SqlWriter * where; + SqlWriter * where { nullptr }; /// An optional SQL writer to append an order by clause. - SqlWriter * order; + SqlWriter * order { nullptr }; /// Enable deletion - bool doDeletes; + bool doDeletes { true }; /// Enable updates - bool doUpdates; + bool doUpdates { true }; /// Enable insertion - bool doInserts; + bool doInserts { true }; /// Before delete audit AuditFunction beforeDelete; /// Before update audit diff --git a/libdbpp/testCore.cpp b/libdbpp/testCore.cpp index 7004fc4..db18316 100644 --- a/libdbpp/testCore.cpp +++ b/libdbpp/testCore.cpp @@ -7,10 +7,7 @@ namespace DB { TestCore::TestCore() : - testInt(43), - testDouble(3.14), testString("Some C String"), - testBool(false), testDateTime(boost::posix_time::from_time_t(1430530593)), testInterval(boost::posix_time::time_duration(1, 2, 3)) { @@ -32,7 +29,6 @@ class Assert : public DB::HandleField { template void operator()(const D & v) { - // NOLINTNEXTLINE(hicpp-braces-around-statements) if constexpr (std::is_convertible::value) { BOOST_REQUIRE_EQUAL(expected, v); } diff --git a/libdbpp/testCore.h b/libdbpp/testCore.h index 71bd732..285c4b7 100644 --- a/libdbpp/testCore.h +++ b/libdbpp/testCore.h @@ -13,10 +13,10 @@ class DLL_PUBLIC TestCore { protected: TestCore(); - int64_t testInt; - double testDouble; + int64_t testInt { 43 }; + double testDouble { 3.14 }; std::string_view testString; - bool testBool; + bool testBool { false }; boost::posix_time::ptime testDateTime; boost::posix_time::time_duration testInterval; diff --git a/libdbpp/unittests/libdbpp-mysql b/libdbpp/unittests/libdbpp-mysql index fef8f7b..ef7a210 160000 --- a/libdbpp/unittests/libdbpp-mysql +++ b/libdbpp/unittests/libdbpp-mysql @@ -1 +1 @@ -Subproject commit fef8f7b2afc7765ad9ffd0c1612eea3d987127bd +Subproject commit ef7a2108654dd8afb18fd27f0f84f152f7f796cc diff --git a/libdbpp/unittests/libdbpp-odbc b/libdbpp/unittests/libdbpp-odbc index fbe5f26..e5c210f 160000 --- a/libdbpp/unittests/libdbpp-odbc +++ b/libdbpp/unittests/libdbpp-odbc @@ -1 +1 @@ -Subproject commit fbe5f26f21c623bc04da312d4869639f9c373192 +Subproject commit e5c210fcbddcbb73ca387cf0eb3c5a6f91b2f4a6 diff --git a/libdbpp/unittests/libdbpp-postgresql b/libdbpp/unittests/libdbpp-postgresql index 6d22e64..4487208 160000 --- a/libdbpp/unittests/libdbpp-postgresql +++ b/libdbpp/unittests/libdbpp-postgresql @@ -1 +1 @@ -Subproject commit 6d22e64c985fd3a55c424fd3b3e5dd49c083cbc9 +Subproject commit 448720848b383639c37f5f0487efdf8c0f0ed433 diff --git a/libdbpp/unittests/libdbpp-sqlite b/libdbpp/unittests/libdbpp-sqlite index 6df49b4..f571f6b 160000 --- a/libdbpp/unittests/libdbpp-sqlite +++ b/libdbpp/unittests/libdbpp-sqlite @@ -1 +1 @@ -Subproject commit 6df49b45f5e905a4ec9114e7a6cbe484ded798ed +Subproject commit f571f6b2bf1370b0757c29162988a40e02a82f91 diff --git a/libdbpp/unittests/testConnection.cpp b/libdbpp/unittests/testConnection.cpp index b874a99..491c236 100644 --- a/libdbpp/unittests/testConnection.cpp +++ b/libdbpp/unittests/testConnection.cpp @@ -25,7 +25,9 @@ BOOST_AUTO_TEST_CASE( resolve ) auto libname = DB::Connection::resolvePlugin(typeid(DB::Connection), "postgresql"); BOOST_REQUIRE(libname); BOOST_REQUIRE_EQUAL("libdbpp-postgresql.so", *libname); - BOOST_REQUIRE_THROW(DB::ConnectionFactory::createNew("otherdb", "doesn't matter"), AdHoc::LoadLibraryException); + BOOST_REQUIRE_THROW( + (void)DB::ConnectionFactory::createNew("otherdb", "doesn't matter"), + AdHoc::LoadLibraryException); } BOOST_AUTO_TEST_CASE( finish ) diff --git a/libdbpp/unittests/testMock.cpp b/libdbpp/unittests/testMock.cpp index 7b71312..43b757d 100644 --- a/libdbpp/unittests/testMock.cpp +++ b/libdbpp/unittests/testMock.cpp @@ -10,7 +10,7 @@ BOOST_AUTO_TEST_CASE( noFactory ) { BOOST_REQUIRE_THROW({ - DB::MockDatabaseFactory::get("not-found"); + (void)DB::MockDatabaseFactory::get("not-found"); }, AdHoc::LoadLibraryException); } @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE( mockFactory ) BOOST_AUTO_TEST_CASE( missingMock ) { BOOST_REQUIRE_THROW({ - DB::MockDatabaseFactory::createNew("MockMock", + (void)DB::MockDatabaseFactory::createNew("MockMock", "user=postgres dbname=postgres", typeid(this).name(), { rootDir / "missing.sql" }); }, std::fstream::failure); } @@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE( missingMock ) BOOST_AUTO_TEST_CASE( failingMock ) { BOOST_REQUIRE_THROW({ - DB::MockDatabaseFactory::createNew("MockMock", + (void)DB::MockDatabaseFactory::createNew("MockMock", "user=postgres dbname=postgres", typeid(this).name(), { rootDir / "badMock.sql" }); }, DB::Error); } diff --git a/libdbpp/unittests/testUtils.cpp b/libdbpp/unittests/testUtils.cpp index a05c831..eed1322 100644 --- a/libdbpp/unittests/testUtils.cpp +++ b/libdbpp/unittests/testUtils.cpp @@ -122,8 +122,8 @@ BOOST_AUTO_TEST_CASE( columns ) auto db = DB::MockDatabase::openConnectionTo("pqmock"); auto sel = db->select("SELECT a, b, c, d, e FROM forEachRow ORDER BY a LIMIT 1"); sel->execute(); - BOOST_REQUIRE_THROW((*sel)[5], DB::ColumnIndexOutOfRange); - BOOST_REQUIRE_THROW((*sel)[-1], DB::ColumnIndexOutOfRange); + BOOST_REQUIRE_THROW((void)(*sel)[5], DB::ColumnIndexOutOfRange); + BOOST_REQUIRE_THROW((void)(*sel)[-1], DB::ColumnIndexOutOfRange); BOOST_REQUIRE_EQUAL(0, (*sel)[0].colNo); BOOST_REQUIRE_EQUAL(4, (*sel)[4].colNo); BOOST_REQUIRE_EQUAL("c", (*sel)[2].name); @@ -131,9 +131,9 @@ BOOST_AUTO_TEST_CASE( columns ) BOOST_REQUIRE_EQUAL(4, (*sel)["e"].colNo); BOOST_REQUIRE_EQUAL(5, sel->columnCount()); BOOST_REQUIRE_EQUAL(1, sel->getOrdinal("b")); - BOOST_REQUIRE_THROW((*sel)["f"], DB::ColumnDoesNotExist); - BOOST_REQUIRE_THROW((*sel)["aa"], DB::ColumnDoesNotExist); - BOOST_REQUIRE_THROW((*sel)[""], DB::ColumnDoesNotExist); + BOOST_REQUIRE_THROW((void)(*sel)["f"], DB::ColumnDoesNotExist); + BOOST_REQUIRE_THROW((void)(*sel)["aa"], DB::ColumnDoesNotExist); + BOOST_REQUIRE_THROW((void)(*sel)[""], DB::ColumnDoesNotExist); } BOOST_AUTO_TEST_CASE( extract ) @@ -206,10 +206,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( nullBind, Str, StringTypes ) unsigned int count = 0; for (const auto & row : sel->as, Str>()) { count += 1; - BOOST_CHECK_THROW(row.template get<0>(), DB::UnexpectedNullValue); + BOOST_CHECK_THROW((void)row.template get<0>(), DB::UnexpectedNullValue); auto nd = row.template get<1>(); BOOST_CHECK(!nd.has_value()); - BOOST_CHECK_THROW(row.template get<2>(), DB::UnexpectedNullValue); + BOOST_CHECK_THROW((void)row.template get<2>(), DB::UnexpectedNullValue); } BOOST_REQUIRE_EQUAL(1, count); } @@ -414,9 +414,9 @@ BOOST_AUTO_TEST_CASE( testBlobCompare ) // These just compile time support, actual data extraction should be tested by the implementing connector. template -void +auto testExtractT(DB::Row row) { - row.template value<0>(); + return row.template value<0>(); } template @@ -429,7 +429,6 @@ testExtractT(const DB::SelectCommandPtr & sel) { #ifdef __clang__ // Clang cannot compile this for reasons largely todo with ambiguousness in the spec // Fixed when we move to std::chrono - // NOLINTNEXTLINE(bugprone-suspicious-semicolon,hicpp-braces-around-statements) if constexpr (!std::is_same::value) { #else if constexpr (true) { -- cgit v1.2.3