Use proper namespace for iostream classes
[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.2 $
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     : Nov 04, 2002
23 **      MODIFICATIONS   : 
24 **************************************************************************/
25
26 /*****************************
27    $Log: database.h,v $
28    Revision 1.2  2002-11-04 10:13:36  arjen
29    Use proper namespace for iostream classes
30
31    Revision 1.1  2002/10/05 10:25:49  arjen
32    Creation of gcm_input and a first approach to a web interface
33
34 *****************************/
35
36 /* static const char *RCSID = "$Id: database.h,v 1.2 2002-11-04 10:13:36 arjen Exp $"; */
37
38 #include <libpq++/pgdatabase.h>
39 #include "gnucomo_config.h"
40
41 /*
42 ///////////////////////////////////////////////////////////////////////////
43 //  NAME           : gnucomo_database
44 //  BASECLASS      : configuration
45 //  MEMBERS        :
46 //  OPERATORS      :
47 //  METHODS        : Database - Obtain the database access string
48 //
49 //  DESCRIPTION    : 
50 //
51 //  RELATIONS      :
52 //  SEE ALSO       :
53 //  LAST MODIFIED  : Sep 16, 2002
54 ///////////////////////////////////////////////////////////////////////////
55 */
56
57 class gnucomo_database
58 {
59    gnucomo_config    *cfg;
60    PgDatabase        *db;
61
62 public:
63
64    gnucomo_database()
65    {
66       cfg = 0;
67       db  = 0;
68    }
69
70    gnucomo_database(gnucomo_config *c);  // Use the configuration to connect to the database
71
72    //  Low-level database access functions
73
74    int Query(String qry)
75    {
76       ExecStatusType  result;
77
78       result = db->Exec(qry);
79       if (result == PGRES_TUPLES_OK || result == PGRES_COMMAND_OK)
80       {
81          return db->Tuples();
82       }
83       else
84       {
85          std::cerr << "Database query error: " << db->ErrorMessage() << "\n";
86          return -1;
87       }
88    }
89
90    //  Return the objectid of the host given its name.
91
92    String find_host(const String hostname);
93 };
94