Main Page | Namespace List | Alphabetical List | Class List | Directories | File List | Class Members | File Members

DBInterface.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   SpikeStream Library                                                   *
00003  *   Copyright (C) 2007 by David Gamez                                     *
00004  *   david@davidgamez.eu                                                   *
00005  *   Version 0.1                                                           *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 #ifndef DBINTERFACE_H
00024 #define DBINTERFACE_H
00025 
00026 //Other includes
00027 #include <mysql++.h>
00028 #include <vector>
00029 using namespace std;
00030 
00031 
00032 /*! Structure to hold database parameters.*/
00033 struct DBParameters{
00034         static const int maxParamLength = 30;
00035         char host[30];
00036         char user[30];
00037         char password[30];
00038         char database[30];
00039 };
00040 
00041 
00042 //-------------------------- Database Interface ---------------------------
00043 /*! Interfaces with the data base, creating query objects for use by other 
00044         classes. */
00045 //-------------------------------------------------------------------------
00046 
00047 class DBInterface {
00048 
00049         public:
00050                 DBInterface();
00051                 DBInterface(const char*, const char*, const char*, const char*);
00052                 ~DBInterface();
00053                 void checkDatabaseConnection(mysqlpp::Connection*& conn);
00054                 bool connectToDatabase(bool useEx);
00055                 const DBParameters getDBParameters();
00056                 mysqlpp::Connection* getNewConnection();
00057                 mysqlpp::Query getQuery();
00058 
00059 
00060         private:
00061                 //=========================== VARIABLES ============================
00062                 /*! Main connection to database. Used most of the time by other classes.*/
00063                 mysqlpp::Connection *connection;
00064                 
00065                 /*! Vector containing other connections to database that have been created
00066                         These are generally created for large fast queries using ResUse.*/
00067                 vector<mysqlpp::Connection*> connectionVector;
00068                 
00069                 /*! Parameters for database connection
00070                         Stored to prevent them from disappearing and to pass them on 
00071                         elsewhere when required.*/
00072                 DBParameters dbParam;
00073 
00074                 /*! Records whether we are using exceptions or not.*/
00075                 bool useExceptions;
00076 
00077 
00078                 //=========================== METHODS ===============================
00079                 /*! Declare copy constructor private so it cannot be used inadvertently.*/
00080                 DBInterface (const DBInterface&);
00081 
00082                 /*! Declare assignment private so it cannot be used.*/
00083                 DBInterface operator = (const DBInterface&);
00084 
00085                 bool connectToDatabase(mysqlpp::Connection*& conn);
00086 };
00087 
00088 
00089 #endif//DBINTERFACE_H
00090 

Generated on Mon Sep 3 22:18:50 2007 for SpikeStream Library by  doxygen 1.4.4