diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-08-04 18:14:09 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-08-04 18:14:09 +0100 |
commit | 937272bd0a7e057ca2208286339894c365282de7 (patch) | |
tree | 8015157daeca83a229a2c023256b1404c4ac9abc | |
parent | Update to glibmm-2.68 (diff) | |
download | libdbpp-937272bd0a7e057ca2208286339894c365282de7.tar.bz2 libdbpp-937272bd0a7e057ca2208286339894c365282de7.tar.xz libdbpp-937272bd0a7e057ca2208286339894c365282de7.zip |
Big tidy up!
-rw-r--r-- | libdbpp/column.cpp | 12 | ||||
-rw-r--r-- | libdbpp/column.h | 4 | ||||
-rw-r--r-- | libdbpp/command.cpp | 1 | ||||
-rw-r--r-- | libdbpp/command.h | 2 | ||||
-rw-r--r-- | libdbpp/connection.cpp | 2 | ||||
-rw-r--r-- | libdbpp/connectionPool.h | 1 | ||||
-rw-r--r-- | libdbpp/createMockDb.cpp | 19 | ||||
-rw-r--r-- | libdbpp/error.h | 1 | ||||
-rw-r--r-- | libdbpp/selectcommand.cpp | 1 | ||||
-rw-r--r-- | libdbpp/selectcommandUtil.impl.h | 1 | ||||
-rw-r--r-- | libdbpp/tablepatch.cpp | 185 | ||||
-rw-r--r-- | libdbpp/unittests/testUtils.cpp | 12 |
12 files changed, 116 insertions, 125 deletions
diff --git a/libdbpp/column.cpp b/libdbpp/column.cpp index 3493bc6..48049d3 100644 --- a/libdbpp/column.cpp +++ b/libdbpp/column.cpp @@ -11,11 +11,13 @@ namespace Glib { namespace DB { Column::Column(const Glib::ustring & n, unsigned int i) : colNo(i), name(n.collate_key()) { } - static std::string - demangle(const char * const mangled) - { - std::unique_ptr<char, decltype(&free)> r(abi::__cxa_demangle(mangled, nullptr, nullptr, nullptr), &free); - return &*r; + namespace { + [[nodiscard]] std::string + demangle(const char * const mangled) + { + std::unique_ptr<char, decltype(&free)> r(abi::__cxa_demangle(mangled, nullptr, nullptr, nullptr), &free); + return &*r; + } } InvalidConversion::InvalidConversion(const char * const f, const char * const t) : diff --git a/libdbpp/column.h b/libdbpp/column.h index 38958ab..faaaa02 100644 --- a/libdbpp/column.h +++ b/libdbpp/column.h @@ -69,12 +69,12 @@ namespace DB { private: template<typename X> struct is_optional { static constexpr bool value = false; - static constexpr bool is_arithmetic = std::is_arithmetic<X>::value; + static constexpr bool is_arithmetic = std::is_arithmetic_v<X>; }; template<typename X> struct is_optional<std::optional<X>> { static constexpr bool value = true; - static constexpr bool is_arithmetic = std::is_arithmetic<X>::value; + static constexpr bool is_arithmetic = std::is_arithmetic_v<X>; }; public: diff --git a/libdbpp/command.cpp b/libdbpp/command.cpp index dc7922a..7adb3c7 100644 --- a/libdbpp/command.cpp +++ b/libdbpp/command.cpp @@ -1,7 +1,6 @@ #include "command.h" #include "connection.h" #include <factory.impl.h> -#include <map> #include <utility> INSTANTIATEFACTORY(DB::CommandOptions, std::size_t, const DB::CommandOptionsMap &) diff --git a/libdbpp/command.h b/libdbpp/command.h index 6815866..517baf5 100644 --- a/libdbpp/command.h +++ b/libdbpp/command.h @@ -53,7 +53,7 @@ namespace DB { get(const CommandOptionsMap & map, const Y & key, const X & def) { if (auto i = map.find(key); i != map.end()) { - if constexpr (std::is_convertible<CommandOptionsMap::mapped_type, X>::value) { + if constexpr (std::is_convertible_v<CommandOptionsMap::mapped_type, X>) { return i->second; } else { diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp index 529b130..8d78aec 100644 --- a/libdbpp/connection.cpp +++ b/libdbpp/connection.cpp @@ -1,6 +1,6 @@ #include "connection.h" #include "error.h" -#include "modifycommand.h" +#include "modifycommand.h" // IWYU pragma: keep #include <array> #include <compileTimeFormatter.h> #include <ctime> diff --git a/libdbpp/connectionPool.h b/libdbpp/connectionPool.h index a50dd37..ab3af2b 100644 --- a/libdbpp/connectionPool.h +++ b/libdbpp/connectionPool.h @@ -4,7 +4,6 @@ #include "connection.h" #include "connection_fwd.h" // for ConnectionPtr #include "resourcePool.impl.h" // for ResourcePool<>::InUse, ResourcePool -#include <map> // for operator!= #include <memory> #include <string> #include <visibility.h> diff --git a/libdbpp/createMockDb.cpp b/libdbpp/createMockDb.cpp index 19d8623..6a30acd 100644 --- a/libdbpp/createMockDb.cpp +++ b/libdbpp/createMockDb.cpp @@ -1,7 +1,6 @@ #include "mockDatabase.h" #include <boost/lexical_cast.hpp> #include <boost/program_options.hpp> -#include <chrono> #include <csignal> #include <cstdlib> #include <exception> @@ -31,7 +30,7 @@ createFailHandler() } } catch (const std::exception & e) { - std::cerr << "Failed to create mock database\n" << e.what() << std::endl; + std::cerr << "Failed to create mock database\n" << e.what() << '\n'; } exit(1); } @@ -62,28 +61,28 @@ main(int argc, char ** argv) po::store(po::command_line_parser(argc, argv).options(opts).positional(p).run(), vm); if (vm.count("help")) { - std::cout << opts << std::endl; - return 1; + std::cout << opts << '\n'; + return EXIT_SUCCESS; } po::notify(vm); std::set_terminate(createFailHandler); std::cout << "Creating database..."; auto mock = DB::MockDatabaseFactory::createNew(connector, master, database, scripts); - std::cout << " done." << std::endl; + std::cout << " done.\n"; std::set_terminate(nullptr); // cppcheck-suppress knownConditionTrueFalse if (!drop) { - std::cout << "Done. ctrl+c to tear down and exit." << std::endl; + std::cout << "Done. ctrl+c to tear down and exit.\n"; signal(SIGINT, &emptyHandler); pause(); - std::cout << std::endl; + std::cout << '\n'; } - std::cout << "Tearing down database..." << std::endl; + std::cout << "Tearing down database...\n"; mock.reset(); - std::cout << " done." << std::endl; - return 0; + std::cout << " done.\n"; + return EXIT_SUCCESS; } diff --git a/libdbpp/error.h b/libdbpp/error.h index 329e8f4..d19943c 100644 --- a/libdbpp/error.h +++ b/libdbpp/error.h @@ -1,7 +1,6 @@ #ifndef DB_ERROR_H #define DB_ERROR_H -#include <cstdlib> #include <exception.h> #include <visibility.h> diff --git a/libdbpp/selectcommand.cpp b/libdbpp/selectcommand.cpp index a378660..03636ec 100644 --- a/libdbpp/selectcommand.cpp +++ b/libdbpp/selectcommand.cpp @@ -1,5 +1,4 @@ #include "selectcommand.h" -#include "error.h" #include <boost/multi_index/indexed_by.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/ordered_index.hpp> diff --git a/libdbpp/selectcommandUtil.impl.h b/libdbpp/selectcommandUtil.impl.h index 86a1502..d145461 100644 --- a/libdbpp/selectcommandUtil.impl.h +++ b/libdbpp/selectcommandUtil.impl.h @@ -2,7 +2,6 @@ #define DB_SELECTCOMMANDUTIL_IMPL_H #include "selectcommand.h" -#include <type_traits> /// @cond namespace DB { diff --git a/libdbpp/tablepatch.cpp b/libdbpp/tablepatch.cpp index b298e5c..6225661 100644 --- a/libdbpp/tablepatch.cpp +++ b/libdbpp/tablepatch.cpp @@ -1,6 +1,6 @@ #include "tablepatch.h" #include "connection.h" -#include "modifycommand.h" +#include "modifycommand.h" // IWYU pragma: keep #include "selectcommand.h" // IWYU pragma: keep #include "sqlWriter.h" #include <boost/format.hpp> @@ -34,59 +34,60 @@ DB::Connection::patchTable(TablePatch * tp) return r; } -template<typename Container> -static inline void -push(const boost::format &, typename Container::const_iterator &) -{ -} +namespace { + template<typename Container> + inline void + push(const boost::format &, typename Container::const_iterator &) + { + } -template<typename Container, typename Value, typename... Values> -static inline void -push(boost::format & f, typename Container::const_iterator & i, const Value & v, Values &&... vs) -{ - f % v(i); - push<Container>(f, i, std::forward<Values>(vs)...); -} + template<typename Container, typename Value, typename... Values> + inline void + push(boost::format & f, typename Container::const_iterator & i, const Value & v, Values &&... vs) + { + f % v(i); + push<Container>(f, i, std::forward<Values>(vs)...); + } -template<typename Separator, typename Container, typename... Ps> -static inline unsigned int -appendIf(AdHoc::Buffer & buf, const Container & c, - const std::function<bool(const typename Container::const_iterator)> & sel, const Separator & sep, - const std::string & fmts, Ps &&... ps) -{ - auto fmt = AdHoc::Buffer::getFormat(fmts); - unsigned int x = 0; - for (auto i = c.begin(); i != c.end(); ++i) { - if (sel(i)) { - if (x > 0) { - buf.appendbf("%s", sep); + template<typename Separator, typename Container, typename... Ps> + inline unsigned int + appendIf(AdHoc::Buffer & buf, const Container & c, + const std::function<bool(const typename Container::const_iterator)> & sel, const Separator & sep, + const std::string & fmts, Ps &&... ps) + { + auto fmt = AdHoc::Buffer::getFormat(fmts); + unsigned int x = 0; + for (auto i = c.begin(); i != c.end(); ++i) { + if (sel(i)) { + if (x > 0) { + buf.appendbf("%s", sep); + } + push<Container>(fmt, i, std::forward<Ps>(ps)...); + buf.append(fmt.str()); + x += 1; } - push<Container>(fmt, i, std::forward<Ps>(ps)...); - buf.append(fmt.str()); - x += 1; } + return x; } - return x; -} -template<typename Separator, typename Container, typename... Ps> -static inline unsigned int -append(AdHoc::Buffer & buf, const Container & c, const Separator & sep, const std::string & fmts, Ps &&... ps) -{ - return appendIf( - buf, c, - [](auto) { - return true; - }, - sep, fmts, std::forward<Ps>(ps)...); -} + template<typename Separator, typename Container, typename... Ps> + inline unsigned int + append(AdHoc::Buffer & buf, const Container & c, const Separator & sep, const std::string & fmts, Ps &&... ps) + { + return appendIf( + buf, c, + [](auto) { + return true; + }, + sep, fmts, std::forward<Ps>(ps)...); + } -template<typename Container> -static inline typename Container::key_type -self(const typename Container::const_iterator & i) -{ - return *i; -} + template<typename Container> + inline typename Container::key_type + self(const typename Container::const_iterator & i) + { + return *i; + } #define selfCols self<decltype(DB::TablePatch::cols)> #define isNotKey(tp) \ @@ -94,18 +95,53 @@ self(const typename Container::const_iterator & i) return !AdHoc::containerContains((tp)->pk, *i); \ } -static void -patchDeletesSelect(AdHoc::Buffer & toDelSql, DB::TablePatch * tp) -{ - toDelSql.append(" WHERE "); - append(toDelSql, tp->pk, " AND ", " b.%s IS NULL", selfCols); - if (tp->where) { - toDelSql.append(" AND "); - tp->where->writeSql(toDelSql); + void + patchDeletesSelect(AdHoc::Buffer & toDelSql, DB::TablePatch * tp) + { + toDelSql.append(" WHERE "); + append(toDelSql, tp->pk, " AND ", " b.%s IS NULL", selfCols); + if (tp->where) { + toDelSql.append(" AND "); + tp->where->writeSql(toDelSql); + } + if (tp->order) { + toDelSql.append(" ORDER BY "); + tp->order->writeSql(toDelSql); + } } - if (tp->order) { - toDelSql.append(" ORDER BY "); - tp->order->writeSql(toDelSql); + + void + patchUpdatesSelect(AdHoc::Buffer & updSql, DB::TablePatch * tp) + { + updSql.append(" WHERE "); + append(updSql, tp->pk, " AND ", " a.%s = b.%s ", selfCols, selfCols); + updSql.append(" AND ("); + appendIf(updSql, tp->cols, isNotKey(tp), " OR ", + " (((CASE WHEN (a.%s IS NULL AND b.%s IS NULL) THEN 1 ELSE 0 END) \ + + (CASE WHEN(a.%s = b.%s) THEN 1 ELSE 0 END)) = 0)", + selfCols, selfCols, selfCols, selfCols); + updSql.append(")"); + if (tp->where) { + updSql.append(" AND "); + tp->where->writeSql(updSql); + } + } + + void + patchInsertsSelect(AdHoc::Buffer & toInsSql, DB::TablePatch * tp) + { + toInsSql.append("SELECT "); + append(toInsSql, tp->cols, ", ", "b.%s", selfCols); + toInsSql.append(" FROM "); + tp->srcExpr->writeSql(toInsSql); + toInsSql.appendbf(" b LEFT OUTER JOIN %s a ON ", tp->dest); + append(toInsSql, tp->pk, " AND ", " a.%s = b.%s", selfCols, selfCols); + toInsSql.append(" WHERE "); + append(toInsSql, tp->pk, " AND ", " a.%s IS NULL", selfCols); + if (tp->order) { + toInsSql.append(" ORDER BY "); + tp->order->writeSql(toInsSql); + } } } @@ -200,22 +236,6 @@ DB::Connection::patchDeletes(TablePatch * tp) return del->execute(); } -static void -patchUpdatesSelect(AdHoc::Buffer & updSql, DB::TablePatch * tp) -{ - updSql.append(" WHERE "); - append(updSql, tp->pk, " AND ", " a.%s = b.%s ", selfCols, selfCols); - updSql.append(" AND ("); - appendIf(updSql, tp->cols, isNotKey(tp), " OR ", " (((CASE WHEN (a.%s IS NULL AND b.%s IS NULL) THEN 1 ELSE 0 END) \ - + (CASE WHEN(a.%s = b.%s) THEN 1 ELSE 0 END)) = 0)", - selfCols, selfCols, selfCols, selfCols); - updSql.append(")"); - if (tp->where) { - updSql.append(" AND "); - tp->where->writeSql(updSql); - } -} - unsigned int DB::Connection::patchUpdates(TablePatch * tp) { @@ -302,23 +322,6 @@ DB::Connection::patchUpdates(TablePatch * tp) return 0; } -static void -patchInsertsSelect(AdHoc::Buffer & toInsSql, DB::TablePatch * tp) -{ - toInsSql.append("SELECT "); - append(toInsSql, tp->cols, ", ", "b.%s", selfCols); - toInsSql.append(" FROM "); - tp->srcExpr->writeSql(toInsSql); - toInsSql.appendbf(" b LEFT OUTER JOIN %s a ON ", tp->dest); - append(toInsSql, tp->pk, " AND ", " a.%s = b.%s", selfCols, selfCols); - toInsSql.append(" WHERE "); - append(toInsSql, tp->pk, " AND ", " a.%s IS NULL", selfCols); - if (tp->order) { - toInsSql.append(" ORDER BY "); - tp->order->writeSql(toInsSql); - } -} - unsigned int DB::Connection::patchInserts(TablePatch * tp) { diff --git a/libdbpp/unittests/testUtils.cpp b/libdbpp/unittests/testUtils.cpp index 59ccf13..d05db3c 100644 --- a/libdbpp/unittests/testUtils.cpp +++ b/libdbpp/unittests/testUtils.cpp @@ -470,16 +470,8 @@ testExtractT(const DB::SelectCommandPtr & sel) for (const auto & row : sel->as<T>()) { testExtractT(row); } -#ifdef __clang__ - // Clang cannot compile this for reasons largely todo with ambiguousness in the spec - // Fixed when we move to std::chrono - if constexpr (!std::is_same<T, boost::posix_time::time_duration>::value) { -#else - if constexpr (true) { -#endif - for (const auto & row : sel->as<std::optional<T>>()) { - testExtractT(row); - } + for (const auto & row : sel->as<std::optional<T>>()) { + testExtractT(row); } } |