00001 /* 00002 * Copyright (c) 2010 Ferruccio Vitale <unixo@devzero.it> 00003 * All rights reserved. 00004 * 00005 * $Id: Database.h 72 2010-08-03 16:43:52Z unixo $ 00006 */ 00007 00008 #ifndef __DATABASE_H__ 00009 #define __DATABASE_H__ 00010 00011 #include <mysql++.h> 00012 #include <query.h> 00013 #include "common.h" 00014 00015 using namespace std; 00016 using namespace mysqlpp; 00017 00035 class Database 00036 { 00037 private: 00038 static Database sharedInstance; 00039 00040 Connection *_conn; 00041 string _server; 00042 string _user; 00043 string _passwd; 00044 string _db; 00045 00046 Database(string server, string user, string pwd, string db); 00047 00052 Database(const Database &); 00053 void operator =(Database &); 00054 00055 protected: 00056 void printRow(IntVector & widths, Row& row); 00057 00058 public: 00059 ~Database(); 00060 00061 static Database & Instance(); 00062 00063 bool isConnected(); 00064 bool connect(); 00065 void disconnect(); 00066 Connection *getConnection(); 00067 void printResult(StoreQueryResult& res); 00068 00069 void setServer(string aValue); 00070 void setUser(string aValue); 00071 void setPassword(string aValue); 00072 void setDB(string aValue); 00073 00074 friend ostream& operator<<(ostream &, Database &); 00075 }; 00076 00077 #endif /* __DATABASE_H__ */