summaryrefslogtreecommitdiff
path: root/libpqpp/column.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-02-09 01:33:33 +0000
committerrandomdan <randomdan@localhost>2011-02-09 01:33:33 +0000
commitcfa36aa5466d4c342c7de0f6cea7b8386984fd36 (patch)
tree17a13c13b3588101a146705839d5da6f280bddb9 /libpqpp/column.cpp
parentCentralise the ICE splicer (diff)
downloadlibdbpp-postgresql-cfa36aa5466d4c342c7de0f6cea7b8386984fd36.tar.bz2
libdbpp-postgresql-cfa36aa5466d4c342c7de0f6cea7b8386984fd36.tar.xz
libdbpp-postgresql-cfa36aa5466d4c342c7de0f6cea7b8386984fd36.zip
Fix the build system to do dependencies properly
Break down libodbcpp into a set of base classes; libdbpp Add a native PostgreSQL implementation of libdbpp; libpqpp Extend project2 rdbms stuff to work with generic connectors Update datasources to specify connector type Build libmisc as .so
Diffstat (limited to 'libpqpp/column.cpp')
-rw-r--r--libpqpp/column.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/libpqpp/column.cpp b/libpqpp/column.cpp
new file mode 100644
index 0000000..1bd212a
--- /dev/null
+++ b/libpqpp/column.cpp
@@ -0,0 +1,73 @@
+#include "column.h"
+#include "selectcommand.h"
+#include "error.h"
+#include <string.h>
+
+PQ::Column::Column(const SelectCommand * s, unsigned int i) :
+ DB::Column(PQfname(s->execRes, i), i),
+ sc(s),
+ oid(PQftype(sc->execRes, colNo))
+{
+}
+
+bool
+PQ::Column::isNull() const
+{
+ return PQgetisnull(sc->execRes, sc->tuple, colNo);
+}
+
+void
+PQ::Column::apply(DB::HandleField & h) const
+{
+ if (isNull()) {
+ h.null();
+ return;
+ }
+ struct tm tm;
+ switch (oid) {
+ case 18: //CHAROID:
+ case 25: //TEXTOID:
+ case 142: //XMLOID:
+ h.string(PQgetvalue(sc->execRes, sc->tuple, colNo), PQgetlength(sc->execRes, sc->tuple, colNo));
+ break;
+ case 16: //BOOLOID:
+ h.integer(PQgetvalue(sc->execRes, sc->tuple, colNo)[0] == 't' ? 1 : 0);
+ break;
+ case 21: //INT2OID:
+ case 23: //INT4OID:
+ case 20: //INT8OID:
+ h.integer(atol(PQgetvalue(sc->execRes, sc->tuple, colNo)));
+ break;
+ case 1700: //NUMERICOID:
+ case 700: //FLOAT4OID:
+ case 701: //FLOAT8OID:
+ h.floatingpoint(atof(PQgetvalue(sc->execRes, sc->tuple, colNo)));
+ break;
+ case 1083: //TIMEOID:
+ memset(&tm, 0, sizeof(tm));
+ strptime(PQgetvalue(sc->execRes, sc->tuple, colNo), "%T", &tm);
+ h.timestamp(tm);
+ break;
+ case 1082: //DATEOID:
+ memset(&tm, 0, sizeof(tm));
+ strptime(PQgetvalue(sc->execRes, sc->tuple, colNo), "%F", &tm);
+ h.timestamp(tm);
+ break;
+ case 702: //ABSTIMEOID:
+ case 1114: //TIMESTAMPOID:
+ case 1184: //TIMESTAMPTZOID:
+ strptime(PQgetvalue(sc->execRes, sc->tuple, colNo), "%F %T", &tm);
+ h.timestamp(tm);
+ break;
+ default:
+ fprintf(stderr, "Unknown Oid %d\n", oid);
+ throw Error("Unknown Oid");
+ }
+}
+
+void
+PQ::Column::rebind(DB::Command *, unsigned int) const
+{
+ throw Error("Not supported");
+}
+