cvs: pear /DB/DB odbc.php

From: Date: Sun, 22 Jun 2003 10:18:16 +0000
Subject: cvs: pear /DB/DB odbc.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-11117@lists.php.net to get a copy of this message
cox Sun Jun 22 06:18:16 2003 EDT Modified files: /pear/DB/DB odbc.php Log: Installed DB2, fixes commited: - Added or remap some native error codes - Droped PHP < 4.0.5 support in fetchInto() - Added key to lower case functionality when portability is set - Added native quote() function - Fixed error handling in netxID() - Speed up a little nextID() by using ORDERED insted of ASSOC Index: pear/DB/DB/odbc.php diff -u pear/DB/DB/odbc.php:1.7 pear/DB/DB/odbc.php:1.8 --- pear/DB/DB/odbc.php:1.7 Tue Jun 10 16:16:39 2003 +++ pear/DB/DB/odbc.php Sun Jun 22 06:18:16 2003 @@ -16,7 +16,7 @@ // | Author: Stig Bakken <ssb@php.net> | // +----------------------------------------------------------------------+ // -// $Id: odbc.php,v 1.7 2003/06/10 20:16:39 cox Exp $ +// $Id: odbc.php,v 1.8 2003/06/22 10:18:16 cox Exp $ // // Database independent query interface definition for PHP's ODBC // extension. @@ -61,21 +61,24 @@ '21S01' => DB_ERROR_MISMATCH, '21S02' => DB_ERROR_MISMATCH, '22003' => DB_ERROR_INVALID_NUMBER, + '22005' => DB_ERROR_INVALID_NUMBER, '22008' => DB_ERROR_INVALID_DATE, '22012' => DB_ERROR_DIVZERO, '23000' => DB_ERROR_CONSTRAINT, + '23503' => DB_ERROR_CONSTRAINT, '24000' => DB_ERROR_INVALID, '34000' => DB_ERROR_INVALID, '37000' => DB_ERROR_SYNTAX, '42000' => DB_ERROR_SYNTAX, + '42601' => DB_ERROR_SYNTAX, 'IM001' => DB_ERROR_UNSUPPORTED, 'S0000' => DB_ERROR_NOSUCHTABLE, - 'S0001' => DB_ERROR_NOT_FOUND, - 'S0002' => DB_ERROR_NOT_FOUND, + 'S0001' => DB_ERROR_ALREADY_EXISTS, + 'S0002' => DB_ERROR_NOSUCHTABLE, 'S0011' => DB_ERROR_ALREADY_EXISTS, 'S0012' => DB_ERROR_NOT_FOUND, 'S0021' => DB_ERROR_ALREADY_EXISTS, - 'S0022' => DB_ERROR_NOT_FOUND, + 'S0022' => DB_ERROR_NOSUCHFIELD, 'S1009' => DB_ERROR_INVALID, 'S1090' => DB_ERROR_INVALID, 'S1C00' => DB_ERROR_NOT_CAPABLE @@ -203,19 +206,13 @@ $row = array(); if ($rownum !== null) { $rownum++; // ODBC first row is 1 - if (!function_exists('version_compare') || version_compare(phpversion(), "4.0.5", "lt")) { - $cols = odbc_fetch_into($result, $rownum, &$row); - } elseif (version_compare(phpversion(), '4.2.0', 'ge')) { + if (version_compare(phpversion(), '4.2.0', 'ge')) { $cols = odbc_fetch_into($result, $row, $rownum); } else { $cols = odbc_fetch_into($result, $rownum, $row); } } else { - if (!function_exists('version_compare') || version_compare(phpversion(), "4.0.5", "lt")) { - $cols = odbc_fetch_into($result, &$row); - } else { - $cols = odbc_fetch_into($result, $row); - } + $cols = odbc_fetch_into($result, $row); } if (!$cols) { @@ -231,6 +228,9 @@ $colName = odbc_field_name($result, $i+1); $a[$colName] = $row[$i]; } + if ($this->options['optimize'] == 'portability') { + $a = array_change_key_case($a, CASE_LOWER); + } $row = $a; } return DB_OK; @@ -305,6 +305,30 @@ return $nrows; } + // {{{ quote() + /** + * Quote the given string so it can be safely used within string delimiters + * in a query. + * @param $string mixed Data to be quoted + * @return mixed "NULL" string, quoted string or original data + */ + function quote($str = null) + { + if (is_numeric($str)) { + return $str; + } + switch (strtolower(gettype($str))) { + case 'null': + return 'NULL'; + case 'boolean': + return $str ? 'TRUE' : 'FALSE'; + case 'string': + default: + $str = str_replace("'", "''", $str); + return "'$str'"; + } + } + // }}} // {{{ errorNative() @@ -346,13 +370,17 @@ $seqname = $this->getSequenceName($seq_name); $repeat = 0; do { + $this->pushErrorHandling(PEAR_ERROR_RETURN); $result = $this->query("update ${seqname} set id = id + 1"); + $this->popErrorHandling(); if ($ondemand && DB::isError($result) && - $result->getCode() == DB_ERROR_NOT_FOUND) { + $result->getCode() == DB_ERROR_NOSUCHTABLE) { $repeat = 1; + $this->pushErrorHandling(PEAR_ERROR_RETURN); $result = $this->createSequence($seq_name); + $this->popErrorHandling(); if (DB::isError($result)) { - return $result; + return $this->raiseError($result); } $result = $this->query("insert into ${seqname} (id) values(0)"); } else { @@ -361,7 +389,7 @@ } while ($repeat); if (DB::isError($result)) { - return $result; + return $this->raiseError($result); } $result = $this->query("select id from ${seqname}"); @@ -369,12 +397,12 @@ return $result; } - $row = $result->fetchRow(DB_FETCHMODE_ASSOC); + $row = $result->fetchRow(DB_FETCHMODE_ORDERED); if (DB::isError($row || !$row)) { return $row; } - return $row['id']; + return $row[0]; } // }}}

« previous php.pear.cvs (#11117) next »