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.cpp
10 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
11 ** VERSION NUMBER : $Revision: 1.3 $
13 ** DESCRIPTION : Implementation of the gnucomo database classes
18 ***************************************************************************
19 ** ADMINISTRATIVE INFORMATION *
20 ********************************
21 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
22 ** CREATION DATE : Sep 10, 2002
23 ** LAST UPDATE : Nov 04, 2002
25 **************************************************************************/
27 /*****************************
28 $Log: database.cpp,v $
29 Revision 1.3 2002-11-09 08:04:27 arjen
30 Added a reference to the GPL
32 Revision 1.2 2002/11/04 10:13:36 arjen
33 Use proper namespace for iostream classes
35 Revision 1.1 2002/10/05 10:25:49 arjen
36 Creation of gcm_input and a first approach to a web interface
38 *****************************/
40 static const char *RCSID = "$Id: database.cpp,v 1.3 2002-11-09 08:04:27 arjen Exp $";
44 extern bool verbose; /* Defined in the main application */
46 /*=========================================================================
47 ** NAME : gnucomo_database
48 ** SYNOPSIS : gnucomo_database(gnucomo_config &c);
50 ** RETURN VALUE : Database constructor. Establishes a connection with
51 ** the database server.
59 ** LAST MODIFIED : Sep 26, 2002
60 **=========================================================================
63 gnucomo_database::gnucomo_database(gnucomo_config *c)
69 std::cout << "Database connection string = " << cfg->Database() << "\n";
72 db = new PgDatabase(cfg->Database());
74 if (db->ConnectionBad())
76 std::cerr << "Can not connect to database: " << db->ErrorMessage();
80 /*=========================================================================
82 ** SYNOPSIS : String gnucomo_database::find_host(String hostname);
84 ** RETURN VALUE : Find a hostname in the 'object' table of the gnucomo database
85 ** and return its object id.
86 ** Return an empty string as objectid if the hostname is
95 ** LAST MODIFIED : Sep 16, 2002
96 **=========================================================================
99 String gnucomo_database::find_host(const String hostname)
102 String check_host("select objectid from object where ");
104 check_host += "objectname = '";
105 check_host += hostname;
108 if (Query(check_host) > 0)
110 objectid = String(db->GetValue(0, "objectid"));