summaryrefslogtreecommitdiff
path: root/libpqpp/pq-binarycolumn.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-06-05 18:53:22 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-06-05 18:53:22 +0100
commit19609c41b15a818df30508576f50fc0eddc11636 (patch)
treeb7b36a9e69689fd2be7c0660728af59eacb02d10 /libpqpp/pq-binarycolumn.cpp
parentAdd wrappers for PQgetvalue and PQgetlength in column to simplify access (diff)
downloadlibdbpp-postgresql-19609c41b15a818df30508576f50fc0eddc11636.tar.bz2
libdbpp-postgresql-19609c41b15a818df30508576f50fc0eddc11636.tar.xz
libdbpp-postgresql-19609c41b15a818df30508576f50fc0eddc11636.zip
Support fetching data in binary format (no numeric, datetime, interval support yet)
Diffstat (limited to 'libpqpp/pq-binarycolumn.cpp')
-rw-r--r--libpqpp/pq-binarycolumn.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/libpqpp/pq-binarycolumn.cpp b/libpqpp/pq-binarycolumn.cpp
new file mode 100644
index 0000000..ff49b26
--- /dev/null
+++ b/libpqpp/pq-binarycolumn.cpp
@@ -0,0 +1,43 @@
+#include "pq-binarycolumn.h"
+#include "pq-selectbase.h"
+#include <error.h>
+
+PQ::BinaryColumn::BinaryColumn(const PQ::SelectBase * s, unsigned int f) :
+ PQ::Column(s, f)
+{
+}
+
+void
+PQ::BinaryColumn::apply(DB::HandleField & h) const
+{
+ if (isNull()) {
+ h.null();
+ return;
+ }
+ switch (oid) {
+ case 18: //CHAROID:
+ case 1043: //VARCHAROID:
+ case 25: //TEXTOID:
+ case 142: //XMLOID:
+ h.string(value(), length());
+ break;
+ case 16: //BOOLOID:
+ h.boolean(valueAs<bool>());
+ break;
+ case 21: //INT2OID:
+ h.integer(be16toh(valueAs<uint16_t>()));
+ break;
+ case 23: //INT4OID:
+ h.integer(be32toh(valueAs<uint32_t>()));
+ break;
+ case 20: //INT8OID:
+ h.integer(be64toh(valueAs<uint64_t>()));
+ break;
+ case 17: //BYTEAOID
+ h.blob(DB::Blob(value(), length()));
+ break;
+ default:
+ throw DB::ColumnTypeNotSupported();
+ }
+}
+