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.2 $
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 : Nov 04, 2002
23 **************************************************************************/
25 /*****************************
26 $Log: database.cpp,v $
27 Revision 1.2 2002-11-04 10:13:36 arjen
28 Use proper namespace for iostream classes
30 Revision 1.1 2002/10/05 10:25:49 arjen
31 Creation of gcm_input and a first approach to a web interface
33 *****************************/
35 static const char *RCSID = "$Id: database.cpp,v 1.2 2002-11-04 10:13:36 arjen Exp $";
39 extern bool verbose; /* Defined in the main application */
41 /*=========================================================================
42 ** NAME : gnucomo_database
43 ** SYNOPSIS : gnucomo_database(gnucomo_config &c);
45 ** RETURN VALUE : Database constructor. Establishes a connection with
46 ** the database server.
54 ** LAST MODIFIED : Sep 26, 2002
55 **=========================================================================
58 gnucomo_database::gnucomo_database(gnucomo_config *c)
64 std::cout << "Database connection string = " << cfg->Database() << "\n";
67 db = new PgDatabase(cfg->Database());
69 if (db->ConnectionBad())
71 std::cerr << "Can not connect to database: " << db->ErrorMessage();
75 /*=========================================================================
77 ** SYNOPSIS : String gnucomo_database::find_host(String hostname);
79 ** RETURN VALUE : Find a hostname in the 'object' table of the gnucomo database
80 ** and return its object id.
81 ** Return an empty string as objectid if the hostname is
90 ** LAST MODIFIED : Sep 16, 2002
91 **=========================================================================
94 String gnucomo_database::find_host(const String hostname)
97 String check_host("select objectid from object where ");
99 check_host += "objectname = '";
100 check_host += hostname;
103 if (Query(check_host) > 0)
105 objectid = String(db->GetValue(0, "objectid"));