cvs: pear(MDB_1) /MDB/MDB fbsql.php ibase.php mssql.php mysql.php oci8.php pgsql.php /MDB/doc skeleton.php
| From: | Lukas Smith | Date: | Fri, 12 Mar 2004 16:19:31 +0000 |
| Subject: | cvs: pear(MDB_1) /MDB/MDB fbsql.php ibase.php mssql.php mysql.php oci8.php pgsql.php /MDB/doc skeleton.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-17348@lists.php.net to get a copy of this message | ||
lsmith Fri Mar 12 11:19:31 2004 EDT
Modified files: (Branch: MDB_1)
/pear/MDB/MDB fbsql.php ibase.php mssql.php mysql.php oci8.php
pgsql.php
/pear/MDB/doc skeleton.php
Log:
- unified the native error raising methods (tested on oracle, pgsql and mysql)
http://cvs.php.net/diff.php/pear/MDB/MDB/fbsql.php?r1=1.16.4.14&r2=1.16.4.15&ty=u Index: pear/MDB/MDB/fbsql.php diff -u pear/MDB/MDB/fbsql.php:1.16.4.14 pear/MDB/MDB/fbsql.php:1.16.4.15 --- pear/MDB/MDB/fbsql.php:1.16.4.14 Wed Mar 10 09:42:29 2004 +++ pear/MDB/MDB/fbsql.php Fri Mar 12 11:19:30 2004 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@dybnet.de> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.16.4.14 2004/03/10 14:42:29 lsmith Exp $ +// $Id: fbsql.php,v 1.16.4.15 2004/03/12 16:19:30 lsmith Exp $ // require_once('MDB/Common.php'); @@ -146,16 +146,27 @@ * that checks for native error msgs. * * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error */ - function fbsqlRaiseError($errno = NULL) + function fbsqlRaiseError($errno = NULL, $message = NULL) { if ($errno == NULL) { - $errno = $this->errorCode(@fbsql_errno($this->connection)); + if ($this->connection) { + $errno = @fbsql_errno($this->connection); + } else { + $errno = @fbsql_errno(); + } + } + if ($this->connection) { + $error = @fbsql_errno($this->connection); + } else { + $error = @fbsql_error(); } - return($this->raiseError($errno, NULL, NULL, NULL, @fbsql_error($this->connection))); + return($this->raiseError($this->errorCode($errno), NULL, NULL, + $message, $error)); } // }}} @@ -520,7 +531,7 @@ } $res = @fbsql_result($result, $row, $field); if ($res === FALSE && $res != NULL) { - return($this->fbsqlRaiseError($errno)); + return($this->fbsqlRaiseError()); } return($res); } http://cvs.php.net/diff.php/pear/MDB/MDB/ibase.php?r1=1.9.4.27&r2=1.9.4.28&ty=u Index: pear/MDB/MDB/ibase.php diff -u pear/MDB/MDB/ibase.php:1.9.4.27 pear/MDB/MDB/ibase.php:1.9.4.28 --- pear/MDB/MDB/ibase.php:1.9.4.27 Tue Mar 9 07:31:19 2004 +++ pear/MDB/MDB/ibase.php Fri Mar 12 11:19:30 2004 @@ -42,7 +42,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.9.4.27 2004/03/09 12:31:19 quipo Exp $ +// $Id: ibase.php,v 1.9.4.28 2004/03/12 16:19:30 lsmith Exp $ require_once 'MDB/Common.php'; @@ -186,24 +186,43 @@ */ function errorCode($errormsg) { - static $error_regexps; - if (empty($error_regexps)) { - $error_regexps = array( - '/[tT]able not found/' => MDB_ERROR_NOSUCHTABLE, - '/[tT]able .* already exists/' => MDB_ERROR_ALREADY_EXISTS, - '/validation error for column .* value "\*\*\* null/' => MDB_ERROR_CONSTRAINT_NOT_NULL, - '/violation of [\w ]+ constraint/' => MDB_ERROR_CONSTRAINT, - '/conversion error from string/' => MDB_ERROR_INVALID_NUMBER, - '/no permission for/' => MDB_ERROR_ACCESS_VIOLATION, - '/arithmetic exception, numeric overflow, or string truncation/' => MDB_ERROR_DIVZERO, - '/deadlock/' => MDB_ERROR_DEADLOCK, - '/attempt to store duplicate value/' => MDB_ERROR_CONSTRAINT - ); - } - foreach ($error_regexps as $regexp => $code) { - if (preg_match($regexp, $errormsg)) { - return $code; - } + // memo for the interbase php module hackers: we need something similar + // to mysql_errno() to retrieve error codes instead of this ugly hack + if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $errormsg, $match)) { + $errno = (int)$match[2]; + } else { + $errno = NULL; + } + switch ($errno) { + case -204: + if (is_int(strpos($match[3], 'Table unknown'))) { + return MDB_ERROR_NOSUCHTABLE; + } + break; + default: + if (isset($this->errorcode_map[$errno])) { + return($this->errorcode_map[$errno]); + } + static $error_regexps; + if (empty($error_regexps)) { + $error_regexps = array( + '/[tT]able not found/' => MDB_ERROR_NOSUCHTABLE, + '/[tT]able unknown/' => MDB_ERROR_NOSUCHTABLE, + '/[tT]able .* already exists/' => MDB_ERROR_ALREADY_EXISTS, + '/validation error for column .* value "\*\*\* null/' => MDB_ERROR_CONSTRAINT_NOT_NULL, + '/violation of [\w ]+ constraint/' => MDB_ERROR_CONSTRAINT, + '/conversion error from string/' => MDB_ERROR_INVALID_NUMBER, + '/no permission for/' => MDB_ERROR_ACCESS_VIOLATION, + '/arithmetic exception, numeric overflow, or string truncation/' => MDB_ERROR_DIVZERO, + '/deadlock/' => MDB_ERROR_DEADLOCK, + '/attempt to store duplicate value/' => MDB_ERROR_CONSTRAINT + ); + } + foreach ($error_regexps as $regexp => $code) { + if (preg_match($regexp, $errormsg)) { + return $code; + } + } } // Fall back to MDB_ERROR if there was no mapping. return MDB_ERROR; @@ -217,40 +236,17 @@ * callbacks etc. Basically a wrapper for MDB::raiseError * that checks for native error msgs. * - * @param integer $db_errno error code + * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error */ - function ibaseRaiseError($db_errno = NULL) + function ibaseRaiseError($errno = NULL, $message = NULL) { - $native_errmsg = $this->errorNative(); - // memo for the interbase php module hackers: we need something similar - // to mysql_errno() to retrieve error codes instead of this ugly hack - if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $native_errmsg, $m)) { - $native_errno = (int)$m[2]; - } else { - $native_errno = NULL; - } - // try to map the native error to the DB one - if (is_null($db_errno)) { - if ($native_errno) { - // try to interpret Interbase error code (that's why we need ibase_errno() - // in the interbase module to return the real error code) - switch ($native_errno) { - case -204: - if (is_int(strpos($m[3], 'Table unknown'))) { - $db_errno = MDB_ERROR_NOSUCHTABLE; - } - break; - default: - $db_errno = $this->errorCode($native_errno); - } - } else { - $db_errno = $this->errorCode($native_errmsg); - } - } - return $this->raiseError($db_errno, NULL, NULL, NULL, $native_errmsg); + $error = $this->errorNative(); + return($this->raiseError($this->errorCode($error), NULL, NULL, + $message, $error)); } // }}} @@ -779,33 +775,33 @@ $rownum = $this->current_row[$result_value] + 1; } if (!isset($this->results[$result_value][$rownum]) - && (!isset($this->results[$result_value][$this->highest_fetched_row[$result_value]]) - || $this->results[$result_value][$this->highest_fetched_row[$result_value]] !== false) + && (!isset($this->results[$result_value][$this->highest_fetched_row[$result_value]]) + || $this->results[$result_value][$this->highest_fetched_row[$result_value]] !== false) ) { if (isset($this->limits[$result_value])) { //upper limit if ($rownum >= $this->limits[$result_value][1]) { - // are all previous rows fetched so that we can set the end - // of the result set and not have any "holes" in between? - if ($rownum == 0 - || (isset($this->results[$result_value]) - && count($this->results[$result_value]) == $rownum) - ) { - $this->highest_fetched_row[$result_value] = $rownum; - $this->current_row[$result_value] = $rownum; - $this->results[$result_value][$rownum] = false; - } - if ($this->options['autofree']) { - $this->freeResult($result); + // are all previous rows fetched so that we can set the end + // of the result set and not have any "holes" in between? + if ($rownum == 0 + || (isset($this->results[$result_value]) + && count($this->results[$result_value]) == $rownum) + ) { + $this->highest_fetched_row[$result_value] = $rownum; + $this->current_row[$result_value] = $rownum; + $this->results[$result_value][$rownum] = false; + } + if ($this->options['autofree']) { + $this->freeResult($result); } return null; } - // offset skipping - if (MDB::isError($this->_skipLimitOffset($result))) { - $this->current_row[$result_value] = 0; - $this->results[$result_value] = array(false); - if ($this->options['autofree']) { - $this->freeResult($result); + // offset skipping + if (MDB::isError($this->_skipLimitOffset($result))) { + $this->current_row[$result_value] = 0; + $this->results[$result_value] = array(false); + if ($this->options['autofree']) { + $this->freeResult($result); } return null; } @@ -816,9 +812,9 @@ $this->row_buffer[$result_value]; unset($this->row_buffer[$result_value]); } - if (!isset($this->results[$result_value][$rownum]) - && (!isset($this->results[$result_value][$this->highest_fetched_row[$result_value]]) - || $this->results[$result_value][$this->highest_fetched_row[$result_value]] !== false) + if (!isset($this->results[$result_value][$rownum]) + && (!isset($this->results[$result_value][$this->highest_fetched_row[$result_value]]) + || $this->results[$result_value][$this->highest_fetched_row[$result_value]] !== false) ) { while ($this->current_row[$result_value] < $rownum && is_array($buffer = @ibase_fetch_row($result)) @@ -826,7 +822,7 @@ $this->current_row[$result_value]++; $this->results[$result_value][$this->current_row[$result_value]] = $buffer; } - // end of result set reached + // end of result set reached if ($this->current_row[$result_value] < $rownum) { $this->current_row[$result_value]++; $this->results[$result_value][$this->current_row[$result_value]] = false; @@ -835,11 +831,11 @@ $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $this->current_row[$result_value]); - } else { - $this->current_row[$result_value]++; + } else { + $this->current_row[$result_value]++; } - if (isset($this->results[$result_value][$rownum]) - && $this->results[$result_value][$rownum] + if (isset($this->results[$result_value][$rownum]) + && $this->results[$result_value][$rownum] ) { $row = $this->results[$result_value][$rownum]; } else { @@ -1631,7 +1627,7 @@ $result = $this->_doQuery($query); $this->popExpect(); if ($ondemand && MDB::isError($result)) { - $result = $this->createSequence($seq_name, 1); + $result = $this->createSequence($seq_name, 1); if (MDB::isError($result)) { return $result; } http://cvs.php.net/diff.php/pear/MDB/MDB/mssql.php?r1=1.6.4.26&r2=1.6.4.27&ty=u Index: pear/MDB/MDB/mssql.php diff -u pear/MDB/MDB/mssql.php:1.6.4.26 pear/MDB/MDB/mssql.php:1.6.4.27 --- pear/MDB/MDB/mssql.php:1.6.4.26 Wed Mar 10 09:42:29 2004 +++ pear/MDB/MDB/mssql.php Fri Mar 12 11:19:30 2004 @@ -43,7 +43,7 @@ // | Author: Frank M. Kromann <frank@kromann.info> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.6.4.26 2004/03/10 14:42:29 lsmith Exp $ +// $Id: mssql.php,v 1.6.4.27 2004/03/12 16:19:30 lsmith Exp $ // require_once('MDB/Common.php'); @@ -120,7 +120,7 @@ } // }}} - // {{{ errorCode() + // {{{ errorNative() /** * Get the native error code of the last error (if any) that @@ -128,21 +128,18 @@ * * @access public * - * @return int native MSSQL error code + * @return int native FrontBase error code */ - function errorCode() + function errorNative() { $res = @mssql_query('select @@ERROR as ErrorCode', $this->connection); - if (!$res) { - return MDB_ERROR; - } - $row = @mssql_fetch_row($res); - if ($row[0] > 0) { - return $row[0]; - } - else { - return null; + if ($res) { + $row = @mssql_fetch_row($res); + if (is_array($row) && $row[0] > 0) { + return $row[0]; + } } + return NULL; } // }}} @@ -153,23 +150,20 @@ * callbacks etc. Basically a wrapper for MDB::raiseError * that checks for native error msgs. * + * @param string $message userinfo message * @param integer $errno error code * @return object a PEAR error object * @access public * @see PEAR_Error */ - function mssqlRaiseError($code = null) + function mssqlRaiseError($errno = NULL, $message = NULL) { - $native_msg = @mssql_get_last_message(); - $native_code = $this->errorCode(); - if ($code === null) { - if (isset($this->errorcode_map[$native_code])) { - $code = $this->errorcode_map[$native_code]; - } else { - $code = MDB_ERROR; - } + if ($errno == NULL) { + $errno = $this->errorNative(); } - return $this->raiseError($code, null, null, null, $native_code . ' - ' . $native_msg); + $error = @mssql_get_last_message(); + return $this->raiseError($this->errorCode(), NULL, NULL, + $message, $error); } // }}} @@ -383,11 +377,11 @@ } $connection = @mssql_connect($this->host,$this->user,$this->password); if($connection == 0) { - return($this->mssqlRaiseError("Query: Could not connect to the Microsoft SQL server")); + return($this->mssqlRaiseError(NULL, "Query: Could not connect to the Microsoft SQL server")); } $result = @mssql_query($query, $connection); if(!$result) { - return($this->mssqlRaiseError("Query: Could not query a Microsoft SQL server")); + return($this->mssqlRaiseError(NULL, "Query: Could not query a Microsoft SQL server")); } @mssql_close($connection); return(MDB_OK); @@ -565,7 +559,7 @@ } $res = @mssql_result($result, $row, $field); if ($res === FALSE && $res != NULL) { - return($this->mssqlRaiseError($errno)); + return($this->mssqlRaiseError()); } return($res); } @@ -1307,7 +1301,7 @@ if (is_string($result)) { if (!@mssql_select_db($this->database_name, $this->connection)) { - return $this->mssqlRaiseError(MDB_ERROR_NODBSELECTED); + return $this->mssqlRaiseError(); } $id = @mssql_query("SELECT * FROM $result", $this->connection); if (empty($id)) { http://cvs.php.net/diff.php/pear/MDB/MDB/mysql.php?r1=1.80.4.13&r2=1.80.4.14&ty=u Index: pear/MDB/MDB/mysql.php diff -u pear/MDB/MDB/mysql.php:1.80.4.13 pear/MDB/MDB/mysql.php:1.80.4.14 --- pear/MDB/MDB/mysql.php:1.80.4.13 Sat Feb 28 05:39:23 2004 +++ pear/MDB/MDB/mysql.php Fri Mar 12 11:19:30 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.80.4.13 2004/02/28 10:39:23 quipo Exp $ +// $Id: mysql.php,v 1.80.4.14 2004/03/12 16:19:30 lsmith Exp $ // require_once('MDB/Common.php'); @@ -156,16 +156,27 @@ * that checks for native error msgs. * * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error */ - function mysqlRaiseError($errno = NULL) + function mysqlRaiseError($errno = NULL, $message = NULL) { if ($errno == NULL) { - $errno = $this->errorCode(@mysql_errno($this->connection)); + if ($this->connection) { + $errno = @mysql_errno($this->connection); + } else { + $errno = @mysql_errno(); + } + } + if ($this->connection) { + $error = @mysql_errno($this->connection); + } else { + $error = @mysql_error(); } - return($this->raiseError($errno, NULL, NULL, NULL, @mysql_error($this->connection))); + return($this->raiseError($this->errorCode($errno), NULL, NULL, + $message, $error)); } // }}} @@ -741,7 +752,7 @@ max($this->highest_fetched_row[$result_value], $row); $res = @mysql_result($result, $row, $field); if ($res === FALSE && $res != NULL) { - return($this->mysqlRaiseError($errno)); + return($this->mysqlRaiseError()); } return($res); } http://cvs.php.net/diff.php/pear/MDB/MDB/oci8.php?r1=1.21.4.22&r2=1.21.4.23&ty=u Index: pear/MDB/MDB/oci8.php diff -u pear/MDB/MDB/oci8.php:1.21.4.22 pear/MDB/MDB/oci8.php:1.21.4.23 --- pear/MDB/MDB/oci8.php:1.21.4.22 Fri Mar 12 09:28:47 2004 +++ pear/MDB/MDB/oci8.php Fri Mar 12 11:19:30 2004 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.21.4.22 2004/03/12 14:28:47 lsmith Exp $ +// $Id: oci8.php,v 1.21.4.23 2004/03/12 16:19:30 lsmith Exp $ require_once('MDB/Common.php'); @@ -175,6 +175,7 @@ * that checks for native error msgs. * * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error http://cvs.php.net/diff.php/pear/MDB/MDB/pgsql.php?r1=1.62.4.19&r2=1.62.4.20&ty=u Index: pear/MDB/MDB/pgsql.php diff -u pear/MDB/MDB/pgsql.php:1.62.4.19 pear/MDB/MDB/pgsql.php:1.62.4.20 --- pear/MDB/MDB/pgsql.php:1.62.4.19 Fri Mar 12 09:17:36 2004 +++ pear/MDB/MDB/pgsql.php Fri Mar 12 11:19:30 2004 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.62.4.19 2004/03/12 14:17:36 lsmith Exp $ +// $Id: pgsql.php,v 1.62.4.20 2004/03/12 16:19:30 lsmith Exp $ require_once('MDB/Common.php'); @@ -145,6 +145,7 @@ // Fall back to MDB_ERROR if there was no mapping. return(MDB_ERROR); } + // }}} // {{{ pgsqlRaiseError() @@ -154,20 +155,19 @@ * that checks for native error msgs. * * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error */ - - function pgsqlRaiseError($errno = NULL) + function pgsqlRaiseError($errno = NULL, $message = NULL) { - $native = $this->errorNative(); - if ($errno === NULL) { - $err = $this->errorCode($native); + if ($this->connection) { + $error = @pg_errormessage($this->connection); } else { - $err = $errno; + $error = @pg_errormessage(); } - return($this->raiseError($err, NULL, NULL, NULL, $native)); + return($this->raiseError($this->errorCode($error), NULL, NULL, $message, $error)); } // }}} @@ -595,7 +595,7 @@ { $result_value = intval($result); if (!isset($this->highest_fetched_row[$result_value])) { - return($this->RaiseError(MDB_ERROR, NULL, NULL, 'End of result attempted to check the end of an unknown result')); + return($this->raiseError(MDB_ERROR, NULL, NULL, 'End of result attempted to check the end of an unknown result')); } return($this->highest_fetched_row[$result_value] >= $this->numRows($result) - 1); } @@ -1208,7 +1208,7 @@ $repeat = 1; $result = $this->createSequence($seq_name); if (MDB::isError($result)) { - return($this->pgsqlRaiseError($result)); + return($this->raiseError($result)); } } else { $repeat = 0; http://cvs.php.net/diff.php/pear/MDB/doc/skeleton.php?r1=1.16.4.1&r2=1.16.4.2&ty=u Index: pear/MDB/doc/skeleton.php diff -u pear/MDB/doc/skeleton.php:1.16.4.1 pear/MDB/doc/skeleton.php:1.16.4.2 --- pear/MDB/doc/skeleton.php:1.16.4.1 Thu Jan 8 08:43:05 2004 +++ pear/MDB/doc/skeleton.php Fri Mar 12 11:19:31 2004 @@ -42,7 +42,7 @@ // | Author: YOUR NAME <YOUR EMAIL> | // +----------------------------------------------------------------------+ // -// $Id: skeleton.php,v 1.16.4.1 2004/01/08 13:43:05 lsmith Exp $ +// $Id: skeleton.php,v 1.16.4.2 2004/03/12 16:19:31 lsmith Exp $ // // This is just a skeleton MDB driver. @@ -132,11 +132,12 @@ * that checks for native error msgs. * * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error */ - function xxxRaiseError($errno = NULL) + function xxxRaiseError($errno = NULL, $message = NULL) { // take this method from the corresponding PEAR DB driver: xxxRaiseError() }
http://cvs.php.net/diff.php/pear/MDB/MDB/fbsql.php?r1=1.16.4.14&r2=1.16.4.15&ty=u Index: pear/MDB/MDB/fbsql.php diff -u pear/MDB/MDB/fbsql.php:1.16.4.14 pear/MDB/MDB/fbsql.php:1.16.4.15 --- pear/MDB/MDB/fbsql.php:1.16.4.14 Wed Mar 10 09:42:29 2004 +++ pear/MDB/MDB/fbsql.php Fri Mar 12 11:19:30 2004 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@dybnet.de> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.16.4.14 2004/03/10 14:42:29 lsmith Exp $ +// $Id: fbsql.php,v 1.16.4.15 2004/03/12 16:19:30 lsmith Exp $ // require_once('MDB/Common.php'); @@ -146,16 +146,27 @@ * that checks for native error msgs. * * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error */ - function fbsqlRaiseError($errno = NULL) + function fbsqlRaiseError($errno = NULL, $message = NULL) { if ($errno == NULL) { - $errno = $this->errorCode(@fbsql_errno($this->connection)); + if ($this->connection) { + $errno = @fbsql_errno($this->connection); + } else { + $errno = @fbsql_errno(); + } + } + if ($this->connection) { + $error = @fbsql_errno($this->connection); + } else { + $error = @fbsql_error(); } - return($this->raiseError($errno, NULL, NULL, NULL, @fbsql_error($this->connection))); + return($this->raiseError($this->errorCode($errno), NULL, NULL, + $message, $error)); } // }}} @@ -520,7 +531,7 @@ } $res = @fbsql_result($result, $row, $field); if ($res === FALSE && $res != NULL) { - return($this->fbsqlRaiseError($errno)); + return($this->fbsqlRaiseError()); } return($res); } http://cvs.php.net/diff.php/pear/MDB/MDB/ibase.php?r1=1.9.4.27&r2=1.9.4.28&ty=u Index: pear/MDB/MDB/ibase.php diff -u pear/MDB/MDB/ibase.php:1.9.4.27 pear/MDB/MDB/ibase.php:1.9.4.28 --- pear/MDB/MDB/ibase.php:1.9.4.27 Tue Mar 9 07:31:19 2004 +++ pear/MDB/MDB/ibase.php Fri Mar 12 11:19:30 2004 @@ -42,7 +42,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.9.4.27 2004/03/09 12:31:19 quipo Exp $ +// $Id: ibase.php,v 1.9.4.28 2004/03/12 16:19:30 lsmith Exp $ require_once 'MDB/Common.php'; @@ -186,24 +186,43 @@ */ function errorCode($errormsg) { - static $error_regexps; - if (empty($error_regexps)) { - $error_regexps = array( - '/[tT]able not found/' => MDB_ERROR_NOSUCHTABLE, - '/[tT]able .* already exists/' => MDB_ERROR_ALREADY_EXISTS, - '/validation error for column .* value "\*\*\* null/' => MDB_ERROR_CONSTRAINT_NOT_NULL, - '/violation of [\w ]+ constraint/' => MDB_ERROR_CONSTRAINT, - '/conversion error from string/' => MDB_ERROR_INVALID_NUMBER, - '/no permission for/' => MDB_ERROR_ACCESS_VIOLATION, - '/arithmetic exception, numeric overflow, or string truncation/' => MDB_ERROR_DIVZERO, - '/deadlock/' => MDB_ERROR_DEADLOCK, - '/attempt to store duplicate value/' => MDB_ERROR_CONSTRAINT - ); - } - foreach ($error_regexps as $regexp => $code) { - if (preg_match($regexp, $errormsg)) { - return $code; - } + // memo for the interbase php module hackers: we need something similar + // to mysql_errno() to retrieve error codes instead of this ugly hack + if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $errormsg, $match)) { + $errno = (int)$match[2]; + } else { + $errno = NULL; + } + switch ($errno) { + case -204: + if (is_int(strpos($match[3], 'Table unknown'))) { + return MDB_ERROR_NOSUCHTABLE; + } + break; + default: + if (isset($this->errorcode_map[$errno])) { + return($this->errorcode_map[$errno]); + } + static $error_regexps; + if (empty($error_regexps)) { + $error_regexps = array( + '/[tT]able not found/' => MDB_ERROR_NOSUCHTABLE, + '/[tT]able unknown/' => MDB_ERROR_NOSUCHTABLE, + '/[tT]able .* already exists/' => MDB_ERROR_ALREADY_EXISTS, + '/validation error for column .* value "\*\*\* null/' => MDB_ERROR_CONSTRAINT_NOT_NULL, + '/violation of [\w ]+ constraint/' => MDB_ERROR_CONSTRAINT, + '/conversion error from string/' => MDB_ERROR_INVALID_NUMBER, + '/no permission for/' => MDB_ERROR_ACCESS_VIOLATION, + '/arithmetic exception, numeric overflow, or string truncation/' => MDB_ERROR_DIVZERO, + '/deadlock/' => MDB_ERROR_DEADLOCK, + '/attempt to store duplicate value/' => MDB_ERROR_CONSTRAINT + ); + } + foreach ($error_regexps as $regexp => $code) { + if (preg_match($regexp, $errormsg)) { + return $code; + } + } } // Fall back to MDB_ERROR if there was no mapping. return MDB_ERROR; @@ -217,40 +236,17 @@ * callbacks etc. Basically a wrapper for MDB::raiseError * that checks for native error msgs. * - * @param integer $db_errno error code + * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error */ - function ibaseRaiseError($db_errno = NULL) + function ibaseRaiseError($errno = NULL, $message = NULL) { - $native_errmsg = $this->errorNative(); - // memo for the interbase php module hackers: we need something similar - // to mysql_errno() to retrieve error codes instead of this ugly hack - if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $native_errmsg, $m)) { - $native_errno = (int)$m[2]; - } else { - $native_errno = NULL; - } - // try to map the native error to the DB one - if (is_null($db_errno)) { - if ($native_errno) { - // try to interpret Interbase error code (that's why we need ibase_errno() - // in the interbase module to return the real error code) - switch ($native_errno) { - case -204: - if (is_int(strpos($m[3], 'Table unknown'))) { - $db_errno = MDB_ERROR_NOSUCHTABLE; - } - break; - default: - $db_errno = $this->errorCode($native_errno); - } - } else { - $db_errno = $this->errorCode($native_errmsg); - } - } - return $this->raiseError($db_errno, NULL, NULL, NULL, $native_errmsg); + $error = $this->errorNative(); + return($this->raiseError($this->errorCode($error), NULL, NULL, + $message, $error)); } // }}} @@ -779,33 +775,33 @@ $rownum = $this->current_row[$result_value] + 1; } if (!isset($this->results[$result_value][$rownum]) - && (!isset($this->results[$result_value][$this->highest_fetched_row[$result_value]]) - || $this->results[$result_value][$this->highest_fetched_row[$result_value]] !== false) + && (!isset($this->results[$result_value][$this->highest_fetched_row[$result_value]]) + || $this->results[$result_value][$this->highest_fetched_row[$result_value]] !== false) ) { if (isset($this->limits[$result_value])) { //upper limit if ($rownum >= $this->limits[$result_value][1]) { - // are all previous rows fetched so that we can set the end - // of the result set and not have any "holes" in between? - if ($rownum == 0 - || (isset($this->results[$result_value]) - && count($this->results[$result_value]) == $rownum) - ) { - $this->highest_fetched_row[$result_value] = $rownum; - $this->current_row[$result_value] = $rownum; - $this->results[$result_value][$rownum] = false; - } - if ($this->options['autofree']) { - $this->freeResult($result); + // are all previous rows fetched so that we can set the end + // of the result set and not have any "holes" in between? + if ($rownum == 0 + || (isset($this->results[$result_value]) + && count($this->results[$result_value]) == $rownum) + ) { + $this->highest_fetched_row[$result_value] = $rownum; + $this->current_row[$result_value] = $rownum; + $this->results[$result_value][$rownum] = false; + } + if ($this->options['autofree']) { + $this->freeResult($result); } return null; } - // offset skipping - if (MDB::isError($this->_skipLimitOffset($result))) { - $this->current_row[$result_value] = 0; - $this->results[$result_value] = array(false); - if ($this->options['autofree']) { - $this->freeResult($result); + // offset skipping + if (MDB::isError($this->_skipLimitOffset($result))) { + $this->current_row[$result_value] = 0; + $this->results[$result_value] = array(false); + if ($this->options['autofree']) { + $this->freeResult($result); } return null; } @@ -816,9 +812,9 @@ $this->row_buffer[$result_value]; unset($this->row_buffer[$result_value]); } - if (!isset($this->results[$result_value][$rownum]) - && (!isset($this->results[$result_value][$this->highest_fetched_row[$result_value]]) - || $this->results[$result_value][$this->highest_fetched_row[$result_value]] !== false) + if (!isset($this->results[$result_value][$rownum]) + && (!isset($this->results[$result_value][$this->highest_fetched_row[$result_value]]) + || $this->results[$result_value][$this->highest_fetched_row[$result_value]] !== false) ) { while ($this->current_row[$result_value] < $rownum && is_array($buffer = @ibase_fetch_row($result)) @@ -826,7 +822,7 @@ $this->current_row[$result_value]++; $this->results[$result_value][$this->current_row[$result_value]] = $buffer; } - // end of result set reached + // end of result set reached if ($this->current_row[$result_value] < $rownum) { $this->current_row[$result_value]++; $this->results[$result_value][$this->current_row[$result_value]] = false; @@ -835,11 +831,11 @@ $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $this->current_row[$result_value]); - } else { - $this->current_row[$result_value]++; + } else { + $this->current_row[$result_value]++; } - if (isset($this->results[$result_value][$rownum]) - && $this->results[$result_value][$rownum] + if (isset($this->results[$result_value][$rownum]) + && $this->results[$result_value][$rownum] ) { $row = $this->results[$result_value][$rownum]; } else { @@ -1631,7 +1627,7 @@ $result = $this->_doQuery($query); $this->popExpect(); if ($ondemand && MDB::isError($result)) { - $result = $this->createSequence($seq_name, 1); + $result = $this->createSequence($seq_name, 1); if (MDB::isError($result)) { return $result; } http://cvs.php.net/diff.php/pear/MDB/MDB/mssql.php?r1=1.6.4.26&r2=1.6.4.27&ty=u Index: pear/MDB/MDB/mssql.php diff -u pear/MDB/MDB/mssql.php:1.6.4.26 pear/MDB/MDB/mssql.php:1.6.4.27 --- pear/MDB/MDB/mssql.php:1.6.4.26 Wed Mar 10 09:42:29 2004 +++ pear/MDB/MDB/mssql.php Fri Mar 12 11:19:30 2004 @@ -43,7 +43,7 @@ // | Author: Frank M. Kromann <frank@kromann.info> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.6.4.26 2004/03/10 14:42:29 lsmith Exp $ +// $Id: mssql.php,v 1.6.4.27 2004/03/12 16:19:30 lsmith Exp $ // require_once('MDB/Common.php'); @@ -120,7 +120,7 @@ } // }}} - // {{{ errorCode() + // {{{ errorNative() /** * Get the native error code of the last error (if any) that @@ -128,21 +128,18 @@ * * @access public * - * @return int native MSSQL error code + * @return int native FrontBase error code */ - function errorCode() + function errorNative() { $res = @mssql_query('select @@ERROR as ErrorCode', $this->connection); - if (!$res) { - return MDB_ERROR; - } - $row = @mssql_fetch_row($res); - if ($row[0] > 0) { - return $row[0]; - } - else { - return null; + if ($res) { + $row = @mssql_fetch_row($res); + if (is_array($row) && $row[0] > 0) { + return $row[0]; + } } + return NULL; } // }}} @@ -153,23 +150,20 @@ * callbacks etc. Basically a wrapper for MDB::raiseError * that checks for native error msgs. * + * @param string $message userinfo message * @param integer $errno error code * @return object a PEAR error object * @access public * @see PEAR_Error */ - function mssqlRaiseError($code = null) + function mssqlRaiseError($errno = NULL, $message = NULL) { - $native_msg = @mssql_get_last_message(); - $native_code = $this->errorCode(); - if ($code === null) { - if (isset($this->errorcode_map[$native_code])) { - $code = $this->errorcode_map[$native_code]; - } else { - $code = MDB_ERROR; - } + if ($errno == NULL) { + $errno = $this->errorNative(); } - return $this->raiseError($code, null, null, null, $native_code . ' - ' . $native_msg); + $error = @mssql_get_last_message(); + return $this->raiseError($this->errorCode(), NULL, NULL, + $message, $error); } // }}} @@ -383,11 +377,11 @@ } $connection = @mssql_connect($this->host,$this->user,$this->password); if($connection == 0) { - return($this->mssqlRaiseError("Query: Could not connect to the Microsoft SQL server")); + return($this->mssqlRaiseError(NULL, "Query: Could not connect to the Microsoft SQL server")); } $result = @mssql_query($query, $connection); if(!$result) { - return($this->mssqlRaiseError("Query: Could not query a Microsoft SQL server")); + return($this->mssqlRaiseError(NULL, "Query: Could not query a Microsoft SQL server")); } @mssql_close($connection); return(MDB_OK); @@ -565,7 +559,7 @@ } $res = @mssql_result($result, $row, $field); if ($res === FALSE && $res != NULL) { - return($this->mssqlRaiseError($errno)); + return($this->mssqlRaiseError()); } return($res); } @@ -1307,7 +1301,7 @@ if (is_string($result)) { if (!@mssql_select_db($this->database_name, $this->connection)) { - return $this->mssqlRaiseError(MDB_ERROR_NODBSELECTED); + return $this->mssqlRaiseError(); } $id = @mssql_query("SELECT * FROM $result", $this->connection); if (empty($id)) { http://cvs.php.net/diff.php/pear/MDB/MDB/mysql.php?r1=1.80.4.13&r2=1.80.4.14&ty=u Index: pear/MDB/MDB/mysql.php diff -u pear/MDB/MDB/mysql.php:1.80.4.13 pear/MDB/MDB/mysql.php:1.80.4.14 --- pear/MDB/MDB/mysql.php:1.80.4.13 Sat Feb 28 05:39:23 2004 +++ pear/MDB/MDB/mysql.php Fri Mar 12 11:19:30 2004 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.80.4.13 2004/02/28 10:39:23 quipo Exp $ +// $Id: mysql.php,v 1.80.4.14 2004/03/12 16:19:30 lsmith Exp $ // require_once('MDB/Common.php'); @@ -156,16 +156,27 @@ * that checks for native error msgs. * * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error */ - function mysqlRaiseError($errno = NULL) + function mysqlRaiseError($errno = NULL, $message = NULL) { if ($errno == NULL) { - $errno = $this->errorCode(@mysql_errno($this->connection)); + if ($this->connection) { + $errno = @mysql_errno($this->connection); + } else { + $errno = @mysql_errno(); + } + } + if ($this->connection) { + $error = @mysql_errno($this->connection); + } else { + $error = @mysql_error(); } - return($this->raiseError($errno, NULL, NULL, NULL, @mysql_error($this->connection))); + return($this->raiseError($this->errorCode($errno), NULL, NULL, + $message, $error)); } // }}} @@ -741,7 +752,7 @@ max($this->highest_fetched_row[$result_value], $row); $res = @mysql_result($result, $row, $field); if ($res === FALSE && $res != NULL) { - return($this->mysqlRaiseError($errno)); + return($this->mysqlRaiseError()); } return($res); } http://cvs.php.net/diff.php/pear/MDB/MDB/oci8.php?r1=1.21.4.22&r2=1.21.4.23&ty=u Index: pear/MDB/MDB/oci8.php diff -u pear/MDB/MDB/oci8.php:1.21.4.22 pear/MDB/MDB/oci8.php:1.21.4.23 --- pear/MDB/MDB/oci8.php:1.21.4.22 Fri Mar 12 09:28:47 2004 +++ pear/MDB/MDB/oci8.php Fri Mar 12 11:19:30 2004 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.21.4.22 2004/03/12 14:28:47 lsmith Exp $ +// $Id: oci8.php,v 1.21.4.23 2004/03/12 16:19:30 lsmith Exp $ require_once('MDB/Common.php'); @@ -175,6 +175,7 @@ * that checks for native error msgs. * * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error http://cvs.php.net/diff.php/pear/MDB/MDB/pgsql.php?r1=1.62.4.19&r2=1.62.4.20&ty=u Index: pear/MDB/MDB/pgsql.php diff -u pear/MDB/MDB/pgsql.php:1.62.4.19 pear/MDB/MDB/pgsql.php:1.62.4.20 --- pear/MDB/MDB/pgsql.php:1.62.4.19 Fri Mar 12 09:17:36 2004 +++ pear/MDB/MDB/pgsql.php Fri Mar 12 11:19:30 2004 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.62.4.19 2004/03/12 14:17:36 lsmith Exp $ +// $Id: pgsql.php,v 1.62.4.20 2004/03/12 16:19:30 lsmith Exp $ require_once('MDB/Common.php'); @@ -145,6 +145,7 @@ // Fall back to MDB_ERROR if there was no mapping. return(MDB_ERROR); } + // }}} // {{{ pgsqlRaiseError() @@ -154,20 +155,19 @@ * that checks for native error msgs. * * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error */ - - function pgsqlRaiseError($errno = NULL) + function pgsqlRaiseError($errno = NULL, $message = NULL) { - $native = $this->errorNative(); - if ($errno === NULL) { - $err = $this->errorCode($native); + if ($this->connection) { + $error = @pg_errormessage($this->connection); } else { - $err = $errno; + $error = @pg_errormessage(); } - return($this->raiseError($err, NULL, NULL, NULL, $native)); + return($this->raiseError($this->errorCode($error), NULL, NULL, $message, $error)); } // }}} @@ -595,7 +595,7 @@ { $result_value = intval($result); if (!isset($this->highest_fetched_row[$result_value])) { - return($this->RaiseError(MDB_ERROR, NULL, NULL, 'End of result attempted to check the end of an unknown result')); + return($this->raiseError(MDB_ERROR, NULL, NULL, 'End of result attempted to check the end of an unknown result')); } return($this->highest_fetched_row[$result_value] >= $this->numRows($result) - 1); } @@ -1208,7 +1208,7 @@ $repeat = 1; $result = $this->createSequence($seq_name); if (MDB::isError($result)) { - return($this->pgsqlRaiseError($result)); + return($this->raiseError($result)); } } else { $repeat = 0; http://cvs.php.net/diff.php/pear/MDB/doc/skeleton.php?r1=1.16.4.1&r2=1.16.4.2&ty=u Index: pear/MDB/doc/skeleton.php diff -u pear/MDB/doc/skeleton.php:1.16.4.1 pear/MDB/doc/skeleton.php:1.16.4.2 --- pear/MDB/doc/skeleton.php:1.16.4.1 Thu Jan 8 08:43:05 2004 +++ pear/MDB/doc/skeleton.php Fri Mar 12 11:19:31 2004 @@ -42,7 +42,7 @@ // | Author: YOUR NAME <YOUR EMAIL> | // +----------------------------------------------------------------------+ // -// $Id: skeleton.php,v 1.16.4.1 2004/01/08 13:43:05 lsmith Exp $ +// $Id: skeleton.php,v 1.16.4.2 2004/03/12 16:19:31 lsmith Exp $ // // This is just a skeleton MDB driver. @@ -132,11 +132,12 @@ * that checks for native error msgs. * * @param integer $errno error code + * @param string $message userinfo message * @return object a PEAR error object * @access public * @see PEAR_Error */ - function xxxRaiseError($errno = NULL) + function xxxRaiseError($errno = NULL, $message = NULL) { // take this method from the corresponding PEAR DB driver: xxxRaiseError() }