diff options
-rw-r--r-- | libpqpp/pq-binarycolumn.cpp | 26 | ||||
-rw-r--r-- | libpqpp/pq-bulkselectcommand.cpp | 9 | ||||
-rw-r--r-- | libpqpp/pq-column.cpp | 26 | ||||
-rw-r--r-- | libpqpp/pq-command.cpp | 90 | ||||
-rw-r--r-- | libpqpp/pq-command.h | 27 | ||||
-rw-r--r-- | libpqpp/pq-connection.cpp | 38 | ||||
-rw-r--r-- | libpqpp/pq-cursorselectcommand.cpp | 26 | ||||
-rw-r--r-- | libpqpp/pq-cursorselectcommand.h | 6 | ||||
-rw-r--r-- | libpqpp/pq-mock.cpp | 27 | ||||
-rw-r--r-- | libpqpp/pq-mock.h | 2 | ||||
-rw-r--r-- | libpqpp/pq-prepared.cpp | 9 | ||||
-rw-r--r-- | libpqpp/pq-selectbase.cpp | 8 | ||||
-rw-r--r-- | libpqpp/unittests/testpq.cpp | 4 |
13 files changed, 144 insertions, 154 deletions
diff --git a/libpqpp/pq-binarycolumn.cpp b/libpqpp/pq-binarycolumn.cpp index 761bf0b..4c7de22 100644 --- a/libpqpp/pq-binarycolumn.cpp +++ b/libpqpp/pq-binarycolumn.cpp @@ -8,25 +8,25 @@ #include <error.h> #include <server/catalog/pg_type_d.h> -PQ::BinaryColumn::BinaryColumn(const PQ::SelectBase * s, unsigned int f) : PQ::Column(s, f) { } +PQ::BinaryColumn::BinaryColumn(const PQ::SelectBase * select, unsigned int field) : PQ::Column(select, field) { } template<std::integral T> inline T PQ::BinaryColumn::valueAs() const { - T v {}; - std::memcpy(&v, value(), sizeof(T)); + T outValue {}; + std::memcpy(&outValue, value(), sizeof(T)); if constexpr (std::endian::native != std::endian::big && sizeof(T) > 1) { - return std::byteswap(v); + return std::byteswap(outValue); } - return v; + return outValue; } void -PQ::BinaryColumn::apply(DB::HandleField & h) const +PQ::BinaryColumn::apply(DB::HandleField & handler) const { if (isNull()) { - h.null(); + handler.null(); return; } switch (oid) { @@ -34,22 +34,22 @@ PQ::BinaryColumn::apply(DB::HandleField & h) const case VARCHAROID: case TEXTOID: case XMLOID: - h.string({value(), length()}); + handler.string({value(), length()}); break; case BOOLOID: - h.boolean(valueAs<bool>()); + handler.boolean(valueAs<bool>()); break; case INT2OID: - h.integer(valueAs<int16_t>()); + handler.integer(valueAs<int16_t>()); break; case INT4OID: - h.integer(valueAs<int32_t>()); + handler.integer(valueAs<int32_t>()); break; case INT8OID: - h.integer(valueAs<int64_t>()); + handler.integer(valueAs<int64_t>()); break; case BYTEAOID: - h.blob(DB::Blob(value(), length())); + handler.blob(DB::Blob(value(), length())); break; default: throw DB::ColumnTypeNotSupported(); diff --git a/libpqpp/pq-bulkselectcommand.cpp b/libpqpp/pq-bulkselectcommand.cpp index 303ed53..4fbb393 100644 --- a/libpqpp/pq-bulkselectcommand.cpp +++ b/libpqpp/pq-bulkselectcommand.cpp @@ -9,8 +9,7 @@ PQ::BulkSelectCommand::BulkSelectCommand(Connection * conn, const std::string & sql, const PQ::CommandOptionsCPtr & pqco, const DB::CommandOptionsCPtr & opts) : - DB::Command(sql), - PQ::SelectBase(sql, pqco), PQ::PreparedStatement(conn, sql, opts) + DB::Command(sql), PQ::SelectBase(sql, pqco), PQ::PreparedStatement(conn, sql, opts) { } @@ -34,8 +33,6 @@ PQ::BulkSelectCommand::fetch() if (++tuple < nTuples) { return true; } - else { - execRes.reset(); - return false; - } + execRes.reset(); + return false; } diff --git a/libpqpp/pq-column.cpp b/libpqpp/pq-column.cpp index e495f2a..6c1c4eb 100644 --- a/libpqpp/pq-column.cpp +++ b/libpqpp/pq-column.cpp @@ -11,8 +11,8 @@ #include <libpq-fe.h> #include <server/catalog/pg_type_d.h> -PQ::Column::Column(const SelectBase * s, unsigned int i) : - DB::Column(PQfname(s->execRes.get(), static_cast<int>(i)), i), sc(s), +PQ::Column::Column(const SelectBase * select, unsigned int field) : + DB::Column(PQfname(select->execRes.get(), static_cast<int>(field)), field), sc(select), oid(PQftype(sc->execRes.get(), static_cast<int>(colNo))) { } @@ -37,10 +37,10 @@ PQ::Column::value() const } void -PQ::Column::apply(DB::HandleField & h) const +PQ::Column::apply(DB::HandleField & handler) const { if (isNull()) { - h.null(); + handler.null(); return; } switch (oid) { @@ -49,20 +49,20 @@ PQ::Column::apply(DB::HandleField & h) const case TEXTOID: case XMLOID: default: - h.string({value(), length()}); + handler.string({value(), length()}); break; case BOOLOID: - h.boolean(*value() == 't'); + handler.boolean(*value() == 't'); break; case INT2OID: case INT4OID: case INT8OID: - h.integer(atol(value())); + handler.integer(atol(value())); break; case NUMERICOID: case FLOAT4OID: case FLOAT8OID: - h.floatingpoint(atof(value())); + handler.floatingpoint(atof(value())); break; case TIMEOID: case INTERVALOID: { @@ -72,22 +72,22 @@ PQ::Column::apply(DB::HandleField & h) const if (sscanf(val, "%d %*[days] %d:%d:%d.%n%d%n", &days, &hours, &minutes, &seconds, &flen1, &fractions, &flen2) >= 4) { - h.interval(boost::posix_time::time_duration((24 * days) + hours, minutes, seconds, + handler.interval(boost::posix_time::time_duration((24 * days) + hours, minutes, seconds, fractions * static_cast<long>(pow(10, boost::posix_time::time_res_traits::num_fractional_digits() + flen1 - flen2)))); } else { - h.interval(boost::posix_time::duration_from_string(val)); + handler.interval(boost::posix_time::duration_from_string(val)); } break; } case DATEOID: - h.timestamp(boost::posix_time::ptime(boost::gregorian::from_string(value()))); + handler.timestamp(boost::posix_time::ptime(boost::gregorian::from_string(value()))); break; case TIMESTAMPOID: case TIMESTAMPTZOID: - h.timestamp(boost::posix_time::time_from_string(value())); + handler.timestamp(boost::posix_time::time_from_string(value())); break; case BYTEAOID: if (sc->tuple != buffer.row || !buffer.data) { @@ -95,7 +95,7 @@ PQ::Column::apply(DB::HandleField & h) const PQunescapeBytea(reinterpret_cast<const unsigned char *>(value()), &buffer.length)}; buffer.row = sc->tuple; } - h.blob(DB::Blob(buffer.data.get(), buffer.length)); + handler.blob(DB::Blob(buffer.data.get(), buffer.length)); break; } } diff --git a/libpqpp/pq-command.cpp b/libpqpp/pq-command.cpp index 3e359c0..550520c 100644 --- a/libpqpp/pq-command.cpp +++ b/libpqpp/pq-command.cpp @@ -24,13 +24,13 @@ PQ::Command::Command(Connection * conn, const std::string & sql, const DB::Comma } PQ::CommandOptions::CommandOptions(std::size_t hash, const DB::CommandOptionsMap & map) : - DB::CommandOptions(hash), fetchTuples(get(map, "page-size", 35U)), useCursor(!isSet(map, "no-cursor")), - fetchBinary(isSet(map, "fetch-binary")) + DB::CommandOptions(hash), fetchTuples(get(map, "page-size", DEFAULT_FETCH_TUPLES)), + useCursor(!isSet(map, "no-cursor")), fetchBinary(isSet(map, "fetch-binary")) { } -PQ::CommandOptions::CommandOptions(std::size_t hash, unsigned int ft, bool uc, bool fb) : - DB::CommandOptions(hash), fetchTuples(ft), useCursor(uc), fetchBinary(fb) +PQ::CommandOptions::CommandOptions(std::size_t hash, unsigned int fetchTuples, bool useCursor, bool fetchBinary) : + DB::CommandOptions(hash), fetchTuples(fetchTuples), useCursor(useCursor), fetchBinary(fetchBinary) { } @@ -43,18 +43,18 @@ PQ::Command::prepareSql(std::stringstream & psql, const std::string & sql) const psql << sql; return; } - int p = 1; + int paramNo = 1; bool inquote = false; - for (const auto & i : sql) { - if (i == '?' && !inquote) { - PQCommandParamName::write(psql, p++); + for (const auto & sqlChr : sql) { + if (sqlChr == '?' && !inquote) { + PQCommandParamName::write(psql, paramNo++); } - else if (i == '\'') { + else if (sqlChr == '\'') { inquote = !inquote; - psql << i; + psql << sqlChr; } else { - psql << i; + psql << sqlChr; } } } @@ -74,111 +74,111 @@ AdHocFormatter(PQCommandParamFmt, "%?"); template<typename... T> void -PQ::Command::paramSet(unsigned int n, T &&... v) +PQ::Command::paramSet(unsigned int n, T &&... paramValues) { paramsAtLeast(n); // cppcheck-suppress constStatement - bufs[n] = std::make_unique<std::string>(PQCommandParamFmt::get(std::forward<T>(v)...)); + bufs[n] = std::make_unique<std::string>(PQCommandParamFmt::get(std::forward<T>(paramValues)...)); lengths[n] = static_cast<int>(bufs[n]->length()); formats[n] = 0; values[n] = bufs[n]->data(); } void -PQ::Command::paramSet(unsigned int n, const std::string_view b) +PQ::Command::paramSet(unsigned int n, const std::string_view paramValue) { paramsAtLeast(n); - bufs[n] = std::make_unique<std::string>(b); - lengths[n] = static_cast<int>(b.length()); + bufs[n] = std::make_unique<std::string>(paramValue); + lengths[n] = static_cast<int>(paramValue.length()); formats[n] = 0; values[n] = bufs[n]->data(); } void -PQ::Command::bindParamI(unsigned int n, int v) +PQ::Command::bindParamI(unsigned int n, int paramValue) { - paramSet(n, v); + paramSet(n, paramValue); } void -PQ::Command::bindParamI(unsigned int n, long int v) +PQ::Command::bindParamI(unsigned int n, long int paramValue) { - paramSet(n, v); + paramSet(n, paramValue); } void -PQ::Command::bindParamI(unsigned int n, long long int v) +PQ::Command::bindParamI(unsigned int n, long long int paramValue) { - paramSet(n, v); + paramSet(n, paramValue); } void -PQ::Command::bindParamI(unsigned int n, unsigned int v) +PQ::Command::bindParamI(unsigned int n, unsigned int paramValue) { - paramSet(n, v); + paramSet(n, paramValue); } void -PQ::Command::bindParamI(unsigned int n, long unsigned int v) +PQ::Command::bindParamI(unsigned int n, long unsigned int paramValue) { - paramSet(n, v); + paramSet(n, paramValue); } void -PQ::Command::bindParamI(unsigned int n, long long unsigned int v) +PQ::Command::bindParamI(unsigned int n, long long unsigned int paramValue) { - paramSet(n, v); + paramSet(n, paramValue); } void -PQ::Command::bindParamB(unsigned int n, bool v) +PQ::Command::bindParamB(unsigned int n, bool paramValue) { - paramSet(n, v); + paramSet(n, paramValue); } void -PQ::Command::bindParamF(unsigned int n, double v) +PQ::Command::bindParamF(unsigned int n, double paramValue) { - paramSet(n, v); + paramSet(n, paramValue); } void -PQ::Command::bindParamF(unsigned int n, float v) +PQ::Command::bindParamF(unsigned int n, float paramValue) { - paramSet(n, v); + paramSet(n, paramValue); } void -PQ::Command::bindParamS(unsigned int n, const Glib::ustring & s) +PQ::Command::bindParamS(unsigned int n, const Glib::ustring & paramValue) { - paramSet(n, std::string_view(s.data(), s.bytes())); + paramSet(n, std::string_view(paramValue.data(), paramValue.bytes())); } void -PQ::Command::bindParamS(unsigned int n, const std::string_view s) +PQ::Command::bindParamS(unsigned int n, const std::string_view paramValue) { - paramSet(n, s); + paramSet(n, paramValue); } void -PQ::Command::bindParamT(unsigned int n, const boost::posix_time::time_duration v) +PQ::Command::bindParamT(unsigned int n, const boost::posix_time::time_duration paramValue) { - paramSet(n, boost::posix_time::to_simple_string(v)); + paramSet(n, boost::posix_time::to_simple_string(paramValue)); } void -PQ::Command::bindParamT(unsigned int n, const boost::posix_time::ptime v) +PQ::Command::bindParamT(unsigned int n, const boost::posix_time::ptime paramValue) { - paramSet(n, boost::posix_time::to_iso_extended_string(v)); + paramSet(n, boost::posix_time::to_iso_extended_string(paramValue)); } void -PQ::Command::bindParamBLOB(unsigned int n, const DB::Blob & v) +PQ::Command::bindParamBLOB(unsigned int n, const DB::Blob & paramValue) { paramsAtLeast(n); - lengths[n] = static_cast<int>(v.len); + lengths[n] = static_cast<int>(paramValue.len); formats[n] = 1; - values[n] = static_cast<const char *>(v.data); + values[n] = static_cast<const char *>(paramValue.data); bufs[n].reset(); } diff --git a/libpqpp/pq-command.h b/libpqpp/pq-command.h index 565bcfb..cfc7ed5 100644 --- a/libpqpp/pq-command.h +++ b/libpqpp/pq-command.h @@ -1,35 +1,30 @@ #pragma once #include "command.h" -#include "pq-connection.h" -#include <memory> -#include <vector> -#include <visibility.h> -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#ifndef __clang__ -# pragma GCC diagnostic ignored "-Wuseless-cast" -#endif -#include <glibmm/ustring.h> -#pragma GCC diagnostic pop #include "command_fwd.h" +#include "pq-connection.h" #include <boost/date_time/posix_time/posix_time.hpp> #include <cstddef> +#include <glibmm/ustring.h> #include <iosfwd> +#include <memory> #include <string> #include <string_view> +#include <vector> +#include <visibility.h> namespace DB { class Blob; } namespace PQ { + constexpr unsigned int DEFAULT_FETCH_TUPLES = 35; + class DLL_PUBLIC CommandOptions : public DB::CommandOptions { public: CommandOptions(std::size_t, const DB::CommandOptionsMap &); - explicit CommandOptions( - std::size_t hash, unsigned int fetchTuples = 35, bool useCursor = true, bool fetchBinary = false); + explicit CommandOptions(std::size_t hash, unsigned int fetchTuples = DEFAULT_FETCH_TUPLES, + bool useCursor = true, bool fetchBinary = false); unsigned int fetchTuples; bool useCursor; @@ -72,8 +67,8 @@ namespace PQ { Connection * const c; void paramsAtLeast(unsigned int); - template<typename... T> void paramSet(unsigned int, T &&... t); - void paramSet(unsigned int, const std::string_view); + template<typename... T> void paramSet(unsigned int, T &&...); + void paramSet(unsigned int, std::string_view); std::vector<const char *> values; std::vector<int> lengths; std::vector<int> formats; diff --git a/libpqpp/pq-connection.cpp b/libpqpp/pq-connection.cpp index 5c50b7c..13bc42e 100644 --- a/libpqpp/pq-connection.cpp +++ b/libpqpp/pq-connection.cpp @@ -41,8 +41,8 @@ PQ::ConnectionError::ConnectionError(const PGconn * conn) : PQ::Error(conn) { } PQ::Connection::Connection(const std::string & info) : conn(PQconnectdb(info.c_str())) { if (PQstatus(conn) != CONNECTION_OK) { - auto dc = std::unique_ptr<PGconn, decltype(&PQfinish)>(conn, &PQfinish); - throw ConnectionError(dc.get()); + auto connDeleter = std::unique_ptr<PGconn, decltype(&PQfinish)>(conn, &PQfinish); + throw ConnectionError(conn); } PQsetNoticeProcessor(conn, noNoticeProcessor, nullptr); } @@ -91,10 +91,8 @@ PQ::Connection::bulkUpdateStyle() const void PQ::Connection::ping() const { - struct pollfd fd { - // NOLINTNEXTLINE(hicpp-signed-bitwise) - PQsocket(conn), POLLRDHUP | POLLERR | POLLHUP | POLLNVAL, 0 - }; + struct pollfd fd {// NOLINTNEXTLINE(hicpp-signed-bitwise) + PQsocket(conn), POLLRDHUP | POLLERR | POLLHUP | POLLNVAL, 0}; if (PQstatus(conn) != CONNECTION_OK || poll(&fd, 1, 0)) { if (inTx()) { @@ -149,11 +147,11 @@ PQ::Connection::beginBulkUpload(const char * table, const char * extra) void PQ::Connection::endBulkUpload(const char * msg) { - int rc; - while (!(rc = PQputCopyEnd(conn, msg))) { + int result = 0; + while (!(result = PQputCopyEnd(conn, msg))) { sleep(1); } - if (rc != 1) { + if (result != 1) { throw Error(conn); } checkResult(PQgetResult(conn), PGRES_COMMAND_OK); @@ -162,29 +160,31 @@ PQ::Connection::endBulkUpload(const char * msg) size_t PQ::Connection::bulkUploadData(const char * data, size_t len) const { - int rc; - while (!(rc = PQputCopyData(conn, data, static_cast<int>(len)))) { + int result = 0; + while (!(result = PQputCopyData(conn, data, static_cast<int>(len)))) { sleep(1); } - if (rc != 1) { + if (result != 1) { throw Error(conn); } return len; } -static const std::string selectLastVal("SELECT lastval()"); -static const DB::CommandOptionsCPtr selectLastValOpts - = std::make_shared<DB::CommandOptions>(std::hash<std::string>()(selectLastVal)); +namespace { + const std::string SELECT_LAST_VAL("SELECT lastval()"); + const DB::CommandOptionsCPtr SELECT_LAST_VAL_OPTS + = std::make_shared<DB::CommandOptions>(std::hash<std::string>()(SELECT_LAST_VAL)); +} int64_t PQ::Connection::insertId() { - BulkSelectCommand getId(this, selectLastVal, nullptr, selectLastValOpts); - int64_t id = -1; + BulkSelectCommand getId(this, SELECT_LAST_VAL, nullptr, SELECT_LAST_VAL_OPTS); + int64_t insertId = -1; while (getId.fetch()) { - getId[0] >> id; + getId[0] >> insertId; } - return id; + return insertId; } int diff --git a/libpqpp/pq-cursorselectcommand.cpp b/libpqpp/pq-cursorselectcommand.cpp index bfb69d4..cd20cf8 100644 --- a/libpqpp/pq-cursorselectcommand.cpp +++ b/libpqpp/pq-cursorselectcommand.cpp @@ -15,16 +15,16 @@ AdHocFormatter(PQCursorSelectClose, "CLOSE %?"); PQ::CursorSelectCommand::CursorSelectCommand(Connection * conn, const std::string & sql, const PQ::CommandOptionsCPtr & pqco, const DB::CommandOptionsCPtr & opts) : - DB::Command(sql), - PQ::SelectBase(sql, pqco), PQ::Command(conn, sql, opts), executed(false), fTuples(pqco ? pqco->fetchTuples : 35), - s_fetch(PQCursorSelectFetch::get(fTuples, stmntName)), s_close(PQCursorSelectClose::get(stmntName)) + DB::Command(sql), PQ::SelectBase(sql, pqco), PQ::Command(conn, sql, opts), executed(false), + fTuples(pqco ? pqco->fetchTuples : DEFAULT_FETCH_TUPLES), sFetch(PQCursorSelectFetch::get(fTuples, stmntName)), + sClose(PQCursorSelectClose::get(stmntName)) { } PQ::CursorSelectCommand::~CursorSelectCommand() { if (executed && PQtransactionStatus(c->conn) != PQTRANS_INERROR) { - c->checkResult(PQexec(c->conn, s_close.c_str()), PGRES_COMMAND_OK); + c->checkResult(PQexec(c->conn, sClose.c_str()), PGRES_COMMAND_OK); } } @@ -41,10 +41,10 @@ void PQ::CursorSelectCommand::execute() { if (!executed) { - if (s_declare.empty()) { - s_declare = mkdeclare(); + if (sDeclare.empty()) { + sDeclare = mkdeclare(); } - c->checkResult(PQexecParams(c->conn, s_declare.c_str(), static_cast<int>(values.size()), nullptr, values.data(), + c->checkResult(PQexecParams(c->conn, sDeclare.c_str(), static_cast<int>(values.size()), nullptr, values.data(), lengths.data(), formats.data(), binary), PGRES_COMMAND_OK); fetchTuples(); @@ -57,7 +57,7 @@ void PQ::CursorSelectCommand::fetchTuples() { execRes = c->checkResult( - PQexecParams(c->conn, s_fetch.c_str(), 0, nullptr, nullptr, nullptr, nullptr, binary), PGRES_TUPLES_OK); + PQexecParams(c->conn, sFetch.c_str(), 0, nullptr, nullptr, nullptr, nullptr, binary), PGRES_TUPLES_OK); nTuples = static_cast<decltype(nTuples)>(PQntuples(execRes.get())); tuple = static_cast<decltype(tuple)>(-1); } @@ -74,10 +74,8 @@ PQ::CursorSelectCommand::fetch() if (++tuple < nTuples) { return true; } - else { - PQclear(PQexec(c->conn, s_close.c_str())); - execRes.reset(); - executed = false; - return false; - } + PQclear(PQexec(c->conn, sClose.c_str())); + execRes.reset(); + executed = false; + return false; } diff --git a/libpqpp/pq-cursorselectcommand.h b/libpqpp/pq-cursorselectcommand.h index 23798cd..4fcf748 100644 --- a/libpqpp/pq-cursorselectcommand.h +++ b/libpqpp/pq-cursorselectcommand.h @@ -25,8 +25,8 @@ namespace PQ { mutable bool executed; unsigned int fTuples; - std::string s_declare; - std::string s_fetch; - std::string s_close; + std::string sDeclare; + std::string sFetch; + std::string sClose; }; } diff --git a/libpqpp/pq-mock.cpp b/libpqpp/pq-mock.cpp index e7faf32..f80c4fd 100644 --- a/libpqpp/pq-mock.cpp +++ b/libpqpp/pq-mock.cpp @@ -14,14 +14,15 @@ NAMEDFACTORY("postgresql", PQ::Mock, DB::MockDatabaseFactory) namespace PQ { - Mock::Mock(const std::string & masterdb, const std::string & name, const std::vector<std::filesystem::path> & ss) : + Mock::Mock( + const std::string & masterdb, const std::string & name, const std::vector<std::filesystem::path> & setup) : MockServerDatabase(masterdb, name, "postgresql"), tablespacePath(std::filesystem::temp_directory_path() / testDbName), serverVersion(std::static_pointer_cast<Connection>(master)->serverVersion()) { try { CreateNewDatabase(); - PlaySchemaScripts(ss); + PlaySchemaScripts(setup); SetTablesToUnlogged(); } catch (...) { @@ -46,7 +47,7 @@ namespace PQ { if (!hasUnloggedTables()) { return; } - auto s = master->select(R"SQL( + auto tables = master->select(R"SQL( SELECT n.nspname, c.relname FROM pg_class c, pg_namespace n WHERE c.relkind = 'r' @@ -61,15 +62,15 @@ AND NOT EXISTS ( AND ck.relpersistence = 'p') AND n.oid = c.relnamespace ORDER BY 1, 2)SQL"); - s->bindParamS(0, "pg_catalog"); - s->bindParamS(1, "information_schema"); - while ([&s, this]() { - unsigned int n = 0; - for (const auto [nspname, relname] : s->as<std::string, std::string>()) { + tables->bindParamS(0, "pg_catalog"); + tables->bindParamS(1, "information_schema"); + while ([&tables, this]() { + unsigned int tableCount = 0; + for (const auto [nspname, relname] : tables->as<std::string, std::string>()) { master->execute(MockSetUnlogged::get(nspname, relname)); - n += 1; + tableCount += 1; } - return n; + return tableCount; }()) { ; } @@ -117,10 +118,10 @@ ORDER BY 1, 2)SQL"); void Mock::DropDatabase() const { - auto t = master->modify( + auto terminate = master->modify( "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE LOWER(datname) = LOWER(?)"); - t->bindParamS(0, testDbName); - t->execute(); + terminate->bindParamS(0, testDbName); + terminate->execute(); MockServerDatabase::DropDatabase(); if (hasCopyToProgram()) { master->execute(MockDropTablespace::get(testDbName)); diff --git a/libpqpp/pq-mock.h b/libpqpp/pq-mock.h index 8785e45..f36128e 100644 --- a/libpqpp/pq-mock.h +++ b/libpqpp/pq-mock.h @@ -11,7 +11,7 @@ namespace PQ { class DLL_PUBLIC Mock : public DB::MockServerDatabase { public: - Mock(const std::string & master, const std::string & name, const std::vector<std::filesystem::path> & ss); + Mock(const std::string & master, const std::string & name, const std::vector<std::filesystem::path> & setup); ~Mock() override; SPECIAL_MEMBERS_MOVE_RO(Mock); diff --git a/libpqpp/pq-prepared.cpp b/libpqpp/pq-prepared.cpp index 8678c11..defcee1 100644 --- a/libpqpp/pq-prepared.cpp +++ b/libpqpp/pq-prepared.cpp @@ -9,8 +9,8 @@ #include <utility> #include <vector> -PQ::PreparedStatement::PreparedStatement(Connection * c, const std::string & sql, const DB::CommandOptionsCPtr & opts) : - DB::Command(sql), Command(c, sql, opts), pstmt(nullptr) +PQ::PreparedStatement::PreparedStatement(Connection * conn, const std::string & sql, + const DB::CommandOptionsCPtr & opts) : DB::Command(sql), Command(conn, sql, opts), pstmt(nullptr) { } @@ -20,9 +20,8 @@ PQ::PreparedStatement::prepare() const if (pstmt) { return pstmt; } - auto i = c->preparedStatements.find(hash); - if (i != c->preparedStatements.end()) { - return (pstmt = i->second.c_str()); + if (auto existingItr = c->preparedStatements.find(hash); existingItr != c->preparedStatements.end()) { + return (pstmt = existingItr->second.c_str()); } std::stringstream psql; prepareSql(psql, sql); diff --git a/libpqpp/pq-selectbase.cpp b/libpqpp/pq-selectbase.cpp index 00abdb9..03301e3 100644 --- a/libpqpp/pq-selectbase.cpp +++ b/libpqpp/pq-selectbase.cpp @@ -5,6 +5,7 @@ #include "pq-command.h" #include <libpq-fe.h> #include <memory> +#include <ranges> #include <selectcommand.h> #include <string> @@ -16,13 +17,12 @@ PQ::SelectBase::SelectBase(const std::string & sql, const PQ::CommandOptionsCPtr void PQ::SelectBase::createColumns() { - auto nFields = PQnfields(execRes.get()); - for (decltype(nFields) f = 0; f < nFields; f += 1) { + for (int field : std::views::iota(0, PQnfields(execRes.get()))) { if (binary) { - insertColumn(std::make_unique<BinaryColumn>(this, f)); + insertColumn(std::make_unique<BinaryColumn>(this, field)); } else { - insertColumn(std::make_unique<Column>(this, f)); + insertColumn(std::make_unique<Column>(this, field)); } } } diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp index d610e41..1307792 100644 --- a/libpqpp/unittests/testpq.cpp +++ b/libpqpp/unittests/testpq.cpp @@ -489,7 +489,7 @@ BOOST_AUTO_TEST_CASE(bulkPerfTest) int64_t tot = 0; for (const auto & [a, b, c, d, e, f] : sel->as<int64_t, double, std::string_view, boost::posix_time::time_duration, - boost::posix_time::ptime, bool>()) { + boost::posix_time::ptime, bool>()) { tot += a + static_cast<int64_t>(b) + static_cast<int64_t>(c.length()) + d.hours() + e.time_of_day().hours() + f; } BOOST_REQUIRE_EQUAL(tot, 1013265); @@ -509,7 +509,7 @@ BOOST_AUTO_TEST_CASE(connfail) } } -BOOST_AUTO_TEST_CASE(ssl) +BOOST_AUTO_TEST_CASE(ssl, *boost::unit_test::disabled()) { auto conn = DB::ConnectionFactory::createNew( "postgresql", "host=randomdan.homeip.net user=gentoo dbname=postgres sslmode=require"); |