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

Database.h

Go to the documentation of this file.
00001 
00002 //
00003 // This file is part of the MADELINE 2 program 
00004 // written by Edward H. Trager,Ritu Khanna and Adrian Marrs
00005 // Copyright (c) 2005 by the
00006 // Regents of the University of Michigan.
00007 // All Rights Reserved.
00008 // 
00009 // The latest version of this program is available from:
00010 // 
00011 //   http://eyegene.ophthy.med.umich.edu/madeline/
00012 //   
00013 // Released under the GNU General Public License.
00014 // A copy of the GPL is included in the distribution
00015 // package of this software, or see:
00016 // 
00017 //   http://www.gnu.org/copyleft/
00018 //   
00019 // ... for licensing details.
00020 // 
00022 
00023 //
00024 // Database.h
00025 //
00026 
00027 #ifndef DATABASE_INCLUDED
00028 #define DATABASE_INCLUDED
00029 
00030 #ifdef MYSQLPP
00031 
00032 #include <mysql++.h>
00033 
00034 #include <iostream>
00035 #include <iomanip>
00036 #include <vector>
00037 #include <cstring>
00038 
00039 #include "TableParser.h"
00040 
00041 class Database : public TableParser{
00042 private:
00043         const char* _host;
00044         const char* _user;
00045         const char* _password;
00046         const char* _database;
00047         unsigned _port;
00048         bool _connected;
00049         mysqlpp::Connection _con;        // Mysql connection object
00050         
00051 public:
00052         
00053         Database() {_connected = false;}
00054         
00055         //
00056         // Constructor:
00057         //
00058         Database(const char* host,const char* user,const char* password,const char* database,unsigned port=0)
00059         {
00060                 _host = host;
00061                 _user = user;
00062                 _password = password;
00063                 _database = database;
00064                 _connected = true;
00065                 _port = port;
00066                 try
00067                 {
00068                         _con.connect(_database,_host,_user,_password,_port);
00069                 }
00070                 catch(...)
00071                 {
00072                         std::cout << "ERROR" << std::endl;
00073                 }
00074         }
00075         
00076         void setup(const char* host,const char* user,const char* password,const char* database,unsigned port=0)
00077         {
00078                 _host = host;
00079                 _user = user;
00080                 _password = password;
00081                 _database = database;
00082                 _port = port;
00083                 _connected = true;
00084                 try
00085                 {
00086                         _con.connect(_database,_host,_user,_password,_port);
00087                 }
00088                 catch(...)
00089                 {
00090                         std::cout << "ERROR" << std::endl;
00091                 }
00092         }
00093         //
00094         // Public Functions:
00095         //
00096         void readTable(const char* sqlQuery); // Store the values retrieved into '_element' vector
00097         void query(const char* sqlQuery);    // Execute a query
00098         // Debugging Function(): display
00099         void display(void);                  // Display the vector
00100 };
00101 
00102 #endif
00103 #endif

Generated on Fri Nov 18 16:24:39 2011 for MADELINE by  doxygen 1.4.4