2 /**************************************************************************
3 ** (c) Copyright 2002, Andromeda Technology & Automation
4 ** This is free software; you can redistribute it and/or modify it under the
5 ** terms of the GNU General Public License, see the file COPYING.
6 ***************************************************************************
7 ** MODULE INFORMATION *
8 ***********************
9 ** FILE NAME : database.h
11 ** VERSION NUMBER : $Revision: 1.8 $
13 ** DESCRIPTION : Classes to provide an abstract layer on the Gnucomo
19 ***************************************************************************
20 ** ADMINISTRATIVE INFORMATION *
21 ********************************
22 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
23 ** CREATION DATE : Sep 10, 2002
24 ** LAST UPDATE : Aug 17, 2003
26 **************************************************************************/
28 /*****************************
30 Revision 1.8 2003-08-17 11:39:33 arjen
31 Changed the gnucomo_database class to the new PostgreSQL
34 Revision 1.7 2003/03/29 08:13:53 arjen
35 New member function gnucomo_database::is_conected().
37 Revision 1.6 2003/02/19 09:54:47 arjen
38 Print the query on cerr, along with the error message when
39 the query results in an error.
41 Revision 1.5 2003/02/05 09:33:17 arjen
42 gnucomo_database::new_notification() retruns the id number of the
43 newly created notification record.
45 Revision 1.4 2003/01/18 08:52:18 arjen
46 New C++ function: gnucomo_database::new_notification()
48 Revision 1.3 2002/11/09 08:04:27 arjen
49 Added a reference to the GPL
51 Revision 1.2 2002/11/04 10:13:36 arjen
52 Use proper namespace for iostream classes
54 Revision 1.1 2002/10/05 10:25:49 arjen
55 Creation of gcm_input and a first approach to a web interface
57 *****************************/
59 /* static const char *RCSID = "$Id: database.h,v 1.8 2003-08-17 11:39:33 arjen Exp $"; */
61 #include <pqxx/transaction.h>
62 #include "gnucomo_config.h"
65 ///////////////////////////////////////////////////////////////////////////
66 // NAME : gnucomo_database
70 // METHODS : is_connected - Return true if the database is connected
76 // LAST MODIFIED : Aug 17, 2003
77 ///////////////////////////////////////////////////////////////////////////
80 class gnucomo_database
83 pqxx::Connection *dbconn;
84 pqxx::Transaction *dbxact;
86 pqxx::Result last_result;
97 // Use the configuration to connect to the database
99 gnucomo_database(gnucomo_config *c);
101 // A copy constructor and the assignement can copy
102 // the connection to the database must create a
103 // new Transaction object.
105 gnucomo_database(const gnucomo_database &gdb);
106 void operator = (const gnucomo_database &gdb);
110 // Error checking and handling.
114 return dbconn != 0 && dbconn->is_open();
117 // Low-level database access functions
119 int Query(String qry)
122 last_result = dbxact->Exec(qry);
124 std::cerr << "Query " << qry << " returned "
125 << last_result.size() << " tuples.\n";
127 return last_result.size();
130 pqxx::Result Result()
135 String Field(int tuple, const char *fieldname)
137 return String(last_result[tuple][fieldname].c_str());
140 // Return the objectid of the host given its name.
142 String find_host(const String hostname);
144 // Create a new notification.
146 String new_notification(String objectid, String issue, String remark);