Commit 61c90626 authored by zYne's avatar zYne

Modified exception classes, new method for connection exceptions...

Modified exception classes, new method for connection exceptions getPortableCode(), refactored some classes
parent 81bc672e
...@@ -613,10 +613,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -613,10 +613,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
return $this->dbh->query($query); return $this->dbh->query($query);
} }
} catch(Doctrine_Adapter_Exception $e) { } catch(Doctrine_Adapter_Exception $e) {
} catch(PDOException $e) { }
$this->rethrowException($e); $this->rethrowException($e);
} catch(PDOException $e) {
$this->rethrowException($e);
}
} }
/** /**
* exec * exec
...@@ -649,9 +648,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -649,9 +648,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$exc = new $name($e->getMessage(), (int) $e->getCode()); $exc = new $name($e->getMessage(), (int) $e->getCode());
if( ! is_array($e->errorInfo)) 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; throw $exc;
} }
...@@ -702,7 +701,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun ...@@ -702,7 +701,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* } * }
* </code> * </code>
* *
* @return ArrayIterator * @return ArrayIterator SPL ArrayIterator object
*/ */
public function getIterator() { public function getIterator() {
return new ArrayIterator($this->tables); return new ArrayIterator($this->tables);
......
...@@ -68,17 +68,41 @@ class Doctrine_Connection_Exception extends Doctrine_Exception { ...@@ -68,17 +68,41 @@ class Doctrine_Connection_Exception extends Doctrine_Exception {
Doctrine::ERR_TRUNCATED => 'truncated', Doctrine::ERR_TRUNCATED => 'truncated',
Doctrine::ERR_DEADLOCK => 'deadlock detected', 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 * Return a textual error message for a Doctrine error code
* *
* @param int|array integer error code, * @param int|array integer error code,
null to get the current error code-message map, * null to get the current error code-message map,
or an array with a new 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 * @return string error message, or false if the error code was
* not recognized * not recognized
*/ */
public function errorMessage($value = null) { public static function errorMessage($value = null) {
return isset(self::$errorMessages[$value]) ? return isset(self::$errorMessages[$value]) ?
self::$errorMessages[$value] : self::$errorMessages[Doctrine::ERR]; self::$errorMessages[$value] : self::$errorMessages[Doctrine::ERR];
} }
......
...@@ -59,19 +59,16 @@ class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception ...@@ -59,19 +59,16 @@ class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception
/** /**
* 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 * 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 * the portable error code is added at the end of array
* *
* @param array $errorInfo error info array * @param array $errorInfo error info array
* @since 1.0 * @since 1.0
* @return array
*/ */
public function processErrorInfo(array $errorInfo) { public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1]; $code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) if(isset(self::$errorCodeMap[$code]))
$errorInfo[3] = self::$errorCodeMap[$code]; $this->portableCode = self::$errorCodeMap[$code];
return $errorInfo;
} }
} }
...@@ -38,8 +38,18 @@ class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception ...@@ -38,8 +38,18 @@ class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception
* error code from a native database error message * error code from a native database error message
*/ */
protected static $errorRegexps = array( 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' '/column .* (of relation .*)?does not exist/i'
=> Doctrine::ERR_NOSUCHFIELD, => 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' '/(relation|sequence|table).*does not exist|class .* not found/i'
=> Doctrine::ERR_NOSUCHTABLE, => Doctrine::ERR_NOSUCHTABLE,
'/index .* does not exist/' '/index .* does not exist/'
...@@ -58,45 +68,38 @@ class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception ...@@ -58,45 +68,38 @@ class Doctrine_Connection_Pgsql_Exception extends Doctrine_Connection_Exception
=> Doctrine::ERR_INVALID_NUMBER, => Doctrine::ERR_INVALID_NUMBER,
'/value too long for type character/i' '/value too long for type character/i'
=> Doctrine::ERR_INVALID, => 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/' '/permission denied/'
=> Doctrine::ERR_ACCESS_VIOLATION, => Doctrine::ERR_ACCESS_VIOLATION,
'/violates not-null constraint/'
=> Doctrine::ERR_CONSTRAINT_NOT_NULL,
'/violates [\w ]+ constraint/' '/violates [\w ]+ constraint/'
=> Doctrine::ERR_CONSTRAINT, => Doctrine::ERR_CONSTRAINT,
'/referential integrity violation/' '/referential integrity violation/'
=> Doctrine::ERR_CONSTRAINT, => Doctrine::ERR_CONSTRAINT,
'/violates not-null constraint/'
=> Doctrine::ERR_CONSTRAINT_NOT_NULL,
'/more expressions than target columns/i' '/more expressions than target columns/i'
=> Doctrine::ERR_VALUE_COUNT_ON_ROW, => 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 * 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 * the portable error code is added at the end of array
* *
* @param array $errorInfo error info array * @param array $errorInfo error info array
* @since 1.0 * @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) { public function processErrorInfo(array $errorInfo) {
foreach (self::$errorRegexps as $regexp => $code) { foreach (self::$errorRegexps as $regexp => $code) {
if (preg_match($regexp, $errorInfo[2])) { if (preg_match($regexp, $errorInfo[2])) {
$errorInfo[3] = $code; $this->portableCode = $code;
break; return true;
} }
} }
return $errorInfo; return false;
} }
} }
...@@ -50,26 +50,26 @@ class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception ...@@ -50,26 +50,26 @@ class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception
'/^near ".*": syntax error$/' => Doctrine::ERR_SYNTAX, '/^near ".*": syntax error$/' => Doctrine::ERR_SYNTAX,
'/[0-9]+ values for [0-9]+ columns/i' => Doctrine::ERR_VALUE_COUNT_ON_ROW, '/[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 * 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 * @param array $errorInfo error info array
* @since 1.0 * @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) { public function processErrorInfo(array $errorInfo) {
foreach (self::$errorRegexps as $regexp => $code) { foreach(self::$errorRegexps as $regexp => $code) {
if (preg_match($regexp, $errorInfo[2])) { if(preg_match($regexp, $errorInfo[2])) {
$errorInfo[3] = $code;
break; $this->portableCode = $code;
return true;
} }
} }
return false;
return $errorInfo;
} }
} }
...@@ -49,44 +49,6 @@ ...@@ -49,44 +49,6 @@
* @version $Revision$ * @version $Revision$
*/ */
class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Interface { 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 * @var array $instances all the instances of this class
*/ */
......
...@@ -550,8 +550,6 @@ class Doctrine_Export extends Doctrine_Connection_Module { ...@@ -550,8 +550,6 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$notnull = empty($field['notnull']) ? '' : ' NOT NULL'; $notnull = empty($field['notnull']) ? '' : ' NOT NULL';
$name = $this->conn->quoteIdentifier($name, true);
$method = 'get' . $field['type'] . 'Declaration'; $method = 'get' . $field['type'] . 'Declaration';
if(method_exists($this->conn->dataDict, $method)) if(method_exists($this->conn->dataDict, $method))
...@@ -559,7 +557,7 @@ class Doctrine_Export extends Doctrine_Connection_Module { ...@@ -559,7 +557,7 @@ class Doctrine_Export extends Doctrine_Connection_Module {
else else
$dec = $this->conn->dataDict->getNativeDeclaration($field); $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 * Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
...@@ -613,7 +611,7 @@ class Doctrine_Export extends Doctrine_Connection_Module { ...@@ -613,7 +611,7 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$reporter = new Doctrine_Reporter(); $reporter = new Doctrine_Reporter();
if( ! Doctrine::isValidClassname($table->getComponentName())) { if( ! Doctrine::isValidClassname($table->getComponentName())) {
$reporter->add(E_WARNING, Doctrine::ERR_CLASS_NAME); $reporter->add(E_WARNING, 'Badly named class.');
} }
try { try {
...@@ -631,10 +629,10 @@ class Doctrine_Export extends Doctrine_Connection_Module { ...@@ -631,10 +629,10 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$columns[$name] = $definition; $columns[$name] = $definition;
} }
$this->createTable($table->getTableName(), $columns); $this->createTable($table->getTableName(), $columns);
} catch(Doctrine_Connection_Exception $e) { } catch(Doctrine_Connection_Exception $e) {
$reporter->add(E_ERROR, $e->getCode()); $reporter->add(E_ERROR, $e->getCode());
} }
......
...@@ -183,28 +183,29 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -183,28 +183,29 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
$this->index++; $this->index++;
} }
switch($adapter->getAttribute(PDO::ATTR_DRIVER_NAME)): switch($adapter->getAttribute(PDO::ATTR_DRIVER_NAME)):
case "mysql": case 'mysql':
$this->connections[$name] = new Doctrine_Connection_Mysql($this, $adapter); $this->connections[$name] = new Doctrine_Connection_Mysql($this, $adapter);
break; break;
case "sqlite": case 'sqlite':
$this->connections[$name] = new Doctrine_Connection_Sqlite($this, $adapter); $this->connections[$name] = new Doctrine_Connection_Sqlite($this, $adapter);
break; break;
case "pgsql": case 'pgsql':
$this->connections[$name] = new Doctrine_Connection_Pgsql($this, $adapter); $this->connections[$name] = new Doctrine_Connection_Pgsql($this, $adapter);
break; break;
case "oci": case 'oci':
case 'oracle':
$this->connections[$name] = new Doctrine_Connection_Oracle($this, $adapter); $this->connections[$name] = new Doctrine_Connection_Oracle($this, $adapter);
break; break;
case "mssql": case 'mssql':
$this->connections[$name] = new Doctrine_Connection_Mssql($this, $adapter); $this->connections[$name] = new Doctrine_Connection_Mssql($this, $adapter);
break; break;
case "firebird": case 'firebird':
$this->connections[$name] = new Doctrine_Connection_Firebird($this, $adapter); $this->connections[$name] = new Doctrine_Connection_Firebird($this, $adapter);
break; break;
case "informix": case 'informix':
$this->connections[$name] = new Doctrine_Connection_Informix($this, $adapter); $this->connections[$name] = new Doctrine_Connection_Informix($this, $adapter);
break; break;
case "mock": case 'mock':
$this->connections[$name] = new Doctrine_Connection_Mock($this, $adapter); $this->connections[$name] = new Doctrine_Connection_Mock($this, $adapter);
break; break;
default: default:
......
...@@ -257,6 +257,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { ...@@ -257,6 +257,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$columns[$name] = $definition; $columns[$name] = $definition;
} }
$this->conn->export->createTable($this->options['tableName'], $columns); $this->conn->export->createTable($this->options['tableName'], $columns);
} catch(Exception $e) { } catch(Exception $e) {
......
...@@ -107,8 +107,8 @@ class Doctrine_View { ...@@ -107,8 +107,8 @@ class Doctrine_View {
public function create() { public function create() {
$sql = sprintf(self::CREATE, $this->name, $this->query->getQuery()); $sql = sprintf(self::CREATE, $this->name, $this->query->getQuery());
try { try {
$this->conn->getDBH()->query($sql); $this->conn->execute($sql);
} catch(Exception $e) { } catch(Doctrine_Exception $e) {
throw new Doctrine_View_Exception($e->__toString()); throw new Doctrine_View_Exception($e->__toString());
} }
} }
...@@ -121,8 +121,8 @@ class Doctrine_View { ...@@ -121,8 +121,8 @@ class Doctrine_View {
*/ */
public function drop() { public function drop() {
try { try {
$this->conn->getDBH()->query(sprintf(self::DROP, $this->name)); $this->conn->execute(sprintf(self::DROP, $this->name));
} catch(Exception $e) { } catch(Doctrine_Exception $e) {
throw new Doctrine_View_Exception($e->__toString()); throw new Doctrine_View_Exception($e->__toString());
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment