summaryrefslogtreecommitdiff
path: root/libpqpp/pq-command.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-06-05 16:47:06 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-06-05 17:17:09 +0100
commitb9aaad1d4d8be6604c84aa11651b99ac932794af (patch)
tree907695b54295aaf3b25240c8c0cb20d56ecc14c6 /libpqpp/pq-command.cpp
parentFix memory leak in unit test (diff)
downloadlibdbpp-postgresql-b9aaad1d4d8be6604c84aa11651b99ac932794af.tar.bz2
libdbpp-postgresql-b9aaad1d4d8be6604c84aa11651b99ac932794af.tar.xz
libdbpp-postgresql-b9aaad1d4d8be6604c84aa11651b99ac932794af.zip
Add support for bytea / blob type data
Diffstat (limited to 'libpqpp/pq-command.cpp')
-rw-r--r--libpqpp/pq-command.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/libpqpp/pq-command.cpp b/libpqpp/pq-command.cpp
index f31d78a..5476393 100644
--- a/libpqpp/pq-command.cpp
+++ b/libpqpp/pq-command.cpp
@@ -23,7 +23,7 @@ PQ::Command::~Command()
if (bufs[i]) {
delete bufs[i];
}
- else {
+ else if (formats[i] == 0) {
free(values[i]);
}
}
@@ -75,6 +75,7 @@ PQ::Command::paramsAtLeast(unsigned int n)
if (values.size() <= n) {
values.resize(n + 1, NULL);
lengths.resize(n + 1, 0);
+ formats.resize(n + 1, 0);
bufs.resize(n + 1, NULL);
}
else {
@@ -82,10 +83,11 @@ PQ::Command::paramsAtLeast(unsigned int n)
delete bufs[n];
bufs[n] = nullptr;
}
- else {
+ else if (formats[n] == 0) {
free(values[n]);
}
values[n] = NULL;
+ formats[n] = 0;
}
}
@@ -95,15 +97,12 @@ PQ::Command::paramSet(unsigned int n, const char * fmt, const T & ... v)
{
paramsAtLeast(n);
lengths[n] = asprintf(&values[n], fmt, v...);
- delete bufs[n];
- bufs[n] = nullptr;
}
void
PQ::Command::paramSet(unsigned int n, const std::string & b)
{
paramsAtLeast(n);
- delete bufs[n];
bufs[n] = new std::string(b);
lengths[n] = b.length();
values[n] = const_cast<char *>(bufs[n]->data());
@@ -170,6 +169,16 @@ PQ::Command::bindParamT(unsigned int n, const boost::posix_time::ptime & v)
paramSet(n, boost::posix_time::to_iso_extended_string(v));
}
void
+PQ::Command::bindParamBLOB(unsigned int n, const DB::Blob & v)
+{
+ paramsAtLeast(n);
+ lengths[n] = v.len;
+ formats[n] = 1;
+ values[n] = reinterpret_cast<char *>(const_cast<void *>(v.data));
+ delete bufs[n];
+ bufs[n] = nullptr;
+}
+void
PQ::Command::bindNull(unsigned int n)
{
paramsAtLeast(n);