summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-10-09 18:10:44 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-10-09 18:10:44 +0100
commitaff4c0da167090a54df4ef2c5f18baffcb6af9fb (patch)
tree76f8af7b8ae7629617fb26f421975cacd7070636
parentEnable all cppcheck checks and fixup (diff)
downloadlibdbpp-aff4c0da167090a54df4ef2c5f18baffcb6af9fb.tar.bz2
libdbpp-aff4c0da167090a54df4ef2c5f18baffcb6af9fb.tar.xz
libdbpp-aff4c0da167090a54df4ef2c5f18baffcb6af9fb.zip
Reformat with new clang-format
-rw-r--r--libdbpp/column.cpp2
-rw-r--r--libdbpp/column.h10
-rw-r--r--libdbpp/command.h15
-rw-r--r--libdbpp/connection.cpp1
-rw-r--r--libdbpp/connection.h1
-rw-r--r--libdbpp/dbTypes.h2
-rw-r--r--libdbpp/error.h9
-rw-r--r--libdbpp/mockDatabase.cpp1
-rw-r--r--libdbpp/mockDatabase.h4
-rw-r--r--libdbpp/modifycommand.h3
-rw-r--r--libdbpp/selectcommand.cpp7
-rw-r--r--libdbpp/selectcommand.h3
-rw-r--r--libdbpp/selectcommandUtil.impl.h1
-rw-r--r--libdbpp/sqlParse.h1
-rw-r--r--libdbpp/sqlParseImpl.cpp1
-rw-r--r--libdbpp/sqlWriter.h1
-rw-r--r--libdbpp/tablepatch.cpp1
-rw-r--r--libdbpp/testCore.cpp8
-rw-r--r--libdbpp/testCore.h1
-rw-r--r--libdbpp/unittests/mockdb.cpp2
-rw-r--r--libdbpp/unittests/testConnectionPool.cpp5
-rw-r--r--libdbpp/unittests/testPatch.cpp2
-rw-r--r--libdbpp/unittests/testUtils.cpp3
23 files changed, 65 insertions, 19 deletions
diff --git a/libdbpp/column.cpp b/libdbpp/column.cpp
index 7190d36..3493bc6 100644
--- a/libdbpp/column.cpp
+++ b/libdbpp/column.cpp
@@ -24,6 +24,7 @@ namespace DB {
}
AdHocFormatter(InvalidConversionMsg, "Invalid conversion from column type (%?) to value type (%?)");
+
std::string
InvalidConversion::message() const noexcept
{
@@ -33,6 +34,7 @@ namespace DB {
UnexpectedNullValue::UnexpectedNullValue(const char * const t) : to(t) { }
AdHocFormatter(UnexpectedNullValueMsg, "Unexpected null value in column expecting type (%?)");
+
std::string
UnexpectedNullValue::message() const noexcept
{
diff --git a/libdbpp/column.h b/libdbpp/column.h
index b9260cb..38958ab 100644
--- a/libdbpp/column.h
+++ b/libdbpp/column.h
@@ -21,6 +21,7 @@
#include <type_traits>
#include <typeinfo>
#include <visibility.h>
+
// IWYU pragma: no_forward_declare DB::Blob
namespace DB {
@@ -70,6 +71,7 @@ namespace DB {
static constexpr bool value = false;
static constexpr bool is_arithmetic = std::is_arithmetic<X>::value;
};
+
template<typename X> struct is_optional<std::optional<X>> {
static constexpr bool value = true;
static constexpr bool is_arithmetic = std::is_arithmetic<X>::value;
@@ -84,36 +86,43 @@ namespace DB {
{
(*this)(v);
}
+
void
integer(int64_t v) override
{
(*this)(v);
}
+
void
boolean(bool v) override
{
(*this)(v);
}
+
void
string(const std::string_view v) override
{
(*this)(v);
}
+
void
timestamp(const boost::posix_time::ptime v) override
{
(*this)(v);
}
+
void
interval(const boost::posix_time::time_duration v) override
{
(*this)(v);
}
+
void
blob(const Blob & v) override
{
(*this)(v);
}
+
void
null() override
{
@@ -161,6 +170,7 @@ namespace DB {
/// This column's name.
const std::string name;
};
+
using ColumnPtr = std::unique_ptr<Column>;
}
diff --git a/libdbpp/command.h b/libdbpp/command.h
index 98e59b4..6815866 100644
--- a/libdbpp/command.h
+++ b/libdbpp/command.h
@@ -21,17 +21,17 @@
#pragma GCC diagnostic pop
#include <type_traits>
#include <visibility.h>
+
// IWYU pragma: no_include "factory.impl.h"
namespace DB {
class Blob;
+
/// Exception thrown when binding a parameter of type the connector doesn't support.
- class DLL_PUBLIC ParameterTypeNotSupported : public Error {
- };
+ class DLL_PUBLIC ParameterTypeNotSupported : public Error { };
/// Exception thrown when binding a parameter out of range of those defined in the command.
- class DLL_PUBLIC ParameterOutOfRange : public Error {
- };
+ class DLL_PUBLIC ParameterOutOfRange : public Error { };
/// Represents the basic options that can be passed when creating new commands.
class DLL_PUBLIC CommandOptions {
@@ -62,6 +62,7 @@ namespace DB {
}
return def;
}
+
/// Helper function to test if a value is set in a CommandOptionsMap
static bool isSet(const CommandOptionsMap & map, const std::string & key);
};
@@ -101,6 +102,7 @@ namespace DB {
virtual void bindParamS(unsigned int i, const Glib::ustring &) = 0;
/// Bind a string_view to parameter i.
virtual void bindParamS(unsigned int i, const std::string_view) = 0;
+
/// Bind a string to parameter i (wraps string_view).
inline void
bindParamS(unsigned int i, const std::string & v)
@@ -174,8 +176,8 @@ namespace DB {
#define OPTWRAPPER(func) \
template<typename O> \
- inline auto func(unsigned int i, const O & o) \
- ->typename std::enable_if<std::is_constructible_v<bool, const O &> && !std::is_void_v<decltype(*o)>>::type \
+ inline auto func(unsigned int i, const O & o) -> \
+ typename std::enable_if<std::is_constructible_v<bool, const O &> && !std::is_void_v<decltype(*o)>>::type \
{ \
bool nn(o); \
if (nn) \
@@ -197,6 +199,7 @@ namespace DB {
/// Bind a (possibly null) c-string to parameter i.
void bindParamS(unsigned int, char * const);
};
+
using CommandOptionsFactory = AdHoc::Factory<CommandOptions, std::size_t, const CommandOptionsMap &>;
}
diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp
index 7208c93..529b130 100644
--- a/libdbpp/connection.cpp
+++ b/libdbpp/connection.cpp
@@ -161,6 +161,7 @@ DB::Connection::bulkUploadData(FILE * in) const
}
AdHocFormatter(PluginLibraryFormat, "libdbpp-%?.so");
+
std::optional<std::string>
DB::Connection::resolvePlugin(const std::type_info &, const std::string_view name)
{
diff --git a/libdbpp/connection.h b/libdbpp/connection.h
index 4399b37..c6d53da 100644
--- a/libdbpp/connection.h
+++ b/libdbpp/connection.h
@@ -18,6 +18,7 @@
#include <sys/types.h>
#include <typeinfo>
#include <visibility.h>
+
// IWYU pragma: no_include "factory.impl.h"
namespace DB {
diff --git a/libdbpp/dbTypes.h b/libdbpp/dbTypes.h
index 5fd0e7b..17d7134 100644
--- a/libdbpp/dbTypes.h
+++ b/libdbpp/dbTypes.h
@@ -13,8 +13,10 @@ namespace DB {
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> 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>
// cppcheck-suppress noExplicitConstructor
diff --git a/libdbpp/error.h b/libdbpp/error.h
index 8245ea9..329e8f4 100644
--- a/libdbpp/error.h
+++ b/libdbpp/error.h
@@ -7,16 +7,13 @@
namespace DB {
/// Base class for database errors.
- class DLL_PUBLIC Error : public virtual std::exception {
- };
+ class DLL_PUBLIC Error : public virtual std::exception { };
/// Exception thrown when attempting to bulk upload with a connector that doesn't support it.
- class DLL_PUBLIC BulkUploadNotSupported : public Error {
- };
+ class DLL_PUBLIC BulkUploadNotSupported : public Error { };
/// Exception thrown when a query returns an unsupported column type.
- class DLL_PUBLIC ColumnTypeNotSupported : public Error {
- };
+ class DLL_PUBLIC ColumnTypeNotSupported : public Error { };
/// Exception thrown on an attempt to convert betweem incompatible types.
class DLL_PUBLIC InvalidConversion : public AdHoc::Exception<Error> {
diff --git a/libdbpp/mockDatabase.cpp b/libdbpp/mockDatabase.cpp
index 797a6af..625e39c 100644
--- a/libdbpp/mockDatabase.cpp
+++ b/libdbpp/mockDatabase.cpp
@@ -55,6 +55,7 @@ namespace DB {
}
AdHocFormatter(MockServerDatabaseName, "libdbpp_mock_%?_%?_%?");
+
MockServerDatabase::MockServerDatabase(
const std::string & masterdb, const std::string & name, const std::string & type) :
master(DB::ConnectionFactory::createNew(type, masterdb)),
diff --git a/libdbpp/mockDatabase.h b/libdbpp/mockDatabase.h
index d067967..71ba729 100644
--- a/libdbpp/mockDatabase.h
+++ b/libdbpp/mockDatabase.h
@@ -11,10 +11,12 @@
#include <utility>
#include <vector>
#include <visibility.h>
+
// IWYU pragma: no_include "factory.impl.h"
namespace DB {
class Connection;
+
/// MockDatabase creates, registers and destroys a database suitable for unit testing.
class DLL_PUBLIC MockDatabase : public AdHoc::AbstractPluginImplementation {
public:
@@ -75,10 +77,12 @@ namespace DB {
AdHoc::PluginManager::getDefault()->create<MockDatabase, T>(
mockName, __FILE__, __LINE__, std::forward<Args>(args)..., name, s);
}
+
~PluginMock()
{
AdHoc::PluginManager::getDefault()->remove<MockDatabase>(mockName);
}
+
/// Standard special members
SPECIAL_MEMBERS_MOVE_RO(PluginMock);
diff --git a/libdbpp/modifycommand.h b/libdbpp/modifycommand.h
index 7b6011e..a1ed7a8 100644
--- a/libdbpp/modifycommand.h
+++ b/libdbpp/modifycommand.h
@@ -8,8 +8,7 @@
namespace DB {
/// Exception thrown when an update affected no rows when some were expected.
- class DLL_PUBLIC NoRowsAffected : public Error {
- };
+ class DLL_PUBLIC NoRowsAffected : public Error { };
/// Presents a command not expected to return any data.
class DLL_PUBLIC ModifyCommand : public virtual Command {
diff --git a/libdbpp/selectcommand.cpp b/libdbpp/selectcommand.cpp
index 3217f3b..a378660 100644
--- a/libdbpp/selectcommand.cpp
+++ b/libdbpp/selectcommand.cpp
@@ -8,12 +8,14 @@
#include <compileTimeFormatter.h>
#include <glibmm/ustring.h>
#include <utility>
+
// IWYU pragma: no_forward_declare boost::multi_index::member
namespace DB {
ColumnIndexOutOfRange::ColumnIndexOutOfRange(unsigned int n) : colNo(n) { }
AdHocFormatter(ColumnIndexOutOfRangeMsg, "Column (%?) index out of range");
+
std::string
ColumnIndexOutOfRange::message() const noexcept
{
@@ -23,6 +25,7 @@ namespace DB {
ColumnDoesNotExist::ColumnDoesNotExist(Glib::ustring n) : colName(std::move(n)) { }
AdHocFormatter(ColumnDoesNotExistMsg, "Column (%?) does not exist");
+
std::string
ColumnDoesNotExist::message() const noexcept
{
@@ -34,8 +37,8 @@ namespace DB {
const unsigned int, &DB::Column::colNo>>,
boost::multi_index::ordered_unique<
boost::multi_index::member<DB::Column, const std::string, &DB::Column::name>>>>;
- class SelectCommand::Columns : public ColumnsBase {
- };
+
+ class SelectCommand::Columns : public ColumnsBase { };
}
DB::SelectCommand::SelectCommand(const std::string & sql) : DB::Command(sql), columns(std::make_unique<Columns>()) { }
diff --git a/libdbpp/selectcommand.h b/libdbpp/selectcommand.h
index de931a5..21491b1 100644
--- a/libdbpp/selectcommand.h
+++ b/libdbpp/selectcommand.h
@@ -81,6 +81,7 @@ namespace DB {
private:
SelectCommand * sel;
};
+
/// @endcond
/// Exception thrown when the requested column is outside the range of the result set.
@@ -154,9 +155,11 @@ namespace std {
template<typename... Fn> struct tuple_size<DB::Row<Fn...>> {
static constexpr auto value = sizeof...(Fn);
};
+
template<size_t C, typename... Fn> struct tuple_element<C, DB::Row<Fn...>> {
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 cd64e7e..86a1502 100644
--- a/libdbpp/selectcommandUtil.impl.h
+++ b/libdbpp/selectcommandUtil.impl.h
@@ -98,6 +98,7 @@ namespace DB {
return a;
}
}
+
/// @endcond
#endif
diff --git a/libdbpp/sqlParse.h b/libdbpp/sqlParse.h
index e84ceb7..f13a9d8 100644
--- a/libdbpp/sqlParse.h
+++ b/libdbpp/sqlParse.h
@@ -56,6 +56,7 @@ namespace DB {
private:
DB::Connection * const conn;
};
+
/// @endcond
}
diff --git a/libdbpp/sqlParseImpl.cpp b/libdbpp/sqlParseImpl.cpp
index 7d00895..7c2f478 100644
--- a/libdbpp/sqlParseImpl.cpp
+++ b/libdbpp/sqlParseImpl.cpp
@@ -10,6 +10,7 @@ namespace DB {
SqlParseException::SqlParseException(const char * r, unsigned int l) : reason(r), line(l) { }
AdHocFormatter(SqlParseExceptionMsg, "Error parsing SQL script: %? at line %?");
+
std::string
SqlParseException::message() const noexcept
{
diff --git a/libdbpp/sqlWriter.h b/libdbpp/sqlWriter.h
index e2cfe2b..e05630d 100644
--- a/libdbpp/sqlWriter.h
+++ b/libdbpp/sqlWriter.h
@@ -8,6 +8,7 @@
namespace AdHoc {
class Buffer;
}
+
namespace DB {
class Command;
diff --git a/libdbpp/tablepatch.cpp b/libdbpp/tablepatch.cpp
index db8cac6..b298e5c 100644
--- a/libdbpp/tablepatch.cpp
+++ b/libdbpp/tablepatch.cpp
@@ -87,6 +87,7 @@ self(const typename Container::const_iterator & i)
{
return *i;
}
+
#define selfCols self<decltype(DB::TablePatch::cols)>
#define isNotKey(tp) \
[tp](auto i) { \
diff --git a/libdbpp/testCore.cpp b/libdbpp/testCore.cpp
index ef2588d..1b9cb5d 100644
--- a/libdbpp/testCore.cpp
+++ b/libdbpp/testCore.cpp
@@ -28,36 +28,43 @@ namespace DB {
{
(*this)(v);
}
+
void
integer(int64_t v) override
{
(*this)(v);
}
+
void
boolean(bool v) override
{
(*this)(v);
}
+
void
string(const std::string_view v) override
{
(*this)(v);
}
+
void
timestamp(const boost::posix_time::ptime v) override
{
(*this)(v);
}
+
void
interval(const boost::posix_time::time_duration v) override
{
(*this)(v);
}
+
void
blob(const Blob & v) override
{
(*this)(v);
}
+
void
null() override
{
@@ -100,6 +107,7 @@ namespace DB {
}
AdHocFormatter(BlobDbg, "Blob[length=%?, addr=%?]");
+
std::ostream &
operator<<(std::ostream & s, const DB::Blob b)
{
diff --git a/libdbpp/testCore.h b/libdbpp/testCore.h
index 16c4999..8749ce4 100644
--- a/libdbpp/testCore.h
+++ b/libdbpp/testCore.h
@@ -30,6 +30,7 @@ namespace DB {
template<typename T> void assertScalarValueHelper(SelectCommand & sel, const T t) const;
template<typename T> void assertColumnValueHelper(SelectCommand & sel, unsigned int col, const T t) const;
};
+
/// @endcond
DLL_PUBLIC
diff --git a/libdbpp/unittests/mockdb.cpp b/libdbpp/unittests/mockdb.cpp
index 247a724..3ee08e1 100644
--- a/libdbpp/unittests/mockdb.cpp
+++ b/libdbpp/unittests/mockdb.cpp
@@ -20,10 +20,12 @@ void
MockDb::commitTxInt()
{
}
+
void
MockDb::rollbackTxInt()
{
}
+
void
MockDb::ping() const
{
diff --git a/libdbpp/unittests/testConnectionPool.cpp b/libdbpp/unittests/testConnectionPool.cpp
index 630cb0a..4140c4a 100644
--- a/libdbpp/unittests/testConnectionPool.cpp
+++ b/libdbpp/unittests/testConnectionPool.cpp
@@ -12,9 +12,8 @@
class MockPool : public DB::PluginMock<PQ::Mock>, public DB::ConnectionPool {
public:
MockPool() :
- PluginMock<PQ::Mock>("pqmock", {}, "user=postgres dbname=postgres"), DB::ConnectionPool(4, 2, "postgresql",
- stringbf("user=postgres dbname=%s",
- databaseName()))
+ PluginMock<PQ::Mock>("pqmock", {}, "user=postgres dbname=postgres"),
+ DB::ConnectionPool(4, 2, "postgresql", stringbf("user=postgres dbname=%s", databaseName()))
{
}
};
diff --git a/libdbpp/unittests/testPatch.cpp b/libdbpp/unittests/testPatch.cpp
index e1361f4..cdf4c5a 100644
--- a/libdbpp/unittests/testPatch.cpp
+++ b/libdbpp/unittests/testPatch.cpp
@@ -36,6 +36,7 @@ public:
{
b.append("a.a = ?");
}
+
void
bindParams(DB::Command * cmd, unsigned int & o) override
{
@@ -50,6 +51,7 @@ public:
{
b.append("deleted = ?");
}
+
void
bindParams(DB::Command * cmd, unsigned int & o) override
{
diff --git a/libdbpp/unittests/testUtils.cpp b/libdbpp/unittests/testUtils.cpp
index 4b3f651..59ccf13 100644
--- a/libdbpp/unittests/testUtils.cpp
+++ b/libdbpp/unittests/testUtils.cpp
@@ -33,6 +33,7 @@
#include <type_traits>
#include <utility>
#include <vector>
+
// IWYU pragma: no_include <boost/date_time/gregorian_calendar.ipp>
namespace DB {
@@ -218,6 +219,7 @@ BOOST_AUTO_TEST_CASE(bulkLoadFile)
}
using StringTypes = std::tuple<std::string, std::string_view, Glib::ustring>;
+
BOOST_AUTO_TEST_CASE_TEMPLATE(nullBind, Str, StringTypes)
{
auto db = DB::MockDatabase::openConnectionTo("pqmock");
@@ -413,6 +415,7 @@ struct S {
int64_t a;
int64_t b;
};
+
BOOST_STATIC_ASSERT(sizeof(S) == 16);
BOOST_AUTO_TEST_CASE(testBlobStruct)