From e5deaae52880e7ddb7efab0b190e5f5c750f55c4 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Mon, 12 May 2008 08:19:32 -0400
Subject: [PATCH] - Updated PEAR::DB package to version 1.7.13

---
 program/lib/DB/sybase.php |   67 +++++++++++++++++++++++++--------
 1 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/program/lib/DB/sybase.php b/program/lib/DB/sybase.php
index 8931782..3172701 100644
--- a/program/lib/DB/sybase.php
+++ b/program/lib/DB/sybase.php
@@ -19,7 +19,7 @@
  * @author     Sterling Hughes <sterling@php.net>
  * @author     Ant�nio Carlos Ven�ncio J�nior <floripa@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  * @version    CVS: $Id$
  * @link       http://pear.php.net/package/DB
@@ -44,9 +44,9 @@
  * @author     Sterling Hughes <sterling@php.net>
  * @author     Ant�nio Carlos Ven�ncio J�nior <floripa@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1997-2005 The PHP Group
+ * @copyright  1997-2007 The PHP Group
  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
- * @version    Release: @package_version@
+ * @version    Release: 1.7.13
  * @link       http://pear.php.net/package/DB
  */
 class DB_sybase extends DB_common
@@ -248,9 +248,9 @@
      */
     function simpleQuery($query)
     {
-        $ismanip = DB::isManip($query);
+        $ismanip = $this->_checkManip($query);
         $this->last_query = $query;
-        if (!@sybase_select_db($this->_db, $this->connection)) {
+        if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
             return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
         }
         $query = $this->modifyQuery($query);
@@ -370,7 +370,7 @@
      */
     function freeResult($result)
     {
-        return @sybase_free_result($result);
+        return is_resource($result) ? sybase_free_result($result) : false;
     }
 
     // }}}
@@ -435,7 +435,7 @@
      */
     function affectedRows()
     {
-        if (DB::isManip($this->last_query)) {
+        if ($this->_last_query_manip) {
             $result = @sybase_affected_rows($this->connection);
         } else {
             $result = 0;
@@ -462,7 +462,7 @@
     function nextId($seq_name, $ondemand = true)
     {
         $seqname = $this->getSequenceName($seq_name);
-        if (!@sybase_select_db($this->_db, $this->connection)) {
+        if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
             return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
         }
         $repeat = 0;
@@ -479,7 +479,7 @@
                     return $this->raiseError($result);
                 }
             } elseif (!DB::isError($result)) {
-                $result =& $this->query("SELECT @@IDENTITY FROM $seqname");
+                $result = $this->query("SELECT @@IDENTITY FROM $seqname");
                 $repeat = 0;
             } else {
                 $repeat = false;
@@ -529,6 +529,22 @@
     }
 
     // }}}
+    // {{{ quoteFloat()
+
+    /**
+     * Formats a float value for use within a query in a locale-independent
+     * manner.
+     *
+     * @param float the float value to be quoted.
+     * @return string the quoted string.
+     * @see DB_common::quoteSmart()
+     * @since Method available since release 1.7.8.
+     */
+    function quoteFloat($float) {
+        return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
+    }
+     
+    // }}}
     // {{{ autoCommit()
 
     /**
@@ -558,7 +574,7 @@
     function commit()
     {
         if ($this->transaction_opcount > 0) {
-            if (!@sybase_select_db($this->_db, $this->connection)) {
+            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
                 return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
             }
             $result = @sybase_query('COMMIT', $this->connection);
@@ -581,7 +597,7 @@
     function rollback()
     {
         if ($this->transaction_opcount > 0) {
-            if (!@sybase_select_db($this->_db, $this->connection)) {
+            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
                 return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
             }
             $result = @sybase_query('ROLLBACK', $this->connection);
@@ -642,6 +658,11 @@
     function errorCode($errormsg)
     {
         static $error_regexps;
+        
+        // PHP 5.2+ prepends the function name to $php_errormsg, so we need
+        // this hack to work around it, per bug #9599.
+        $errormsg = preg_replace('/^sybase[a-z_]+\(\): /', '', $errormsg);
+        
         if (!isset($error_regexps)) {
             $error_regexps = array(
                 '/Incorrect syntax near/'
@@ -674,6 +695,8 @@
                     => DB_ERROR_ALREADY_EXISTS,
                 '/^There are fewer columns in the INSERT statement than values specified/i'
                     => DB_ERROR_VALUE_COUNT_ON_ROW,
+                '/Divide by zero/i'
+                    => DB_ERROR_DIVZERO,
             );
         }
 
@@ -714,7 +737,7 @@
              * Probably received a table name.
              * Create a result resource identifier.
              */
-            if (!@sybase_select_db($this->_db, $this->connection)) {
+            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
                 return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
             }
             $id = @sybase_query("SELECT * FROM $result WHERE 1=0",
@@ -811,14 +834,24 @@
             $flags = array();
             $tableName = $table;
 
-            // get unique/primary keys
-            $res = $this->getAll("sp_helpindex $table", DB_FETCHMODE_ASSOC);
+            /* We're running sp_helpindex directly because it doesn't exist in
+             * older versions of ASE -- unfortunately, we can't just use
+             * DB::isError() because the user may be using callback error
+             * handling. */
+            $res = @sybase_query("sp_helpindex $table", $this->connection);
 
-            if (!isset($res[0]['index_description'])) {
+            if ($res === false || $res === true) {
+                // Fake a valid response for BC reasons.
                 return '';
             }
 
-            foreach ($res as $val) {
+            while (($val = sybase_fetch_assoc($res)) !== false) {
+                if (!isset($val['index_keys'])) {
+                    /* No useful information returned. Break and be done with
+                     * it, which preserves the pre-1.7.9 behaviour. */
+                    break;
+                }
+
                 $keys = explode(', ', trim($val['index_keys']));
 
                 if (sizeof($keys) > 1) {
@@ -834,6 +867,8 @@
                 }
             }
 
+            sybase_free_result($res);
+
         }
 
         if (array_key_exists($column, $flags)) {

--
Gitblit v1.9.1