diff options
author | randomdan <randomdan@localhost> | 2012-03-20 01:24:43 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2012-03-20 01:24:43 +0000 |
commit | 27603486be2576b1b1311d85719d109ed59cd224 (patch) | |
tree | 4b097d215d7b7e12661659226d4c48216e63de37 /libpqpp/connection.cpp | |
parent | Fix double free on cursor error (diff) | |
download | libdbpp-postgresql-27603486be2576b1b1311d85719d109ed59cd224.tar.bz2 libdbpp-postgresql-27603486be2576b1b1311d85719d109ed59cd224.tar.xz libdbpp-postgresql-27603486be2576b1b1311d85719d109ed59cd224.zip |
A stream interface, an RDBMS bulk load interface, a decompression layer, an implementation of CURL streams and a sqlbulkload task.
Diffstat (limited to 'libpqpp/connection.cpp')
-rw-r--r-- | libpqpp/connection.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libpqpp/connection.cpp b/libpqpp/connection.cpp index 8bfc2ff..d07b9d2 100644 --- a/libpqpp/connection.cpp +++ b/libpqpp/connection.cpp @@ -130,3 +130,41 @@ PQ::Connection::checkResultFree(PGresult * res, int expected, int alt) const PQclear(res); } +void +PQ::Connection::beginBulkUpload(const char * table, const char * extra) const +{ + char buf[BUFSIZ]; + snprintf(buf, BUFSIZ, "COPY %s FROM STDIN %s", table, extra); + checkResultFree(PQexec(conn, buf), PGRES_COPY_IN); +} + +void +PQ::Connection::endBulkUpload(const char * msg) const +{ + 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(PQerrorMessage(conn)); + } +} + +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(PQerrorMessage(conn)); + } +} + |