a5Helper_getAuditInfoFromSQLStatement Function
Syntax
dim resultJSON as C = a5Helper_getAuditInfoFromSQLStatement(cn as sql::Connection, sql as C, argsxml as C [, comment as C])
Arguments
- cnSQL::Connection
An open connection to the database where the audit table is located.
- sqlCharacter
An INSERT, UPDATE, or DELETE SQL statement.
- argsxmlCharacter
The arguments referenced by the SQL statement in XML format. See the SQL::Arguments XML property to retrieve arguments in an XML format from a SQL::Arguments object.
- commentCharacter
An optional comment to include in the audit log, such as the name of the script that performs the update.
Returns
- resultJSONCharacter
Returns a JSON object that contains the information for the audit table. If auditing is not enabled in the Web Project Properties, this function will return an empty string. The JSON object contains the following properties:
- fields
An array of objects containing the following properties:
- fieldname
The name of the field in the table being modified.
- value
The new value.
- oldvalue
The original value.
- operation
The type of operation being performed: UPDATE, INSERT, or DELETE.
- tableName
The name of the table being modified.
Description
Computes the fields and operation for a SQL statement as a JSON object in an application with auditing enabled.
Discussion
The a5Helper_getAuditInfoFromSQLStatement function takes a SQL statement (INSERT, UPDATE, or DELETE) and a set of arguments defined as XML and generates the information to log in the Audit Table.
Example
dim cn as sql::Connection cn.open("::Name::Northwind") dim args as sql::arguments args.add("primaryKey","ALFKI") args.add("title","Manager") dim sql as c sql = "update Customers set ContactTitle = :title where CustomerID = :primaryKey" 'capture the BEFORE update values dim dataJson as c dataJson = a5Helper_getAuditInfoFromSQLStatement(cn,sql,args.xml) ? dataJson = { "fields": "[\n{\n\t\"fieldname\": \"ContactTitle\",\n\t\"value\": \"Manager\",\n\t\"oldvalue\": \"Sales Representative\"\n}]", "operation": "Update", "tableName": "Customers" }
This function does not support multi-row updates.
Limitations
Used in Web Applications Configured to use an Audit Table
See Also