DBC AFTERINSERT

From Lianjapedia
Jump to: navigation, search

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_AFTERINSERT database event is triggered following an insert operation when a database is open and runs dbc_afterinsert.prg (.dbo compiled/runtime) if it exists.

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_afterinsert 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_afterinsert event, <cJSON> will contain the data for the new record, e.g.

{"shipperid":4,"companyname":"Acme International Inc.","phone":"(123) 456 7890"}

Example

//
// Database: dbcdoc 
// Event: dbc_afterinsert
//
parameters cDatabase, cTable, cJSON
userlog("====================================")
userlog("After Insert in "+"dbcdoc database")
userlog("Database: " +cDatabase)
userlog("Table: " +cTable)
if ! isserver()
	for i = 1 to fldcount()
		if type("&(field(i))") = "G"
			loop
		endif		
		userlog("Field: " + field(i))
		userlog("Value: " + etos(&(field(i))))
	endfor
else
	userlog("JSON: " + base64_decode(cJSON))
endif
userlog("End of After Insert")
userlog("====================================")
return .t.