Guest User

Untitled

a guest
Aug 19th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. Connection to Postgres Database using libpqxx
  2. class databaseConnection
  3. {
  4. public:
  5. pqxx::connection* conn;
  6. void SetConnection(){
  7. conn=new pqxx::connection("username=temp host=db.corral.tacc.utexas.edu password=timelione dbname=temp");
  8.  
  9. }
  10.  
  11. void Disconnect(){
  12. conn->disconnect();
  13. }
  14.  
  15. pqxx::result querry(std::string strSQL){
  16. //SetConnection();
  17. pqxx::work trans(*conn,"trans");
  18.  
  19. pqxx::result res=trans.exec(strSQL);
  20.  
  21. trans.commit();
  22. return res;
  23. }
  24. };
  25.  
  26. int main()
  27. {
  28. databaseConnection* pdatabase;
  29. pdatabase->SetConnection();
  30. return 0;
  31. }
  32.  
  33. databaseConnection database;
  34. database.SetConnection();
  35.  
  36. databaseConnection* pdatabase = new databaseConnection();
  37. pdatabase->SetConnection();
Add Comment
Please, Sign In to add comment