diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-06-05 16:47:06 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-06-05 17:17:09 +0100 |
commit | b9aaad1d4d8be6604c84aa11651b99ac932794af (patch) | |
tree | 907695b54295aaf3b25240c8c0cb20d56ecc14c6 /libpqpp/pq-column.cpp | |
parent | Fix memory leak in unit test (diff) | |
download | libdbpp-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-column.cpp')
-rw-r--r-- | libpqpp/pq-column.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/libpqpp/pq-column.cpp b/libpqpp/pq-column.cpp index bb09c45..92107e8 100644 --- a/libpqpp/pq-column.cpp +++ b/libpqpp/pq-column.cpp @@ -7,10 +7,18 @@ PQ::Column::Column(const SelectBase * s, unsigned int i) : DB::Column(PQfname(s->execRes, i), i), sc(s), - oid(PQftype(sc->execRes, colNo)) + oid(PQftype(sc->execRes, colNo)), + buf(nullptr) { } +PQ::Column::~Column() +{ + if (buf) { + PQfreemem(buf); + } +} + bool PQ::Column::isNull() const { @@ -67,6 +75,16 @@ PQ::Column::apply(DB::HandleField & h) const case 1184: //TIMESTAMPTZOID: h.timestamp(boost::posix_time::time_from_string(PQgetvalue(sc->execRes, sc->tuple, colNo))); break; + case 17: //BYTEAOID + { + if (buf) { + PQfreemem(buf); + } + size_t len; + buf = PQunescapeBytea((unsigned char *)PQgetvalue(sc->execRes, sc->tuple, colNo), &len); + h.blob(DB::Blob(buf, len)); + break; + } default: h.string(PQgetvalue(sc->execRes, sc->tuple, colNo), PQgetlength(sc->execRes, sc->tuple, colNo)); } |