- Updated PEAR::DB package to version 1.7.13
| | |
| | | CHANGELOG RoundCube Webmail |
| | | --------------------------- |
| | | |
| | | 2008/05/12 (alec) |
| | | - Updated PEAR::DB package to version 1.7.13 |
| | | |
| | | 2008/05/10 (alec) |
| | | - Make password input fields of type password in installer (#1484886) |
| | | |
| | |
| | | * @author Stig Bakken <ssb@php.net> |
| | | * @author Tomas V.V.Cox <cox@idecnet.com> |
| | | * @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 Stig Bakken <ssb@php.net> |
| | | * @author Tomas V.V.Cox <cox@idecnet.com> |
| | | * @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 |
| | |
| | | return $tmp; |
| | | } |
| | | |
| | | @$obj =& new $classname; |
| | | @$obj = new $classname; |
| | | |
| | | foreach ($options as $option => $value) { |
| | | $test = $obj->setOption($option, $value); |
| | |
| | | return $tmp; |
| | | } |
| | | |
| | | @$obj =& new $classname; |
| | | @$obj = new $classname; |
| | | |
| | | foreach ($options as $option => $value) { |
| | | $test = $obj->setOption($option, $value); |
| | |
| | | |
| | | $err = $obj->connect($dsninfo, $obj->getOption('persistent')); |
| | | if (DB::isError($err)) { |
| | | $err->addUserInfo($dsn); |
| | | if (is_array($dsn)) { |
| | | $err->addUserInfo(DB::getDSNString($dsn, true)); |
| | | } else { |
| | | $err->addUserInfo($dsn); |
| | | } |
| | | return $err; |
| | | } |
| | | |
| | |
| | | */ |
| | | function apiVersion() |
| | | { |
| | | return '@package_version@'; |
| | | return '1.7.13'; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | { |
| | | $manips = 'INSERT|UPDATE|DELETE|REPLACE|' |
| | | . 'CREATE|DROP|' |
| | | . 'LOAD DATA|SELECT .* INTO|COPY|' |
| | | . 'LOAD DATA|SELECT .* INTO .* FROM|COPY|' |
| | | . 'ALTER|GRANT|REVOKE|' |
| | | . 'LOCK|UNLOCK'; |
| | | if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $query)) { |
| | |
| | | // process the different protocol options |
| | | $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp'; |
| | | $proto_opts = rawurldecode($proto_opts); |
| | | if (strpos($proto_opts, ':') !== false) { |
| | | list($proto_opts, $parsed['port']) = explode(':', $proto_opts); |
| | | } |
| | | if ($parsed['protocol'] == 'tcp') { |
| | | if (strpos($proto_opts, ':') !== false) { |
| | | list($parsed['hostspec'], |
| | | $parsed['port']) = explode(':', $proto_opts); |
| | | } else { |
| | | $parsed['hostspec'] = $proto_opts; |
| | | } |
| | | $parsed['hostspec'] = $proto_opts; |
| | | } elseif ($parsed['protocol'] == 'unix') { |
| | | $parsed['socket'] = $proto_opts; |
| | | } |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ getDSNString() |
| | | |
| | | /** |
| | | * Returns the given DSN in a string format suitable for output. |
| | | * |
| | | * @param array|string the DSN to parse and format |
| | | * @param boolean true to hide the password, false to include it |
| | | * @return string |
| | | */ |
| | | function getDSNString($dsn, $hidePassword) { |
| | | /* Calling parseDSN will ensure that we have all the array elements |
| | | * defined, and means that we deal with strings and array in the same |
| | | * manner. */ |
| | | $dsnArray = DB::parseDSN($dsn); |
| | | |
| | | if ($hidePassword) { |
| | | $dsnArray['password'] = 'PASSWORD'; |
| | | } |
| | | |
| | | /* Protocol is special-cased, as using the default "tcp" along with an |
| | | * Oracle TNS connection string fails. */ |
| | | if (is_string($dsn) && strpos($dsn, 'tcp') === false && $dsnArray['protocol'] == 'tcp') { |
| | | $dsnArray['protocol'] = false; |
| | | } |
| | | |
| | | // Now we just have to construct the actual string. This is ugly. |
| | | $dsnString = $dsnArray['phptype']; |
| | | if ($dsnArray['dbsyntax']) { |
| | | $dsnString .= '('.$dsnArray['dbsyntax'].')'; |
| | | } |
| | | $dsnString .= '://' |
| | | .$dsnArray['username'] |
| | | .':' |
| | | .$dsnArray['password'] |
| | | .'@' |
| | | .$dsnArray['protocol']; |
| | | if ($dsnArray['socket']) { |
| | | $dsnString .= '('.$dsnArray['socket'].')'; |
| | | } |
| | | if ($dsnArray['protocol'] && $dsnArray['hostspec']) { |
| | | $dsnString .= '+'; |
| | | } |
| | | $dsnString .= $dsnArray['hostspec']; |
| | | if ($dsnArray['port']) { |
| | | $dsnString .= ':'.$dsnArray['port']; |
| | | } |
| | | $dsnString .= '/'.$dsnArray['database']; |
| | | |
| | | /* Option handling. Unfortunately, parseDSN simply places options into |
| | | * the top-level array, so we'll first get rid of the fields defined by |
| | | * DB and see what's left. */ |
| | | unset($dsnArray['phptype'], |
| | | $dsnArray['dbsyntax'], |
| | | $dsnArray['username'], |
| | | $dsnArray['password'], |
| | | $dsnArray['protocol'], |
| | | $dsnArray['socket'], |
| | | $dsnArray['hostspec'], |
| | | $dsnArray['port'], |
| | | $dsnArray['database'] |
| | | ); |
| | | if (count($dsnArray) > 0) { |
| | | $dsnString .= '?'; |
| | | $i = 0; |
| | | foreach ($dsnArray as $key => $value) { |
| | | if (++$i > 1) { |
| | | $dsnString .= '&'; |
| | | } |
| | | $dsnString .= $key.'='.$value; |
| | | } |
| | | } |
| | | |
| | | return $dsnString; |
| | | } |
| | | |
| | | // }}} |
| | | } |
| | | |
| | | // }}} |
| | |
| | | * @category Database |
| | | * @package DB |
| | | * @author Stig Bakken <ssb@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_Error extends PEAR_Error |
| | |
| | | * @category Database |
| | | * @package DB |
| | | * @author Stig Bakken <ssb@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_result |
| | |
| | | $fetchmode = DB_FETCHMODE_ASSOC; |
| | | $object_class = $this->fetchmode_object_class; |
| | | } |
| | | if ($this->limit_from !== null) { |
| | | if (is_null($rownum) && $this->limit_from !== null) { |
| | | if ($this->row_counter === null) { |
| | | $this->row_counter = $this->limit_from; |
| | | // Skip rows |
| | |
| | | if ($object_class == 'stdClass') { |
| | | $arr = (object) $arr; |
| | | } else { |
| | | $arr = &new $object_class($arr); |
| | | $arr = new $object_class($arr); |
| | | } |
| | | } |
| | | return $arr; |
| | |
| | | $fetchmode = DB_FETCHMODE_ASSOC; |
| | | $object_class = $this->fetchmode_object_class; |
| | | } |
| | | if ($this->limit_from !== null) { |
| | | if (is_null($rownum) && $this->limit_from !== null) { |
| | | if ($this->row_counter === null) { |
| | | $this->row_counter = $this->limit_from; |
| | | // Skip rows |
| | |
| | | while ($res->fetchInto($tmp, DB_FETCHMODE_ORDERED)) { |
| | | $i++; |
| | | } |
| | | return $i; |
| | | $count = $i; |
| | | } else { |
| | | return $this->dbh->numRows($this->result); |
| | | $count = $this->dbh->numRows($this->result); |
| | | } |
| | | |
| | | /* fbsql is checked for here because limit queries are implemented |
| | | * using a TOP() function, which results in fbsql_num_rows still |
| | | * returning the total number of rows that would have been returned, |
| | | * rather than the real number. As a result, we'll just do the limit |
| | | * calculations for fbsql in the same way as a database with emulated |
| | | * limits. Unfortunately, we can't just do this in DB_fbsql::numRows() |
| | | * because that only gets the result resource, rather than the full |
| | | * DB_Result object. */ |
| | | if (($this->dbh->features['limit'] === 'emulate' |
| | | && $this->limit_from !== null) |
| | | || $this->dbh->phptype == 'fbsql') { |
| | | $limit_count = is_null($this->limit_count) ? $count : $this->limit_count; |
| | | if ($count < $this->limit_from) { |
| | | $count = 0; |
| | | } elseif ($count < ($this->limit_from + $limit_count)) { |
| | | $count -= $this->limit_from; |
| | | } else { |
| | | $count = $limit_count; |
| | | } |
| | | } |
| | | |
| | | return $count; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | * @category Database |
| | | * @package DB |
| | | * @author Stig Bakken <ssb@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 |
| | | * @see DB_common::setFetchMode() |
| | | */ |
| | |
| | | * @author Stig Bakken <ssb@php.net> |
| | | * @author Tomas V.V. Cox <cox@idecnet.com> |
| | | * @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 Stig Bakken <ssb@php.net> |
| | | * @author Tomas V.V. Cox <cox@idecnet.com> |
| | | * @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_common extends PEAR |
| | |
| | | * @var array |
| | | */ |
| | | var $prepared_queries = array(); |
| | | |
| | | /** |
| | | * Flag indicating that the last query was a manipulation query. |
| | | * @access protected |
| | | * @var boolean |
| | | */ |
| | | var $_last_query_manip = false; |
| | | |
| | | /** |
| | | * Flag indicating that the next query <em>must</em> be a manipulation |
| | | * query. |
| | | * @access protected |
| | | * @var boolean |
| | | */ |
| | | var $_next_query_manip = false; |
| | | |
| | | |
| | | // }}} |
| | |
| | | */ |
| | | function quoteSmart($in) |
| | | { |
| | | if (is_int($in) || is_double($in)) { |
| | | if (is_int($in)) { |
| | | return $in; |
| | | } elseif (is_float($in)) { |
| | | return $this->quoteFloat($in); |
| | | } elseif (is_bool($in)) { |
| | | return $in ? 1 : 0; |
| | | return $this->quoteBoolean($in); |
| | | } elseif (is_null($in)) { |
| | | return 'NULL'; |
| | | } else { |
| | | if ($this->dbsyntax == 'access' |
| | | && preg_match('/^#.+#$/', $in)) |
| | | { |
| | | return $this->escapeSimple($in); |
| | | } |
| | | return "'" . $this->escapeSimple($in) . "'"; |
| | | } |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ quoteBoolean() |
| | | |
| | | /** |
| | | * Formats a boolean value for use within a query in a locale-independent |
| | | * manner. |
| | | * |
| | | * @param boolean the boolean value to be quoted. |
| | | * @return string the quoted string. |
| | | * @see DB_common::quoteSmart() |
| | | * @since Method available since release 1.7.8. |
| | | */ |
| | | function quoteBoolean($boolean) { |
| | | return $boolean ? '1' : '0'; |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ 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))))."'"; |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ escapeSimple() |
| | | |
| | |
| | | if (DB::isError($sth)) { |
| | | return $sth; |
| | | } |
| | | $ret =& $this->execute($sth, array_values($fields_values)); |
| | | $ret = $this->execute($sth, array_values($fields_values)); |
| | | $this->freePrepared($sth); |
| | | return $ret; |
| | | |
| | |
| | | * "'it''s good'", |
| | | * 'filename.txt' |
| | | * ); |
| | | * $res =& $db->execute($sth, $data); |
| | | * $res = $db->execute($sth, $data); |
| | | * </code> |
| | | * |
| | | * @param resource $stmt a DB statement resource returned from prepare() |
| | |
| | | if ($result === DB_OK || DB::isError($result)) { |
| | | return $result; |
| | | } else { |
| | | $tmp =& new DB_result($this, $result); |
| | | $tmp = new DB_result($this, $result); |
| | | return $tmp; |
| | | } |
| | | } |
| | |
| | | function executeMultiple($stmt, $data) |
| | | { |
| | | foreach ($data as $value) { |
| | | $res =& $this->execute($stmt, $value); |
| | | $res = $this->execute($stmt, $value); |
| | | if (DB::isError($res)) { |
| | | return $res; |
| | | } |
| | |
| | | if (DB::isError($sth)) { |
| | | return $sth; |
| | | } |
| | | $ret =& $this->execute($sth, $params); |
| | | $ret = $this->execute($sth, $params); |
| | | $this->freePrepared($sth, false); |
| | | return $ret; |
| | | } else { |
| | |
| | | if ($result === DB_OK || DB::isError($result)) { |
| | | return $result; |
| | | } else { |
| | | $tmp =& new DB_result($this, $result); |
| | | $tmp = new DB_result($this, $result); |
| | | return $tmp; |
| | | } |
| | | } |
| | |
| | | if (DB::isError($query)){ |
| | | return $query; |
| | | } |
| | | $result =& $this->query($query, $params); |
| | | $result = $this->query($query, $params); |
| | | if (is_a($result, 'DB_result')) { |
| | | $result->setOption('limit_from', $from); |
| | | $result->setOption('limit_count', $count); |
| | |
| | | if (DB::isError($sth)) { |
| | | return $sth; |
| | | } |
| | | $res =& $this->execute($sth, $params); |
| | | $res = $this->execute($sth, $params); |
| | | $this->freePrepared($sth); |
| | | } else { |
| | | $res =& $this->query($query); |
| | | $res = $this->query($query); |
| | | } |
| | | |
| | | if (DB::isError($res)) { |
| | |
| | | if (DB::isError($sth)) { |
| | | return $sth; |
| | | } |
| | | $res =& $this->execute($sth, $params); |
| | | $res = $this->execute($sth, $params); |
| | | $this->freePrepared($sth); |
| | | } else { |
| | | $res =& $this->query($query); |
| | | $res = $this->query($query); |
| | | } |
| | | |
| | | if (DB::isError($res)) { |
| | |
| | | return $sth; |
| | | } |
| | | |
| | | $res =& $this->execute($sth, $params); |
| | | $res = $this->execute($sth, $params); |
| | | $this->freePrepared($sth); |
| | | } else { |
| | | $res =& $this->query($query); |
| | | $res = $this->query($query); |
| | | } |
| | | |
| | | if (DB::isError($res)) { |
| | |
| | | $ret = array(); |
| | | } else { |
| | | if (!array_key_exists($col, $row)) { |
| | | $ret =& $this->raiseError(DB_ERROR_NOSUCHFIELD); |
| | | $ret = $this->raiseError(DB_ERROR_NOSUCHFIELD); |
| | | } else { |
| | | $ret = array($row[$col]); |
| | | while (is_array($row = $res->fetchRow($fetchmode))) { |
| | |
| | | return $sth; |
| | | } |
| | | |
| | | $res =& $this->execute($sth, $params); |
| | | $res = $this->execute($sth, $params); |
| | | $this->freePrepared($sth); |
| | | } else { |
| | | $res =& $this->query($query); |
| | | $res = $this->query($query); |
| | | } |
| | | |
| | | if (DB::isError($res)) { |
| | |
| | | $cols = $res->numCols(); |
| | | |
| | | if ($cols < 2) { |
| | | $tmp =& $this->raiseError(DB_ERROR_TRUNCATED); |
| | | $tmp = $this->raiseError(DB_ERROR_TRUNCATED); |
| | | return $tmp; |
| | | } |
| | | |
| | |
| | | return $sth; |
| | | } |
| | | |
| | | $res =& $this->execute($sth, $params); |
| | | $res = $this->execute($sth, $params); |
| | | $this->freePrepared($sth); |
| | | } else { |
| | | $res =& $this->query($query); |
| | | $res = $this->query($query); |
| | | } |
| | | |
| | | if ($res === DB_OK || DB::isError($res)) { |
| | |
| | | $res->free(); |
| | | |
| | | if (DB::isError($row)) { |
| | | $tmp =& $this->raiseError($row); |
| | | $tmp = $this->raiseError($row); |
| | | return $tmp; |
| | | } |
| | | return $results; |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ nextQueryIsManip() |
| | | |
| | | /** |
| | | * Sets (or unsets) a flag indicating that the next query will be a |
| | | * manipulation query, regardless of the usual DB::isManip() heuristics. |
| | | * |
| | | * @param boolean true to set the flag overriding the isManip() behaviour, |
| | | * false to clear it and fall back onto isManip() |
| | | * |
| | | * @return void |
| | | * |
| | | * @access public |
| | | */ |
| | | function nextQueryIsManip($manip) |
| | | { |
| | | $this->_next_query_manip = $manip; |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ _checkManip() |
| | | |
| | | /** |
| | | * Checks if the given query is a manipulation query. This also takes into |
| | | * account the _next_query_manip flag and sets the _last_query_manip flag |
| | | * (and resets _next_query_manip) according to the result. |
| | | * |
| | | * @param string The query to check. |
| | | * |
| | | * @return boolean true if the query is a manipulation query, false |
| | | * otherwise |
| | | * |
| | | * @access protected |
| | | */ |
| | | function _checkManip($query) |
| | | { |
| | | if ($this->_next_query_manip || DB::isManip($query)) { |
| | | $this->_last_query_manip = true; |
| | | } else { |
| | | $this->_last_query_manip = false; |
| | | } |
| | | $this->_next_query_manip = false; |
| | | return $this->_last_query_manip; |
| | | $manip = $this->_next_query_manip; |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ _rtrimArrayValues() |
| | | |
| | | /** |
| | |
| | | * @package DB |
| | | * @author Tomas V.V. Cox <cox@idecnet.com> |
| | | * @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 |
| | |
| | | * @package DB |
| | | * @author Tomas V.V. Cox <cox@idecnet.com> |
| | | * @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_dbase extends DB_common |
| | |
| | | * 'portability' => DB_PORTABILITY_ALL, |
| | | * ); |
| | | * |
| | | * $db =& DB::connect($dsn, $options); |
| | | * $db = DB::connect($dsn, $options); |
| | | * if (PEAR::isError($db)) { |
| | | * die($db->getMessage()); |
| | | * } |
| | |
| | | * Turn track_errors on for entire script since $php_errormsg |
| | | * is the only way to find errors from the dbase extension. |
| | | */ |
| | | ini_set('track_errors', 1); |
| | | @ini_set('track_errors', 1); |
| | | $php_errormsg = ''; |
| | | |
| | | if (!file_exists($dsn['database'])) { |
| | |
| | | { |
| | | // emulate result resources |
| | | $this->res_row[(int)$this->result] = 0; |
| | | $tmp =& new DB_result($this, $this->result++); |
| | | $tmp = new DB_result($this, $this->result++); |
| | | return $tmp; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ freeResult() |
| | | |
| | | /** |
| | | * Deletes the result set and frees the memory occupied by the result set. |
| | | * |
| | | * This method is a no-op for dbase, as there aren't result resources in |
| | | * the same sense as most other database backends. |
| | | * |
| | | * @param resource $result PHP's query result resource |
| | | * |
| | | * @return bool TRUE on success, FALSE if $result is invalid |
| | | * |
| | | * @see DB_result::free() |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ numCols() |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ quoteSmart() |
| | | // {{{ quoteBoolean() |
| | | |
| | | /** |
| | | * Formats input so it can be safely used in a query |
| | | * Formats a boolean value for use within a query in a locale-independent |
| | | * manner. |
| | | * |
| | | * @param mixed $in the data to be formatted |
| | | * |
| | | * @return mixed the formatted data. The format depends on the input's |
| | | * PHP type: |
| | | * + null = the string <samp>NULL</samp> |
| | | * + boolean = <samp>T</samp> if true or |
| | | * <samp>F</samp> if false. Use the <kbd>Logical</kbd> |
| | | * data type. |
| | | * + integer or double = the unquoted number |
| | | * + other (including strings and numeric strings) = |
| | | * the data with single quotes escaped by preceeding |
| | | * single quotes then the whole string is encapsulated |
| | | * between single quotes |
| | | * |
| | | * @param boolean the boolean value to be quoted. |
| | | * @return string the quoted string. |
| | | * @see DB_common::quoteSmart() |
| | | * @since Method available since Release 1.6.0 |
| | | * @since Method available since release 1.7.8. |
| | | */ |
| | | function quoteSmart($in) |
| | | { |
| | | if (is_int($in) || is_double($in)) { |
| | | return $in; |
| | | } elseif (is_bool($in)) { |
| | | return $in ? 'T' : 'F'; |
| | | } elseif (is_null($in)) { |
| | | return 'NULL'; |
| | | } else { |
| | | return "'" . $this->escapeSimple($in) . "'"; |
| | | } |
| | | function quoteBoolean($boolean) { |
| | | return $boolean ? 'T' : 'F'; |
| | | } |
| | | |
| | | |
| | | // }}} |
| | | // {{{ tableInfo() |
| | | |
| | |
| | | * @package DB |
| | | * @author Frank M. Kromann <frank@frontbase.com> |
| | | * @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 |
| | |
| | | * @package DB |
| | | * @author Frank M. Kromann <frank@frontbase.com> |
| | | * @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 |
| | | * @since Class functional since Release 1.7.0 |
| | | */ |
| | |
| | | $this->connection = @call_user_func_array($connect_function, |
| | | $params); |
| | | } else { |
| | | ini_set('track_errors', 1); |
| | | @ini_set('track_errors', 1); |
| | | $this->connection = @call_user_func_array($connect_function, |
| | | $params); |
| | | ini_set('track_errors', $ini); |
| | | @ini_set('track_errors', $ini); |
| | | } |
| | | |
| | | if (!$this->connection) { |
| | |
| | | } |
| | | // Determine which queries that should return data, and which |
| | | // should return an error code only. |
| | | if (DB::isManip($query)) { |
| | | if ($this->_checkManip($query)) { |
| | | return DB_OK; |
| | | } |
| | | return $result; |
| | |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return @fbsql_free_result($result); |
| | | return is_resource($result) ? fbsql_free_result($result) : false; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | */ |
| | | function commit() |
| | | { |
| | | @fbsql_commit(); |
| | | @fbsql_commit($this->connection); |
| | | } |
| | | |
| | | // }}} |
| | |
| | | */ |
| | | function rollback() |
| | | { |
| | | @fbsql_rollback(); |
| | | @fbsql_rollback($this->connection); |
| | | } |
| | | |
| | | // }}} |
| | |
| | | */ |
| | | function affectedRows() |
| | | { |
| | | if (DB::isManip($this->last_query)) { |
| | | if ($this->_last_query_manip) { |
| | | $result = @fbsql_affected_rows($this->connection); |
| | | } else { |
| | | $result = 0; |
| | |
| | | */ |
| | | function modifyLimitQuery($query, $from, $count, $params = array()) |
| | | { |
| | | if (DB::isManip($query)) { |
| | | if (DB::isManip($query) || $this->_next_query_manip) { |
| | | return preg_replace('/^([\s(])*SELECT/i', |
| | | "\\1SELECT TOP($count)", $query); |
| | | } else { |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ quoteSmart() |
| | | // {{{ quoteBoolean() |
| | | |
| | | /** |
| | | * Formats input so it can be safely used in a query |
| | | * Formats a boolean value for use within a query in a locale-independent |
| | | * manner. |
| | | * |
| | | * @param mixed $in the data to be formatted |
| | | * |
| | | * @return mixed the formatted data. The format depends on the input's |
| | | * PHP type: |
| | | * + null = the string <samp>NULL</samp> |
| | | * + boolean = string <samp>TRUE</samp> or <samp>FALSE</samp> |
| | | * + integer or double = the unquoted number |
| | | * + other (including strings and numeric strings) = |
| | | * the data escaped according to FrontBase's settings |
| | | * then encapsulated between single quotes |
| | | * |
| | | * @param boolean the boolean value to be quoted. |
| | | * @return string the quoted string. |
| | | * @see DB_common::quoteSmart() |
| | | * @since Method available since Release 1.6.0 |
| | | * @since Method available since release 1.7.8. |
| | | */ |
| | | function quoteSmart($in) |
| | | { |
| | | if (is_int($in) || is_double($in)) { |
| | | return $in; |
| | | } elseif (is_bool($in)) { |
| | | return $in ? 'TRUE' : 'FALSE'; |
| | | } elseif (is_null($in)) { |
| | | return 'NULL'; |
| | | } else { |
| | | return "'" . $this->escapeSimple($in) . "'"; |
| | | } |
| | | function quoteBoolean($boolean) { |
| | | return $boolean ? 'TRUE' : '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)))); |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ fbsqlRaiseError() |
| | | |
| | |
| | | * @package DB |
| | | * @author Sterling Hughes <sterling@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 |
| | |
| | | * @package DB |
| | | * @author Sterling Hughes <sterling@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 |
| | | * @since Class became stable in Release 1.7.0 |
| | | */ |
| | |
| | | -625 => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | -803 => DB_ERROR_CONSTRAINT, |
| | | -804 => DB_ERROR_VALUE_COUNT_ON_ROW, |
| | | // -902 => // Covers too many errors, need to use regex on msg |
| | | -904 => DB_ERROR_CONNECT_FAILED, |
| | | -922 => DB_ERROR_NOSUCHDB, |
| | | -923 => DB_ERROR_CONNECT_FAILED, |
| | |
| | | */ |
| | | function simpleQuery($query) |
| | | { |
| | | $ismanip = DB::isManip($query); |
| | | $ismanip = $this->_checkManip($query); |
| | | $this->last_query = $query; |
| | | $query = $this->modifyQuery($query); |
| | | $result = @ibase_query($this->connection, $query); |
| | |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return @ibase_free_result($result); |
| | | return is_resource($result) ? ibase_free_result($result) : false; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | |
| | | function freeQuery($query) |
| | | { |
| | | @ibase_free_query($query); |
| | | return true; |
| | | return is_resource($query) ? ibase_free_query($query) : false; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | $this->last_query = $query; |
| | | $newquery = $this->modifyQuery($newquery); |
| | | $stmt = @ibase_prepare($this->connection, $newquery); |
| | | $this->prepare_types[(int)$stmt] = $types; |
| | | $this->manip_query[(int)$stmt] = DB::isManip($query); |
| | | |
| | | if ($stmt === false) { |
| | | $stmt = $this->ibaseRaiseError(); |
| | | } else { |
| | | $this->prepare_types[(int)$stmt] = $types; |
| | | $this->manip_query[(int)$stmt] = DB::isManip($query); |
| | | } |
| | | |
| | | return $stmt; |
| | | } |
| | | |
| | |
| | | $data = (array)$data; |
| | | $this->last_parameters = $data; |
| | | |
| | | $types =& $this->prepare_types[(int)$stmt]; |
| | | $types = $this->prepare_types[(int)$stmt]; |
| | | if (count($types) != count($data)) { |
| | | $tmp =& $this->raiseError(DB_ERROR_MISMATCH); |
| | | $tmp = $this->raiseError(DB_ERROR_MISMATCH); |
| | | return $tmp; |
| | | } |
| | | |
| | |
| | | } elseif ($types[$i] == DB_PARAM_OPAQUE) { |
| | | $fp = @fopen($data[$key], 'rb'); |
| | | if (!$fp) { |
| | | $tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION); |
| | | $tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION); |
| | | return $tmp; |
| | | } |
| | | $data[$key] = fread($fp, filesize($data[$key])); |
| | |
| | | |
| | | $res = call_user_func_array('ibase_execute', $data); |
| | | if (!$res) { |
| | | $tmp =& $this->ibaseRaiseError(); |
| | | $tmp = $this->ibaseRaiseError(); |
| | | return $tmp; |
| | | } |
| | | /* XXX need this? |
| | |
| | | @ibase_commit($this->connection); |
| | | }*/ |
| | | $this->last_stmt = $stmt; |
| | | if ($this->manip_query[(int)$stmt]) { |
| | | if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) { |
| | | $this->_last_query_manip = true; |
| | | $this->_next_query_manip = false; |
| | | $tmp = DB_OK; |
| | | } else { |
| | | $tmp =& new DB_result($this, $res); |
| | | $this->_last_query_manip = false; |
| | | $tmp = new DB_result($this, $res); |
| | | } |
| | | return $tmp; |
| | | } |
| | |
| | | $repeat = 0; |
| | | do { |
| | | $this->pushErrorHandling(PEAR_ERROR_RETURN); |
| | | $result =& $this->query("SELECT GEN_ID(${sqn}, 1) " |
| | | $result = $this->query("SELECT GEN_ID(${sqn}, 1) " |
| | | . 'FROM RDB$GENERATORS ' |
| | | . "WHERE RDB\$GENERATOR_NAME='${sqn}'"); |
| | | $this->popErrorHandling(); |
| | |
| | | if ($errno === null) { |
| | | $errno = $this->errorCode($this->errorNative()); |
| | | } |
| | | $tmp =& $this->raiseError($errno, null, null, null, @ibase_errmsg()); |
| | | $tmp = $this->raiseError($errno, null, null, null, @ibase_errmsg()); |
| | | return $tmp; |
| | | } |
| | | |
| | |
| | | => DB_ERROR_ACCESS_VIOLATION, |
| | | '/arithmetic exception, numeric overflow, or string truncation/i' |
| | | => DB_ERROR_INVALID, |
| | | '/feature is not supported/i' |
| | | => DB_ERROR_NOT_CAPABLE, |
| | | ); |
| | | } |
| | | |
| | |
| | | * @package DB |
| | | * @author Tomas V.V.Cox <cox@idecnet.com> |
| | | * @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 |
| | |
| | | * @package DB |
| | | * @author Tomas V.V.Cox <cox@idecnet.com> |
| | | * @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_ifx extends DB_common |
| | |
| | | '-236' => DB_ERROR_VALUE_COUNT_ON_ROW, |
| | | '-239' => DB_ERROR_CONSTRAINT, |
| | | '-253' => DB_ERROR_SYNTAX, |
| | | '-268' => DB_ERROR_CONSTRAINT, |
| | | '-292' => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | '-310' => DB_ERROR_ALREADY_EXISTS, |
| | | '-316' => DB_ERROR_ALREADY_EXISTS, |
| | |
| | | '-691' => DB_ERROR_CONSTRAINT, |
| | | '-692' => DB_ERROR_CONSTRAINT, |
| | | '-703' => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | '-1202' => DB_ERROR_DIVZERO, |
| | | '-1204' => DB_ERROR_INVALID_DATE, |
| | | '-1205' => DB_ERROR_INVALID_DATE, |
| | | '-1206' => DB_ERROR_INVALID_DATE, |
| | |
| | | */ |
| | | function simpleQuery($query) |
| | | { |
| | | $ismanip = DB::isManip($query); |
| | | $ismanip = $this->_checkManip($query); |
| | | $this->last_query = $query; |
| | | $this->affected = null; |
| | | if (preg_match('/(SELECT)/i', $query)) { //TESTME: Use !DB::isManip()? |
| | | if (preg_match('/(SELECT|EXECUTE)/i', $query)) { //TESTME: Use !DB::isManip()? |
| | | // the scroll is needed for fetching absolute row numbers |
| | | // in a select query result |
| | | $result = @ifx_query($query, $this->connection, IFX_SCROLL); |
| | |
| | | $this->affected = @ifx_affected_rows($result); |
| | | // Determine which queries should return data, and which |
| | | // should return an error code only. |
| | | if (preg_match('/(SELECT)/i', $query)) { |
| | | if (preg_match('/(SELECT|EXECUTE)/i', $query)) { |
| | | return $result; |
| | | } |
| | | // XXX Testme: free results inside a transaction |
| | |
| | | */ |
| | | function affectedRows() |
| | | { |
| | | if (DB::isManip($this->last_query)) { |
| | | if ($this->_last_query_manip) { |
| | | return $this->affected; |
| | | } else { |
| | | return 0; |
| | |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return @ifx_free_result($result); |
| | | return is_resource($result) ? ifx_free_result($result) : false; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | * @category Database |
| | | * @package DB |
| | | * @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 |
| | |
| | | * @category Database |
| | | * @package DB |
| | | * @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 |
| | | * @since Class not functional until Release 1.7.0 |
| | | */ |
| | |
| | | * 'portability' => DB_PORTABILITY_ALL, |
| | | * ); |
| | | * |
| | | * $db =& DB::connect($dsn, $options); |
| | | * $db = DB::connect($dsn, $options); |
| | | * if (PEAR::isError($db)) { |
| | | * die($db->getMessage()); |
| | | * } |
| | |
| | | $this->connection = @call_user_func_array($connect_function, |
| | | $params); |
| | | } else { |
| | | ini_set('track_errors', 1); |
| | | @ini_set('track_errors', 1); |
| | | $this->connection = @call_user_func_array($connect_function, |
| | | $params); |
| | | ini_set('track_errors', $ini); |
| | | @ini_set('track_errors', $ini); |
| | | } |
| | | |
| | | if (!$this->connection) { |
| | |
| | | } |
| | | // Determine which queries that should return data, and which |
| | | // should return an error code only. |
| | | if (DB::isManip($query)) { |
| | | if ($this->_checkManip($query)) { |
| | | $this->_result = $result; |
| | | return DB_OK; |
| | | } else { |
| | |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return @msql_free_result($result); |
| | | return is_resource($result) ? msql_free_result($result) : false; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | $repeat = false; |
| | | do { |
| | | $this->pushErrorHandling(PEAR_ERROR_RETURN); |
| | | $result =& $this->query("SELECT _seq FROM ${seqname}"); |
| | | $result = $this->query("SELECT _seq FROM ${seqname}"); |
| | | $this->popErrorHandling(); |
| | | if ($ondemand && DB::isError($result) && |
| | | $result->getCode() == DB_ERROR_NOSUCHTABLE) { |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ 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)))); |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ escapeSimple() |
| | | |
| | | /** |
| | |
| | | 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('/^msql[a-z_]+\(\): /', '', $errormsg); |
| | | |
| | | if (!isset($error_regexps)) { |
| | | $error_regexps = array( |
| | | '/^Access to database denied/i' |
| | |
| | | * @package DB |
| | | * @author Sterling Hughes <sterling@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 |
| | |
| | | * |
| | | * These methods overload the ones declared in DB_common. |
| | | * |
| | | * DB's mssql driver is only for Microsfoft SQL Server databases. |
| | | * |
| | | * If you're connecting to a Sybase database, you MUST specify "sybase" |
| | | * as the "phptype" in the DSN. |
| | | * |
| | | * This class only works correctly if you have compiled PHP using |
| | | * --with-mssql=[dir_to_FreeTDS]. |
| | | * |
| | | * @category Database |
| | | * @package DB |
| | | * @author Sterling Hughes <sterling@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_mssql extends DB_common |
| | |
| | | */ |
| | | // XXX Add here error codes ie: 'S100E' => DB_ERROR_SYNTAX |
| | | var $errorcode_map = array( |
| | | 102 => DB_ERROR_SYNTAX, |
| | | 110 => DB_ERROR_VALUE_COUNT_ON_ROW, |
| | | 155 => DB_ERROR_NOSUCHFIELD, |
| | | 156 => DB_ERROR_SYNTAX, |
| | | 170 => DB_ERROR_SYNTAX, |
| | | 207 => DB_ERROR_NOSUCHFIELD, |
| | | 208 => DB_ERROR_NOSUCHTABLE, |
| | | 245 => DB_ERROR_INVALID_NUMBER, |
| | | 319 => DB_ERROR_SYNTAX, |
| | | 321 => DB_ERROR_NOSUCHFIELD, |
| | | 325 => DB_ERROR_SYNTAX, |
| | | 336 => DB_ERROR_SYNTAX, |
| | | 515 => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | 547 => DB_ERROR_CONSTRAINT, |
| | | 1018 => DB_ERROR_SYNTAX, |
| | | 1035 => DB_ERROR_SYNTAX, |
| | | 1913 => DB_ERROR_ALREADY_EXISTS, |
| | | 2209 => DB_ERROR_SYNTAX, |
| | | 2223 => DB_ERROR_SYNTAX, |
| | | 2248 => DB_ERROR_SYNTAX, |
| | | 2256 => DB_ERROR_SYNTAX, |
| | | 2257 => DB_ERROR_SYNTAX, |
| | | 2627 => DB_ERROR_CONSTRAINT, |
| | | 2714 => DB_ERROR_ALREADY_EXISTS, |
| | | 3607 => DB_ERROR_DIVZERO, |
| | | 3701 => DB_ERROR_NOSUCHTABLE, |
| | | 7630 => DB_ERROR_SYNTAX, |
| | | 8134 => DB_ERROR_DIVZERO, |
| | | 9303 => DB_ERROR_SYNTAX, |
| | | 9317 => DB_ERROR_SYNTAX, |
| | | 9318 => DB_ERROR_SYNTAX, |
| | | 9331 => DB_ERROR_SYNTAX, |
| | | 9332 => DB_ERROR_SYNTAX, |
| | | 15253 => DB_ERROR_SYNTAX, |
| | | ); |
| | | |
| | | /** |
| | |
| | | */ |
| | | function simpleQuery($query) |
| | | { |
| | | $ismanip = DB::isManip($query); |
| | | $ismanip = $this->_checkManip($query); |
| | | $this->last_query = $query; |
| | | if (!@mssql_select_db($this->_db, $this->connection)) { |
| | | return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED); |
| | |
| | | } |
| | | } |
| | | if ($fetchmode & DB_FETCHMODE_ASSOC) { |
| | | $arr = @mssql_fetch_array($result, MSSQL_ASSOC); |
| | | $arr = @mssql_fetch_assoc($result); |
| | | if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { |
| | | $arr = array_change_key_case($arr, CASE_LOWER); |
| | | } |
| | |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return @mssql_free_result($result); |
| | | return is_resource($result) ? mssql_free_result($result) : false; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | */ |
| | | function affectedRows() |
| | | { |
| | | if (DB::isManip($this->last_query)) { |
| | | if ($this->_last_query_manip) { |
| | | $res = @mssql_query('select @@rowcount', $this->connection); |
| | | if (!$res) { |
| | | return $this->mssqlRaiseError(); |
| | |
| | | return $this->raiseError($result); |
| | | } |
| | | } elseif (!DB::isError($result)) { |
| | | $result =& $this->query("SELECT @@IDENTITY FROM $seqname"); |
| | | $result = $this->query("SELECT IDENT_CURRENT('$seqname')"); |
| | | if (DB::isError($result)) { |
| | | /* Fallback code for MS SQL Server 7.0, which doesn't have |
| | | * IDENT_CURRENT. This is *not* safe for concurrent |
| | | * requests, and really, if you're using it, you're in a |
| | | * world of hurt. Nevertheless, it's here to ensure BC. See |
| | | * bug #181 for the gory details.*/ |
| | | $result = $this->query("SELECT @@IDENTITY FROM $seqname"); |
| | | } |
| | | $repeat = 0; |
| | | } else { |
| | | $repeat = false; |
| | |
| | | } |
| | | |
| | | for ($i = 0; $i < $count; $i++) { |
| | | if ($got_string) { |
| | | $flags = $this->_mssql_field_flags($result, |
| | | @mssql_field_name($id, $i)); |
| | | if (DB::isError($flags)) { |
| | | return $flags; |
| | | } |
| | | } else { |
| | | $flags = ''; |
| | | } |
| | | |
| | | $res[$i] = array( |
| | | 'table' => $got_string ? $case_func($result) : '', |
| | | 'name' => $case_func(@mssql_field_name($id, $i)), |
| | | 'type' => @mssql_field_type($id, $i), |
| | | 'len' => @mssql_field_length($id, $i), |
| | | // We only support flags for table |
| | | 'flags' => $got_string |
| | | ? $this->_mssql_field_flags($result, |
| | | @mssql_field_name($id, $i)) |
| | | : '', |
| | | 'flags' => $flags, |
| | | ); |
| | | if ($mode & DB_TABLEINFO_ORDER) { |
| | | $res['order'][$res[$i]['name']] = $i; |
| | |
| | | $tableName = $table; |
| | | |
| | | // get unique and primary keys |
| | | $res = $this->getAll("EXEC SP_HELPINDEX[$table]", DB_FETCHMODE_ASSOC); |
| | | $res = $this->getAll("EXEC SP_HELPINDEX $table", DB_FETCHMODE_ASSOC); |
| | | if (DB::isError($res)) { |
| | | return $res; |
| | | } |
| | | |
| | | foreach ($res as $val) { |
| | | $keys = explode(', ', $val['index_keys']); |
| | |
| | | } |
| | | |
| | | // get auto_increment, not_null and timestamp |
| | | $res = $this->getAll("EXEC SP_COLUMNS[$table]", DB_FETCHMODE_ASSOC); |
| | | $res = $this->getAll("EXEC SP_COLUMNS $table", DB_FETCHMODE_ASSOC); |
| | | if (DB::isError($res)) { |
| | | return $res; |
| | | } |
| | | |
| | | foreach ($res as $val) { |
| | | $val = array_change_key_case($val, CASE_LOWER); |
| | |
| | | * @package DB |
| | | * @author Stig Bakken <ssb@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 |
| | |
| | | * @package DB |
| | | * @author Stig Bakken <ssb@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_mysql extends DB_common |
| | |
| | | 1146 => DB_ERROR_NOSUCHTABLE, |
| | | 1216 => DB_ERROR_CONSTRAINT, |
| | | 1217 => DB_ERROR_CONSTRAINT, |
| | | 1356 => DB_ERROR_DIVZERO, |
| | | 1451 => DB_ERROR_CONSTRAINT, |
| | | 1452 => DB_ERROR_CONSTRAINT, |
| | | ); |
| | | |
| | | /** |
| | |
| | | $this->connection = @call_user_func_array($connect_function, |
| | | $params); |
| | | } else { |
| | | ini_set('track_errors', 1); |
| | | @ini_set('track_errors', 1); |
| | | $this->connection = @call_user_func_array($connect_function, |
| | | $params); |
| | | ini_set('track_errors', $ini); |
| | | @ini_set('track_errors', $ini); |
| | | } |
| | | |
| | | if (!$this->connection) { |
| | |
| | | */ |
| | | function simpleQuery($query) |
| | | { |
| | | $ismanip = DB::isManip($query); |
| | | $ismanip = $this->_checkManip($query); |
| | | $this->last_query = $query; |
| | | $query = $this->modifyQuery($query); |
| | | if ($this->_db) { |
| | |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return @mysql_free_result($result); |
| | | return is_resource($result) ? mysql_free_result($result) : false; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | */ |
| | | function affectedRows() |
| | | { |
| | | if (DB::isManip($this->last_query)) { |
| | | if ($this->_last_query_manip) { |
| | | return @mysql_affected_rows($this->connection); |
| | | } else { |
| | | return 0; |
| | |
| | | |
| | | /** |
| | | * Quotes a string so it can be safely used as a table or column name |
| | | * (WARNING: using names that require this is a REALLY BAD IDEA) |
| | | * |
| | | * MySQL can't handle the backtick character (<kbd>`</kbd>) in |
| | | * table or column names. |
| | | * WARNING: Older versions of MySQL can't handle the backtick |
| | | * character (<kbd>`</kbd>) in table or column names. |
| | | * |
| | | * @param string $str identifier name to be quoted |
| | | * |
| | |
| | | */ |
| | | function quoteIdentifier($str) |
| | | { |
| | | return '`' . $str . '`'; |
| | | return '`' . str_replace('`', '``', $str) . '`'; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | */ |
| | | function modifyLimitQuery($query, $from, $count, $params = array()) |
| | | { |
| | | if (DB::isManip($query)) { |
| | | if (DB::isManip($query) || $this->_next_query_manip) { |
| | | return $query . " LIMIT $count"; |
| | | } else { |
| | | return $query . " LIMIT $from, $count"; |
| | |
| | | function tableInfo($result, $mode = null) |
| | | { |
| | | if (is_string($result)) { |
| | | // Fix for bug #11580. |
| | | if ($this->_db) { |
| | | if (!@mysql_select_db($this->_db, $this->connection)) { |
| | | return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); |
| | | } |
| | | } |
| | | |
| | | /* |
| | | * Probably received a table name. |
| | | * Create a result resource identifier. |
| | | */ |
| | | $id = @mysql_list_fields($this->dsn['database'], |
| | | $result, $this->connection); |
| | | $id = @mysql_query("SELECT * FROM $result LIMIT 0", |
| | | $this->connection); |
| | | $got_string = true; |
| | | } elseif (isset($result->result)) { |
| | | /* |
| | |
| | | * @category Database |
| | | * @package DB |
| | | * @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 |
| | |
| | | * @category Database |
| | | * @package DB |
| | | * @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 |
| | | * @since Class functional since Release 1.6.3 |
| | | */ |
| | |
| | | 1146 => DB_ERROR_NOSUCHTABLE, |
| | | 1216 => DB_ERROR_CONSTRAINT, |
| | | 1217 => DB_ERROR_CONSTRAINT, |
| | | 1356 => DB_ERROR_DIVZERO, |
| | | 1451 => DB_ERROR_CONSTRAINT, |
| | | 1452 => DB_ERROR_CONSTRAINT, |
| | | ); |
| | | |
| | | /** |
| | |
| | | MYSQLI_TYPE_VAR_STRING => 'varchar', |
| | | MYSQLI_TYPE_STRING => 'char', |
| | | MYSQLI_TYPE_GEOMETRY => 'geometry', |
| | | /* These constants are conditionally compiled in ext/mysqli, so we'll |
| | | * define them by number rather than constant. */ |
| | | 16 => 'bit', |
| | | 246 => 'decimal', |
| | | ); |
| | | |
| | | |
| | |
| | | * 'ssl' => true, |
| | | * ); |
| | | * |
| | | * $db =& DB::connect($dsn, $options); |
| | | * $db = DB::connect($dsn, $options); |
| | | * if (PEAR::isError($db)) { |
| | | * die($db->getMessage()); |
| | | * } |
| | |
| | | } |
| | | |
| | | $ini = ini_get('track_errors'); |
| | | ini_set('track_errors', 1); |
| | | @ini_set('track_errors', 1); |
| | | $php_errormsg = ''; |
| | | |
| | | if ($this->getOption('ssl') === true) { |
| | | if (((int) $this->getOption('ssl')) === 1) { |
| | | $init = mysqli_init(); |
| | | mysqli_ssl_set( |
| | | $init, |
| | |
| | | ); |
| | | } |
| | | |
| | | ini_set('track_errors', $ini); |
| | | @ini_set('track_errors', $ini); |
| | | |
| | | if (!$this->connection) { |
| | | if (($err = @mysqli_connect_error()) != '') { |
| | |
| | | */ |
| | | function simpleQuery($query) |
| | | { |
| | | $ismanip = DB::isManip($query); |
| | | $ismanip = $this->_checkManip($query); |
| | | $this->last_query = $query; |
| | | $query = $this->modifyQuery($query); |
| | | if ($this->_db) { |
| | |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return @mysqli_free_result($result); |
| | | return is_resource($result) ? mysqli_free_result($result) : false; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | */ |
| | | function affectedRows() |
| | | { |
| | | if (DB::isManip($this->last_query)) { |
| | | if ($this->_last_query_manip) { |
| | | return @mysqli_affected_rows($this->connection); |
| | | } else { |
| | | return 0; |
| | |
| | | |
| | | /** |
| | | * Quotes a string so it can be safely used as a table or column name |
| | | * (WARNING: using names that require this is a REALLY BAD IDEA) |
| | | * |
| | | * MySQL can't handle the backtick character (<kbd>`</kbd>) in |
| | | * table or column names. |
| | | * WARNING: Older versions of MySQL can't handle the backtick |
| | | * character (<kbd>`</kbd>) in table or column names. |
| | | * |
| | | * @param string $str identifier name to be quoted |
| | | * |
| | |
| | | */ |
| | | function quoteIdentifier($str) |
| | | { |
| | | return '`' . $str . '`'; |
| | | return '`' . str_replace('`', '``', $str) . '`'; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | */ |
| | | function modifyLimitQuery($query, $from, $count, $params = array()) |
| | | { |
| | | if (DB::isManip($query)) { |
| | | if (DB::isManip($query) || $this->_next_query_manip) { |
| | | return $query . " LIMIT $count"; |
| | | } else { |
| | | return $query . " LIMIT $from, $count"; |
| | |
| | | function tableInfo($result, $mode = null) |
| | | { |
| | | if (is_string($result)) { |
| | | // Fix for bug #11580. |
| | | if ($this->_db) { |
| | | if (!@mysqli_select_db($this->connection, $this->_db)) { |
| | | return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED); |
| | | } |
| | | } |
| | | |
| | | /* |
| | | * Probably received a table name. |
| | | * Create a result resource identifier. |
| | |
| | | 'type' => isset($this->mysqli_types[$tmp->type]) |
| | | ? $this->mysqli_types[$tmp->type] |
| | | : 'unknown', |
| | | 'len' => $tmp->max_length, |
| | | // http://bugs.php.net/?id=36579 |
| | | 'len' => $tmp->length, |
| | | 'flags' => $flags, |
| | | ); |
| | | |
| | |
| | | * @package DB |
| | | * @author James L. Pine <jlp@valinux.com> |
| | | * @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 |
| | |
| | | * @package DB |
| | | * @author James L. Pine <jlp@valinux.com> |
| | | * @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_oci8 extends DB_common |
| | |
| | | * @var array |
| | | */ |
| | | var $errorcode_map = array( |
| | | 1 => DB_ERROR_CONSTRAINT, |
| | | 900 => DB_ERROR_SYNTAX, |
| | | 904 => DB_ERROR_NOSUCHFIELD, |
| | | 913 => DB_ERROR_VALUE_COUNT_ON_ROW, |
| | | 921 => DB_ERROR_SYNTAX, |
| | | 923 => DB_ERROR_SYNTAX, |
| | | 942 => DB_ERROR_NOSUCHTABLE, |
| | | 955 => DB_ERROR_ALREADY_EXISTS, |
| | | 1400 => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | 1401 => DB_ERROR_INVALID, |
| | | 1407 => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | 1418 => DB_ERROR_NOT_FOUND, |
| | | 1476 => DB_ERROR_DIVZERO, |
| | | 1722 => DB_ERROR_INVALID_NUMBER, |
| | | 2289 => DB_ERROR_NOSUCHTABLE, |
| | | 2291 => DB_ERROR_CONSTRAINT, |
| | | 2292 => DB_ERROR_CONSTRAINT, |
| | | 2449 => DB_ERROR_CONSTRAINT, |
| | | 1 => DB_ERROR_CONSTRAINT, |
| | | 900 => DB_ERROR_SYNTAX, |
| | | 904 => DB_ERROR_NOSUCHFIELD, |
| | | 913 => DB_ERROR_VALUE_COUNT_ON_ROW, |
| | | 921 => DB_ERROR_SYNTAX, |
| | | 923 => DB_ERROR_SYNTAX, |
| | | 942 => DB_ERROR_NOSUCHTABLE, |
| | | 955 => DB_ERROR_ALREADY_EXISTS, |
| | | 1400 => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | 1401 => DB_ERROR_INVALID, |
| | | 1407 => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | 1418 => DB_ERROR_NOT_FOUND, |
| | | 1476 => DB_ERROR_DIVZERO, |
| | | 1722 => DB_ERROR_INVALID_NUMBER, |
| | | 2289 => DB_ERROR_NOSUCHTABLE, |
| | | 2291 => DB_ERROR_CONSTRAINT, |
| | | 2292 => DB_ERROR_CONSTRAINT, |
| | | 2449 => DB_ERROR_CONSTRAINT, |
| | | 12899 => DB_ERROR_INVALID, |
| | | ); |
| | | |
| | | /** |
| | |
| | | * @access private |
| | | */ |
| | | var $manip_query = array(); |
| | | |
| | | /** |
| | | * Store of prepared SQL queries. |
| | | * @var array |
| | | * @access private |
| | | */ |
| | | var $_prepared_queries = array(); |
| | | |
| | | |
| | | // }}} |
| | |
| | | $this->dbsyntax = $dsn['dbsyntax']; |
| | | } |
| | | |
| | | // Backwards compatibility with DB < 1.7.0 |
| | | if (empty($dsn['database']) && !empty($dsn['hostspec'])) { |
| | | $db = $dsn['hostspec']; |
| | | } else { |
| | | $db = $dsn['database']; |
| | | } |
| | | |
| | | if (function_exists('oci_connect')) { |
| | | if (isset($dsn['new_link']) |
| | | && ($dsn['new_link'] == 'true' || $dsn['new_link'] === true)) |
| | |
| | | $connect_function = $persistent ? 'oci_pconnect' |
| | | : 'oci_connect'; |
| | | } |
| | | |
| | | // Backwards compatibility with DB < 1.7.0 |
| | | if (empty($dsn['database']) && !empty($dsn['hostspec'])) { |
| | | $db = $dsn['hostspec']; |
| | | } else { |
| | | $db = $dsn['database']; |
| | | if (isset($this->dsn['port']) && $this->dsn['port']) { |
| | | $db = '//'.$db.':'.$this->dsn['port']; |
| | | } |
| | | |
| | | $char = empty($dsn['charset']) ? null : $dsn['charset']; |
| | |
| | | } |
| | | } else { |
| | | $connect_function = $persistent ? 'OCIPLogon' : 'OCILogon'; |
| | | if ($dsn['hostspec']) { |
| | | if ($db) { |
| | | $this->connection = @$connect_function($dsn['username'], |
| | | $dsn['password'], |
| | | $dsn['hostspec']); |
| | | $db); |
| | | } elseif ($dsn['username'] || $dsn['password']) { |
| | | $this->connection = @$connect_function($dsn['username'], |
| | | $dsn['password']); |
| | |
| | | return $this->oci8RaiseError($result); |
| | | } |
| | | $this->last_stmt = $result; |
| | | if (DB::isManip($query)) { |
| | | if ($this->_checkManip($query)) { |
| | | return DB_OK; |
| | | } else { |
| | | @ocisetprefetch($result, $this->options['result_buffering']); |
| | |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return @OCIFreeStatement($result); |
| | | return is_resource($result) ? OCIFreeStatement($result) : false; |
| | | } |
| | | |
| | | /** |
| | |
| | | $save_query = $this->last_query; |
| | | $save_stmt = $this->last_stmt; |
| | | |
| | | if (count($this->_data)) { |
| | | $smt = $this->prepare('SELECT COUNT(*) FROM ('.$this->last_query.')'); |
| | | $count = $this->execute($smt, $this->_data); |
| | | } else { |
| | | $count =& $this->query($countquery); |
| | | } |
| | | $count = $this->query($countquery); |
| | | |
| | | // Restore the last query and statement. |
| | | $this->last_query = $save_query; |
| | | $this->last_stmt = $save_stmt; |
| | | |
| | | if (DB::isError($count) || |
| | | DB::isError($row = $count->fetchRow(DB_FETCHMODE_ORDERED))) |
| | | { |
| | | $this->last_query = $save_query; |
| | | $this->last_stmt = $save_stmt; |
| | | return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
| | | } |
| | | |
| | | return $row[0]; |
| | | } |
| | | return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
| | |
| | | } |
| | | $this->prepare_types[(int)$stmt] = $types; |
| | | $this->manip_query[(int)$stmt] = DB::isManip($query); |
| | | $this->_prepared_queries[(int)$stmt] = $newquery; |
| | | return $stmt; |
| | | } |
| | | |
| | |
| | | { |
| | | $data = (array)$data; |
| | | $this->last_parameters = $data; |
| | | $this->last_query = $this->_prepared_queries[(int)$stmt]; |
| | | $this->_data = $data; |
| | | |
| | | $types =& $this->prepare_types[(int)$stmt]; |
| | | $types = $this->prepare_types[(int)$stmt]; |
| | | if (count($types) != count($data)) { |
| | | $tmp =& $this->raiseError(DB_ERROR_MISMATCH); |
| | | $tmp = $this->raiseError(DB_ERROR_MISMATCH); |
| | | return $tmp; |
| | | } |
| | | |
| | |
| | | } elseif ($types[$i] == DB_PARAM_OPAQUE) { |
| | | $fp = @fopen($data[$key], 'rb'); |
| | | if (!$fp) { |
| | | $tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION); |
| | | $tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION); |
| | | return $tmp; |
| | | } |
| | | $data[$key] = fread($fp, filesize($data[$key])); |
| | | fclose($fp); |
| | | } elseif ($types[$i] == DB_PARAM_SCALAR) { |
| | | // Floats have to be converted to a locale-neutral |
| | | // representation. |
| | | if (is_float($data[$key])) { |
| | | $data[$key] = $this->quoteFloat($data[$key]); |
| | | } |
| | | } |
| | | if (!@OCIBindByName($stmt, ':bind' . $i, $data[$key], -1)) { |
| | | $tmp = $this->oci8RaiseError($stmt); |
| | | return $tmp; |
| | | } |
| | | $this->last_query = str_replace(':bind'.$i, $this->quoteSmart($data[$key]), $this->last_query); |
| | | $i++; |
| | | } |
| | | if ($this->autocommit) { |
| | |
| | | return $tmp; |
| | | } |
| | | $this->last_stmt = $stmt; |
| | | if ($this->manip_query[(int)$stmt]) { |
| | | if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) { |
| | | $this->_last_query_manip = true; |
| | | $this->_next_query_manip = false; |
| | | $tmp = DB_OK; |
| | | } else { |
| | | $this->_last_query_manip = false; |
| | | @ocisetprefetch($stmt, $this->options['result_buffering']); |
| | | $tmp =& new DB_result($this, $stmt); |
| | | $tmp = new DB_result($this, $stmt); |
| | | } |
| | | return $tmp; |
| | | } |
| | |
| | | if (count($params)) { |
| | | $result = $this->prepare("SELECT * FROM ($query) " |
| | | . 'WHERE NULL = NULL'); |
| | | $tmp =& $this->execute($result, $params); |
| | | $tmp = $this->execute($result, $params); |
| | | } else { |
| | | $q_fields = "SELECT * FROM ($query) WHERE NULL = NULL"; |
| | | |
| | |
| | | $repeat = 0; |
| | | do { |
| | | $this->expectError(DB_ERROR_NOSUCHTABLE); |
| | | $result =& $this->query("SELECT ${seqname}.nextval FROM dual"); |
| | | $result = $this->query("SELECT ${seqname}.nextval FROM dual"); |
| | | $this->popExpect(); |
| | | if ($ondemand && DB::isError($result) && |
| | | $result->getCode() == DB_ERROR_NOSUCHTABLE) { |
| | |
| | | if (!@OCIExecute($stmt, OCI_DEFAULT)) { |
| | | return $this->oci8RaiseError($stmt); |
| | | } |
| | | |
| | | |
| | | $i = 0; |
| | | while (@OCIFetch($stmt)) { |
| | | $res[$i] = array( |
| | |
| | | return 'SELECT table_name FROM user_tables'; |
| | | case 'synonyms': |
| | | return 'SELECT synonym_name FROM user_synonyms'; |
| | | case 'views': |
| | | return 'SELECT view_name FROM user_views'; |
| | | default: |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ 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)))); |
| | | } |
| | | |
| | | // }}} |
| | | |
| | | } |
| | | |
| | |
| | | * @package DB |
| | | * @author Stig Bakken <ssb@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 |
| | |
| | | * @package DB |
| | | * @author Stig Bakken <ssb@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_odbc extends DB_common |
| | |
| | | } |
| | | // Determine which queries that should return data, and which |
| | | // should return an error code only. |
| | | if (DB::isManip($query)) { |
| | | if ($this->_checkManip($query)) { |
| | | $this->affected = $result; // For affectedRows() |
| | | return DB_OK; |
| | | } |
| | |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return @odbc_free_result($result); |
| | | return is_resource($result) ? odbc_free_result($result) : false; |
| | | } |
| | | |
| | | // }}} |
| | |
| | | * @author Rui Hirokawa <hirokawa@php.net> |
| | | * @author Stig Bakken <ssb@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 Rui Hirokawa <hirokawa@php.net> |
| | | * @author Stig Bakken <ssb@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_pgsql extends DB_common |
| | |
| | | * 'portability' => DB_PORTABILITY_ALL, |
| | | * ); |
| | | * |
| | | * $db =& DB::connect($dsn, $options); |
| | | * $db = DB::connect($dsn, $options); |
| | | * if (PEAR::isError($db)) { |
| | | * die($db->getMessage()); |
| | | * } |
| | |
| | | $this->connection = @call_user_func_array($connect_function, |
| | | $params); |
| | | } else { |
| | | ini_set('track_errors', 1); |
| | | @ini_set('track_errors', 1); |
| | | $this->connection = @call_user_func_array($connect_function, |
| | | $params); |
| | | ini_set('track_errors', $ini); |
| | | @ini_set('track_errors', $ini); |
| | | } |
| | | |
| | | if (!$this->connection) { |
| | |
| | | */ |
| | | function simpleQuery($query) |
| | | { |
| | | $ismanip = DB::isManip($query); |
| | | $ismanip = $this->_checkManip($query); |
| | | $this->last_query = $query; |
| | | $query = $this->modifyQuery($query); |
| | | if (!$this->autocommit && $ismanip) { |
| | |
| | | if (!$result) { |
| | | return $this->pgsqlRaiseError(); |
| | | } |
| | | // Determine which queries that should return data, and which |
| | | // should return an error code only. |
| | | |
| | | /* |
| | | * Determine whether queries produce affected rows, result or nothing. |
| | | * |
| | | * This logic was introduced in version 1.1 of the file by ssb, |
| | | * though the regex has been modified slightly since then. |
| | | * |
| | | * PostgreSQL commands: |
| | | * ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY, |
| | | * CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH, |
| | | * GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET, |
| | | * REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW, |
| | | * UNLISTEN, UPDATE, VACUUM |
| | | */ |
| | | if ($ismanip) { |
| | | $this->affected = @pg_affected_rows($result); |
| | | return DB_OK; |
| | | } elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|SHOW)\s/si', $query)) { |
| | | /* PostgreSQL commands: |
| | | ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY, |
| | | CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH, |
| | | GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET, |
| | | REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW, |
| | | UNLISTEN, UPDATE, VACUUM |
| | | */ |
| | | } elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|FETCH|SHOW)\s/si', |
| | | $query)) |
| | | { |
| | | $this->row[(int)$result] = 0; // reset the row counter. |
| | | $numrows = $this->numRows($result); |
| | | if (is_object($numrows)) { |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ quoteSmart() |
| | | // {{{ quoteBoolean() |
| | | |
| | | /** |
| | | * Formats input so it can be safely used in a query |
| | | * Formats a boolean value for use within a query in a locale-independent |
| | | * manner. |
| | | * |
| | | * @param mixed $in the data to be formatted |
| | | * |
| | | * @return mixed the formatted data. The format depends on the input's |
| | | * PHP type: |
| | | * + null = the string <samp>NULL</samp> |
| | | * + boolean = string <samp>TRUE</samp> or <samp>FALSE</samp> |
| | | * + integer or double = the unquoted number |
| | | * + other (including strings and numeric strings) = |
| | | * the data escaped according to MySQL's settings |
| | | * then encapsulated between single quotes |
| | | * |
| | | * @param boolean the boolean value to be quoted. |
| | | * @return string the quoted string. |
| | | * @see DB_common::quoteSmart() |
| | | * @since Method available since Release 1.6.0 |
| | | * @since Method available since release 1.7.8. |
| | | */ |
| | | function quoteSmart($in) |
| | | { |
| | | if (is_int($in) || is_double($in)) { |
| | | return $in; |
| | | } elseif (is_bool($in)) { |
| | | return $in ? 'TRUE' : 'FALSE'; |
| | | } elseif (is_null($in)) { |
| | | return 'NULL'; |
| | | } else { |
| | | return "'" . $this->escapeSimple($in) . "'"; |
| | | } |
| | | function quoteBoolean($boolean) { |
| | | return $boolean ? 'TRUE' : 'FALSE'; |
| | | } |
| | | |
| | | |
| | | // }}} |
| | | // {{{ escapeSimple() |
| | | |
| | |
| | | * |
| | | * {@internal PostgreSQL treats a backslash as an escape character, |
| | | * so they are escaped as well. |
| | | * |
| | | * Not using pg_escape_string() yet because it requires PostgreSQL |
| | | * to be at version 7.2 or greater.}} |
| | | * |
| | | * @param string $str the string to be escaped |
| | | * |
| | |
| | | */ |
| | | function escapeSimple($str) |
| | | { |
| | | return str_replace("'", "''", str_replace('\\', '\\\\', $str)); |
| | | if (function_exists('pg_escape_string')) { |
| | | /* This fixes an undocumented BC break in PHP 5.2.0 which changed |
| | | * the prototype of pg_escape_string. I'm not thrilled about having |
| | | * to sniff the PHP version, quite frankly, but it's the only way |
| | | * to deal with the problem. Revision 1.331.2.13.2.10 on |
| | | * php-src/ext/pgsql/pgsql.c (PHP_5_2 branch) is to blame, for the |
| | | * record. */ |
| | | if (version_compare(PHP_VERSION, '5.2.0', '>=')) { |
| | | return pg_escape_string($this->connection, $str); |
| | | } else { |
| | | return pg_escape_string($str); |
| | | } |
| | | } else { |
| | | return str_replace("'", "''", str_replace('\\', '\\\\', $str)); |
| | | } |
| | | } |
| | | |
| | | // }}} |
| | |
| | | $repeat = false; |
| | | do { |
| | | $this->pushErrorHandling(PEAR_ERROR_RETURN); |
| | | $result =& $this->query("SELECT NEXTVAL('${seqname}')"); |
| | | $result = $this->query("SELECT NEXTVAL('${seqname}')"); |
| | | $this->popErrorHandling(); |
| | | if ($ondemand && DB::isError($result) && |
| | | $result->getCode() == DB_ERROR_NOSUCHTABLE) { |
| | |
| | | function pgsqlRaiseError($errno = null) |
| | | { |
| | | $native = $this->errorNative(); |
| | | if (!$native) { |
| | | $native = 'Database connection has been lost.'; |
| | | $errno = DB_ERROR_CONNECT_FAILED; |
| | | } |
| | | if ($errno === null) { |
| | | $errno = $this->errorCode($native); |
| | | } |
| | |
| | | static $error_regexps; |
| | | if (!isset($error_regexps)) { |
| | | $error_regexps = array( |
| | | '/column .* (of relation .*)?does not exist/i' |
| | | => DB_ERROR_NOSUCHFIELD, |
| | | '/(relation|sequence|table).*does not exist|class .* not found/i' |
| | | => DB_ERROR_NOSUCHTABLE, |
| | | '/index .* does not exist/' |
| | | => DB_ERROR_NOT_FOUND, |
| | | '/column .* does not exist/i' |
| | | => DB_ERROR_NOSUCHFIELD, |
| | | '/relation .* already exists/i' |
| | | => DB_ERROR_ALREADY_EXISTS, |
| | | '/(divide|division) by zero$/i' |
| | |
| | | { |
| | | $field_name = @pg_fieldname($resource, $num_field); |
| | | |
| | | // Check if there's a schema in $table_name and update things |
| | | // accordingly. |
| | | $from = 'pg_attribute f, pg_class tab, pg_type typ'; |
| | | if (strpos($table_name, '.') !== false) { |
| | | $from .= ', pg_namespace nsp'; |
| | | list($schema, $table) = explode('.', $table_name); |
| | | $tableWhere = "tab.relname = '$table' AND tab.relnamespace = nsp.oid AND nsp.nspname = '$schema'"; |
| | | } else { |
| | | $tableWhere = "tab.relname = '$table_name'"; |
| | | } |
| | | |
| | | $result = @pg_exec($this->connection, "SELECT f.attnotnull, f.atthasdef |
| | | FROM pg_attribute f, pg_class tab, pg_type typ |
| | | FROM $from |
| | | WHERE tab.relname = typ.typname |
| | | AND typ.typrelid = f.attrelid |
| | | AND f.attname = '$field_name' |
| | | AND tab.relname = '$table_name'"); |
| | | AND $tableWhere"); |
| | | if (@pg_numrows($result) > 0) { |
| | | $row = @pg_fetch_row($result, 0); |
| | | $flags = ($row[0] == 't') ? 'not_null ' : ''; |
| | | |
| | | if ($row[1] == 't') { |
| | | $result = @pg_exec($this->connection, "SELECT a.adsrc |
| | | FROM pg_attribute f, pg_class tab, pg_type typ, pg_attrdef a |
| | | FROM $from, pg_attrdef a |
| | | WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid |
| | | AND f.attrelid = a.adrelid AND f.attname = '$field_name' |
| | | AND tab.relname = '$table_name' AND f.attnum = a.adnum"); |
| | | AND $tableWhere AND f.attnum = a.adnum"); |
| | | $row = @pg_fetch_row($result, 0); |
| | | $num = preg_replace("/'(.*)'::\w+/", "\\1", $row[0]); |
| | | $flags .= 'default_' . rawurlencode($num) . ' '; |
| | |
| | | $flags = ''; |
| | | } |
| | | $result = @pg_exec($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey |
| | | FROM pg_attribute f, pg_class tab, pg_type typ, pg_index i |
| | | FROM $from, pg_index i |
| | | WHERE tab.relname = typ.typname |
| | | AND typ.typrelid = f.attrelid |
| | | AND f.attrelid = i.indrelid |
| | | AND f.attname = '$field_name' |
| | | AND tab.relname = '$table_name'"); |
| | | AND $tableWhere"); |
| | | $count = @pg_numrows($result); |
| | | |
| | | for ($i = 0; $i < $count ; $i++) { |
| | |
| | | . ' FROM pg_catalog.pg_tables' |
| | | . ' WHERE schemaname NOT IN' |
| | | . " ('pg_catalog', 'information_schema', 'pg_toast')"; |
| | | case 'schema.views': |
| | | return "SELECT schemaname || '.' || viewname from pg_views WHERE schemaname" |
| | | . " NOT IN ('information_schema', 'pg_catalog')"; |
| | | case 'views': |
| | | // Table cols: viewname | viewowner | definition |
| | | return 'SELECT viewname from pg_views WHERE schemaname' |
| | |
| | | * @author Urs Gehrig <urs@circle.ch> |
| | | * @author Mika Tuupola <tuupola@appelsiini.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 3.0 |
| | | * @version CVS: $Id$ |
| | | * @link http://pear.php.net/package/DB |
| | |
| | | * @author Urs Gehrig <urs@circle.ch> |
| | | * @author Mika Tuupola <tuupola@appelsiini.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 3.0 |
| | | * @version Release: @package_version@ |
| | | * @version Release: 1.7.13 |
| | | * @link http://pear.php.net/package/DB |
| | | */ |
| | | class DB_sqlite extends DB_common |
| | |
| | | * 'portability' => DB_PORTABILITY_ALL, |
| | | * ); |
| | | * |
| | | * $db =& DB::connect($dsn, $options); |
| | | * $db = DB::connect($dsn, $options); |
| | | * if (PEAR::isError($db)) { |
| | | * die($db->getMessage()); |
| | | * } |
| | |
| | | $this->dbsyntax = $dsn['dbsyntax']; |
| | | } |
| | | |
| | | if ($dsn['database']) { |
| | | if (!$dsn['database']) { |
| | | return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); |
| | | } |
| | | |
| | | if ($dsn['database'] !== ':memory:') { |
| | | if (!file_exists($dsn['database'])) { |
| | | if (!touch($dsn['database'])) { |
| | | return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND); |
| | |
| | | if (!is_readable($dsn['database'])) { |
| | | return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); |
| | | } |
| | | } else { |
| | | return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); |
| | | } |
| | | |
| | | $connect_function = $persistent ? 'sqlite_popen' : 'sqlite_open'; |
| | | |
| | | // track_errors must remain on for simpleQuery() |
| | | ini_set('track_errors', 1); |
| | | @ini_set('track_errors', 1); |
| | | $php_errormsg = ''; |
| | | |
| | | if (!$this->connection = @$connect_function($dsn['database'])) { |
| | |
| | | */ |
| | | function simpleQuery($query) |
| | | { |
| | | $ismanip = DB::isManip($query); |
| | | $ismanip = $this->_checkManip($query); |
| | | $this->last_query = $query; |
| | | $query = $this->modifyQuery($query); |
| | | |
| | |
| | | $arr = @sqlite_fetch_array($result, SQLITE_ASSOC); |
| | | if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { |
| | | $arr = array_change_key_case($arr, CASE_LOWER); |
| | | } |
| | | |
| | | /* Remove extraneous " characters from the fields in the result. |
| | | * Fixes bug #11716. */ |
| | | if (is_array($arr) && count($arr) > 0) { |
| | | $strippedArr = array(); |
| | | foreach ($arr as $field => $value) { |
| | | $strippedArr[trim($field, '"')] = $value; |
| | | } |
| | | $arr = $strippedArr; |
| | | } |
| | | } else { |
| | | $arr = @sqlite_fetch_array($result, SQLITE_NUM); |
| | |
| | | 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('/^sqlite[a-z_]+\(\): /', '', $errormsg); |
| | | |
| | | if (!isset($error_regexps)) { |
| | | $error_regexps = array( |
| | | '/^no such table:/' => DB_ERROR_NOSUCHTABLE, |
| | |
| | | * @category Database |
| | | * @package DB |
| | | * @author Stig Bakken <stig@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 |
| | |
| | | * @category Database |
| | | * @package DB |
| | | * @author Stig Bakken <stig@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_storage extends PEAR |
| | |
| | | function &create($table, &$data) |
| | | { |
| | | $classname = strtolower(get_class($this)); |
| | | $obj =& new $classname($table); |
| | | $obj = new $classname($table); |
| | | foreach ($data as $name => $value) { |
| | | $obj->_properties[$name] = true; |
| | | $obj->$name = &$value; |
| | |
| | | */ |
| | | function store() |
| | | { |
| | | $params = array(); |
| | | $vars = array(); |
| | | foreach ($this->_changes as $name => $foo) { |
| | | $params[] = &$this->$name; |
| | | $vars[] = $name . ' = ?'; |
| | |
| | | * @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)) { |