From fea1965942d2b48f4c0f6c50de3113cf02d6e33e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 2 May 2015 18:41:53 +0100 Subject: Add support for RDBMS boolean/bit types --- libpqpp/column.cpp | 2 +- libpqpp/command.cpp | 7 +++++++ libpqpp/command.h | 8 +++++--- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'libpqpp') diff --git a/libpqpp/column.cpp b/libpqpp/column.cpp index 745fdd5..c43e4ab 100644 --- a/libpqpp/column.cpp +++ b/libpqpp/column.cpp @@ -32,7 +32,7 @@ PQ::Column::apply(DB::HandleField & h) const 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); + h.boolean(PQgetvalue(sc->execRes, sc->tuple, colNo)[0] == 't' ? 1 : 0); break; case 21: //INT2OID: case 23: //INT4OID: diff --git a/libpqpp/command.cpp b/libpqpp/command.cpp index abd37e6..ba12574 100644 --- a/libpqpp/command.cpp +++ b/libpqpp/command.cpp @@ -81,6 +81,13 @@ PQ::Command::bindParamI(unsigned int n, long long unsigned int v) formats[n] = 0; } void +PQ::Command::bindParamB(unsigned int n, bool v) +{ + paramsAtLeast(n); + lengths[n] = asprintf(&values[n], "%s", v ? "true" : "false"); + formats[n] = 0; +} +void PQ::Command::bindParamF(unsigned int n, double v) { paramsAtLeast(n); diff --git a/libpqpp/command.h b/libpqpp/command.h index e78722b..a3601c4 100644 --- a/libpqpp/command.h +++ b/libpqpp/command.h @@ -19,14 +19,16 @@ namespace PQ { void bindParamI(unsigned int, long unsigned int); void bindParamI(unsigned int, long long unsigned int); + void bindParamB(unsigned int, bool); + void bindParamF(unsigned int, double); void bindParamF(unsigned int, float); - + void bindParamS(unsigned int, const Glib::ustring&); - + void bindParamT(unsigned int, const boost::posix_time::time_duration &); void bindParamT(unsigned int, const boost::posix_time::ptime &); - + void bindNull(unsigned int); protected: const std::string stmntName; -- cgit v1.2.3