Advanced Operations : Running a Query on the Current View File

Running a Query on the Current View File
Before querying for audit records described under The Structure of an Audit Record, be sure to have done the following:
n
Run qdmg to generate a script to populate a virtual database with views linked to audit records
n
n
If you’ve completed these tasks, you’re ready to run direct queries for audit records as shown in the continuing example in this section. Steps for a simple query are given, as well as those for a more complex delta query to compare Before and After field values.
‰
1
2
In SQL Editor, the default query SELECT * FROM "Student" returns all rows.
3
4
In Pervasive PSQL Control Center, select File New SQL Document.
5
6
SELECT AM$rec_id, AM$opdate, AM$optext, ID, Cumulative_GPA FROM VStudent
The query should return a result like the following:
AM$rec_id AM$opdate AM$optext ID Cumulative_GPA
========== ========== ============= ========= ==============
637 6/2/2005 Modify Before 190907350 4.000
638 6/2/2005 Modify After 190907350 3.000
‰
For a more complex example, you may run a delta query to compare Before and After values. The general syntax for a delta query is as follows:
SELECT field1, field2,...
FROM view after, view before
WHERE after.AM$rec_id = before.AM$dep_rec_id AND
after.AM$field3 <> before.AM$field3
This type of query will display audit records for every instance of an update to field 3. For a large set of audit records, however, such a query may return too large a result. In this example, we will limit the delta query to a specific student ID.
1
2
SELECT after.AM$rec_id, after.AM$opdate, after.AM$optime, after.AM$net_user_id, before.Cumulative_GPA AS "GPA Before", after.Cumulative_GPA AS "GPA After"
FROM "VStudent" after, "VStudent" before
WHERE after.ID = '190907350' AND after.AM$rec_id = before.AM$dep_rec_id
AND after.Cumulative_GPA <> before.Cumulative_GPA;
The query should return a result like the following:
AM$rec_id AM$opdate AM$optime AM$net_user_id GPA Before GPA After
========= ========== ========== ============== ========== ==========
637 6/2/2005 6:23:49 PM db_user 4.000 3.000
Note