Modified exception classes, new method for connection exceptions getPortableCode(), refactored some classes
This commit is contained in:
parent
81bc672eab
commit
61c906266b
@ -223,8 +223,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
public function quoteIdentifier($str, $checkOption = true) {
|
||||
if ($checkOption && ! $this->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) {
|
||||
return $str;
|
||||
}
|
||||
$str = str_replace($this->properties['identifier_quoting']['end'],
|
||||
}
|
||||
$str = str_replace($this->properties['identifier_quoting']['end'],
|
||||
$this->properties['identifier_quoting']['escape'] .
|
||||
$this->properties['identifier_quoting']['end'], $str);
|
||||
|
||||
@ -613,10 +613,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
return $this->dbh->query($query);
|
||||
}
|
||||
} catch(Doctrine_Adapter_Exception $e) {
|
||||
$this->rethrowException($e);
|
||||
} catch(PDOException $e) {
|
||||
$this->rethrowException($e);
|
||||
}
|
||||
} catch(PDOException $e) { }
|
||||
|
||||
$this->rethrowException($e);
|
||||
}
|
||||
/**
|
||||
* exec
|
||||
@ -649,9 +648,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
|
||||
$exc = new $name($e->getMessage(), (int) $e->getCode());
|
||||
if( ! is_array($e->errorInfo))
|
||||
$e->errorInfo = array();
|
||||
$e->errorInfo = array(null, null, null, null);
|
||||
|
||||
$exc->errorInfo = $exc->processErrorInfo($e->errorInfo);
|
||||
$exc->processErrorInfo($e->errorInfo);
|
||||
|
||||
throw $exc;
|
||||
}
|
||||
@ -702,7 +701,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @return ArrayIterator
|
||||
* @return ArrayIterator SPL ArrayIterator object
|
||||
*/
|
||||
public function getIterator() {
|
||||
return new ArrayIterator($this->tables);
|
||||
|
@ -67,18 +67,42 @@ class Doctrine_Connection_Exception extends Doctrine_Exception {
|
||||
Doctrine::ERR_LOADMODULE => 'error while including on demand module',
|
||||
Doctrine::ERR_TRUNCATED => 'truncated',
|
||||
Doctrine::ERR_DEADLOCK => 'deadlock detected',
|
||||
);
|
||||
);
|
||||
/**
|
||||
* @see Doctrine::ERR_* constants
|
||||
* @since 1.0
|
||||
* @var integer $portableCode portable error code
|
||||
*/
|
||||
protected $portableCode;
|
||||
/**
|
||||
* getPortableCode
|
||||
* returns portable error code
|
||||
*
|
||||
* @return integer portable error code
|
||||
*/
|
||||
public function getPortableCode() {
|
||||
return $this->portableCode;
|
||||
}
|
||||
/**
|
||||
* getPortableMessage
|
||||
* returns portable error message
|
||||
*
|
||||
* @return string portable error message
|
||||
*/
|
||||
public function getPortableMessage() {
|
||||
return self::errorMessage($this->portableCode);
|
||||
}
|
||||
/**
|
||||
* Return a textual error message for a Doctrine error code
|
||||
*
|
||||
* @param int|array integer error code,
|
||||
null to get the current error code-message map,
|
||||
or an array with a new error code-message map
|
||||
* null to get the current error code-message map,
|
||||
* or an array with a new error code-message map
|
||||
*
|
||||
* @return string error message, or false if the error code was
|
||||
* not recognized
|
||||
*/
|
||||
public function errorMessage($value = null) {
|
||||
public static function errorMessage($value = null) {
|
||||
return isset(self::$errorMessages[$value]) ?
|
||||
self::$errorMessages[$value] : self::$errorMessages[Doctrine::ERR];
|
||||
}
|
||||
|
@ -57,21 +57,18 @@ class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception
|
||||
2449 => Doctrine::ERR_CONSTRAINT,
|
||||
);
|
||||
/**
|
||||
* This method checks if native error code/message can be
|
||||
* This method checks if native error code/message can be
|
||||
* converted into a portable code and then adds this
|
||||
* portable error code to errorInfo array and returns the modified array
|
||||
* portable error code to $portableCode field
|
||||
*
|
||||
* the portable error code is added at the end of array
|
||||
*
|
||||
* @param array $errorInfo error info array
|
||||
* @since 1.0
|
||||
* @return array
|
||||
*/
|
||||
public function processErrorInfo(array $errorInfo) {
|
||||
$code = $errorInfo[1];
|
||||
if(isset(self::$errorCodeMap[$code]))
|
||||
$errorInfo[3] = self::$errorCodeMap[$code];
|
||||
|
||||
return $errorInfo;
|
||||
$this->portableCode = self::$errorCodeMap[$code];
|
||||
}
|
||||
}
|
||||
|
@ -38,8 +38,18 @@ class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception
|
||||
* error code from a native database error message
|
||||
*/
|
||||
protected static $errorRegexps = array(
|
||||
'/parser: parse error at or near/i'
|
||||
=> Doctrine::ERR_SYNTAX,
|
||||
'/syntax error at/'
|
||||
=> Doctrine::ERR_SYNTAX,
|
||||
'/column reference .* is ambiguous/i'
|
||||
=> Doctrine::ERR_SYNTAX,
|
||||
'/column .* (of relation .*)?does not exist/i'
|
||||
=> Doctrine::ERR_NOSUCHFIELD,
|
||||
'/attribute .* not found|relation .* does not have attribute/i'
|
||||
=> Doctrine::ERR_NOSUCHFIELD,
|
||||
'/column .* specified in USING clause does not exist in (left|right) table/i'
|
||||
=> Doctrine::ERR_NOSUCHFIELD,
|
||||
'/(relation|sequence|table).*does not exist|class .* not found/i'
|
||||
=> Doctrine::ERR_NOSUCHTABLE,
|
||||
'/index .* does not exist/'
|
||||
@ -58,45 +68,38 @@ class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception
|
||||
=> Doctrine::ERR_INVALID_NUMBER,
|
||||
'/value too long for type character/i'
|
||||
=> Doctrine::ERR_INVALID,
|
||||
'/attribute .* not found|relation .* does not have attribute/i'
|
||||
=> Doctrine::ERR_NOSUCHFIELD,
|
||||
'/column .* specified in USING clause does not exist in (left|right) table/i'
|
||||
=> Doctrine::ERR_NOSUCHFIELD,
|
||||
'/parser: parse error at or near/i'
|
||||
=> Doctrine::ERR_SYNTAX,
|
||||
'/syntax error at/'
|
||||
=> Doctrine::ERR_SYNTAX,
|
||||
'/column reference .* is ambiguous/i'
|
||||
=> Doctrine::ERR_SYNTAX,
|
||||
'/permission denied/'
|
||||
=> Doctrine::ERR_ACCESS_VIOLATION,
|
||||
'/violates not-null constraint/'
|
||||
=> Doctrine::ERR_CONSTRAINT_NOT_NULL,
|
||||
'/violates [\w ]+ constraint/'
|
||||
=> Doctrine::ERR_CONSTRAINT,
|
||||
'/referential integrity violation/'
|
||||
=> Doctrine::ERR_CONSTRAINT,
|
||||
'/violates not-null constraint/'
|
||||
=> Doctrine::ERR_CONSTRAINT_NOT_NULL,
|
||||
'/more expressions than target columns/i'
|
||||
=> Doctrine::ERR_VALUE_COUNT_ON_ROW,
|
||||
);
|
||||
/**
|
||||
* This method checks if native error code/message can be
|
||||
* This method checks if native error code/message can be
|
||||
* converted into a portable code and then adds this
|
||||
* portable error code to errorInfo array and returns the modified array
|
||||
* portable error code to $portableCode field
|
||||
*
|
||||
* the portable error code is added at the end of array
|
||||
*
|
||||
* @param array $errorInfo error info array
|
||||
* @since 1.0
|
||||
* @return array
|
||||
* @see Doctrine::ERR_* constants
|
||||
* @see Doctrine_Connection::$portableCode
|
||||
* @return boolean whether or not the error info processing was successfull
|
||||
* (the process is successfull if portable error code was found)
|
||||
*/
|
||||
public function processErrorInfo(array $errorInfo) {
|
||||
foreach (self::$errorRegexps as $regexp => $code) {
|
||||
if (preg_match($regexp, $errorInfo[2])) {
|
||||
$errorInfo[3] = $code;
|
||||
break;
|
||||
$this->portableCode = $code;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return $errorInfo;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -50,26 +50,26 @@ class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception
|
||||
'/^near ".*": syntax error$/' => Doctrine::ERR_SYNTAX,
|
||||
'/[0-9]+ values for [0-9]+ columns/i' => Doctrine::ERR_VALUE_COUNT_ON_ROW,
|
||||
);
|
||||
|
||||
/**
|
||||
* This method checks if native error code/message can be
|
||||
* This method checks if native error code/message can be
|
||||
* converted into a portable code and then adds this
|
||||
* portable error code to errorInfo array and returns the modified array
|
||||
*
|
||||
* the portable error code is added at the end of array
|
||||
* portable error code to $portableCode field
|
||||
*
|
||||
* @param array $errorInfo error info array
|
||||
* @since 1.0
|
||||
* @return array
|
||||
* @see Doctrine::ERR_* constants
|
||||
* @see Doctrine_Connection::$portableCode
|
||||
* @return boolean whether or not the error info processing was successfull
|
||||
* (the process is successfull if portable error code was found)
|
||||
*/
|
||||
public function processErrorInfo(array $errorInfo) {
|
||||
foreach (self::$errorRegexps as $regexp => $code) {
|
||||
if (preg_match($regexp, $errorInfo[2])) {
|
||||
$errorInfo[3] = $code;
|
||||
break;
|
||||
foreach(self::$errorRegexps as $regexp => $code) {
|
||||
if(preg_match($regexp, $errorInfo[2])) {
|
||||
|
||||
$this->portableCode = $code;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $errorInfo;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -49,44 +49,6 @@
|
||||
* @version $Revision$
|
||||
*/
|
||||
class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Interface {
|
||||
/**
|
||||
* error constants
|
||||
*/
|
||||
const ERR = -1;
|
||||
const ERR_SYNTAX = -2;
|
||||
const ERR_CONSTRAINT = -3;
|
||||
const ERR_NOT_FOUND = -4;
|
||||
const ERR_ALREADY_EXISTS = -5;
|
||||
const ERR_UNSUPPORTED = -6;
|
||||
const ERR_MISMATCH = -7;
|
||||
const ERR_INVALID = -8;
|
||||
const ERR_NOT_CAPABLE = -9;
|
||||
const ERR_TRUNCATED = -10;
|
||||
const ERR_INVALID_NUMBER = -11;
|
||||
const ERR_INVALID_DATE = -12;
|
||||
const ERR_DIVZERO = -13;
|
||||
const ERR_NODBSELECTED = -14;
|
||||
const ERR_CANNOT_CREATE = -15;
|
||||
const ERR_CANNOT_DELETE = -16;
|
||||
const ERR_CANNOT_DROP = -17;
|
||||
const ERR_NOSUCHTABLE = -18;
|
||||
const ERR_NOSUCHFIELD = -19;
|
||||
const ERR_NEED_MORE_DATA = -20;
|
||||
const ERR_NOT_LOCKED = -21;
|
||||
const ERR_VALUE_COUNT_ON_ROW = -22;
|
||||
const ERR_INVALID_DSN = -23;
|
||||
const ERR_CONNECT_FAILED = -24;
|
||||
const ERR_EXTENSION_NOT_FOUND = -25;
|
||||
const ERR_NOSUCHDB = -26;
|
||||
const ERR_ACCESS_VIOLATION = -27;
|
||||
const ERR_CANNOT_REPLACE = -28;
|
||||
const ERR_CONSTRAINT_NOT_NULL = -29;
|
||||
const ERR_DEADLOCK = -30;
|
||||
const ERR_CANNOT_ALTER = -31;
|
||||
const ERR_MANAGER = -32;
|
||||
const ERR_MANAGER_PARSE = -33;
|
||||
const ERR_LOADMODULE = -34;
|
||||
const ERR_INSUFFICIENT_DATA = -35;
|
||||
/**
|
||||
* @var array $instances all the instances of this class
|
||||
*/
|
||||
|
@ -550,8 +550,6 @@ class Doctrine_Export extends Doctrine_Connection_Module {
|
||||
|
||||
$notnull = empty($field['notnull']) ? '' : ' NOT NULL';
|
||||
|
||||
$name = $this->conn->quoteIdentifier($name, true);
|
||||
|
||||
$method = 'get' . $field['type'] . 'Declaration';
|
||||
|
||||
if(method_exists($this->conn->dataDict, $method))
|
||||
@ -559,7 +557,7 @@ class Doctrine_Export extends Doctrine_Connection_Module {
|
||||
else
|
||||
$dec = $this->conn->dataDict->getNativeDeclaration($field);
|
||||
|
||||
return $name . ' ' . $dec . $charset . $default . $notnull . $collation;
|
||||
return $this->conn->quoteIdentifier($name, true) . ' ' . $dec . $charset . $default . $notnull . $collation;
|
||||
}
|
||||
/**
|
||||
* Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
|
||||
@ -613,7 +611,7 @@ class Doctrine_Export extends Doctrine_Connection_Module {
|
||||
$reporter = new Doctrine_Reporter();
|
||||
|
||||
if( ! Doctrine::isValidClassname($table->getComponentName())) {
|
||||
$reporter->add(E_WARNING, Doctrine::ERR_CLASS_NAME);
|
||||
$reporter->add(E_WARNING, 'Badly named class.');
|
||||
}
|
||||
|
||||
try {
|
||||
@ -631,12 +629,12 @@ class Doctrine_Export extends Doctrine_Connection_Module {
|
||||
|
||||
$columns[$name] = $definition;
|
||||
}
|
||||
|
||||
$this->createTable($table->getTableName(), $columns);
|
||||
|
||||
} catch(Doctrine_Connection_Exception $e) {
|
||||
|
||||
$reporter->add(E_ERROR, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
return $reporter;
|
||||
}
|
||||
|
@ -183,28 +183,29 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
$this->index++;
|
||||
}
|
||||
switch($adapter->getAttribute(PDO::ATTR_DRIVER_NAME)):
|
||||
case "mysql":
|
||||
case 'mysql':
|
||||
$this->connections[$name] = new Doctrine_Connection_Mysql($this, $adapter);
|
||||
break;
|
||||
case "sqlite":
|
||||
case 'sqlite':
|
||||
$this->connections[$name] = new Doctrine_Connection_Sqlite($this, $adapter);
|
||||
break;
|
||||
case "pgsql":
|
||||
case 'pgsql':
|
||||
$this->connections[$name] = new Doctrine_Connection_Pgsql($this, $adapter);
|
||||
break;
|
||||
case "oci":
|
||||
case 'oci':
|
||||
case 'oracle':
|
||||
$this->connections[$name] = new Doctrine_Connection_Oracle($this, $adapter);
|
||||
break;
|
||||
case "mssql":
|
||||
case 'mssql':
|
||||
$this->connections[$name] = new Doctrine_Connection_Mssql($this, $adapter);
|
||||
break;
|
||||
case "firebird":
|
||||
case 'firebird':
|
||||
$this->connections[$name] = new Doctrine_Connection_Firebird($this, $adapter);
|
||||
break;
|
||||
case "informix":
|
||||
case 'informix':
|
||||
$this->connections[$name] = new Doctrine_Connection_Informix($this, $adapter);
|
||||
break;
|
||||
case "mock":
|
||||
case 'mock':
|
||||
$this->connections[$name] = new Doctrine_Connection_Mock($this, $adapter);
|
||||
break;
|
||||
default:
|
||||
|
@ -257,6 +257,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
||||
|
||||
$columns[$name] = $definition;
|
||||
}
|
||||
|
||||
$this->conn->export->createTable($this->options['tableName'], $columns);
|
||||
} catch(Exception $e) {
|
||||
|
||||
|
@ -23,14 +23,14 @@
|
||||
*
|
||||
* this class represents a database view
|
||||
*
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @package Doctrine
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @package Doctrine
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @category Object Relational Mapping
|
||||
* @link www.phpdoctrine.com
|
||||
* @since 1.0
|
||||
* @version $Revision$
|
||||
*/
|
||||
class Doctrine_View {
|
||||
/**
|
||||
* SQL DROP constant
|
||||
@ -107,8 +107,8 @@ class Doctrine_View {
|
||||
public function create() {
|
||||
$sql = sprintf(self::CREATE, $this->name, $this->query->getQuery());
|
||||
try {
|
||||
$this->conn->getDBH()->query($sql);
|
||||
} catch(Exception $e) {
|
||||
$this->conn->execute($sql);
|
||||
} catch(Doctrine_Exception $e) {
|
||||
throw new Doctrine_View_Exception($e->__toString());
|
||||
}
|
||||
}
|
||||
@ -121,8 +121,8 @@ class Doctrine_View {
|
||||
*/
|
||||
public function drop() {
|
||||
try {
|
||||
$this->conn->getDBH()->query(sprintf(self::DROP, $this->name));
|
||||
} catch(Exception $e) {
|
||||
$this->conn->execute(sprintf(self::DROP, $this->name));
|
||||
} catch(Doctrine_Exception $e) {
|
||||
throw new Doctrine_View_Exception($e->__toString());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user