summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libpqpp/pq-column.cpp13
-rw-r--r--libpqpp/pq-column.h10
2 files changed, 15 insertions, 8 deletions
diff --git a/libpqpp/pq-column.cpp b/libpqpp/pq-column.cpp
index 5a5f6b6..e495f2a 100644
--- a/libpqpp/pq-column.cpp
+++ b/libpqpp/pq-column.cpp
@@ -89,12 +89,13 @@ PQ::Column::apply(DB::HandleField & h) const
case TIMESTAMPTZOID:
h.timestamp(boost::posix_time::time_from_string(value()));
break;
- case BYTEAOID: {
- size_t len = 0;
- // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
- buf = BufPtr {PQunescapeBytea(reinterpret_cast<const unsigned char *>(value()), &len)};
- h.blob(DB::Blob(buf.get(), len));
+ case BYTEAOID:
+ if (sc->tuple != buffer.row || !buffer.data) {
+ buffer.data = Buffer::BufPtr {// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
+ PQunescapeBytea(reinterpret_cast<const unsigned char *>(value()), &buffer.length)};
+ buffer.row = sc->tuple;
+ }
+ h.blob(DB::Blob(buffer.data.get(), buffer.length));
break;
- }
}
}
diff --git a/libpqpp/pq-column.h b/libpqpp/pq-column.h
index fa4a78a..4ef102d 100644
--- a/libpqpp/pq-column.h
+++ b/libpqpp/pq-column.h
@@ -24,8 +24,14 @@ namespace PQ {
const Oid oid;
// Buffer for PQunescapeBytea
- using BufPtr = std::unique_ptr<unsigned char, pq_deleter<PQfreemem>>;
- mutable BufPtr buf;
+ struct Buffer {
+ using BufPtr = std::unique_ptr<unsigned char, pq_deleter<PQfreemem>>;
+ size_t row {};
+ size_t length {};
+ BufPtr data;
+ };
+
+ mutable Buffer buffer;
};
}