/trunk/bibliotheque/pear/DB/NestedSet.php |
---|
File deleted |
\ No newline at end of file |
/trunk/bibliotheque/pear/DB/Pager.php |
---|
File deleted |
/trunk/bibliotheque/pear/DB/DataObject.php |
---|
File deleted |
/trunk/bibliotheque/pear/DB/QueryTool.php |
---|
File deleted |
\ No newline at end of file |
/trunk/bibliotheque/pear/DB/ldap.php |
---|
File deleted |
/trunk/bibliotheque/pear/DB/sqlite.php |
---|
6,7 → 6,7 |
* The PEAR DB driver for PHP's sqlite extension |
* for interacting with SQLite databases |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
19,9 → 19,9 |
* @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: sqlite.php,v 1.109 2005/03/10 01:22:48 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
45,9 → 45,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_sqlite extends DB_common |
152,13 → 152,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_sqlite() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
182,7 → 182,7 |
* 'portability' => DB_PORTABILITY_ALL, |
* ); |
* |
* $db =& DB::connect($dsn, $options); |
* $db = DB::connect($dsn, $options); |
* if (PEAR::isError($db)) { |
* die($db->getMessage()); |
* } |
204,7 → 204,11 |
$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); |
229,14 → 233,12 |
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'])) { |
280,7 → 282,7 |
*/ |
function simpleQuery($query) |
{ |
$ismanip = DB::isManip($query); |
$ismanip = $this->_checkManip($query); |
$this->last_query = $query; |
$query = $this->modifyQuery($query); |
357,6 → 359,16 |
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); |
} |
727,6 → 739,11 |
function errorCode($errormsg) |
{ |
static $error_regexps; |
// PHP 5.2+ prepends the function name to $php_errormsg, so we need |
// this hack to work around it, per bug #9599. |
$errormsg = preg_replace('/^sqlite[a-z_]+\(\): /', '', $errormsg); |
if (!isset($error_regexps)) { |
$error_regexps = array( |
'/^no such table:/' => DB_ERROR_NOSUCHTABLE, |
738,6 → 755,7 |
'/uniqueness constraint failed/' => DB_ERROR_CONSTRAINT, |
'/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL, |
'/^no such column:/' => DB_ERROR_NOSUCHFIELD, |
'/no column named/' => DB_ERROR_NOSUCHFIELD, |
'/column not present in both tables/i' => DB_ERROR_NOSUCHFIELD, |
'/^near ".*": syntax error$/' => DB_ERROR_SYNTAX, |
'/[0-9]+ values for [0-9]+ columns/i' => DB_ERROR_VALUE_COUNT_ON_ROW, |
811,6 → 829,9 |
$flags = ''; |
if ($id[$i]['pk']) { |
$flags .= 'primary_key '; |
if (strtoupper($type) == 'INTEGER') { |
$flags .= 'auto_increment '; |
} |
} |
if ($id[$i]['notnull']) { |
$flags .= 'not_null '; |
/trunk/bibliotheque/pear/DB/oci8.php |
---|
6,7 → 6,7 |
* The PEAR DB driver for PHP's oci8 extension |
* for interacting with Oracle databases |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
18,9 → 18,9 |
* @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: oci8.php,v 1.103 2005/04/11 15:10:22 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
45,9 → 45,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_oci8 extends DB_common |
94,24 → 94,25 |
* @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, |
); |
/** |
160,18 → 161,25 |
*/ |
var $manip_query = array(); |
/** |
* Store of prepared SQL queries. |
* @var array |
* @access private |
*/ |
var $_prepared_queries = array(); |
// }}} |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_oci8() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
216,6 → 224,13 |
$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)) |
225,12 → 240,8 |
$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']; |
248,10 → 259,10 |
} |
} 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']); |
322,7 → 333,7 |
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']); |
415,7 → 426,7 |
*/ |
function freeResult($result) |
{ |
return @OCIFreeStatement($result); |
return is_resource($result) ? OCIFreeStatement($result) : false; |
} |
/** |
441,6 → 452,7 |
if (isset($this->prepare_types[(int)$stmt])) { |
unset($this->prepare_types[(int)$stmt]); |
unset($this->manip_query[(int)$stmt]); |
unset($this->_prepared_queries[(int)$stmt]); |
} else { |
return false; |
} |
476,20 → 488,18 |
$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); |
590,6 → 600,7 |
} |
$this->prepare_types[(int)$stmt] = $types; |
$this->manip_query[(int)$stmt] = DB::isManip($query); |
$this->_prepared_queries[(int)$stmt] = $newquery; |
return $stmt; |
} |
620,11 → 631,12 |
{ |
$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; |
} |
643,16 → 655,24 |
} 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 = preg_replace("/:bind$i(?!\d)/", |
$this->quoteSmart($data[$key]), $this->last_query, 1); |
$i++; |
} |
if ($this->autocommit) { |
665,11 → 685,14 |
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; |
} |
797,7 → 820,7 |
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"; |
857,7 → 880,7 |
$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) { |
1015,7 → 1038,7 |
if (!@OCIExecute($stmt, OCI_DEFAULT)) { |
return $this->oci8RaiseError($stmt); |
} |
$i = 0; |
while (@OCIFetch($stmt)) { |
$res[$i] = array( |
1098,6 → 1121,8 |
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; |
} |
1104,7 → 1129,23 |
} |
// }}} |
// {{{ 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)))); |
} |
// }}} |
} |
/* |
/trunk/bibliotheque/pear/DB/ibase.php |
---|
9,7 → 9,7 |
* While this class works with PHP 4, PHP's InterBase extension is |
* unstable in PHP 4. Use PHP 5. |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
21,9 → 21,9 |
* @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: ibase.php,v 1.109 2005/03/04 23:12:36 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
47,9 → 47,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
* @since Class became stable in Release 1.7.0 |
*/ |
123,6 → 123,7 |
-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, |
179,13 → 180,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_ibase() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
275,7 → 276,7 |
*/ |
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); |
412,7 → 413,7 |
*/ |
function freeResult($result) |
{ |
return @ibase_free_result($result); |
return is_resource($result) ? ibase_free_result($result) : false; |
} |
// }}} |
420,8 → 421,7 |
function freeQuery($query) |
{ |
@ibase_free_query($query); |
return true; |
return is_resource($query) ? ibase_free_query($query) : false; |
} |
// }}} |
521,8 → 521,14 |
$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; |
} |
547,9 → 553,9 |
$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; |
} |
568,7 → 574,7 |
} 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])); |
581,7 → 587,7 |
$res = call_user_func_array('ibase_execute', $data); |
if (!$res) { |
$tmp =& $this->ibaseRaiseError(); |
$tmp = $this->ibaseRaiseError(); |
return $tmp; |
} |
/* XXX need this? |
589,10 → 595,13 |
@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; |
} |
698,7 → 707,7 |
$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(); |
856,7 → 865,7 |
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; |
} |
907,6 → 916,8 |
$error_regexps = array( |
'/generator .* is not defined/' |
=> DB_ERROR_SYNTAX, // for compat. w ibase_errcode() |
'/violation of [\w ]+ constraint/i' |
=> DB_ERROR_CONSTRAINT, |
'/table.*(not exist|not found|unknown)/i' |
=> DB_ERROR_NOSUCHTABLE, |
'/table .* already exists/i' |
917,8 → 928,6 |
=> DB_ERROR_NOT_FOUND, |
'/validation error for column .* value "\*\*\* null/i' |
=> DB_ERROR_CONSTRAINT_NOT_NULL, |
'/violation of [\w ]+ constraint/i' |
=> DB_ERROR_CONSTRAINT, |
'/conversion error from string/i' |
=> DB_ERROR_INVALID_NUMBER, |
'/no permission for/i' |
925,6 → 934,8 |
=> DB_ERROR_ACCESS_VIOLATION, |
'/arithmetic exception, numeric overflow, or string truncation/i' |
=> DB_ERROR_INVALID, |
'/feature is not supported/i' |
=> DB_ERROR_NOT_CAPABLE, |
); |
} |
/trunk/bibliotheque/pear/DB/storage.php |
---|
5,7 → 5,7 |
/** |
* Provides an object interface to a table row |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
16,9 → 16,9 |
* @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: storage.php,v 1.21 2005/02/02 02:54:51 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
36,9 → 36,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_storage extends PEAR |
94,7 → 94,7 |
* a reference to this object |
* |
*/ |
function DB_storage($table, $keycolumn, &$dbh, $validator = null) |
function __construct($table, $keycolumn, &$dbh, $validator = null) |
{ |
$this->PEAR('DB_Error'); |
$this->_table = $table; |
293,7 → 293,7 |
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; |
445,6 → 445,8 |
*/ |
function store() |
{ |
$params = array(); |
$vars = array(); |
foreach ($this->_changes as $name => $foo) { |
$params[] = &$this->$name; |
$vars[] = $name . ' = ?'; |
/trunk/bibliotheque/pear/DB/mysql.php |
---|
6,7 → 6,7 |
* The PEAR DB driver for PHP's mysql extension |
* for interacting with MySQL databases |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
18,9 → 18,9 |
* @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: mysql.php,v 1.117 2005/03/29 15:03:26 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
39,9 → 39,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_mysql extends DB_common |
111,6 → 111,9 |
1146 => DB_ERROR_NOSUCHTABLE, |
1216 => DB_ERROR_CONSTRAINT, |
1217 => DB_ERROR_CONSTRAINT, |
1356 => DB_ERROR_DIVZERO, |
1451 => DB_ERROR_CONSTRAINT, |
1452 => DB_ERROR_CONSTRAINT, |
); |
/** |
159,13 → 162,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_mysql() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
236,10 → 239,10 |
$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) { |
297,7 → 300,7 |
*/ |
function simpleQuery($query) |
{ |
$ismanip = DB::isManip($query); |
$ismanip = $this->_checkManip($query); |
$this->last_query = $query; |
$query = $this->modifyQuery($query); |
if ($this->_db) { |
419,7 → 422,7 |
*/ |
function freeResult($result) |
{ |
return @mysql_free_result($result); |
return is_resource($result) ? mysql_free_result($result) : false; |
} |
// }}} |
555,7 → 558,7 |
*/ |
function affectedRows() |
{ |
if (DB::isManip($this->last_query)) { |
if ($this->_last_query_manip) { |
return @mysql_affected_rows($this->connection); |
} else { |
return 0; |
752,9 → 755,10 |
/** |
* 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 |
* |
765,21 → 769,10 |
*/ |
function quoteIdentifier($str) |
{ |
return '`' . $str . '`'; |
return '`' . str_replace('`', '``', $str) . '`'; |
} |
// }}} |
// {{{ quote() |
/** |
* @deprecated Deprecated in release 1.6.0 |
*/ |
function quote($str) |
{ |
return $this->quoteSmart($str); |
} |
// }}} |
// {{{ escapeSimple() |
/** |
852,7 → 845,7 |
*/ |
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"; |
928,12 → 921,19 |
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)) { |
/* |
/trunk/bibliotheque/pear/DB/ifx.php |
---|
6,7 → 6,7 |
* The PEAR DB driver for PHP's ifx extension |
* for interacting with Informix databases |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
18,9 → 18,9 |
* @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: ifx.php,v 1.70 2005/02/20 00:44:48 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
46,9 → 46,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_ifx extends DB_common |
101,6 → 101,7 |
'-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, |
113,6 → 114,7 |
'-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, |
165,13 → 167,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_ifx() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
243,10 → 245,10 |
*/ |
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); |
268,7 → 270,7 |
$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 |
309,7 → 311,7 |
*/ |
function affectedRows() |
{ |
if (DB::isManip($this->last_query)) { |
if ($this->_last_query_manip) { |
return $this->affected; |
} else { |
return 0; |
420,7 → 422,7 |
*/ |
function freeResult($result) |
{ |
return @ifx_free_result($result); |
return is_resource($result) ? ifx_free_result($result) : false; |
} |
// }}} |
534,7 → 536,7 |
*/ |
function errorCode($nativecode) |
{ |
if (ereg('SQLCODE=(.*)]', $nativecode, $match)) { |
if (preg_match('/SQLCODE=(.*)]/', $nativecode, $match)) { |
$code = $match[1]; |
if (isset($this->errorcode_map[$code])) { |
return $this->errorcode_map[$code]; |
/trunk/bibliotheque/pear/DB/pgsql.php |
---|
6,7 → 6,7 |
* The PEAR DB driver for PHP's pgsql extension |
* for interacting with PostgreSQL databases |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
19,9 → 19,9 |
* @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: pgsql.php,v 1.126 2005/03/04 23:12:36 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
41,9 → 41,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_pgsql extends DB_common |
148,13 → 148,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_pgsql() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
193,7 → 193,7 |
* 'portability' => DB_PORTABILITY_ALL, |
* ); |
* |
* $db =& DB::connect($dsn, $options); |
* $db = DB::connect($dsn, $options); |
* if (PEAR::isError($db)) { |
* die($db->getMessage()); |
* } |
277,10 → 277,10 |
$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) { |
320,7 → 320,7 |
*/ |
function simpleQuery($query) |
{ |
$ismanip = DB::isManip($query); |
$ismanip = $this->_checkManip($query); |
$this->last_query = $query; |
$query = $this->modifyQuery($query); |
if (!$this->autocommit && $ismanip) { |
336,19 → 336,26 |
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, WITH |
*/ |
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|WITH)\s/si', |
$query)) |
{ |
$this->row[(int)$result] = 0; // reset the row counter. |
$numrows = $this->numRows($result); |
if (is_object($numrows)) { |
459,50 → 466,21 |
} |
// }}} |
// {{{ quote() |
// {{{ quoteBoolean() |
/** |
* @deprecated Deprecated in release 1.6.0 |
* @internal |
*/ |
function quote($str) |
{ |
return $this->quoteSmart($str); |
} |
// }}} |
// {{{ quoteSmart() |
/** |
* 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() |
512,9 → 490,6 |
* {@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 |
* |
* @return string the escaped string |
524,7 → 499,21 |
*/ |
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)); |
} |
} |
// }}} |
675,7 → 664,7 |
$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) { |
779,6 → 768,10 |
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); |
} |
815,12 → 808,12 |
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' |
976,12 → 969,23 |
{ |
$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 ' : ''; |
988,10 → 992,10 |
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) . ' '; |
1000,12 → 1004,12 |
$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++) { |
1066,6 → 1070,9 |
. ' 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' |
1084,7 → 1091,26 |
} |
// }}} |
// {{{ _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) |
{ |
return (preg_match('/^\s*(SAVEPOINT|RELEASE)\s+/i', $query) |
|| parent::_checkManip($query)); |
} |
} |
/* |
/trunk/bibliotheque/pear/DB/sybase.php |
---|
6,7 → 6,7 |
* The PEAR DB driver for PHP's sybase extension |
* for interacting with Sybase databases |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
19,9 → 19,9 |
* @author Sterling Hughes <sterling@php.net> |
* @author Antônio Carlos Venâncio Júnior <floripa@php.net> |
* @author Daniel Convissor <danielc@php.net> |
* @copyright 1997-2005 The PHP Group |
* @copyright 1997-2007 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version CVS: $Id: sybase.php,v 1.78 2005/02/20 00:44:48 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
44,9 → 44,9 |
* @author Sterling Hughes <sterling@php.net> |
* @author Antônio Carlos Venâncio Júnior <floripa@php.net> |
* @author Daniel Convissor <danielc@php.net> |
* @copyright 1997-2005 The PHP Group |
* @copyright 1997-2007 The PHP Group |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @version Release: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_sybase extends DB_common |
141,13 → 141,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_sybase() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
248,9 → 248,9 |
*/ |
function simpleQuery($query) |
{ |
$ismanip = DB::isManip($query); |
$ismanip = $this->_checkManip($query); |
$this->last_query = $query; |
if (!@sybase_select_db($this->_db, $this->connection)) { |
if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) { |
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); |
} |
$query = $this->modifyQuery($query); |
370,7 → 370,7 |
*/ |
function freeResult($result) |
{ |
return @sybase_free_result($result); |
return is_resource($result) ? sybase_free_result($result) : false; |
} |
// }}} |
435,7 → 435,7 |
*/ |
function affectedRows() |
{ |
if (DB::isManip($this->last_query)) { |
if ($this->_last_query_manip) { |
$result = @sybase_affected_rows($this->connection); |
} else { |
$result = 0; |
462,7 → 462,7 |
function nextId($seq_name, $ondemand = true) |
{ |
$seqname = $this->getSequenceName($seq_name); |
if (!@sybase_select_db($this->_db, $this->connection)) { |
if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) { |
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); |
} |
$repeat = 0; |
479,7 → 479,7 |
return $this->raiseError($result); |
} |
} elseif (!DB::isError($result)) { |
$result =& $this->query("SELECT @@IDENTITY FROM $seqname"); |
$result = $this->query("SELECT @@IDENTITY FROM $seqname"); |
$repeat = 0; |
} else { |
$repeat = false; |
529,6 → 529,22 |
} |
// }}} |
// {{{ quoteFloat() |
/** |
* Formats a float value for use within a query in a locale-independent |
* manner. |
* |
* @param float the float value to be quoted. |
* @return string the quoted string. |
* @see DB_common::quoteSmart() |
* @since Method available since release 1.7.8. |
*/ |
function quoteFloat($float) { |
return $this->escapeSimple(str_replace(',', '.', strval(floatval($float)))); |
} |
// }}} |
// {{{ autoCommit() |
/** |
558,7 → 574,7 |
function commit() |
{ |
if ($this->transaction_opcount > 0) { |
if (!@sybase_select_db($this->_db, $this->connection)) { |
if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) { |
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); |
} |
$result = @sybase_query('COMMIT', $this->connection); |
581,7 → 597,7 |
function rollback() |
{ |
if ($this->transaction_opcount > 0) { |
if (!@sybase_select_db($this->_db, $this->connection)) { |
if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) { |
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); |
} |
$result = @sybase_query('ROLLBACK', $this->connection); |
642,6 → 658,11 |
function errorCode($errormsg) |
{ |
static $error_regexps; |
// PHP 5.2+ prepends the function name to $php_errormsg, so we need |
// this hack to work around it, per bug #9599. |
$errormsg = preg_replace('/^sybase[a-z_]+\(\): /', '', $errormsg); |
if (!isset($error_regexps)) { |
$error_regexps = array( |
'/Incorrect syntax near/' |
674,6 → 695,8 |
=> DB_ERROR_ALREADY_EXISTS, |
'/^There are fewer columns in the INSERT statement than values specified/i' |
=> DB_ERROR_VALUE_COUNT_ON_ROW, |
'/Divide by zero/i' |
=> DB_ERROR_DIVZERO, |
); |
} |
714,7 → 737,7 |
* Probably received a table name. |
* Create a result resource identifier. |
*/ |
if (!@sybase_select_db($this->_db, $this->connection)) { |
if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) { |
return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); |
} |
$id = @sybase_query("SELECT * FROM $result WHERE 1=0", |
811,14 → 834,24 |
$flags = array(); |
$tableName = $table; |
// get unique/primary keys |
$res = $this->getAll("sp_helpindex $table", DB_FETCHMODE_ASSOC); |
/* We're running sp_helpindex directly because it doesn't exist in |
* older versions of ASE -- unfortunately, we can't just use |
* DB::isError() because the user may be using callback error |
* handling. */ |
$res = @sybase_query("sp_helpindex $table", $this->connection); |
if (!isset($res[0]['index_description'])) { |
if ($res === false || $res === true) { |
// Fake a valid response for BC reasons. |
return ''; |
} |
foreach ($res as $val) { |
while (($val = sybase_fetch_assoc($res)) !== false) { |
if (!isset($val['index_keys'])) { |
/* No useful information returned. Break and be done with |
* it, which preserves the pre-1.7.9 behaviour. */ |
break; |
} |
$keys = explode(', ', trim($val['index_keys'])); |
if (sizeof($keys) > 1) { |
834,6 → 867,8 |
} |
} |
sybase_free_result($res); |
} |
if (array_key_exists($column, $flags)) { |
/trunk/bibliotheque/pear/DB/fbsql.php |
---|
6,7 → 6,7 |
* The PEAR DB driver for PHP's fbsql extension |
* for interacting with FrontBase databases |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
18,9 → 18,9 |
* @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: fbsql.php,v 1.82 2005/03/04 23:12:36 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
39,9 → 39,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
* @since Class functional since Release 1.7.0 |
*/ |
124,13 → 124,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_fbsql() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
171,10 → 171,10 |
$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) { |
229,7 → 229,7 |
} |
// 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; |
320,7 → 320,7 |
*/ |
function freeResult($result) |
{ |
return @fbsql_free_result($result); |
return is_resource($result) ? fbsql_free_result($result) : false; |
} |
// }}} |
353,7 → 353,7 |
*/ |
function commit() |
{ |
@fbsql_commit(); |
@fbsql_commit($this->connection); |
} |
// }}} |
366,7 → 366,7 |
*/ |
function rollback() |
{ |
@fbsql_rollback(); |
@fbsql_rollback($this->connection); |
} |
// }}} |
431,7 → 431,7 |
*/ |
function affectedRows() |
{ |
if (DB::isManip($this->last_query)) { |
if ($this->_last_query_manip) { |
$result = @fbsql_affected_rows($this->connection); |
} else { |
$result = 0; |
543,7 → 543,7 |
*/ |
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 { |
553,38 → 553,37 |
} |
// }}} |
// {{{ 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 |
* @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 ? 'TRUE' : 'FALSE'; |
} |
// }}} |
// {{{ quoteFloat() |
/** |
* Formats a float value for use within a query in a locale-independent |
* manner. |
* |
* @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 float the float 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 quoteFloat($float) { |
return $this->escapeSimple(str_replace(',', '.', strval(floatval($float)))); |
} |
// }}} |
// {{{ fbsqlRaiseError() |
/trunk/bibliotheque/pear/DB/odbc.php |
---|
6,7 → 6,7 |
* The PEAR DB driver for PHP's odbc extension |
* for interacting with databases via ODBC connections |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
18,9 → 18,9 |
* @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: odbc.php,v 1.78 2005/02/28 01:42:17 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
42,9 → 42,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_odbc extends DB_common |
153,13 → 153,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_odbc() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
266,7 → 266,7 |
} |
// 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; |
} |
367,7 → 367,7 |
*/ |
function freeResult($result) |
{ |
return @odbc_free_result($result); |
return is_resource($result) ? odbc_free_result($result) : false; |
} |
// }}} |
481,18 → 481,6 |
} |
// }}} |
// {{{ quote() |
/** |
* @deprecated Deprecated in release 1.6.0 |
* @internal |
*/ |
function quote($str) |
{ |
return $this->quoteSmart($str); |
} |
// }}} |
// {{{ nextId() |
/** |
/trunk/bibliotheque/pear/DB/common.php |
---|
5,7 → 5,7 |
/** |
* Contains the DB_common base class |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
18,9 → 18,9 |
* @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: common.php,v 1.137 2005/04/07 14:27:35 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
40,9 → 40,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_common extends PEAR |
121,7 → 121,22 |
*/ |
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; |
// }}} |
// {{{ DB_common |
130,7 → 145,7 |
* |
* @return void |
*/ |
function DB_common() |
function __construct() |
{ |
$this->PEAR('DB_Error'); |
} |
189,7 → 204,7 |
function __wakeup() |
{ |
if ($this->was_connected) { |
$this->connect($this->dsn, $this->options); |
$this->connect($this->dsn, $this->options['persistent']); |
} |
} |
246,7 → 261,7 |
*/ |
function quoteString($string) |
{ |
$string = $this->quote($string); |
$string = $this->quoteSmart($string); |
if ($string{0} == "'") { |
return substr($string, 1, -1); |
} |
269,8 → 284,7 |
*/ |
function quote($string = null) |
{ |
return ($string === null) ? 'NULL' |
: "'" . str_replace("'", "''", $string) . "'"; |
return $this->quoteSmart($string); |
} |
// }}} |
424,18 → 438,57 |
*/ |
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() |
/** |
837,7 → 890,7 |
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; |
931,7 → 984,7 |
* "'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() |
960,7 → 1013,7 |
if ($result === DB_OK || DB::isError($result)) { |
return $result; |
} else { |
$tmp =& new DB_result($this, $result); |
$tmp = new DB_result($this, $result); |
return $tmp; |
} |
} |
1041,7 → 1094,7 |
function executeMultiple($stmt, $data) |
{ |
foreach ($data as $value) { |
$res =& $this->execute($stmt, $value); |
$res = $this->execute($stmt, $value); |
if (DB::isError($res)) { |
return $res; |
} |
1154,7 → 1207,7 |
if (DB::isError($sth)) { |
return $sth; |
} |
$ret =& $this->execute($sth, $params); |
$ret = $this->execute($sth, $params); |
$this->freePrepared($sth, false); |
return $ret; |
} else { |
1163,7 → 1216,7 |
if ($result === DB_OK || DB::isError($result)) { |
return $result; |
} else { |
$tmp =& new DB_result($this, $result); |
$tmp = new DB_result($this, $result); |
return $tmp; |
} |
} |
1194,8 → 1247,8 |
if (DB::isError($query)){ |
return $query; |
} |
$result =& $this->query($query, $params); |
if (is_a($result, 'DB_result')) { |
$result = $this->query($query, $params); |
if (is_object($result) && is_a($result, 'DB_result')) { |
$result->setOption('limit_from', $from); |
$result->setOption('limit_count', $count); |
} |
1229,10 → 1282,10 |
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)) { |
1293,10 → 1346,10 |
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)) { |
1344,10 → 1397,10 |
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)) { |
1360,7 → 1413,7 |
$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))) { |
1476,10 → 1529,10 |
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)) { |
1491,7 → 1544,7 |
$cols = $res->numCols(); |
if ($cols < 2) { |
$tmp =& $this->raiseError(DB_ERROR_TRUNCATED); |
$tmp = $this->raiseError(DB_ERROR_TRUNCATED); |
return $tmp; |
} |
1603,10 → 1656,10 |
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)) { |
1627,7 → 1680,7 |
$res->free(); |
if (DB::isError($row)) { |
$tmp =& $this->raiseError($row); |
$tmp = $this->raiseError($row); |
return $tmp; |
} |
return $results; |
1814,6 → 1867,10 |
* query and native error code. |
* @param mixed native error code, integer or string depending the |
* backend |
* @param mixed dummy parameter for E_STRICT compatibility with |
* PEAR::raiseError |
* @param mixed dummy parameter for E_STRICT compatibility with |
* PEAR::raiseError |
* |
* @return object the PEAR_Error object |
* |
1820,7 → 1877,8 |
* @see PEAR_Error |
*/ |
function &raiseError($code = DB_ERROR, $mode = null, $options = null, |
$userinfo = null, $nativecode = null) |
$userinfo = null, $nativecode = null, $dummy1 = null, |
$dummy2 = null) |
{ |
// The error is yet a DB error object |
if (is_object($code)) { |
2103,6 → 2161,52 |
} |
// }}} |
// {{{ 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() |
/** |
/trunk/bibliotheque/pear/DB/msql.php |
---|
10,7 → 10,7 |
* 4.3.11 and 5.0.4. Make sure your version of PHP meets or exceeds |
* those versions. |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
21,9 → 21,9 |
* @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: msql.php,v 1.57 2005/02/22 07:26:46 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
45,9 → 45,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
* @since Class not functional until Release 1.7.0 |
*/ |
126,13 → 126,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_msql() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
153,7 → 153,7 |
* 'portability' => DB_PORTABILITY_ALL, |
* ); |
* |
* $db =& DB::connect($dsn, $options); |
* $db = DB::connect($dsn, $options); |
* if (PEAR::isError($db)) { |
* die($db->getMessage()); |
* } |
190,10 → 190,10 |
$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) { |
251,7 → 251,7 |
} |
// 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 { |
350,7 → 350,7 |
*/ |
function freeResult($result) |
{ |
return @msql_free_result($result); |
return is_resource($result) ? msql_free_result($result) : false; |
} |
// }}} |
443,7 → 443,7 |
$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) { |
531,6 → 531,22 |
} |
// }}} |
// {{{ quoteFloat() |
/** |
* Formats a float value for use within a query in a locale-independent |
* manner. |
* |
* @param float the float value to be quoted. |
* @return string the quoted string. |
* @see DB_common::quoteSmart() |
* @since Method available since release 1.7.8. |
*/ |
function quoteFloat($float) { |
return $this->escapeSimple(str_replace(',', '.', strval(floatval($float)))); |
} |
// }}} |
// {{{ escapeSimple() |
/** |
598,6 → 614,11 |
function errorCode($errormsg) |
{ |
static $error_regexps; |
// PHP 5.2+ prepends the function name to $php_errormsg, so we need |
// this hack to work around it, per bug #9599. |
$errormsg = preg_replace('/^msql[a-z_]+\(\): /', '', $errormsg); |
if (!isset($error_regexps)) { |
$error_regexps = array( |
'/^Access to database denied/i' |
/trunk/bibliotheque/pear/DB/dbase.php |
---|
6,7 → 6,7 |
* The PEAR DB driver for PHP's dbase extension |
* for interacting with dBase databases |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
18,9 → 18,9 |
* @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: dbase.php,v 1.39 2005/02/19 23:25:25 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
39,9 → 39,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_dbase extends DB_common |
140,13 → 140,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_dbase() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
188,7 → 188,7 |
* 'portability' => DB_PORTABILITY_ALL, |
* ); |
* |
* $db =& DB::connect($dsn, $options); |
* $db = DB::connect($dsn, $options); |
* if (PEAR::isError($db)) { |
* die($db->getMessage()); |
* } |
214,7 → 214,7 |
* 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'])) { |
273,7 → 273,7 |
{ |
// 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; |
} |
326,6 → 326,26 |
} |
// }}} |
// {{{ 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() |
/** |
368,41 → 388,21 |
} |
// }}} |
// {{{ 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() |
/trunk/bibliotheque/pear/DB/mysqli.php |
---|
6,7 → 6,7 |
* The PEAR DB driver for PHP's mysqli extension |
* for interacting with MySQL databases |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
17,9 → 17,9 |
* @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: mysqli.php,v 1.69 2005/03/04 23:12:36 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
41,9 → 41,9 |
* @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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
* @since Class functional since Release 1.6.3 |
*/ |
114,6 → 114,9 |
1146 => DB_ERROR_NOSUCHTABLE, |
1216 => DB_ERROR_CONSTRAINT, |
1217 => DB_ERROR_CONSTRAINT, |
1356 => DB_ERROR_DIVZERO, |
1451 => DB_ERROR_CONSTRAINT, |
1452 => DB_ERROR_CONSTRAINT, |
); |
/** |
210,6 → 213,10 |
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', |
); |
217,13 → 224,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_mysqli() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
264,7 → 271,7 |
* 'ssl' => true, |
* ); |
* |
* $db =& DB::connect($dsn, $options); |
* $db = DB::connect($dsn, $options); |
* if (PEAR::isError($db)) { |
* die($db->getMessage()); |
* } |
287,10 → 294,10 |
} |
$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, |
322,7 → 329,7 |
); |
} |
ini_set('track_errors', $ini); |
@ini_set('track_errors', $ini); |
if (!$this->connection) { |
if (($err = @mysqli_connect_error()) != '') { |
372,7 → 379,7 |
*/ |
function simpleQuery($query) |
{ |
$ismanip = DB::isManip($query); |
$ismanip = $this->_checkManip($query); |
$this->last_query = $query; |
$query = $this->modifyQuery($query); |
if ($this->_db) { |
490,7 → 497,11 |
*/ |
function freeResult($result) |
{ |
return @mysqli_free_result($result); |
if (! $result instanceof mysqli_result) { |
return false; |
} |
mysqli_free_result($result); |
return true; |
} |
// }}} |
626,7 → 637,7 |
*/ |
function affectedRows() |
{ |
if (DB::isManip($this->last_query)) { |
if ($this->_last_query_manip) { |
return @mysqli_affected_rows($this->connection); |
} else { |
return 0; |
823,9 → 834,10 |
/** |
* 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 |
* |
836,7 → 848,7 |
*/ |
function quoteIdentifier($str) |
{ |
return '`' . $str . '`'; |
return '`' . str_replace('`', '``', $str) . '`'; |
} |
// }}} |
878,7 → 890,7 |
*/ |
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"; |
954,6 → 966,13 |
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. |
978,7 → 997,7 |
$got_string = false; |
} |
if (!is_a($id, 'mysqli_result')) { |
if (!is_object($id) || !is_a($id, 'mysqli_result')) { |
return $this->mysqliRaiseError(DB_ERROR_NEED_MORE_DATA); |
} |
1015,7 → 1034,12 |
'type' => isset($this->mysqli_types[$tmp->type]) |
? $this->mysqli_types[$tmp->type] |
: 'unknown', |
'len' => $tmp->max_length, |
// http://bugs.php.net/?id=36579 |
// Doc Bug #36579: mysqli_fetch_field length handling |
// https://bugs.php.net/bug.php?id=62426 |
// Bug #62426: mysqli_fetch_field_direct returns incorrect |
// length on UTF8 fields |
'len' => $tmp->length, |
'flags' => $flags, |
); |
/trunk/bibliotheque/pear/DB/mssql.php |
---|
6,7 → 6,7 |
* The PEAR DB driver for PHP's mssql extension |
* for interacting with Microsoft SQL Server databases |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
* that is available through the world-wide-web at the following URI: |
18,9 → 18,9 |
* @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: mssql.php,v 1.83 2005/03/07 18:24:51 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
35,13 → 35,21 |
* |
* 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: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_mssql extends DB_common |
89,19 → 97,40 |
*/ |
// 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, |
); |
/** |
150,13 → 179,13 |
// {{{ constructor |
/** |
* This constructor calls <kbd>$this->DB_common()</kbd> |
* This constructor calls <kbd>parent::__construct()</kbd> |
* |
* @return void |
*/ |
function DB_mssql() |
function __construct() |
{ |
$this->DB_common(); |
parent::__construct(); |
} |
// }}} |
244,7 → 273,7 |
*/ |
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); |
316,7 → 345,7 |
} |
} |
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); |
} |
353,7 → 382,7 |
*/ |
function freeResult($result) |
{ |
return @mssql_free_result($result); |
return is_resource($result) ? mssql_free_result($result) : false; |
} |
// }}} |
483,7 → 512,7 |
*/ |
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(); |
537,7 → 566,15 |
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; |
587,6 → 624,27 |
} |
// }}} |
// {{{ escapeSimple() |
/** |
* Escapes a string in a manner suitable for SQL Server. |
* |
* @param string $str the string to be escaped |
* @return string the escaped string |
* |
* @see DB_common::quoteSmart() |
* @since Method available since Release 1.6.0 |
*/ |
function escapeSimple($str) |
{ |
return str_replace( |
array("'", "\\\r\n", "\\\n"), |
array("''", "\\\\\r\n\r\n", "\\\\\n\n"), |
$str |
); |
} |
// }}} |
// {{{ quoteIdentifier() |
/** |
745,16 → 803,22 |
} |
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; |
805,7 → 869,10 |
$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']); |
828,7 → 895,10 |
} |
// 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); |