summaryrefslogtreecommitdiff
path: root/program/lib/DB/sybase.php
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2008-05-12 12:19:32 +0000
committeralecpl <alec@alec.pl>2008-05-12 12:19:32 +0000
commite5deaae52880e7ddb7efab0b190e5f5c750f55c4 (patch)
treef3a45e99480c5818dde1f939fc75e11bce8bb3d5 /program/lib/DB/sybase.php
parenta6f90e1b2bea6602f7056986ee8dbd59afeee90c (diff)
- Updated PEAR::DB package to version 1.7.13
Diffstat (limited to 'program/lib/DB/sybase.php')
-rw-r--r--program/lib/DB/sybase.php67
1 files changed, 51 insertions, 16 deletions
diff --git a/program/lib/DB/sybase.php b/program/lib/DB/sybase.php
index 893178213..3172701cb 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 @@ require_once 'DB/common.php';
* @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 @@ class DB_sybase extends DB_common
*/
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 @@ class DB_sybase extends DB_common
*/
function freeResult($result)
{
- return @sybase_free_result($result);
+ return is_resource($result) ? sybase_free_result($result) : false;
}
// }}}
@@ -435,7 +435,7 @@ class DB_sybase extends DB_common
*/
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 @@ class DB_sybase extends DB_common
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 @@ class DB_sybase extends DB_common
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 @@ class DB_sybase extends DB_common
}
// }}}
+ // {{{ 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 @@ class DB_sybase extends DB_common
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 @@ class DB_sybase extends DB_common
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 @@ class DB_sybase extends DB_common
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 @@ class DB_sybase extends DB_common
=> 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 @@ class DB_sybase extends DB_common
* 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 @@ class DB_sybase extends DB_common
$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 @@ class DB_sybase extends DB_common
}
}
+ sybase_free_result($res);
+
}
if (array_key_exists($column, $flags)) {