#ifndef __AUDIT_TRAIL_H #define __AUDIT_TRAIL_H /*------------------------------------------------------------------------- * Copyright (c) 2000-2002 Kenneth W. Sodemann (stuffle@charter.net) *------------------------------------------------------------------------- * $Id: audit_trail.h,v 1.1 2003/03/09 20:59:11 stuffle Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA *------------------------------------------------------------------------- */ /*! \file audit_trail.h \brief Audit trail macros This file contains two macros, \b PR_SUBMIT_DATE_QUERY and \b SELECT_AUDIT_TRAIL. These macros define the SQL that is needed when fetching the audit trail information from the database. \b PR_SUBMIT_DATE_QUERY is used to get the submittion information. \b SELECT_AUDIT_TRAIL is used to get the rest of the audit trail. Typical code that fetches and prints out the audit trail will look like this (C compilers hate embedded C-style comments, so I put C++ style comments in the code example): \code // For this code snippet, the following variables are defined // and setup: // sql_buffer : already allocated GString* (see glib) // pr_pk : primary key of problem report // conn : pointer to database connection (see libpq) // res : result pointer to store our results (see libpq) // First, get the submittion information for the problem report. // This information consists of who submitted it, and when. The // query should only return on row (if it ever returns more, there // is serious trouble). g_string_sprintf (sql_buffer, PR_SUBMIT_DATE_QUERY, pr_pk); res = PQexec (conn, sql_buffer->str); fprintf (out_file, "%s\n", PQgetvalue (res, 0, 0)); PQclear (res); // After this, get the rest of the audit trail information. This // query may return more than one row, so we need to loop through // the results to get them all. g_string_sprintf (sql_buffer, SELECT_AUDIT_TRAIL, pr_pk, pr_pk); res = PQexec (conn, sql_buffer->str); num = PQntuples (res); for (i = 0; i < num; i++) { fprintf (out_file, "%s\n", PQgetvalue (res, i, 0)); } \endcode \author Kenneth W. Sodemann (stuffle@charter.net) $Revision: 1.1 $ $Date: 2003/03/09 20:59:11 $ */ #define SELECT_AUDIT_TRAIL "\ SELECT at.the_date || ' - Status changed from ' || stat1.name || \ ' to ' || stat2.name || ' by ' || at.login_id \ FROM audit_trail at, status stat1, status stat2 \ WHERE stat1.status_num = at.prev_state \ AND stat2.status_num = at.new_state \ AND at.prev_state <> at.new_state \ AND at.problem_num = %d \ UNION \ SELECT at.the_date || ' - Severity changed from ' || sevr1.name || \ ' to ' || sevr2.name || ' by ' || at.login_id \ FROM audit_trail at, severity sevr1, severity sevr2 \ WHERE sevr1.severity_num = at.prev_sevr \ AND sevr2.severity_num = at.new_sevr \ AND at.prev_sevr <> at.new_sevr \ AND at.problem_num = %d \ ORDER BY 1 " #define PR_SUBMIT_DATE_QUERY "\ SELECT creation_date || ' - Problem report submitted by ' || submitter_id \ FROM problem_report \ WHERE problem_num = %d " #endif