onBeforeSQLCommandExecute and onAfterSQLCommandExecute Events


In a Grid component that is based on a SQL database, the Insert, Update and Delete SQL statements that are executed when a user inserts, updates or deletes a record are automatically computed by Alpha Anywhere. In some cases, a user might want more control over how these SQL statements are executed, or might want to use stored procedures to insert, update or delete records.

The onBeforerSQLCommandExecuteand onAfterSQLCommandExecuteserver side events allow you fully customize the SQL statements that the Grid executes in order to insert, update or delete records. In addition, another common use for these events is to update some other table at the same time as the update is being performed in the tables the Grid is based on. For example, you might want to add a record to a log table. When you perform updates against some other table as part of our update, insert or delete, you might want to wrap the entire operation into a single transaction. This is easily done by starting a transaction in the onBeforeSQLCommandExecuteevent and then either committing or rolling back the transaction in the onAfterSQLCommandExecuteevent. In the onBeforeSQLCommandExecuteevent you can execute any SQL that you want. If you choose to handle the update, delete or insert operation yourself, you can set the .SQLCommandWasHandled event to .t. and then Alpha Anywhere will not execute the SQL that it computed. On the other hand you might use the onBeforeSQLCommandExecuteevent to modify in some way the SQL that Alpha Anywhere generated, but not actually execute the SQL . In this case you will set the .SQLCommandWasHandled event to .f.