DBC BEFOREINSERT

From Lianjapedia
Revision as of 05:58, 20 October 2016 by Yvonne.milne (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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_BEFOREINSERT database event is triggered prior to committing an insert operation when a database is open and runs dbc_beforeinsert.prg (.dbo compiled/runtime) if it exists.

If dbc_beforeinsert returns .F. (false) the insert 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_beforeinsert 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_beforeinsert 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_beforeinsert
//
parameters cDatabase, cTable, cJSON
userlog("====================================")
userlog("Before 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 Before Insert")
userlog("====================================")
return .t.