| | |
| | | * @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 |
| | |
| | | * @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 |
| | |
| | | */ |
| | | 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); |
| | |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return @sybase_free_result($result); |
| | | return is_resource($result) ? sybase_free_result($result) : false; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | */ |
| | | function affectedRows() |
| | | { |
| | | if (DB::isManip($this->last_query)) { |
| | | if ($this->_last_query_manip) { |
| | | $result = @sybase_affected_rows($this->connection); |
| | | } else { |
| | | $result = 0; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ 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() |
| | | |
| | | /** |
| | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | 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/' |
| | |
| | | => 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, |
| | | ); |
| | | } |
| | | |
| | |
| | | * 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", |
| | |
| | | $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) { |
| | |
| | | } |
| | | } |
| | | |
| | | sybase_free_result($res); |
| | | |
| | | } |
| | | |
| | | if (array_key_exists($column, $flags)) { |