From 9858018b407d81b1f9fd8440e719f1348d26430b Mon Sep 17 00:00:00 2001 From: dairiki Date: Wed, 19 Sep 2001 19:20:30 +0000 Subject: [PATCH] Search some standard locations for PEAR library code if DB.php is not found in PHP's include_path. Added some workarounds for a bug in the PEAR DB code which ships with PHP 4.0.6. (I have now tested the MySQL backend with PEAR code from PHP 4.0.4pl1, PHP 4.0.5 and PHP 4.0.6. Only the 4.0.6 code is buggy. With the new fixes, all three versions seem to work fine. The bug is reported to be fixed in the CVS version of the PHP source code.) git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@568 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/WikiDB/backend/PearDB.php | 55 ++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/lib/WikiDB/backend/PearDB.php b/lib/WikiDB/backend/PearDB.php index 575d4eb55..da99ea27f 100644 --- a/lib/WikiDB/backend/PearDB.php +++ b/lib/WikiDB/backend/PearDB.php @@ -1,13 +1,23 @@ includeOnce('DB.php'); + + // Install filter to handle bogus error notices from buggy DB.php's. + global $ErrorManager; + $ErrorManager->pushErrorHandler(array($this, '_pear_notice_filter')); + // Open connection to database $dsn = $dbparams['dsn']; $this->_dbh = DB::connect($dsn, true); //FIXME: true -> persistent connection @@ -633,10 +643,31 @@ extends WikiDB_backend * @param A PEAR_error object. */ function _pear_error_callback($error) { + if ($this->_is_false_error($error)) + return; + $this->_dbh->setErrorHandling(PEAR_ERROR_PRINT); // prevent recursive loops. $this->close(); - //trigger_error($this->_pear_error_message($error), E_USER_WARNING); - ExitWiki($this->_pear_error_message($error)); + trigger_error($this->_pear_error_message($error), E_USER_ERROR); + } + + /** + * Detect false errors messages from PEAR DB. + * + * The version of PEAR DB which ships with PHP 4.0.6 has a bug in that + * it doesn't recognize "LOCK" and "UNLOCK" as SQL commands which don't + * return any data. (So when a "LOCK" command doesn't return any data, + * DB reports it as an error, when in fact, it's not.) + * + * @access private + * @return bool True iff error is not really an error. + */ + function _is_false_error($error) { + $code = $error->getCode(); + $query = $this->_dbh->last_query; + return ($code == DB_ERROR + && ! DB::isManip($query) + && preg_match('/^\s*"?(LOCK|UNLOCK)\s/', $query)); } function _pear_error_message($error) { @@ -647,6 +678,22 @@ extends WikiDB_backend return $message; } + + /** + * Filter PHP errors notices from PEAR DB code. + * + * The PEAR DB code which ships with PHP 4.0.6 produces spurious + * errors and notices. This is an error callback (for use with + * ErrorManager which will filter out those spurious messages.) + * @see _is_false_error, ErrorManager + * @access private + */ + function _pear_notice_filter($err) { + return ( $err->isNotice() + && $err->errfile == 'DB/common.php' + && $err->errline == 126 + && preg_match('/Undefined offset: +0\b/', $err->errstr) ); + } }; class WikiDB_backend_PearDB_iter -- 2.45.0