Database header
This commit is contained in:
		
							
								
								
									
										22
									
								
								Database.cpp
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								Database.cpp
									
									
									
									
									
								
							@ -1,4 +1,26 @@
 | 
				
			|||||||
#include "Database.hpp"
 | 
					#include "Database.hpp"
 | 
				
			||||||
 | 
					#include "Config.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Database::Database(){
 | 
					Database::Database(){
 | 
				
			||||||
 | 
						Config conf("config.txt");
 | 
				
			||||||
 | 
						std::ostringstream pgsqlConnectingString;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pgsqlConnectingString 
 | 
				
			||||||
 | 
							<< " host=" << conf.getValue("db_host") 
 | 
				
			||||||
 | 
							<< " dbname=" << conf.getValue("db_name") 
 | 
				
			||||||
 | 
							<< " user=" << conf.getValue("db_user") 
 | 
				
			||||||
 | 
							<< " password=" << conf.getValue("db_pass");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						dbconn = new pqxx::connection(pgsqlConnectingString.str());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pqxx::result Database::execute(std::string cmd){
 | 
				
			||||||
 | 
						pqxx::work w(*dbconn);
 | 
				
			||||||
 | 
						pqxx::result r(w.exec(cmd));
 | 
				
			||||||
 | 
						w.commit();
 | 
				
			||||||
 | 
						return r;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Database::disconnect(){
 | 
				
			||||||
 | 
						dbconn->close();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -7,9 +7,14 @@ class Database
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						pqxx::connection *dbconn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	Database();
 | 
						Database();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pqxx::result execute(std::string cmd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void disconnect();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* DATABASE_H */
 | 
					#endif /* DATABASE_H */
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							@ -1,7 +1,7 @@
 | 
				
			|||||||
CC=g++
 | 
					CC=g++
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CFLAGS= -Wall -g
 | 
					CFLAGS= -Wall -g
 | 
				
			||||||
LDLIBS= -lpqxx
 | 
					LDLIBS= -lpqxx -lpq
 | 
				
			||||||
SOURCES= $(wildcard *.cpp)
 | 
					SOURCES= $(wildcard *.cpp)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
all: main
 | 
					all: main
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user