summaryrefslogtreecommitdiff
path: root/libpqpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2020-12-10 19:20:10 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2020-12-10 19:20:10 +0000
commit3eccf84ccf887fb75d9a8305de74414df5115db1 (patch)
tree36638376172fc727ebb3e675510a0cca51f214a1 /libpqpp
parentMove suppression comment (diff)
downloadlibdbpp-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.cpp32
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()");