gnucomo_database::new_notification() retruns the id number of the
[gnucomo.git] / src / include / database.h
1
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
10 **      SYSTEM NAME    : 
11 **      VERSION NUMBER : $Revision: 1.5 $
12 **
13 **  DESCRIPTION      :  Classes to provide an abstract layer on the Gnucomo
14 **                      database.
15 **
16 **  EXPORTED OBJECTS : 
17 **  LOCAL    OBJECTS : 
18 **  MODULES  USED    :
19 ***************************************************************************
20 **  ADMINISTRATIVE INFORMATION *
21 ********************************
22 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
23 **      CREATION DATE   : Sep 10, 2002
24 **      LAST UPDATE     : Jan 31, 2003
25 **      MODIFICATIONS   : 
26 **************************************************************************/
27
28 /*****************************
29    $Log: database.h,v $
30    Revision 1.5  2003-02-05 09:33:17  arjen
31    gnucomo_database::new_notification() retruns the id number of the
32    newly created notification record.
33
34    Revision 1.4  2003/01/18 08:52:18  arjen
35    New C++ function: gnucomo_database::new_notification()
36
37    Revision 1.3  2002/11/09 08:04:27  arjen
38    Added a reference to the GPL
39
40    Revision 1.2  2002/11/04 10:13:36  arjen
41    Use proper namespace for iostream classes
42
43    Revision 1.1  2002/10/05 10:25:49  arjen
44    Creation of gcm_input and a first approach to a web interface
45
46 *****************************/
47
48 /* static const char *RCSID = "$Id: database.h,v 1.5 2003-02-05 09:33:17 arjen Exp $"; */
49
50 #include <libpq++/pgdatabase.h>
51 #include "gnucomo_config.h"
52
53 /*
54 ///////////////////////////////////////////////////////////////////////////
55 //  NAME           : gnucomo_database
56 //  BASECLASS      : configuration
57 //  MEMBERS        :
58 //  OPERATORS      :
59 //  METHODS        : Database - Obtain the database access string
60 //
61 //  DESCRIPTION    : 
62 //
63 //  RELATIONS      :
64 //  SEE ALSO       :
65 //  LAST MODIFIED  : Jan 17, 2003
66 ///////////////////////////////////////////////////////////////////////////
67 */
68
69 class gnucomo_database
70 {
71    gnucomo_config    *cfg;
72    PgDatabase        *db;
73
74 public:
75
76    gnucomo_database()
77    {
78       cfg = 0;
79       db  = 0;
80    }
81
82    gnucomo_database(gnucomo_config *c);  // Use the configuration to connect to the database
83
84    //  Low-level database access functions
85
86    int Query(String qry)
87    {
88       ExecStatusType  result;
89
90       result = db->Exec(qry);
91       if (result == PGRES_TUPLES_OK || result == PGRES_COMMAND_OK)
92       {
93          return db->Tuples();
94       }
95       else
96       {
97          std::cerr << "Database query error: " << db->ErrorMessage() << "\n";
98          return -1;
99       }
100    }
101
102    String Field(int tuple, const char *fieldname)
103    {
104       return String(db->GetValue(tuple, fieldname));
105    }
106
107    //  Return the objectid of the host given its name.
108
109    String find_host(const String hostname);
110
111    //  Create a new notification.
112
113    String new_notification(String objectid, String issue, String remark);
114 };
115