diff options
-rw-r--r-- | libdbpp/Jamfile.jam | 14 | ||||
-rw-r--r-- | libdbpp/column.cpp | 13 | ||||
-rw-r--r-- | libdbpp/column.h | 33 | ||||
-rw-r--r-- | libdbpp/command.cpp | 11 | ||||
-rw-r--r-- | libdbpp/command.h | 35 | ||||
-rw-r--r-- | libdbpp/connection.cpp | 6 | ||||
-rw-r--r-- | libdbpp/connection.h | 27 | ||||
-rw-r--r-- | libdbpp/error.cpp | 13 | ||||
-rw-r--r-- | libdbpp/error.h | 18 | ||||
-rw-r--r-- | libdbpp/modifycommand.cpp | 11 | ||||
-rw-r--r-- | libdbpp/modifycommand.h | 17 | ||||
-rw-r--r-- | libdbpp/selectcommand.cpp | 11 | ||||
-rw-r--r-- | libdbpp/selectcommand.h | 22 |
13 files changed, 231 insertions, 0 deletions
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 : : : : + <cflags>"`pkg-config --cflags glibmm-2.4`" + <linkflags>"`pkg-config --libs glibmm-2.4`" + ; + +lib dbpp : + [ glob *.cpp ] : + <cflags>-fPIC + <library>glibmm + : : + <include>. + <library>../libmisc//misc + <library>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 <glibmm/ustring.h> +#include <vector> +#include <stdlib.h> + +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 <glibmm/ustring.h> + +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 <string> + +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 <time.h> + +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 <stdlib.h> +#include <exception> + +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 + |