X-Git-Url: http://www.andromeda.nl/gitweb/?a=blobdiff_plain;f=src%2Finclude%2Fdatabase.h;h=60f3796380f3086274783b9a4c829d3be1d7c9bb;hb=8cd0ddcb32dac84d8fc613da70bcb0e66ea19962;hp=1d94e64a7a429f35426a27cf19dd3789498312ef;hpb=8618048bd20a6b9302982755c6717d3ab8110bec;p=gnucomo.git diff --git a/src/include/database.h b/src/include/database.h index 1d94e64..60f3796 100644 --- a/src/include/database.h +++ b/src/include/database.h @@ -8,7 +8,7 @@ *********************** ** FILE NAME : database.h ** SYSTEM NAME : -** VERSION NUMBER : $Revision: 1.11 $ +** VERSION NUMBER : $Revision: 1.12 $ ** ** DESCRIPTION : Classes to provide an abstract layer on the Gnucomo ** database. @@ -27,7 +27,10 @@ /***************************** $Log: database.h,v $ - Revision 1.11 2007-01-11 13:50:10 arjen + Revision 1.12 2011-03-24 10:21:43 arjen + Adjusted to new version of libpqxx. + + Revision 1.11 2007/01/11 13:50:10 arjen Experimental start of database OO abstraction layer. Revision 1.10 2003/12/04 10:39:36 arjen @@ -66,11 +69,11 @@ *****************************/ -/* static const char *RCSID = "$Id: database.h,v 1.11 2007-01-11 13:50:10 arjen Exp $"; */ +/* static const char *RCSID = "$Id: database.h,v 1.12 2011-03-24 10:21:43 arjen Exp $"; */ -#include -#include -#include +#include +#include +#include #include "gnucomo_config.h" /* @@ -92,10 +95,11 @@ class gnucomo_database { gnucomo_config *cfg; - pqxx::Connection *dbconn; - pqxx::Transaction *dbxact; + pqxx::connection *dbconn; + //pqxx::transaction *dbxact; + pqxx::work *dbxact; - pqxx::Result last_result; + pqxx::result last_result; public: @@ -130,23 +134,31 @@ public: int Query(String qry) { - - last_result = dbxact->Exec(qry); + try + { + last_result = dbxact->exec((char *)qry); #ifdef DEBUG std::cerr << "Query " << qry << " returned " << last_result.size() << " tuples.\n"; #endif + } + catch (const pqxx::pqxx_exception &e) + { + std::cerr << "Error in QUERY " << qry << ":\n"; + std::cerr << e.base().what() << std::endl; + } + return last_result.size(); } - pqxx::Result Result() + pqxx::result Result() { return last_result; } // The field value of a specific result. - String Field(pqxx::Result res, int tuple, const char *fieldname) + String Field(pqxx::result res, int tuple, const char *fieldname) { return String(res[tuple][fieldname].c_str()); }