diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-12-10 19:20:10 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-12-10 19:20:10 +0000 |
commit | 3eccf84ccf887fb75d9a8305de74414df5115db1 (patch) | |
tree | 36638376172fc727ebb3e675510a0cca51f214a1 /libpqpp | |
parent | Move suppression comment (diff) | |
download | libdbpp-postgresql-3eccf84ccf887fb75d9a8305de74414df5115db1.tar.bz2 libdbpp-postgresql-3eccf84ccf887fb75d9a8305de74414df5115db1.tar.xz libdbpp-postgresql-3eccf84ccf887fb75d9a8305de74414df5115db1.zip |
Loop based bulkUpload functions
not recursive.
Diffstat (limited to 'libpqpp')
-rw-r--r-- | libpqpp/pq-connection.cpp | 32 |
1 files changed, 14 insertions, 18 deletions
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()"); |