From acbf539574cb4caa21bdc1814f94815a081847c5 Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 9 Feb 2011 01:33:33 +0000 Subject: 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 --- libdbpp/Jamfile.jam | 14 ++++++++++++++ libdbpp/column.cpp | 13 +++++++++++++ libdbpp/column.h | 33 +++++++++++++++++++++++++++++++++ libdbpp/command.cpp | 11 +++++++++++ libdbpp/command.h | 35 +++++++++++++++++++++++++++++++++++ libdbpp/connection.cpp | 6 ++++++ libdbpp/connection.h | 27 +++++++++++++++++++++++++++ libdbpp/error.cpp | 13 +++++++++++++ libdbpp/error.h | 18 ++++++++++++++++++ libdbpp/modifycommand.cpp | 11 +++++++++++ libdbpp/modifycommand.h | 17 +++++++++++++++++ libdbpp/selectcommand.cpp | 11 +++++++++++ libdbpp/selectcommand.h | 22 ++++++++++++++++++++++ 13 files changed, 231 insertions(+) create mode 100644 libdbpp/Jamfile.jam create mode 100644 libdbpp/column.cpp create mode 100644 libdbpp/column.h create mode 100644 libdbpp/command.cpp create mode 100644 libdbpp/command.h create mode 100644 libdbpp/connection.cpp create mode 100644 libdbpp/connection.h create mode 100644 libdbpp/error.cpp create mode 100644 libdbpp/error.h create mode 100644 libdbpp/modifycommand.cpp create mode 100644 libdbpp/modifycommand.h create mode 100644 libdbpp/selectcommand.cpp create mode 100644 libdbpp/selectcommand.h diff --git a/libdbpp/Jamfile.jam b/libdbpp/Jamfile.jam new file mode 100644 index 0000000..0c56e62 --- /dev/null +++ b/libdbpp/Jamfile.jam @@ -0,0 +1,14 @@ +alias glibmm : : : : + "`pkg-config --cflags glibmm-2.4`" + "`pkg-config --libs glibmm-2.4`" + ; + +lib dbpp : + [ glob *.cpp ] : + -fPIC + glibmm + : : + . + ../libmisc//misc + glibmm + ; diff --git a/libdbpp/column.cpp b/libdbpp/column.cpp new file mode 100644 index 0000000..91d26f5 --- /dev/null +++ b/libdbpp/column.cpp @@ -0,0 +1,13 @@ +#include "column.h" + +DB::Column::Column(const Glib::ustring & n, unsigned int i) : + colNo(i), + name(n) +{ +} + +DB::Column::~Column() +{ +} + + diff --git a/libdbpp/column.h b/libdbpp/column.h new file mode 100644 index 0000000..c0b3c37 --- /dev/null +++ b/libdbpp/column.h @@ -0,0 +1,33 @@ +#ifndef DB_COLUMN_H +#define DB_COLUMN_H + +#include +#include +#include + +namespace DB { + class HandleField { + public: + virtual void null() = 0; + virtual void string(const char *, size_t len) = 0; + virtual void integer(int64_t) = 0; + virtual void floatingpoint(double) = 0; + virtual void timestamp(const struct tm &) = 0; + }; + class Command; + class Column { + public: + Column(const Glib::ustring &, unsigned int); + virtual ~Column() = 0; + + virtual bool isNull() const = 0; + virtual void apply(HandleField &) const = 0; + virtual void rebind(Command *, unsigned int) const = 0; + + const unsigned int colNo; + const Glib::ustring name; + }; +} + +#endif + diff --git a/libdbpp/command.cpp b/libdbpp/command.cpp new file mode 100644 index 0000000..8bdb96c --- /dev/null +++ b/libdbpp/command.cpp @@ -0,0 +1,11 @@ +#include "command.h" + +DB::Command::Command(const std::string & s) : + sql(s) +{ +} + +DB::Command::~Command() +{ +} + diff --git a/libdbpp/command.h b/libdbpp/command.h new file mode 100644 index 0000000..90bd5e4 --- /dev/null +++ b/libdbpp/command.h @@ -0,0 +1,35 @@ +#ifndef DB_COMMAND_H +#define DB_COMMAND_H + +#include + +namespace DB { + class Command { + public: + Command(const std::string & sql); + virtual ~Command() = 0; + + virtual void bindParamI(unsigned int i, int val) = 0; + virtual void bindParamI(unsigned int i, long val) = 0; + virtual void bindParamI(unsigned int i, long long val) = 0; + virtual void bindParamI(unsigned int i, unsigned int val) = 0; + virtual void bindParamI(unsigned int i, unsigned long int val) = 0; + virtual void bindParamI(unsigned int i, unsigned long long int val) = 0; + + virtual void bindParamF(unsigned int i, double val) = 0; + virtual void bindParamF(unsigned int i, float val) = 0; + + virtual void bindParamS(unsigned int i, const Glib::ustring &) = 0; + + virtual void bindParamT(unsigned int i, const struct tm *) = 0; + virtual void bindParamT(unsigned int i, time_t) = 0; + + virtual void bindNull(unsigned int i) = 0; + + protected: + std::string sql; + }; +} + +#endif + diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp new file mode 100644 index 0000000..5b72467 --- /dev/null +++ b/libdbpp/connection.cpp @@ -0,0 +1,6 @@ +#include "connection.h" + +DB::Connection::~Connection() +{ +} + diff --git a/libdbpp/connection.h b/libdbpp/connection.h new file mode 100644 index 0000000..8959840 --- /dev/null +++ b/libdbpp/connection.h @@ -0,0 +1,27 @@ +#ifndef CONNECTION_H +#define CONNECTION_H + +#include + +namespace DB { + class SelectCommand; + class ModifyCommand; + class Connection { + public: + virtual ~Connection(); + + virtual int beginTx() const = 0; + virtual int commitTx() const = 0; + virtual int rollbackTx() const = 0; + virtual bool inTx() const = 0; + virtual void ping() const = 0; + + virtual SelectCommand * newSelectCommand(const std::string & sql) const = 0; + virtual ModifyCommand * newModifyCommand(const std::string & sql) const = 0; + + private: + }; +} + +#endif + diff --git a/libdbpp/error.cpp b/libdbpp/error.cpp new file mode 100644 index 0000000..372cc4b --- /dev/null +++ b/libdbpp/error.cpp @@ -0,0 +1,13 @@ +#include "error.h" +#include + +DB::ConnectionError::ConnectionError() : + FailureTime(time(NULL)) +{ +} + +DB::ConnectionError::ConnectionError(time_t t) : + FailureTime(t) +{ +} + diff --git a/libdbpp/error.h b/libdbpp/error.h new file mode 100644 index 0000000..3da6316 --- /dev/null +++ b/libdbpp/error.h @@ -0,0 +1,18 @@ +#ifndef DB_ERROR_H +#define DB_ERROR_H + +#include +#include + +namespace DB { + class Error : public virtual std::exception { }; + class ConnectionError : public Error { + public: + ConnectionError(); + ConnectionError(time_t); + + const time_t FailureTime; + }; +} + +#endif diff --git a/libdbpp/modifycommand.cpp b/libdbpp/modifycommand.cpp new file mode 100644 index 0000000..f864b72 --- /dev/null +++ b/libdbpp/modifycommand.cpp @@ -0,0 +1,11 @@ +#include "modifycommand.h" + +DB::ModifyCommand::ModifyCommand(const std::string & s) : + DB::Command(s) +{ +} + +DB::ModifyCommand::~ModifyCommand() +{ +} + diff --git a/libdbpp/modifycommand.h b/libdbpp/modifycommand.h new file mode 100644 index 0000000..304603b --- /dev/null +++ b/libdbpp/modifycommand.h @@ -0,0 +1,17 @@ +#ifndef DB_MODIFYCOMMAND_H +#define DB_MODIFYCOMMAND_H + +#include "command.h" + +namespace DB { + class ModifyCommand : public virtual Command { + public: + ModifyCommand(const std::string & sql); + ~ModifyCommand(); + // Execute the command and return effected row count + virtual unsigned int execute(bool allowNoChange = true) = 0; + }; +} + +#endif + diff --git a/libdbpp/selectcommand.cpp b/libdbpp/selectcommand.cpp new file mode 100644 index 0000000..662ced4 --- /dev/null +++ b/libdbpp/selectcommand.cpp @@ -0,0 +1,11 @@ +#include "selectcommand.h" + +DB::SelectCommand::SelectCommand(const std::string & sql) : + DB::Command(sql) +{ +} + +DB::SelectCommand::~SelectCommand() +{ +} + diff --git a/libdbpp/selectcommand.h b/libdbpp/selectcommand.h new file mode 100644 index 0000000..943e724 --- /dev/null +++ b/libdbpp/selectcommand.h @@ -0,0 +1,22 @@ +#ifndef DB_SELECTCOMMAND_H +#define DB_SELECTCOMMAND_H + +#include "command.h" + +namespace DB { + class Column; + class SelectCommand : public virtual Command { + public: + SelectCommand(const std::string & sql); + ~SelectCommand(); + virtual bool fetch() = 0; + virtual void execute() = 0; + virtual const Column & operator[](unsigned int col) const = 0; + virtual const Column & operator[](const Glib::ustring &) const = 0; + virtual unsigned int columnCount() const = 0; + virtual unsigned int getOrdinal(const Glib::ustring &) const = 0; + }; +} + +#endif + -- cgit v1.2.3