Capture INNODB - ON DELETE Restrict Errors
Archived from the Xataface Users forum.
Paul — Mon Feb 25, 2008 11:29 pm
Hi Steve,
Im using INNODB Tables and have all my relationships working well with xataface eg. Cascade Updates work perfect.
I have some foreign key restraints on my tables of ON DELETE Restrict as I don’t want users to accidentally delete a parent record and result in all the children records being deleted.
So now if I try to delete a parent I get this error (see below) which is correct referential integrity is being maintained.
How can I capture this error and return a simple message “Record cannot be deleted due to existing child records”
ERROR:
Fatal error: [pear_error: message=”Failed to delete record ‘AG Stn2’ because of an SQL error: ‘Cannot delete or update a parent row: a foreign key constraint fails (roxspacetest/outcropsample, CONSTRAINT outcropsample\_ibfk\_9 FOREIGN KEY (Station\_idStation) REFERENCES station (idStation) ON UPDATE CASCADE)’” code=321 mode=return level=notice prefix=”” info=””] in C:\Program Files\xampp\htdocs\dataface\Dataface\Application.php on line 1323
Regards
Paul
shannah — Tue Feb 26, 2008 8:14 am
One quick way would be to change the level of a delete error from an error to a warning.
You can do this by modifying the Dataface/Error.php file as follows:
Near the top you’ll see:
- Code: Select all
define('DATAFACE_E_DELETE_FAILED', 321);
Change the code to something between 100 and 199 (this is the range of warnings). E.g. change it to
- Code: Select all
define('DATAFACE_E_DELETE_FAILED', 121);
This will at least cause Xataface to show the error as part of an info dialog rather than a fatal error.
Another way to improve the display of fatal errors is to implement your own error handler:
http://ca3.php.net/manual/en/function.s … andler.php
Best regards
Steve
Paul — Tue Feb 26, 2008 3:44 pm
Thanks Steve,
Changing to
- Code: Select all
define('DATAFACE_E_DELETE_FAILED', 121)
worked exactly how I wanted it to. This will do me for now. I will work on implementing my own error handler latter.
cheers
Paul