DBC BEFOREDELETE
Contents
Purpose
Database events are triggered by certain database operations
See Also
ADATABASES(), ALTER TABLE, ADD TABLE, ALTER INDEX, BASE64_DECODE(), BASE64_ENCODE(), CLOSE DATABASES, CLOSE TABLES, COMPILE DATABASE, CREATE DATABASE, CREATE TABLE, CREATE INDEX, CREATE VIEW, DATABASE(), Database Events, DBUSED(), DISPLAY DATABASE, DISPLAY INDEXES, DISPLAY TABLES, DROP DATABASE, DROP INDEX, DROP TABLE, GETENV(), LIST DATABASE, LIST INDEXES, LIST TABLES, OPEN DATABASE, PACK DATABASE, REBUILD DATABASE, REINDEX DATABASE, SET AUTOCATALOG, SET EXCLUSIVE, USE, USERLOG()
Description
The DBC_BEFOREDELETE database event is triggered prior to committing a delete operation when a database is open and runs dbc_beforedelete.prg (.dbo compiled/runtime) if it exists.
If dbc_beforedelete returns .F. (false) the delete operation is cancelled.
Programs associated with database events should reside in the database's directory. These can be created and modified from the Events tab in the Data Workspace when a database is open.
The following parameters are passed to the dbc_beforedelete program:
Parameter | Description |
---|---|
<cDatabase> | The database name |
<cTable> | The table name |
<cJSON> | Base64 encoded JSON data for the operation. See notes below. |
<cJSON>
<cJSON> is populated on the Web and Mobile clients. For the Desktop client, where <cJSON> is empty, the current record is accessible and can be queried using standard Lianja/VFP functions (recno(), field(), fldcount() etc.).
If the JSON data exceeds the maximum command line length (16KB), <cJSON> will contain '@' and the data can be accessed using the JSONDATASTRING() function up to maximum string length (64KB).
For the dbc_beforedelete event, <cJSON> will contain the rowid, e.g.
{"__rowid":19}
Example
// // Database: dbcdoc // Event: dbc_beforedelete // parameters cDatabase, cTable, cJSON userlog("====================================") userlog("Before Delete in "+"dbcdoc database") userlog("Database: " +cDatabase) userlog("Table: " +cTable) if ! isserver() userlog("Delete record number: " + etos(recno()) else userlog("JSON: " +base64_decode(cJSON)) endif userlog("End of Before Delete") userlog("====================================") return .t.