summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-10-08 14:26:11 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-10-08 14:37:42 +0100
commit8a9378134b8cc3f48c07ba47e692934401c51715 (patch)
tree8e96e98bb39d7e075e8214fc2e0b3b98f5fd3cfc
parentDon't use &vector.front() for vector which might be empty (diff)
downloadlibdbpp-postgresql-8a9378134b8cc3f48c07ba47e692934401c51715.tar.bz2
libdbpp-postgresql-8a9378134b8cc3f48c07ba47e692934401c51715.tar.xz
libdbpp-postgresql-8a9378134b8cc3f48c07ba47e692934401c51715.zip
Use proper defines for column types
-rw-r--r--libpqpp/pq-binarycolumn.cpp19
-rw-r--r--libpqpp/pq-column.cpp39
2 files changed, 29 insertions, 29 deletions
diff --git a/libpqpp/pq-binarycolumn.cpp b/libpqpp/pq-binarycolumn.cpp
index 0a488f7..514a145 100644
--- a/libpqpp/pq-binarycolumn.cpp
+++ b/libpqpp/pq-binarycolumn.cpp
@@ -5,6 +5,7 @@
#include <cstdint>
#include <endian.h>
#include <error.h>
+#include <server/catalog/pg_type_d.h>
PQ::BinaryColumn::BinaryColumn(const PQ::SelectBase * s, unsigned int f) : PQ::Column(s, f) { }
@@ -16,25 +17,25 @@ PQ::BinaryColumn::apply(DB::HandleField & h) const
return;
}
switch (oid) {
- case 18: // CHAROID:
- case 1043: // VARCHAROID:
- case 25: // TEXTOID:
- case 142: // XMLOID:
+ case CHAROID:
+ case VARCHAROID:
+ case TEXTOID:
+ case XMLOID:
h.string({value(), length()});
break;
- case 16: // BOOLOID:
+ case BOOLOID:
h.boolean(valueAs<bool>());
break;
- case 21: // INT2OID:
+ case INT2OID:
h.integer(static_cast<int64_t>(be16toh(valueAs<uint16_t>())));
break;
- case 23: // INT4OID:
+ case INT4OID:
h.integer(static_cast<int64_t>(be32toh(valueAs<uint32_t>())));
break;
- case 20: // INT8OID:
+ case INT8OID:
h.integer(static_cast<int64_t>(be64toh(valueAs<uint64_t>())));
break;
- case 17: // BYTEAOID
+ case BYTEAOID:
h.blob(DB::Blob(value(), length()));
break;
default:
diff --git a/libpqpp/pq-column.cpp b/libpqpp/pq-column.cpp
index 446fe38..e85ead5 100644
--- a/libpqpp/pq-column.cpp
+++ b/libpqpp/pq-column.cpp
@@ -10,6 +10,7 @@
#include <cstring>
#include <libpq-fe.h>
#include <memory>
+#include <server/catalog/pg_type_d.h>
PQ::Column::Column(const SelectBase * s, unsigned int i) :
DB::Column(PQfname(s->execRes, static_cast<int>(i)), i), sc(s), oid(PQftype(sc->execRes, static_cast<int>(colNo))),
@@ -50,30 +51,29 @@ PQ::Column::apply(DB::HandleField & h) const
return;
}
switch (oid) {
- case 18: // CHAROID:
- case 1043: // VARCHAROID:
- case 25: // TEXTOID:
- case 142: // XMLOID:
+ case CHAROID:
+ case VARCHAROID:
+ case TEXTOID:
+ case XMLOID:
default:
h.string({value(), length()});
break;
- case 16: // BOOLOID:
+ case BOOLOID:
h.boolean(value()[0] == 't');
break;
- case 21: // INT2OID:
- case 23: // INT4OID:
- case 20: // INT8OID:
+ case INT2OID:
+ case INT4OID:
+ case INT8OID:
h.integer(atol(value()));
break;
- case 1700: // NUMERICOID:
- case 700: // FLOAT4OID:
- case 701: // FLOAT8OID:
+ case NUMERICOID:
+ case FLOAT4OID:
+ case FLOAT8OID:
h.floatingpoint(atof(value()));
break;
- case 704: // TINTERVALOID
- case 1083: // TIMEOID:
- case 1186: // INTERVALOID
- {
+ case TIMEOID:
+ case INTERVALOID:
+ {
int days = 0, hours = 0, minutes = 0, seconds = 0, fractions = 0, flen1 = 0, flen2 = 0;
const char * val = value();
// NOLINTNEXTLINE(hicpp-vararg)
@@ -90,15 +90,14 @@ PQ::Column::apply(DB::HandleField & h) const
}
break;
}
- case 1082: // DATEOID:
+ case DATEOID:
h.timestamp(boost::posix_time::ptime(boost::gregorian::from_string(value())));
break;
- case 702: // ABSTIMEOID:
- case 1114: // TIMESTAMPOID:
- case 1184: // TIMESTAMPTZOID:
+ case TIMESTAMPOID:
+ case TIMESTAMPTZOID:
h.timestamp(boost::posix_time::time_from_string(value()));
break;
- case 17: // BYTEAOID
+ case BYTEAOID:
{
if (buf) {
PQfreemem(buf);