Re: expect()/popExpect()
| From: | Greg Beaver | Date: | Fri, 01 Oct 2004 21:09:52 +0000 |
| Subject: | Re: expect()/popExpect() | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-33607@lists.php.net to get a copy of this message | ||
Lukas Smith wrote:
Here is the piece of code inside MDB2 which I would have to modify. Could you give me some more hints how I would need to transform the code in question? $this->expectError(MDB2_ERROR_NOSUCHTABLE); $result =& $this->_doQuery($query); $this->popExpect(); if (MDB2::isError($result)) { if ($ondemand && $result->getCode() == MDB2_ERROR_NOSUCHTABLE) {The implementation of expectError() is pretty straightforward. You actually would only need to change the MDB2::isError(). If you would like to keep it, this is still possible, all you need to do is do the reverse of what I have here - push and log only if it is a MDB2_ERROR_NOSUCHTABLE, and pass everything else to the default callback. I'm assuming in this example, that there is a callback that MDB2 already has set which will end the script. If in fact, you want to handle the possibility of all callbacks set by the user, you'll need a bit more checking (if the callback is false, then grab the default callback and use it for _oldCallback()) function doExpectError($err) {// handle the expected error ..} }
if (in_array($err['code'], $this->_expectedErrors)) {
$this->_flag[] = $err; // one possibility
return PEAR_ERRORSTACK_IGNORE;
} else {
if (is_callable($this->_oldCallback)) {
return $this->_oldCallback($err);
}
}
}
function expectError($errors)
{
if (!is_array($errors)) {
$errors = array($errors);
}
$this->_oldCallback = $this->_stack->popCallback();
if ($this->_oldCallback) { // save the existing callback
$this->_stack->pushCallback($this->_oldCallback());
}
$this->_expectedErrors = $errors;
$this->_stack->pushCallback(array(&$this, 'doExpectError'));
}
function popExpect()
{
$this->_expectedErrors = array();
$this->_stack->popCallback();
}
.....
$this->expectError(MDB2_ERROR_NOSUCHTABLE);
$result = &$this->doQuery();
$this->popExpect();
if (count($this->_flag) && $ondemand) {
// handle the error}