X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/3e32eb8e48a56bca543faa522909d3d83538c55d..9701b7ab4dc4cd709ad4dcaa750fc0021f15e231:/include/stg/base_db.h diff --git a/include/stg/base_db.h b/include/stg/base_db.h new file mode 100644 index 00000000..8aa05508 --- /dev/null +++ b/include/stg/base_db.h @@ -0,0 +1,75 @@ +#ifndef __BASE_DB_H__ +#define __BASE_DB_H__ + +#include +#include +#include + +class BASE_DB { +public: + + typedef std::map TUPLE; + typedef std::vector TUPLES; + typedef std::vector COLUMNS; + + BASE_DB() {}; + BASE_DB(std::string & dbHost, + std::string & dbDatabase, + std::string & dbUser, + std::string & dbPassword) + : host(dbHost), + database(dbDatabase), + user(dbUser), + password(dbPassword) + {}; + virtual ~BASE_DB() {}; + + void SetHost(const std::string & h) { host = h; }; + void SetDatabase(const std::string & db) { database = db; }; + void SetUser(const std::string & u) { user = u; }; + void SetPassword(const std::string & p) { password = p; }; + + const std::string & GetHost() const { return host; }; + const std::string & GetDatabase() const { return database; }; + const std::string & GetUser() const { return user; }; + const std::string & GetPassword() const { return password; }; + + const std::string & GetErrorMsg() const { return errorMsg; }; + + virtual bool Connect() { return true; }; + virtual bool Disconnect() { return true; }; + virtual bool Query(const std::string & q) { return true; }; + virtual bool Start() { return true; }; + virtual bool Commit() { return true; }; + virtual bool Rollback() { return true; }; + + int GetTuples() const { return tuples; }; + int GetColumns() const { return columns; }; + int GetAffectedRows() const { return affected; }; + + virtual TUPLES GetResult() const { return TUPLES(); }; + virtual TUPLE GetTuple(int n = 0) const { return TUPLE(); }; + const COLUMNS & GetColumnsNames() const { return cols; }; + +protected: + std::string host; + std::string database; + std::string user; + std::string password; + + std::string errorMsg; + + COLUMNS cols; + + int columns; + int tuples; + int affected; +}; + +extern "C" BASE_DB * CreateDriver(); +extern "C" void DestroyDriver(BASE_DB *); + +typedef BASE_DB * (* CreateDriverFn)(); +typedef void (* DestroyDriverFn)(BASE_DB *); + +#endif