summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2020-03-28 17:57:10 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2020-03-28 17:57:10 +0000
commit72e0fba3aec8b0b4a4a6d1d2fe964ccd32db29a1 (patch)
tree19e1d251101ad5789d936a9f02d3b006d486b3a1
parentFixes for tidy (diff)
downloadlibdbpp-72e0fba3aec8b0b4a4a6d1d2fe964ccd32db29a1.tar.bz2
libdbpp-72e0fba3aec8b0b4a4a6d1d2fe964ccd32db29a1.tar.xz
libdbpp-72e0fba3aec8b0b4a4a6d1d2fe964ccd32db29a1.zip
Modernize and tidylibdbpp-1.4.3
-rw-r--r--Jamroot.jam1
-rw-r--r--libdbpp/column.h8
-rw-r--r--libdbpp/command.h39
-rw-r--r--libdbpp/command_fwd.h12
-rw-r--r--libdbpp/connection.cpp27
-rw-r--r--libdbpp/connection.h43
-rw-r--r--libdbpp/connectionPool.h2
-rw-r--r--libdbpp/connection_fwd.h4
-rw-r--r--libdbpp/dbTypes.cpp6
-rw-r--r--libdbpp/dbTypes.h12
-rw-r--r--libdbpp/error.h4
-rw-r--r--libdbpp/mockDatabase.h21
-rw-r--r--libdbpp/modifycommand.h2
-rw-r--r--libdbpp/selectcommand.h36
-rw-r--r--libdbpp/selectcommandUtil.impl.h6
-rw-r--r--libdbpp/sqlWriter.h8
-rw-r--r--libdbpp/tablepatch.cpp11
-rw-r--r--libdbpp/tablepatch.h29
-rw-r--r--libdbpp/testCore.cpp4
-rw-r--r--libdbpp/testCore.h6
m---------libdbpp/unittests/libdbpp-mysql0
m---------libdbpp/unittests/libdbpp-odbc0
m---------libdbpp/unittests/libdbpp-postgresql0
m---------libdbpp/unittests/libdbpp-sqlite0
-rw-r--r--libdbpp/unittests/testConnection.cpp4
-rw-r--r--libdbpp/unittests/testMock.cpp6
-rw-r--r--libdbpp/unittests/testUtils.cpp19
27 files changed, 145 insertions, 165 deletions
diff --git a/Jamroot.jam b/Jamroot.jam
index 824be0e..9177f1e 100644
--- a/Jamroot.jam
+++ b/Jamroot.jam
@@ -25,6 +25,7 @@ project
<toolset>tidy:<checkxx>misc-*
<toolset>tidy:<checkxx>modernize-*
<toolset>tidy:<xcheckxx>modernize-use-trailing-return-type
+ <toolset>tidy:<xcheckxx>misc-non-private-member-variables-in-classes
<toolset>tidy:<checkxx>hicpp-*
<toolset>tidy:<checkxx>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 <exception.h>
#include "dbTypes.h"
#include "error.h"
+#include <c++11Helpers.h>
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<T>::is_arithmetic == std::is_arithmetic<D>::value) {
if constexpr (std::is_assignable<T, D>::value) {
target = v;
@@ -115,7 +117,7 @@ namespace DB {
/// This column's name.
const std::string name;
};
- typedef std::unique_ptr<Column> ColumnPtr;
+ using ColumnPtr = std::unique_ptr<Column>;
}
#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 <type_traits>
#include "dbTypes.h"
#include "error.h"
+#include <c++11Helpers.h>
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<std::size_t> 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<typename O>
inline void bindParam(unsigned int i, const O & o)
{
- if constexpr (std::is_null_pointer<O>::value) {
- bindNull(i);
- }
- else if constexpr (std::is_same<O, std::nullopt_t>::value) {
+ if constexpr (std::is_null_pointer<O>::value ||
+ std::is_same<O, std::nullopt_t>::value) {
bindNull(i);
}
else if constexpr (std::is_same<O, bool>::value) {
@@ -119,10 +123,8 @@ namespace DB {
else if constexpr (std::is_floating_point<O>::value) {
bindParamF(i, o);
}
- else if constexpr (std::is_same<O, boost::posix_time::time_duration>::value) {
- bindParamT(i, o);
- }
- else if constexpr (std::is_same<O, boost::posix_time::ptime>::value) {
+ else if constexpr (std::is_same<O, boost::posix_time::time_duration>::value ||
+ std::is_same<O, boost::posix_time::ptime>::value) {
bindParamT(i, o);
}
else if constexpr (std::is_same<O, Blob>::value) {
@@ -131,7 +133,8 @@ namespace DB {
else if constexpr (std::is_integral<O>::value && !std::is_pointer<O>::value) {
bindParamI(i, o);
}
- else if constexpr (std::is_convertible<O, std::string_view>::value && std::is_pointer<O>::value) {
+ else if constexpr (std::is_convertible<O, std::string_view>::value &&
+ std::is_pointer<O>::value) {
if (o) {
bindParamS(i, o);
}
@@ -139,10 +142,9 @@ namespace DB {
bindNull(i);
}
}
- else if constexpr (std::is_same<O, Glib::ustring>::value) {
- bindParamS(i, o);
- }
- else if constexpr (std::is_convertible<O, std::string_view>::value) {
+ else if constexpr (std::is_same<O, Glib::ustring>::value ||
+ std::is_convertible<O, std::string_view>::value) {
+ // NOLINTNEXTLINE(hicpp-no-array-decay)
bindParamS(i, o);
}
else if constexpr (std::is_constructible<bool, const O &>::value) {
@@ -162,8 +164,8 @@ namespace DB {
template<typename O> \
inline auto \
func(unsigned int i, const O & o) -> typename std::enable_if< \
- std::is_constructible<bool, const O &>::value \
- && !std::is_void<decltype(*o)>::value \
+ std::is_constructible_v<bool, const O &> \
+ && !std::is_void_v<decltype(*o)> \
>::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<CommandOptions, std::size_t, const CommandOptionsMap &> CommandOptionsFactory;
+ using CommandOptionsFactory = AdHoc::Factory<CommandOptions, std::size_t, const CommandOptionsMap &>;
}
#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 <memory>
namespace DB {
- typedef std::map<std::string, std::string, std::less<>> CommandOptionsMap;
+ using CommandOptionsMap = std::map<std::string, std::string, std::less<>>;
class CommandOptions;
- typedef std::shared_ptr<CommandOptions> CommandOptionsPtr;
- typedef std::shared_ptr<const CommandOptions> CommandOptionsCPtr;
+ using CommandOptionsPtr = std::shared_ptr<CommandOptions>;
+ using CommandOptionsCPtr = std::shared_ptr<const CommandOptions>;
class Command;
- typedef std::shared_ptr<Command> CommandPtr;
+ using CommandPtr = std::shared_ptr<Command>;
class ModifyCommand;
- typedef std::shared_ptr<ModifyCommand> ModifyCommandPtr;
+ using ModifyCommandPtr = std::shared_ptr<ModifyCommand>;
class SelectCommand;
- typedef std::shared_ptr<SelectCommand> SelectCommandPtr;
+ using SelectCommandPtr = std::shared_ptr<SelectCommand>;
}
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 <string>
#include <set>
#include <factory.h>
@@ -11,20 +12,13 @@
#include <memory>
#include <optional>
#include "error.h"
+#include <c++11Helpers.h>
namespace AdHoc {
class Buffer;
}
namespace DB {
- class Command;
- class CommandOptions;
- typedef std::shared_ptr<CommandOptions> CommandOptionsPtr;
- typedef std::shared_ptr<const CommandOptions> CommandOptionsCPtr;
- class SelectCommand;
- typedef std::shared_ptr<SelectCommand> SelectCommandPtr;
- class ModifyCommand;
- typedef std::shared_ptr<ModifyCommand> ModifyCommandPtr;
class TablePatch;
enum BulkDeleteStyle {
@@ -38,11 +32,11 @@ namespace DB {
BulkUpdateUsingJoin = 2,
};
- typedef std::string TableName;
- typedef std::string ColumnName;
- typedef std::set<ColumnName> ColumnNames;
- typedef ColumnNames PrimaryKey;
- typedef PrimaryKey::const_iterator PKI;
+ using TableName = std::string;
+ using ColumnName = std::string;
+ using ColumnNames = std::set<ColumnName>;
+ 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<Connection> {
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<Connection, std::string> ConnectionFactory;
- typedef std::shared_ptr<const ConnectionFactory> ConnectionFactoryCPtr;
+ using ConnectionFactory = AdHoc::Factory<Connection, std::string>;
+ using ConnectionFactoryCPtr = std::shared_ptr<const ConnectionFactory>;
}
#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<BasicConnectionPool> ConnectionPoolPtr;
+ using ConnectionPoolPtr = std::shared_ptr<BasicConnectionPool>;
}
#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<Connection> ConnectionPtr;
- typedef std::shared_ptr<const Connection> ConnectionCPtr;
+ using ConnectionPtr = std::shared_ptr<Connection>;
+ using ConnectionCPtr = std::shared_ptr<const Connection>;
}
#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 <memory.h>
-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 <visibility.h>
-#include <stdlib.h>
+#include <cstdlib>
#include <vector>
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<typename T>
- 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<typename T>
- Blob(const std::vector<T> & v) :
+ explicit Blob(const std::vector<T> & 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 <stdlib.h>
+#include <cstdlib>
#include <exception.h>
#include <visibility.h>
@@ -36,7 +36,7 @@ namespace DB {
class DLL_PUBLIC UnexpectedNullValue : public AdHoc::Exception<Error> {
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<MockDatabase>(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<MockServerDatabase>(AdHoc::PluginManager::getDefault()->get<MockDatabase>(mockName)->implementation())->databaseName();
}
@@ -87,7 +86,7 @@ class PluginMock {
const std::string mockName;
};
-typedef AdHoc::Factory<MockDatabase, const std::string &, const std::string &, const std::vector<std::filesystem::path> &> MockDatabaseFactory;
+using MockDatabaseFactory = AdHoc::Factory<MockDatabase, const std::string &, const std::string &, const std::vector<std::filesystem::path> &>;
}
#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<typename ... Fn>
class Row : public RowBase {
public:
- Row(SelectCommand *);
+ explicit Row(SelectCommand *);
+
+ template<unsigned int C>
+ using FieldType = typename std::tuple_element<C, std::tuple<Fn...>>::type;
/// Get value of column C in current row.
template<unsigned int C>
- typename std::tuple_element<C, std::tuple<Fn...>>::type value() const DEPRECATE ;
+ [[nodiscard]] FieldType<C> value() const DEPRECATE ;
template<unsigned int C>
- typename std::tuple_element<C, std::tuple<Fn...>>::type get() const;
+ [[nodiscard]] FieldType<C> get() const;
};
template<typename ... Fn>
class RowRangeIterator {
public:
- RowRangeIterator(SelectCommand *);
+ explicit RowRangeIterator(SelectCommand *);
bool operator!=(const RowRangeIterator &) const;
void operator++();
@@ -62,7 +65,7 @@ namespace DB {
template<typename ... Fn>
class RowRange {
public:
- RowRange(SelectCommand *);
+ explicit RowRange(SelectCommand *);
RowRangeIterator<Fn...> begin() const;
RowRangeIterator<Fn...> 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<typename ... Fn, typename Func = std::function<void(Fn...)>>
void forEachRow(const Func & func);
@@ -143,7 +149,7 @@ namespace std {
static constexpr auto value = sizeof...(Fn);
};
template<size_t C, typename ... Fn> struct tuple_element<C, DB::Row<Fn...>> {
- typedef typename std::tuple_element<C, std::tuple<Fn...>>::type type;
+ using type = typename std::tuple_element<C, std::tuple<Fn...>>::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<typename ... Fn>
template<unsigned int C>
- inline typename std::tuple_element<C, std::tuple<Fn...>>::type Row<Fn...>::value() const
+ inline typename Row<Fn...>::template FieldType<C> Row<Fn...>::value() const
{
return get<C>();
}
template<typename ... Fn>
template<unsigned int C>
- inline typename std::tuple_element<C, std::tuple<Fn...>>::type Row<Fn...>::get() const
+ inline typename Row<Fn...>::template FieldType<C> Row<Fn...>::get() const
{
- typename std::tuple_element<C, std::tuple<Fn...>>::type a;
+ FieldType<C> 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 <visibility.h>
#include <buffer.h>
+#include <c++11Helpers.h>
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 <safeMapFind.h>
#include <boost/algorithm/string/join.hpp>
-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<ColumnName> ColumnNames;
- typedef ColumnNames PrimaryKey;
- typedef PrimaryKey::const_iterator PKI;
- typedef std::function<void(DB::SelectCommandPtr)> AuditFunction;
+ using TableName = std::string;
+ using ColumnName = std::string;
+ using ColumnNames = std::set<ColumnName>;
+ using PrimaryKey = ColumnNames;
+ using PKI = PrimaryKey::const_iterator;
+ using AuditFunction = std::function<void(DB::SelectCommandPtr)>;
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 <typename D>
void operator()(const D & v) {
- // NOLINTNEXTLINE(hicpp-braces-around-statements)
if constexpr (std::is_convertible<D, T>::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
-Subproject fef8f7b2afc7765ad9ffd0c1612eea3d987127b
+Subproject ef7a2108654dd8afb18fd27f0f84f152f7f796c
diff --git a/libdbpp/unittests/libdbpp-odbc b/libdbpp/unittests/libdbpp-odbc
-Subproject fbe5f26f21c623bc04da312d4869639f9c37319
+Subproject e5c210fcbddcbb73ca387cf0eb3c5a6f91b2f4a
diff --git a/libdbpp/unittests/libdbpp-postgresql b/libdbpp/unittests/libdbpp-postgresql
-Subproject 6d22e64c985fd3a55c424fd3b3e5dd49c083cbc
+Subproject 448720848b383639c37f5f0487efdf8c0f0ed43
diff --git a/libdbpp/unittests/libdbpp-sqlite b/libdbpp/unittests/libdbpp-sqlite
-Subproject 6df49b45f5e905a4ec9114e7a6cbe484ded798e
+Subproject f571f6b2bf1370b0757c29162988a40e02a82f9
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<int, std::optional<double>, 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<typename T>
-void
+auto
testExtractT(DB::Row<T> row) {
- row.template value<0>();
+ return row.template value<0>();
}
template<typename T>
@@ -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<T, boost::posix_time::time_duration>::value) {
#else
if constexpr (true) {