A database delete operation (under the comment text "Delete existing records" in the previous example) would look like:
database phbook action="delete";
However, deleting multiple records from a database table in one operation is not always a good idea. It is recommended NOT to use the "delete" action. Instead, update the deleted records with a "flag" value in a particular field (e.g. 0 qty for a shopping cart item or false in the Active field), then either delete all flagged records afterwards via a query (optionally after user confirmation) or leave them there but skip them in subsequent processing.
As a protection from programming error, BEE will NOT delete multiple records based on a matrix, even if the "delete" action is used. Instead, it will only select the first record from the matrix, extract its key value (the value of the field indicated by "keyfield"), delete just that record and stop.
The query would look like "delete from table where keyfield = keyvalue".
If you really want to delete multiple records, you can either specify the "query" parameter or to specify the "search" variable as in a "select" operation. (The variable "keyfield" should be cleared in order to have the "delete" operation use the "search" variable to build the where-clause. Otherwise, it will use the key field of the first matrix record as mentioned before.)
The error code and error message are contained in status%database and message%database respectively. (For the integrity of the database object, you will have them in the database object as well. In our example, they are phbook%status and phbook%message.)
|