From 3526af7ec50e46aaa73d038566f42554f70f27b0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 4 Aug 2025 19:48:20 +0100 Subject: Fix a lot of clang-tidy warnings --- libpqpp/pq-connection.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'libpqpp/pq-connection.cpp') 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(conn, &PQfinish); - throw ConnectionError(dc.get()); + auto connDeleter = std::unique_ptr(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(len)))) { + int result = 0; + while (!(result = PQputCopyData(conn, data, static_cast(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(std::hash()(selectLastVal)); +namespace { + const std::string SELECT_LAST_VAL("SELECT lastval()"); + const DB::CommandOptionsCPtr SELECT_LAST_VAL_OPTS + = std::make_shared(std::hash()(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 -- cgit v1.2.3