Mise jour de Pear MDB2

This commit is contained in:
Regis Houssin 2007-08-17 08:46:04 +00:00
parent 57d530f142
commit 4ebb2bc445

View File

@ -282,7 +282,7 @@ class MDB2
if (is_array($options)) { if (is_array($options)) {
foreach ($options as $option => $value) { foreach ($options as $option => $value) {
$test = $db->setOption($option, $value); $test = $db->setOption($option, $value);
if (PEAR::isError($test)) { if (DOLIPEAR::isError($test)) {
return $test; return $test;
} }
} }
@ -384,14 +384,14 @@ class MDB2
$debug = (!empty($options['debug'])); $debug = (!empty($options['debug']));
$err = MDB2::loadClass($class_name, $debug); $err = MDB2::loadClass($class_name, $debug);
if (PEAR::isError($err)) { if (DOLIPEAR::isError($err)) {
return $err; return $err;
} }
$db =& new $class_name(); $db =& new $class_name();
$db->setDSN($dsninfo); $db->setDSN($dsninfo);
$err = MDB2::setOptions($db, $options); $err = MDB2::setOptions($db, $options);
if (PEAR::isError($err)) { if (DOLIPEAR::isError($err)) {
return $err; return $err;
} }
@ -432,12 +432,12 @@ class MDB2
function &connect($dsn, $options = false) function &connect($dsn, $options = false)
{ {
$db =& MDB2::factory($dsn, $options); $db =& MDB2::factory($dsn, $options);
if (PEAR::isError($db)) { if (DOLIPEAR::isError($db)) {
return $db; return $db;
} }
$err = $db->connect(); $err = $db->connect();
if (PEAR::isError($err)) { if (DOLIPEAR::isError($err)) {
$dsn = $db->getDSN('string', 'xxx'); $dsn = $db->getDSN('string', 'xxx');
$db->disconnect(); $db->disconnect();
$err->addUserInfo($dsn); $err->addUserInfo($dsn);
@ -548,7 +548,7 @@ class MDB2
/** /**
* This method is used to communicate an error and invoke error * This method is used to communicate an error and invoke error
* callbacks etc. Basically a wrapper for PEAR::raiseError * callbacks etc. Basically a wrapper for DOLIPEAR::raiseError
* without the message string. * without the message string.
* *
* @param mixed int error code * @param mixed int error code
@ -572,7 +572,7 @@ class MDB2
*/ */
function &raiseError($code = null, $mode = null, $options = null, $userinfo = null) function &raiseError($code = null, $mode = null, $options = null, $userinfo = null)
{ {
$err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true); $err =& DOLIPEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
return $err; return $err;
} }
@ -741,7 +741,7 @@ class MDB2
return $errorMessages; return $errorMessages;
} }
if (PEAR::isError($value)) { if (DOLIPEAR::isError($value)) {
$value = $value->getCode(); $value = $value->getCode();
} }
@ -1384,7 +1384,7 @@ class MDB2_Driver_Common extends PEAR
/** /**
* This method is used to communicate an error and invoke error * This method is used to communicate an error and invoke error
* callbacks etc. Basically a wrapper for PEAR::raiseError * callbacks etc. Basically a wrapper for DOLIPEAR::raiseError
* without the message string. * without the message string.
* *
* @param mixed integer error code, or a PEAR error object (all other * @param mixed integer error code, or a PEAR error object (all other
@ -1409,8 +1409,8 @@ class MDB2_Driver_Common extends PEAR
{ {
$userinfo = "[Error message: $userinfo]\n"; $userinfo = "[Error message: $userinfo]\n";
// The error is yet a MDB2 error object // The error is yet a MDB2 error object
if (PEAR::isError($code)) { if (DOLIPEAR::isError($code)) {
// because we use the static PEAR::raiseError, our global // because we use the static DOLIPEAR::raiseError, our global
// handler should be used if it is set // handler should be used if it is set
if (is_null($mode) && !empty($this->_default_error_mode)) { if (is_null($mode) && !empty($this->_default_error_mode)) {
$mode = $this->_default_error_mode; $mode = $this->_default_error_mode;
@ -1440,7 +1440,7 @@ class MDB2_Driver_Common extends PEAR
} }
} }
$err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true); $err =& DOLIPEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
if ($err->getMode() !== PEAR_ERROR_RETURN if ($err->getMode() !== PEAR_ERROR_RETURN
&& isset($this->nested_transaction_counter) && !$this->has_transaction_error) { && isset($this->nested_transaction_counter) && !$this->has_transaction_error) {
$this->has_transaction_error =& $err; $this->has_transaction_error =& $err;
@ -1734,7 +1734,7 @@ class MDB2_Driver_Common extends PEAR
function getConnection() function getConnection()
{ {
$result = $this->connect(); $result = $this->connect();
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
return $this->connection; return $this->connection;
@ -1860,7 +1860,7 @@ class MDB2_Driver_Common extends PEAR
} }
$err = MDB2::loadClass($class_name, $this->getOption('debug')); $err = MDB2::loadClass($class_name, $this->getOption('debug'));
if (PEAR::isError($err)) { if (DOLIPEAR::isError($err)) {
return $err; return $err;
} }
@ -1871,7 +1871,7 @@ class MDB2_Driver_Common extends PEAR
if ($class_name != $class_name_new) { if ($class_name != $class_name_new) {
$class_name = $class_name_new; $class_name = $class_name_new;
$err = MDB2::loadClass($class_name, $this->getOption('debug')); $err = MDB2::loadClass($class_name, $this->getOption('debug'));
if (PEAR::isError($err)) { if (DOLIPEAR::isError($err)) {
return $err; return $err;
} }
} }
@ -1917,7 +1917,7 @@ class MDB2_Driver_Common extends PEAR
$method = strtolower($match[2]).$match[3]; $method = strtolower($match[2]).$match[3];
if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) { if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) {
$result =& $this->loadModule($module); $result =& $this->loadModule($module);
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
} }
@ -2104,7 +2104,7 @@ class MDB2_Driver_Common extends PEAR
if ($this->supports('savepoints') && $savepoint) { if ($this->supports('savepoints') && $savepoint) {
if ($force_rollback || $this->has_transaction_error) { if ($force_rollback || $this->has_transaction_error) {
$result = $this->rollback($savepoint); $result = $this->rollback($savepoint);
if (!PEAR::isError($result)) { if (!DOLIPEAR::isError($result)) {
$result = false; $result = false;
$this->has_transaction_error = false; $this->has_transaction_error = false;
} }
@ -2125,7 +2125,7 @@ class MDB2_Driver_Common extends PEAR
if ($this->in_transaction) { if ($this->in_transaction) {
if ($force_rollback || $this->has_transaction_error) { if ($force_rollback || $this->has_transaction_error) {
$result = $this->rollback(); $result = $this->rollback();
if (!PEAR::isError($result)) { if (!DOLIPEAR::isError($result)) {
$result = false; $result = false;
} }
} else { } else {
@ -2366,12 +2366,12 @@ class MDB2_Driver_Common extends PEAR
$query = $this->_modifyQuery($query, $is_manip, $limit, $offset); $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
$connection = $this->getConnection(); $connection = $this->getConnection();
if (PEAR::isError($connection)) { if (DOLIPEAR::isError($connection)) {
return $connection; return $connection;
} }
$result =& $this->_doQuery($query, $is_manip, $connection, false); $result =& $this->_doQuery($query, $is_manip, $connection, false);
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
@ -2422,7 +2422,7 @@ class MDB2_Driver_Common extends PEAR
$this->last_query = $query; $this->last_query = $query;
$result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre')); $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
if ($result) { if ($result) {
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
$query = $result; $query = $result;
@ -2471,12 +2471,12 @@ class MDB2_Driver_Common extends PEAR
$query = $this->_modifyQuery($query, true, $limit, $offset); $query = $this->_modifyQuery($query, true, $limit, $offset);
$connection = $this->getConnection(); $connection = $this->getConnection();
if (PEAR::isError($connection)) { if (DOLIPEAR::isError($connection)) {
return $connection; return $connection;
} }
$result =& $this->_doQuery($query, true, $connection, $this->database_name); $result =& $this->_doQuery($query, true, $connection, $this->database_name);
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
@ -2508,12 +2508,12 @@ class MDB2_Driver_Common extends PEAR
$query = $this->_modifyQuery($query, false, $limit, $offset); $query = $this->_modifyQuery($query, false, $limit, $offset);
$connection = $this->getConnection(); $connection = $this->getConnection();
if (PEAR::isError($connection)) { if (DOLIPEAR::isError($connection)) {
return $connection; return $connection;
} }
$result =& $this->_doQuery($query, false, $connection, $this->database_name); $result =& $this->_doQuery($query, false, $connection, $this->database_name);
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
@ -2546,7 +2546,7 @@ class MDB2_Driver_Common extends PEAR
if ($this->supports('result_introspection')) { if ($this->supports('result_introspection')) {
$this->loadModule('Reverse', null, true); $this->loadModule('Reverse', null, true);
$tableInfo = $this->reverse->tableInfo($result); $tableInfo = $this->reverse->tableInfo($result);
if (PEAR::isError($tableInfo)) { if (DOLIPEAR::isError($tableInfo)) {
return $tableInfo; return $tableInfo;
} }
$types = array(); $types = array();
@ -2578,7 +2578,7 @@ class MDB2_Driver_Common extends PEAR
} }
if (!empty($types)) { if (!empty($types)) {
$err = $result->setResultTypes($types); $err = $result->setResultTypes($types);
if (PEAR::isError($err)) { if (DOLIPEAR::isError($err)) {
$result->free(); $result->free();
return $err; return $err;
} }
@ -2679,7 +2679,7 @@ class MDB2_Driver_Common extends PEAR
} }
$col = $this->queryCol($query, $type); $col = $this->queryCol($query, $type);
if (PEAR::isError($col)) { if (DOLIPEAR::isError($col)) {
return $col; return $col;
} }
if (!is_array($col) || count($col) == 0) { if (!is_array($col) || count($col) == 0) {
@ -2790,38 +2790,38 @@ class MDB2_Driver_Common extends PEAR
$result = null; $result = null;
$in_transaction = $this->in_transaction; $in_transaction = $this->in_transaction;
if (!$in_transaction && PEAR::isError($result = $this->beginTransaction())) { if (!$in_transaction && DOLIPEAR::isError($result = $this->beginTransaction())) {
return $result; return $result;
} }
$connection = $this->getConnection(); $connection = $this->getConnection();
if (PEAR::isError($connection)) { if (DOLIPEAR::isError($connection)) {
return $connection; return $connection;
} }
$condition = ' WHERE '.implode(' AND ', $condition); $condition = ' WHERE '.implode(' AND ', $condition);
$query = "DELETE FROM $table$condition"; $query = "DELETE FROM $table$condition";
$result =& $this->_doQuery($query, true, $connection); $result =& $this->_doQuery($query, true, $connection);
if (!PEAR::isError($result)) { if (!DOLIPEAR::isError($result)) {
$affected_rows = $this->_affectedRows($connection, $result); $affected_rows = $this->_affectedRows($connection, $result);
$insert = implode(', ', array_keys($values)); $insert = implode(', ', array_keys($values));
$values = implode(', ', $values); $values = implode(', ', $values);
$query = "INSERT INTO $table ($insert) VALUES ($values)"; $query = "INSERT INTO $table ($insert) VALUES ($values)";
$result =& $this->_doQuery($query, true, $connection); $result =& $this->_doQuery($query, true, $connection);
if (!PEAR::isError($result)) { if (!DOLIPEAR::isError($result)) {
$affected_rows += $this->_affectedRows($connection, $result);; $affected_rows += $this->_affectedRows($connection, $result);;
} }
} }
if (!$in_transaction) { if (!$in_transaction) {
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
$this->rollback(); $this->rollback();
} else { } else {
$result = $this->commit(); $result = $this->commit();
} }
} }
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
@ -2861,7 +2861,7 @@ class MDB2_Driver_Common extends PEAR
$this->offset = $this->limit = 0; $this->offset = $this->limit = 0;
$result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre')); $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
if ($result) { if ($result) {
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
$query = $result; $query = $result;
@ -2891,7 +2891,7 @@ class MDB2_Driver_Common extends PEAR
} }
$new_pos = $this->_skipDelimitedStrings($query, $position, $p_position); $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
if (PEAR::isError($new_pos)) { if (DOLIPEAR::isError($new_pos)) {
return $new_pos; return $new_pos;
} }
if ($new_pos != $position) { if ($new_pos != $position) {
@ -3010,7 +3010,7 @@ class MDB2_Driver_Common extends PEAR
function quote($value, $type = null, $quote = true, $escape_wildcards = false) function quote($value, $type = null, $quote = true, $escape_wildcards = false)
{ {
$result = $this->loadModule('Datatype', null, true); $result = $this->loadModule('Datatype', null, true);
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
@ -3036,7 +3036,7 @@ class MDB2_Driver_Common extends PEAR
function getDeclaration($type, $name, $field) function getDeclaration($type, $name, $field)
{ {
$result = $this->loadModule('Datatype', null, true); $result = $this->loadModule('Datatype', null, true);
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
return $this->datatype->getDeclaration($type, $name, $field); return $this->datatype->getDeclaration($type, $name, $field);
@ -3058,7 +3058,7 @@ class MDB2_Driver_Common extends PEAR
function compareDefinition($current, $previous) function compareDefinition($current, $previous)
{ {
$result = $this->loadModule('Datatype', null, true); $result = $this->loadModule('Datatype', null, true);
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
return $this->datatype->compareDefinition($current, $previous); return $this->datatype->compareDefinition($current, $previous);
@ -3407,11 +3407,11 @@ class MDB2_Result_Common extends MDB2_Result
function setResultTypes($types) function setResultTypes($types)
{ {
$load = $this->db->loadModule('Datatype', null, true); $load = $this->db->loadModule('Datatype', null, true);
if (PEAR::isError($load)) { if (DOLIPEAR::isError($load)) {
return $load; return $load;
} }
$types = $this->db->datatype->checkResultTypes($types); $types = $this->db->datatype->checkResultTypes($types);
if (PEAR::isError($types)) { if (DOLIPEAR::isError($types)) {
return $types; return $types;
} }
$this->types = $types; $this->types = $types;
@ -3480,7 +3480,7 @@ class MDB2_Result_Common extends MDB2_Result
{ {
$fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC; $fetchmode = is_numeric($colnum) ? MDB2_FETCHMODE_ORDERED : MDB2_FETCHMODE_ASSOC;
$row = $this->fetchRow($fetchmode, $rownum); $row = $this->fetchRow($fetchmode, $rownum);
if (!is_array($row) || PEAR::isError($row)) { if (!is_array($row) || DOLIPEAR::isError($row)) {
return $row; return $row;
} }
if (!array_key_exists($colnum, $row)) { if (!array_key_exists($colnum, $row)) {
@ -3516,7 +3516,7 @@ class MDB2_Result_Common extends MDB2_Result
$column[] = $row[$colnum]; $column[] = $row[$colnum];
} while (is_array($row = $this->fetchRow($fetchmode))); } while (is_array($row = $this->fetchRow($fetchmode)));
} }
if (PEAR::isError($row)) { if (DOLIPEAR::isError($row)) {
return $row; return $row;
} }
return $column; return $column;
@ -3553,7 +3553,7 @@ class MDB2_Result_Common extends MDB2_Result
{ {
$all = array(); $all = array();
$row = $this->fetchRow($fetchmode); $row = $this->fetchRow($fetchmode);
if (PEAR::isError($row)) { if (DOLIPEAR::isError($row)) {
return $row; return $row;
} elseif (!$row) { } elseif (!$row) {
return $all; return $all;
@ -3676,7 +3676,7 @@ class MDB2_Result_Common extends MDB2_Result
{ {
if (!isset($this->column_names)) { if (!isset($this->column_names)) {
$result = $this->_getColumnNames(); $result = $this->_getColumnNames();
if (PEAR::isError($result)) { if (DOLIPEAR::isError($result)) {
return $result; return $result;
} }
$this->column_names = $result; $this->column_names = $result;
@ -3964,7 +3964,7 @@ class MDB2_Statement_Common
$parameters = array_keys($values); $parameters = array_keys($values);
foreach ($parameters as $key => $parameter) { foreach ($parameters as $key => $parameter) {
$err = $this->bindValue($parameter, $values[$parameter], $types[$key]); $err = $this->bindValue($parameter, $values[$parameter], $types[$key]);
if (PEAR::isError($err)) { if (DOLIPEAR::isError($err)) {
return $err; return $err;
} }
} }
@ -4025,7 +4025,7 @@ class MDB2_Statement_Common
$parameters = array_keys($values); $parameters = array_keys($values);
foreach ($parameters as $key => $parameter) { foreach ($parameters as $key => $parameter) {
$err = $this->bindParam($parameter, $values[$parameter], $types[$key]); $err = $this->bindParam($parameter, $values[$parameter], $types[$key]);
if (PEAR::isError($err)) { if (DOLIPEAR::isError($err)) {
return $err; return $err;
} }
} }
@ -4058,7 +4058,7 @@ class MDB2_Statement_Common
$values = (array)$values; $values = (array)$values;
if (!empty($values)) { if (!empty($values)) {
$err = $this->bindValueArray($values); $err = $this->bindValueArray($values);
if (PEAR::isError($err)) { if (DOLIPEAR::isError($err)) {
return $this->db->raiseError(MDB2_ERROR, null, null, return $this->db->raiseError(MDB2_ERROR, null, null,
'Binding Values failed with message: ' . $err->getMessage(), __FUNCTION__); 'Binding Values failed with message: ' . $err->getMessage(), __FUNCTION__);
} }
@ -4097,7 +4097,7 @@ class MDB2_Statement_Common
} else { } else {
$type = !empty($this->types[$parameter]) ? $this->types[$parameter] : null; $type = !empty($this->types[$parameter]) ? $this->types[$parameter] : null;
$value_quoted = $this->db->quote($value, $type); $value_quoted = $this->db->quote($value, $type);
if (PEAR::isError($value_quoted)) { if (DOLIPEAR::isError($value_quoted)) {
return $value_quoted; return $value_quoted;
} }
} }