00001 /* 00002 * Copyright (c) 2010 Ferruccio Vitale <unixo@devzero.it> 00003 * All rights reserved. 00004 * 00005 * $Id: Database.h 75 2010-09-13 09:25:53Z 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 00027 class Database : public Singleton<Database> 00028 { 00029 private: 00030 Connection *_conn; 00031 string _server; 00032 string _user; 00033 string _passwd; 00034 string _db; 00035 00036 protected: 00037 friend class Singleton<Database>; 00038 Database(); 00039 00040 void printRow(IntVector & widths, Row& row); 00041 00042 public: 00043 virtual ~Database(); 00044 00045 bool isConnected(); 00046 bool connect(); 00047 void disconnect(); 00048 Connection *getConnection(); 00049 void printResult(StoreQueryResult& res); 00050 00051 void setServer(string aValue); 00052 void setUser(string aValue); 00053 void setPassword(string aValue); 00054 void setDB(string aValue); 00055 00056 friend ostream& operator<<(ostream &, Database &); 00057 }; 00058 00059 #endif /* __DATABASE_H__ */