Main Page   File List   File Members  

audit_trail.h File Reference

Audit trail macros. More...

Go to the source code of this file.

Defines

#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 "


Detailed Description

Audit trail macros.

This file contains two macros, PR_SUBMIT_DATE_QUERY and SELECT_AUDIT_TRAIL. These macros define the SQL that is needed when fetching the audit trail information from the database.

PR_SUBMIT_DATE_QUERY is used to get the submittion information.

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):

 // 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));
    }

Author:
Kenneth W. Sodemann (stuffle@charter.net)
Revision:
1.7
Date:
2002/01/30 00:40:02


Generated on Sun Oct 20 18:15:09 2002 for libPRepS by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002