***********************
** 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.
/*****************************
$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
*****************************/
-/* 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 <pqxx/connection.h>
-#include <pqxx/transaction.h>
-#include <pqxx/result.h>
+#include <pqxx/connection>
+#include <pqxx/transaction>
+#include <pqxx/result>
#include "gnucomo_config.h"
/*
class gnucomo_database
{
gnucomo_config *cfg;
- pqxx::Connection *dbconn;
- pqxx::Transaction *dbxact;
+ pqxx::connection *dbconn;
+ //pqxx::transaction<pqxx::serializable> *dbxact;
+ pqxx::work *dbxact;
- pqxx::Result last_result;
+ pqxx::result last_result;
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());
}
***********************
** FILE NAME : database.cpp
** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
-** VERSION NUMBER : $Revision: 1.12 $
+** VERSION NUMBER : $Revision: 1.13 $
**
** DESCRIPTION : Implementation of the gnucomo database classes
**
/*****************************
$Log: database.cpp,v $
- Revision 1.12 2003-12-22 10:28:26 arjen
+ Revision 1.13 2011-03-24 10:21:47 arjen
+ Adjusted to new version of libpqxx.
+
+ Revision 1.12 2003/12/22 10:28:26 arjen
Catch an exception if we can not setup a database transaction.
Revision 1.11 2003/12/04 10:40:28 arjen
*****************************/
-static const char *RCSID = "$Id: database.cpp,v 1.12 2003-12-22 10:28:26 arjen Exp $";
+static const char *RCSID = "$Id: database.cpp,v 1.13 2011-03-24 10:21:47 arjen Exp $";
#include <AXE/date.h>
+//#define DEBUG
+
#include "database.h"
extern std::ostream *Log;
{
cfg = c;
- dbconn = new pqxx::Connection(cfg->Database());
+ dbconn = new pqxx::connection(cfg->Database());
if (!dbconn->is_open())
{
{
// Create the transaction object
- dbxact = new pqxx::Transaction(*dbconn, "GnuCoMo");
+ //dbxact = new pqxx::transaction<pqxx::serializable>(*dbconn, "GnuCoMo");
+ dbxact = new pqxx::work(*dbconn, "GnuCoMo");
}
catch (std::exception &e)
{
{
if (--gdb_refcount == 0 && dbconn != 0 && dbxact != 0)
{
- dbxact->Commit();
+ dbxact->commit();
delete dbxact;
dbxact = 0;
delete dbconn;