Back
eventPostInsertSQL
Editing, Updating and Creating Records
eventPostInsertSQL
Name of function to call after New Record is created
Default:
The function is passed 3 parameters. The first parameter is $key, the primary key. The second is $insertok which is set to true if the record was inserted correctly. The 3rd parameter is the $lens object.

Due to a bug, in phpLens 4.0.4 or earlier, $insertok returned the strings 'true' or 'false'. In 4.0.5, $insertok will return 'true' (string) if the insert succeeded or false (boolean) if the insert failed.

Note that some PHP extensions do not support the insert_id() function such as Oracle/OCI8 and Interbase (we set $key to the OID in PostgreSQL). For those databases, the $key variable will be empty. If you are using sequences to set the default value of the primary key, then you can still obtain the current value of the sequence. For example if you are using oci8 and $seqname holds the name of your sequence:

$rs = $lens->connection->Execute("SELECT $seqname.currval FROM dual");
$key = $rs->fields[0];

Syntax
function preinsert($lens)
{
GLOBAL $HTTP_POST_VARS;

$lens->connection->BeginTrans();
}


function postinsert($key, $insertok, $lens)
{
if ($insertok) {
$rs = $lens->Execute("insert into childtable (parent) values ($key)");
if ($rs) $lens->connection->CommitTrans();
else $insertok = false;
}

if (!$insertok) {
$lens->connection->RollbackTrans();
}
}

$lens->eventPreInsertSQL = 'preinsert';
$lens->eventPostInsertSQL = 'postinsert';

 Basic:Yes  Advanced/Enterprise:Yes  DynamicEdit:Yes   [Version 1.0]