Capture INNODB - ON DELETE Restrict Errors

A place for users and developers of the Xataface to discuss and receive support.

Capture INNODB - ON DELETE Restrict Errors

Postby 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
Paul
 
Posts: 20
Joined: Wed Jan 30, 2008 12:04 am

Postby 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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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
Paul
 
Posts: 20
Joined: Wed Jan 30, 2008 12:04 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 17 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved