projects
/
gnucomo.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8618048
)
Adjusted to new version of libpqxx.
author
arjen
<arjen>
Thu, 24 Mar 2011 10:21:43 +0000
(10:21 +0000)
committer
arjen
<arjen>
Thu, 24 Mar 2011 10:21:43 +0000
(10:21 +0000)
src/include/database.h
patch
|
blob
|
history
src/lib/database.cpp
patch
|
blob
|
history
diff --git
a/src/include/database.h
b/src/include/database.h
index
1d94e64
..
60f3796
100644
(file)
--- a/
src/include/database.h
+++ b/
src/include/database.h
@@
-8,7
+8,7
@@
***********************
** FILE NAME : database.h
** SYSTEM NAME :
***********************
** FILE NAME : database.h
** SYSTEM NAME :
-** VERSION NUMBER : $Revision: 1.1
1
$
+** VERSION NUMBER : $Revision: 1.1
2
$
**
** DESCRIPTION : Classes to provide an abstract layer on the Gnucomo
** database.
**
** DESCRIPTION : Classes to provide an abstract layer on the Gnucomo
** database.
@@
-27,7
+27,10
@@
/*****************************
$Log: database.h,v $
/*****************************
$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
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.1
1 2007-01-11 13:50:10
arjen Exp $"; */
+/* static const char *RCSID = "$Id: database.h,v 1.1
2 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"
/*
#include "gnucomo_config.h"
/*
@@
-92,10
+95,11
@@
class gnucomo_database
{
gnucomo_config *cfg;
class gnucomo_database
{
gnucomo_config *cfg;
- pqxx::Connection *dbconn;
- pqxx::Transaction *dbxact;
+ pqxx::connection *dbconn;
+ //pqxx::transaction<pqxx::serializable> *dbxact;
+ pqxx::work *dbxact;
- pqxx::
R
esult last_result;
+ pqxx::
r
esult last_result;
public:
public:
@@
-130,23
+134,31
@@
public:
int Query(String qry)
{
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
#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();
}
return last_result.size();
}
- pqxx::
R
esult Result()
+ pqxx::
r
esult Result()
{
return last_result;
}
// The field value of a specific result.
{
return last_result;
}
// The field value of a specific result.
- String Field(pqxx::
R
esult res, int tuple, const char *fieldname)
+ String Field(pqxx::
r
esult res, int tuple, const char *fieldname)
{
return String(res[tuple][fieldname].c_str());
}
{
return String(res[tuple][fieldname].c_str());
}
diff --git
a/src/lib/database.cpp
b/src/lib/database.cpp
index
fb497ec
..
c585712
100644
(file)
--- a/
src/lib/database.cpp
+++ b/
src/lib/database.cpp
@@
-8,7
+8,7
@@
***********************
** FILE NAME : database.cpp
** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
***********************
** FILE NAME : database.cpp
** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
-** VERSION NUMBER : $Revision: 1.1
2
$
+** VERSION NUMBER : $Revision: 1.1
3
$
**
** DESCRIPTION : Implementation of the gnucomo database classes
**
**
** DESCRIPTION : Implementation of the gnucomo database classes
**
@@
-26,7
+26,10
@@
/*****************************
$Log: database.cpp,v $
/*****************************
$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
Catch an exception if we can not setup a database transaction.
Revision 1.11 2003/12/04 10:40:28 arjen
@@
-67,10
+70,12
@@
*****************************/
*****************************/
-static const char *RCSID = "$Id: database.cpp,v 1.1
2 2003-12-22 10:28:26
arjen Exp $";
+static const char *RCSID = "$Id: database.cpp,v 1.1
3 2011-03-24 10:21:47
arjen Exp $";
#include <AXE/date.h>
#include <AXE/date.h>
+//#define DEBUG
+
#include "database.h"
extern std::ostream *Log;
#include "database.h"
extern std::ostream *Log;
@@
-98,7
+103,7
@@
gnucomo_database::gnucomo_database(gnucomo_config *c)
{
cfg = c;
{
cfg = c;
- dbconn = new pqxx::
C
onnection(cfg->Database());
+ dbconn = new pqxx::
c
onnection(cfg->Database());
if (!dbconn->is_open())
{
if (!dbconn->is_open())
{
@@
-110,7
+115,8
@@
gnucomo_database::gnucomo_database(gnucomo_config *c)
{
// Create the transaction object
{
// 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)
{
}
catch (std::exception &e)
{
@@
-146,7
+152,7
@@
gnucomo_database::~gnucomo_database()
{
if (--gdb_refcount == 0 && dbconn != 0 && dbxact != 0)
{
{
if (--gdb_refcount == 0 && dbconn != 0 && dbxact != 0)
{
- dbxact->
C
ommit();
+ dbxact->
c
ommit();
delete dbxact;
dbxact = 0;
delete dbconn;
delete dbxact;
dbxact = 0;
delete dbconn;