From 3eccf84ccf887fb75d9a8305de74414df5115db1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 10 Dec 2020 19:20:10 +0000 Subject: Loop based bulkUpload functions not recursive. --- libpqpp/pq-connection.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'libpqpp') diff --git a/libpqpp/pq-connection.cpp b/libpqpp/pq-connection.cpp index d2c02b2..46e1917 100644 --- a/libpqpp/pq-connection.cpp +++ b/libpqpp/pq-connection.cpp @@ -147,31 +147,27 @@ PQ::Connection::beginBulkUpload(const char * table, const char * extra) void PQ::Connection::endBulkUpload(const char * msg) { - switch (PQputCopyEnd(conn, msg)) { - case 0: // block - sleep(1); - endBulkUpload(msg); - return; - case 1: // success - checkResultFree(PQgetResult(conn), PGRES_COMMAND_OK); - return; - default: // -1 is error - throw Error(conn); + int rc; + while (!(rc = PQputCopyEnd(conn, msg))) { + sleep(1); } + if (rc != 1) { + throw Error(conn); + } + checkResultFree(PQgetResult(conn), PGRES_COMMAND_OK); } size_t PQ::Connection::bulkUploadData(const char * data, size_t len) const { - switch (PQputCopyData(conn, data, len)) { - case 0: // block - sleep(1); - return bulkUploadData(data, len); - case 1: // success - return len; - default: // -1 is error - throw Error(conn); + int rc; + while (!(rc = PQputCopyData(conn, data, len))) { + sleep(1); + } + if (rc != 1) { + throw Error(conn); } + return len; } static const std::string selectLastVal("SELECT lastval()"); -- cgit v1.2.3