From b9aaad1d4d8be6604c84aa11651b99ac932794af Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 5 Jun 2017 16:47:06 +0100 Subject: Add support for bytea / blob type data --- libpqpp/pq-command.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'libpqpp/pq-command.cpp') 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(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(const_cast(v.data)); + delete bufs[n]; + bufs[n] = nullptr; +} +void PQ::Command::bindNull(unsigned int n) { paramsAtLeast(n); -- cgit v1.2.3