ionflux.org | Impressum

Database.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_DATABASE
00002 #define IONFLUX_TOOLS_DATABASE
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2004 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * Database.hpp                   Database (abstract class).
00009  * ==========================================================================
00010  * 
00011  * This file is part of Ionflux Tools.
00012  * 
00013  * Ionflux Tools is free software; you can redistribute it and/or modify it 
00014  * under the terms of the GNU General Public License as published by the Free
00015  * Software Foundation; either version 2 of the License, or (at  your option)
00016  * any later version.
00017  * 
00018  * Ionflux Tools is distributed in the hope that it will be useful, but 
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00021  * for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License
00024  * along with Ionflux Tools; if not, write to the Free Software Foundation, 
00025  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00026  * 
00027  * ========================================================================== */
00028 
00029 #include <string>
00030 #include <vector>
00031 #include <map>
00032 #include "ionflux/Node.hpp"
00033 #include "ionflux/ManagedObject.hpp"
00034 
00035 namespace Ionflux
00036 {
00037 
00038 namespace Tools
00039 {
00040 
00048 
00049 typedef std::vector<std::string> DbRow;
00051 typedef std::map<std::string, std::string> DbRowMap;
00053 typedef std::vector<DbRow> DbResult;
00055 typedef std::vector<DbRowMap> DbResultMap;
00057 typedef std::vector<std::string> DbTables;
00059 typedef std::vector<std::string> DbColumns;
00060 
00062 struct DatabaseConfig
00063 {
00065     std::string server;
00067     unsigned int port;
00069     std::string username;
00071     std::string password;
00073     std::string database;
00074 };
00075 
00077 struct DatabaseError
00078 {
00080     unsigned int errNum;
00082     std::string error;
00083 };
00084 
00086 class DatabaseClassInfo
00087 : public ClassInfo
00088 {
00089     public:
00091         DatabaseClassInfo();
00093         virtual ~DatabaseClassInfo() { };
00094 };
00095 
00100 class Database
00101 : public ManagedObject
00102 {
00103     public:
00105         static const int NODE_ORDER_ROWS;
00107         static const int NODE_ORDER_NAMED_FIELDS;
00109         static const int NODE_ORDER_COLUMNS;
00111         static const DatabaseClassInfo databaseClassInfo;
00113         static const ClassInfo* CLASS_INFO;
00114         
00119         Database();
00120         
00125         Database(const DatabaseConfig &initConfig);
00126         
00131         virtual ~Database();
00132         
00139         virtual void setConfig(const DatabaseConfig &newConfig) = 0;
00140         
00152         virtual void setConfig(Ionflux::Tools::Node &newConfig) = 0;
00153         
00160         virtual DatabaseConfig getConfig() = 0;
00161         
00168         virtual bool connect() = 0;
00169         
00171         virtual void close() = 0;
00172         
00181         virtual bool query(const std::string &command) = 0;
00182         
00193         virtual bool listTables(DbTables &tables, 
00194             const std::string &pattern = "") = 0;
00195         
00205         virtual bool listColumns(DbColumns &columns, 
00206             const std::string &table) = 0;
00207         
00216         virtual unsigned int getNumRows(const std::string &table) = 0;
00217         
00224         virtual unsigned int getNumRows() = 0;
00225         
00232         virtual unsigned int getNumAffectedRows() = 0;
00233         
00242         virtual bool fetchRow(DbRow &row) = 0;
00243         
00253         virtual bool fetchRowMap(DbRowMap &rowMap) = 0;
00254         
00264         virtual bool fetchRowTree(Node &rowNode) = 0;
00265         
00274         virtual bool fetchResult(DbResult &result) = 0;
00275         
00285         virtual bool fetchResultMap(DbResultMap &resultMap) = 0;
00286         
00307         virtual bool fetchResultTree(Node &resultNode, int nodeOrder) = 0;
00308         
00317         virtual std::string sqlEscape(const std::string &source) = 0;
00318         
00333         virtual bool validateTable(const std::string& tableName, 
00334             const std::string& createTemplate = "", 
00335             Node* createConfig = 0) = 0;
00336         
00343         virtual DatabaseError getError() = 0;
00344         
00345 };
00346 
00348 
00349 }
00350 
00351 }
00352 
00356 #endif

Generated on Tue Mar 14 20:58:29 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6