PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB_DataObject_FormBuilder » Bug #3096

processForm() should quit and return errors when they occur

Details

Submitted2005-01-04 17:32 UTC
Fromate2 at cornell dot edu
Assignedjustinpatrin
StatusClosed
PackageDB_DataObject_FormBuilder
PHP VersionIrrelevant
OSIrrelevant (but Debian sarge)
Roadmaps(Not assigned)

Comments

[2005-01-04 17:32 UTC] ate2 at cornell dot edu

Description:
------------
The processForm() method does a lot of database
operations and from what I can tell it does not return
any errors. Often, I want to handle certain errors that
only occur after attempting to insert/update a record
(i.e. report to a user that the unique "title" they
selected for the record is already taken, handle complex
multi-query transactions where an error should trigger a
rollback() call).
It seems to me that any call to insert(), update(),
delete() or any other method that returns errors should
be followed by a check.
Thanks.

Reproduce code:
---------------
$do =& new DB_DataObject();
$db =& $do->getDatabaseConnection();
$fb =& DB_DataObject_FormBuilder::create($do);
$form =& $fb->getForm();
if ($form->validate()) {
$db->autoCommit(false);
$e = $fb->processForm();
if (PEAR::isError($e)) {
echo "Ack! Error occurred during processing.";
$db->rollback();
}
echo "Transaction succeeded!";
$db->commit();
$form->freeze();
}
echo $form->toHtml();

Expected result:
----------------
"Ack! Error occurred during processing."

Actual result:
--------------
"Transaction succeeded!"

[2005-01-04 21:50 UTC] ate2 at cornell dot edu

Something I didn't understand before (maybe you also
weren't aware):
DB_DataObject methods don't normally return errors.
Instead they stop short and store the error in $do-
>_lastError .
There's also supposed to be a "static"
variable that stores the most recent DBDO error, but it
seems like that is not in the present implementation of
DBDO (see bug #3098). But presently there's no proper
public means of accessing the error. Strange.