1
0
mirror of synced 2024-12-14 07:06:04 +03:00

Added portable error code constants to Doctrine_Db, errorCodeMaps to sqlite and mysql drivers

This commit is contained in:
zYne 2006-11-08 12:11:55 +00:00
parent a0aa16bbea
commit 0cdd144bd5
3 changed files with 94 additions and 1 deletions

View File

@ -28,6 +28,44 @@
* @package Doctrine
*/
class Doctrine_DB2 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
*/

View File

@ -28,5 +28,29 @@ Doctrine::autoload('Doctrine_Db');
* @version $Id$
*/
class Doctrine_Db_Mysql extends Doctrine_Db {
protected static $errorCodeMap = array(
1004 => Doctrine_Db::ERR_CANNOT_CREATE,
1005 => Doctrine_Db::ERR_CANNOT_CREATE,
1006 => Doctrine_Db::ERR_CANNOT_CREATE,
1007 => Doctrine_Db::ERR_ALREADY_EXISTS,
1008 => Doctrine_Db::ERR_CANNOT_DROP,
1022 => Doctrine_Db::ERR_ALREADY_EXISTS,
1044 => Doctrine_Db::ERR_ACCESS_VIOLATION,
1046 => Doctrine_Db::ERR_NODBSELECTED,
1048 => Doctrine_Db::ERR_CONSTRAINT,
1049 => Doctrine_Db::ERR_NOSUCHDB,
1050 => Doctrine_Db::ERR_ALREADY_EXISTS,
1051 => Doctrine_Db::ERR_NOSUCHTABLE,
1054 => Doctrine_Db::ERR_NOSUCHFIELD,
1061 => Doctrine_Db::ERR_ALREADY_EXISTS,
1062 => Doctrine_Db::ERR_ALREADY_EXISTS,
1064 => Doctrine_Db::ERR_SYNTAX,
1091 => Doctrine_Db::ERR_NOT_FOUND,
1100 => Doctrine_Db::ERR_NOT_LOCKED,
1136 => Doctrine_Db::ERR_VALUE_COUNT_ON_ROW,
1142 => Doctrine_Db::ERR_ACCESS_VIOLATION,
1146 => Doctrine_Db::ERR_NOSUCHTABLE,
1216 => Doctrine_Db::ERR_CONSTRAINT,
1217 => Doctrine_Db::ERR_CONSTRAINT,
);
}

View File

@ -28,5 +28,36 @@ Doctrine::autoload('Doctrine_Db');
* @version $Id$
*/
class Doctrine_Db_Sqlite extends Doctrine_Db {
protected static $errorRegexps = array(
'/^no such table:/' => Doctrine_Db::ERR_NOSUCHTABLE,
'/^no such index:/' => Doctrine_Db::ERR_NOT_FOUND,
'/^(table|index) .* already exists$/' => Doctrine_Db::ERR_ALREADY_EXISTS,
'/PRIMARY KEY must be unique/i' => Doctrine_Db::ERR_CONSTRAINT,
'/is not unique/' => Doctrine_Db::ERR_CONSTRAINT,
'/columns .* are not unique/i' => Doctrine_Db::ERR_CONSTRAINT,
'/uniqueness constraint failed/' => Doctrine_Db::ERR_CONSTRAINT,
'/may not be NULL/' => Doctrine_Db::ERR_CONSTRAINT_NOT_NULL,
'/^no such column:/' => Doctrine_Db::ERR_NOSUCHFIELD,
'/column not present in both tables/i' => Doctrine_Db::ERR_NOSUCHFIELD,
'/^near ".*": syntax error$/' => Doctrine_Db::ERR_SYNTAX,
'/[0-9]+ values for [0-9]+ columns/i' => Doctrine_Db::ERR_VALUE_COUNT_ON_ROW,
);
/**
* This method is used to collect information about an error
*
* @param integer $error
* @return array
* @access public
*/
public function processErrorInfo(array $errorInfo) {
foreach (self::$errorRegexps as $regexp => $code) {
if (preg_match($regexp, $native_msg)) {
$error = $code;
break;
}
}
return array($error, $native_code, $native_msg);
}
}