5fb2323e7a0765cc36d1bc6801cfb470e0017e0a
[gnucomo.git] / src / include / database.h
1
2 /**************************************************************************
3 **  (c) Copyright 2002, Andromeda Technology & Automation
4 ***************************************************************************
5 ** MODULE INFORMATION *
6 ***********************
7 **      FILE NAME      : database.h
8 **      SYSTEM NAME    : 
9 **      VERSION NUMBER : $Revision: 1.1 $
10 **
11 **  DESCRIPTION      :  Classes to provide an abstract layer on the Gnucomo
12 **                      database.
13 **
14 **  EXPORTED OBJECTS : 
15 **  LOCAL    OBJECTS : 
16 **  MODULES  USED    :
17 ***************************************************************************
18 **  ADMINISTRATIVE INFORMATION *
19 ********************************
20 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
21 **      CREATION DATE   : Sep 10, 2002
22 **      LAST UPDATE     : 
23 **      MODIFICATIONS   : 
24 **************************************************************************/
25
26 /*****************************
27    $Log: database.h,v $
28    Revision 1.1  2002-10-05 10:25:49  arjen
29    Creation of gcm_input and a first approach to a web interface
30
31 *****************************/
32
33 /* static const char *RCSID = "$Id: database.h,v 1.1 2002-10-05 10:25:49 arjen Exp $"; */
34
35 #include <libpq++/pgdatabase.h>
36 #include "gnucomo_config.h"
37
38 /*
39 ///////////////////////////////////////////////////////////////////////////
40 //  NAME           : gnucomo_database
41 //  BASECLASS      : configuration
42 //  MEMBERS        :
43 //  OPERATORS      :
44 //  METHODS        : Database - Obtain the database access string
45 //
46 //  DESCRIPTION    : 
47 //
48 //  RELATIONS      :
49 //  SEE ALSO       :
50 //  LAST MODIFIED  : Sep 16, 2002
51 ///////////////////////////////////////////////////////////////////////////
52 */
53
54 class gnucomo_database
55 {
56    gnucomo_config    *cfg;
57    PgDatabase        *db;
58
59 public:
60
61    gnucomo_database()
62    {
63       cfg = 0;
64       db  = 0;
65    }
66
67    gnucomo_database(gnucomo_config *c);  // Use the configuration to connect to the database
68
69    //  Low-level database access functions
70
71    int Query(String qry)
72    {
73       ExecStatusType  result;
74
75       result = db->Exec(qry);
76       if (result == PGRES_TUPLES_OK || result == PGRES_COMMAND_OK)
77       {
78          return db->Tuples();
79       }
80       else
81       {
82          cerr << "Database query error: " << db->ErrorMessage() << "\n";
83          return -1;
84       }
85    }
86
87    //  Return the objectid of the host given its name.
88
89    String find_host(const String hostname);
90 };
91