ionflux.org | Impressum

MySQLDatabase.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_MYSQLDATABASE
00002 #define IONFLUX_TOOLS_MYSQLDATABASE
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2004 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * MySQLDatabase.hpp                   MySQL database wrapper
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 <iostream>
00030 #include <mysql/mysql.h>
00031 #include "ionflux/Database.hpp"
00032 
00033 namespace Ionflux
00034 {
00035 
00036 namespace Tools
00037 {
00038 
00040 class MySQLDatabaseClassInfo
00041 : public ClassInfo
00042 {
00043     public:
00045         MySQLDatabaseClassInfo();
00047         virtual ~MySQLDatabaseClassInfo() { };
00048 };
00049 
00059 class MySQLDatabase
00060 : public Database
00061 {
00062     protected:
00064         DatabaseConfig config;
00066         MYSQL *mysql;
00068         MYSQL_RES *queryResult;
00070         unsigned int numRows;
00072         unsigned int numFields;
00074         int numAffectedRows;
00076         DatabaseError lastError;
00077         
00079         void freeResult();
00080         
00081     public:
00083         static const std::string DEFAULT_SERVER;
00085         static const unsigned int DEFAULT_PORT;
00087         static const std::string DEFAULT_USERNAME;
00089         static const std::string DEFAULT_PASSWORD;
00091         static const std::string DEFAULT_DATABASE;
00093         static const MySQLDatabaseClassInfo mySQLDatabaseClassInfo;
00095         static const ClassInfo* CLASS_INFO;
00096         
00101         MySQLDatabase();
00102         
00107         MySQLDatabase(const DatabaseConfig &initConfig);
00108         
00113         virtual ~MySQLDatabase();
00114         
00121         virtual void setConfig(const DatabaseConfig &newConfig);
00122         
00134         virtual void setConfig(Ionflux::Tools::Node &newConfig);
00135         
00142         virtual DatabaseConfig getConfig();
00143         
00150         virtual bool connect();
00151         
00153         virtual void close();
00154         
00163         virtual bool query(const std::string &command);
00164         
00175         virtual bool listTables(DbTables &tables, 
00176             const std::string &pattern = "");
00177         
00187         virtual bool listColumns(DbColumns &columns, 
00188             const std::string &table);
00189         
00198         virtual unsigned int getNumRows(const std::string &table);
00199         
00206         virtual unsigned int getNumRows();
00207         
00214         virtual unsigned int getNumAffectedRows();
00215         
00224         virtual bool fetchRow(DbRow &row);
00225         
00235         virtual bool fetchRowMap(DbRowMap &rowMap);
00236         
00246         virtual bool fetchRowTree(Node &rowNode);
00247         
00256         virtual bool fetchResult(DbResult &result);
00257         
00267         virtual bool fetchResultMap(DbResultMap &resultMap);
00268         
00289         virtual bool fetchResultTree(Node &resultNode, int nodeOrder);
00290         
00299         virtual std::string sqlEscape(const std::string &source);
00300         
00315         virtual bool validateTable(const std::string& tableName, 
00316             const std::string& createTemplate = "", 
00317             Node* createConfig = 0);
00318         
00325         virtual DatabaseError getError();
00326         
00327 };
00328 
00329 }
00330 
00331 }
00332 
00336 #endif

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