2 /**************************************************************************
3 ** (c) Copyright 2002, Andromeda Technology & Automation
4 ***************************************************************************
5 ** MODULE INFORMATION *
6 ***********************
7 ** FILE NAME : database.cpp
8 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
9 ** VERSION NUMBER : $Revision: 1.1 $
11 ** DESCRIPTION : Implementation of the gnucomo database classes
16 ***************************************************************************
17 ** ADMINISTRATIVE INFORMATION *
18 ********************************
19 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
20 ** CREATION DATE : Sep 10, 2002
21 ** LAST UPDATE : Sep 26, 2002
23 **************************************************************************/
25 /*****************************
26 $Log: database.cpp,v $
27 Revision 1.1 2002-10-05 10:25:49 arjen
28 Creation of gcm_input and a first approach to a web interface
30 *****************************/
32 static const char *RCSID = "$Id: database.cpp,v 1.1 2002-10-05 10:25:49 arjen Exp $";
36 extern bool verbose; /* Defined in the main application */
38 /*=========================================================================
39 ** NAME : gnucomo_database
40 ** SYNOPSIS : gnucomo_database(gnucomo_config &c);
42 ** RETURN VALUE : Database constructor. Establishes a connection with
43 ** the database server.
51 ** LAST MODIFIED : Sep 26, 2002
52 **=========================================================================
55 gnucomo_database::gnucomo_database(gnucomo_config *c)
61 cout << "Database connection string = " << cfg->Database() << "\n";
64 db = new PgDatabase(cfg->Database());
66 if (db->ConnectionBad())
68 cerr << "Can not connect to database: " << db->ErrorMessage();
72 /*=========================================================================
74 ** SYNOPSIS : String gnucomo_database::find_host(String hostname);
76 ** RETURN VALUE : Find a hostname in the 'object' table of the gnucomo database
77 ** and return its object id.
78 ** Return an empty string as objectid if the hostname is
87 ** LAST MODIFIED : Sep 16, 2002
88 **=========================================================================
91 String gnucomo_database::find_host(const String hostname)
94 String check_host("select objectid from object where ");
96 check_host += "objectname = '";
97 check_host += hostname;
100 if (Query(check_host) > 0)
102 objectid = String(db->GetValue(0, "objectid"));