Stored procedure to insert a new record Default: The SQL to perform the insert. For example, if you need to use the following stored procedure NewRow to insert a record for a table with columns col1 and col2, we would use:
call NewRow({col1},{col2})
and the variables {col1} and {col2} will be substituted with the correct values. Only columns that are defined in newLens and readonlyLens will be substituted in.
If the first character is '=', then it is evaluated by PHP first like the powerLens.
New in phpLens 2.0 is support for calling PHP programs. Simply prepend an = sign to your code. Before phpLens 3.1, we always assume that spNew succeeds and the return value is ignored. In 3.1 and later, if you return:
-1: Show New Record form and display SQL error message
-2: Show New Record form, and do not display any error message
array($error): Show New Record form, display $error msg (phpLens 3.3+)
other values: Assume successful save, switch to the firstState.
For example:
$lens->spNew = '=ProcessRec({name},{postcode});
function ProcessRec($name, $postcode)
{
global $DB;
if (strlen($postcode) < 5) {
printError("Invalid postcode");
return -2;
}
return DoStoreRecord($name,$postcode);
}
To perform validation, use the eventPreInsertField property.
Commits
We use the default auto-commit behaviour. If you want to control your own transactions, you will need to use $DB->BeginTrans() and $DB->EndTrans(), assuming that $DB has been pre-defined as the database connection.
Error Handling
Using this property means that you, the programmer, will have to code all the error-handling (eg. duplicate record errors, constraint violations) and error message display yourself. Database error messages can be retrieved using
$err = $DB->ErrorMsg();
assuming your database connection global variable is $DB. If no error occurred, $err will be empty.Syntax
$lens->spNew = 'call NewRow({col1},{col2})';
or
$lens->spNew = 'insert into table values({col1},{col2})';
or
$lens->spNew = '=PHPFunction({col1},{col2})'; Basic:Yes Advanced/Enterprise:Yes DynamicEdit:Yes [Version 1.0]
|