diff --git a/lib/Doctrine.php b/lib/Doctrine.php index 8c02c4152..02e4ac07b 100644 --- a/lib/Doctrine.php +++ b/lib/Doctrine.php @@ -25,6 +25,7 @@ * * @package Doctrine * @author Konsta Vesterinen + * @author Lukas Smith (PEAR MDB2 library) * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @category Object Relational Mapping * @link www.phpdoctrine.com @@ -32,45 +33,6 @@ * @version $Revision$ */ final class Doctrine { - /** - * 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; - /** * ATTRIBUTE CONSTANTS */ @@ -83,26 +45,6 @@ final class Doctrine { * fetchmode attribute */ const ATTR_FETCHMODE = 2; - /** - * cache directory attribute - */ - const ATTR_CACHE_DIR = 3; - /** - * cache time to live attribute - */ - const ATTR_CACHE_TTL = 4; - /** - * cache size attribute - */ - const ATTR_CACHE_SIZE = 5; - /** - * cache slam defense probability - */ - const ATTR_CACHE_SLAM = 6; - /** - * cache container attribute - */ - const ATTR_CACHE = 7; /** * batch size attribute */ @@ -147,15 +89,11 @@ final class Doctrine { * automatic type validations attribute */ const ATTR_AUTO_TYPE_VLD = 20; - /** - * short aliases attribute - */ - const ATTR_SHORT_ALIASES = 21; - + /** * LIMIT CONSTANTS */ - + /** * constant for row limiting */ @@ -236,8 +174,54 @@ final class Doctrine { * constant for both accessors get and set */ const ACCESSOR_BOTH = 4; + + /** + * PORTABILITY CONSTANTS + */ + /** + * Portability: turn off all portability features. + * @see Doctrine::ATTR_PORTABILITY + */ + const PORTABILITY_NONE = 0; + + /** + * Portability: convert names of tables and fields to case defined in the + * "field_case" option when using the query*(), fetch*() methods. + * @see Doctrine::ATTR_PORTABILITY + */ + const PORTABILITY_FIX_CASE = 1; + + /** + * Portability: right trim the data output by query*() and fetch*(). + * @see Doctrine::ATTR_PORTABILITY + */ + const PORTABILITY_RTRIM = 2; + + /** + * Portability: force reporting the number of rows deleted. + * @see Doctrine::ATTR_PORTABILITY + */ + const PORTABILITY_DELETE_COUNT = 4; + /** + * Portability: convert empty values to null strings in data output by + * query*() and fetch*(). + * @see Doctrine::ATTR_PORTABILITY + */ + const PORTABILITY_EMPTY_TO_NULL = 8; + /** + * Portability: removes database/table qualifiers from associative indexes + * @see Doctrine::ATTR_PORTABILITY + */ + const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16; + + /** + * Portability: turn on all portability features. + * @see Doctrine::ATTR_PORTABILITY + */ + const PORTABILITY_ALL = 17; + /** * LOCKMODE CONSTANTS */ diff --git a/lib/Doctrine/Configurable.php b/lib/Doctrine/Configurable.php index 262b92a4d..80ad06891 100644 --- a/lib/Doctrine/Configurable.php +++ b/lib/Doctrine/Configurable.php @@ -55,24 +55,7 @@ abstract class Doctrine_Configurable { if($value < 0) throw new Doctrine_Exception("Batch size should be greater than or equal to zero"); break; - case Doctrine::ATTR_CACHE_DIR: - if(substr(trim($value),0,6) == "%ROOT%") { - $dir = dirname(__FILE__); - $value = $dir.substr($value,6); - } - break; - case Doctrine::ATTR_CACHE_TTL: - if($value < 1) - throw new Doctrine_Exception("Cache TimeToLive should be greater than or equal to 1"); - break; - case Doctrine::ATTR_CACHE_SIZE: - if($value < 1) - throw new Doctrine_Exception("Cache size should be greater than or equal to 1"); - break; - case Doctrine::ATTR_CACHE_SLAM: - if($value < 0 || $value > 1) - throw new Doctrine_Exception("Cache slam defense should be a floating point number between 0 and 1"); - break; + case Doctrine::ATTR_FETCHMODE: if($value < 0) throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants."); @@ -121,7 +104,6 @@ abstract class Doctrine_Configurable { case Doctrine::ATTR_VLD: case Doctrine::ATTR_AUTO_LENGTH_VLD: case Doctrine::ATTR_AUTO_TYPE_VLD: - case Doctrine::ATTR_SHORT_ALIASES: case Doctrine::ATTR_QUERY_LIMIT: break; diff --git a/lib/Doctrine/Db.php b/lib/Doctrine/Db.php index 0ca904ee4..7ca4a6f9e 100644 --- a/lib/Doctrine/Db.php +++ b/lib/Doctrine/Db.php @@ -410,76 +410,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte return $rows; } - /** - * fetchAll - * - * @param string $statement sql query to be executed - * @param array $params prepared statement params - * @return array - */ - public function fetchAll($statement, array $params = array()) { - return $this->query($statement, $params)->fetchAll(PDO::FETCH_ASSOC); - } - /** - * fetchOne - * - * @param string $statement sql query to be executed - * @param array $params prepared statement params - * @return mixed - */ - public function fetchOne($statement, array $params = array()) { - return current($this->query($statement, $params)->fetch(PDO::FETCH_NUM)); - } - /** - * fetchRow - * - * @param string $statement sql query to be executed - * @param array $params prepared statement params - * @return array - */ - public function fetchRow($statement, array $params = array()) { - return $this->query($statement, $params)->fetch(PDO::FETCH_ASSOC); - } - /** - * fetchArray - * - * @param string $statement sql query to be executed - * @param array $params prepared statement params - * @return array - */ - public function fetchArray($statement, array $params = array()) { - return $this->query($statement, $params)->fetch(PDO::FETCH_NUM); - } - /** - * fetchColumn - * - * @param string $statement sql query to be executed - * @param array $params prepared statement params - * @return array - */ - public function fetchColumn($statement, array $params = array()) { - return $this->query($statement, $params)->fetchAll(PDO::FETCH_COLUMN); - } - /** - * fetchAssoc - * - * @param string $statement sql query to be executed - * @param array $params prepared statement params - * @return array - */ - public function fetchAssoc($statement, array $params = array()) { - return $this->query($statement, $params)->fetchAll(PDO::FETCH_ASSOC); - } - /** - * fetchBoth - * - * @param string $statement sql query to be executed - * @param array $params prepared statement params - * @return array - */ - public function fetchBoth($statement, array $params = array()) { - return $this->query($statement, $params)->fetchAll(PDO::FETCH_BOTH); - } + /** * lastInsertId * diff --git a/lib/Doctrine/Db/Exception.php b/lib/Doctrine/Db/Exception.php index d07502e06..6a4fe89b0 100644 --- a/lib/Doctrine/Db/Exception.php +++ b/lib/Doctrine/Db/Exception.php @@ -21,12 +21,66 @@ /** * Doctrine_Db_Exception * - * @author Konsta Vesterinen - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @package Doctrine - * @category Object Relational Mapping - * @link www.phpdoctrine.com - * @since 1.0 - * @version $Revision$ - */ -class Doctrine_Db_Exception extends Doctrine_Exception { } + * @author Konsta Vesterinen + * @author Lukas Smith (PEAR MDB2 library) + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @package Doctrine + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Db_Exception extends Doctrine_Exception { + /** + * @var array $errorMessages an array containing messages for portable error codes + */ + protected static $errorMessages = array( + Doctrine_Db::ERR => 'unknown error', + Doctrine_Db::ERR_ALREADY_EXISTS => 'already exists', + Doctrine_Db::ERR_CANNOT_CREATE => 'can not create', + Doctrine_Db::ERR_CANNOT_ALTER => 'can not alter', + Doctrine_Db::ERR_CANNOT_REPLACE => 'can not replace', + Doctrine_Db::ERR_CANNOT_DELETE => 'can not delete', + Doctrine_Db::ERR_CANNOT_DROP => 'can not drop', + Doctrine_Db::ERR_CONSTRAINT => 'constraint violation', + Doctrine_Db::ERR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint', + Doctrine_Db::ERR_DIVZERO => 'division by zero', + Doctrine_Db::ERR_INVALID => 'invalid', + Doctrine_Db::ERR_INVALID_DATE => 'invalid date or time', + Doctrine_Db::ERR_INVALID_NUMBER => 'invalid number', + Doctrine_Db::ERR_MISMATCH => 'mismatch', + Doctrine_Db::ERR_NODBSELECTED => 'no database selected', + Doctrine_Db::ERR_NOSUCHFIELD => 'no such field', + Doctrine_Db::ERR_NOSUCHTABLE => 'no such table', + Doctrine_Db::ERR_NOT_CAPABLE => 'MDB2 backend not capable', + Doctrine_Db::ERR_NOT_FOUND => 'not found', + Doctrine_Db::ERR_NOT_LOCKED => 'not locked', + Doctrine_Db::ERR_SYNTAX => 'syntax error', + Doctrine_Db::ERR_UNSUPPORTED => 'not supported', + Doctrine_Db::ERR_VALUE_COUNT_ON_ROW => 'value count on row', + Doctrine_Db::ERR_INVALID_DSN => 'invalid DSN', + Doctrine_Db::ERR_CONNECT_FAILED => 'connect failed', + Doctrine_Db::ERR_NEED_MORE_DATA => 'insufficient data supplied', + Doctrine_Db::ERR_EXTENSION_NOT_FOUND=> 'extension not found', + Doctrine_Db::ERR_NOSUCHDB => 'no such database', + Doctrine_Db::ERR_ACCESS_VIOLATION => 'insufficient permissions', + Doctrine_Db::ERR_LOADMODULE => 'error while including on demand module', + Doctrine_Db::ERR_TRUNCATED => 'truncated', + Doctrine_Db::ERR_DEADLOCK => 'deadlock detected', + ); + + /** + * Return a textual error message for a Doctrine_Db 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 + * + * @return string error message, or false if the error code was + * not recognized + */ + public function errorMessage($value = null) { + return isset(self::$errorMessages[$value]) ? + self::$errorMessages[$value] : self::$errorMessages[Doctrine_Db::ERR]; + } +} diff --git a/tests/ConfigurableTestCase.php b/tests/ConfigurableTestCase.php index f4f43f486..6a395aef3 100644 --- a/tests/ConfigurableTestCase.php +++ b/tests/ConfigurableTestCase.php @@ -6,16 +6,16 @@ class Doctrine_ConfigurableTestCase extends Doctrine_UnitTestCase { public function prepareData() { } public function testSetAttribute() { $table = $this->connection->getTable("User"); - + /** $this->manager->setAttribute(Doctrine::ATTR_CACHE_TTL,100); $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_TTL),100); - + $this->manager->setAttribute(Doctrine::ATTR_CACHE_SIZE,1); $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_SIZE),1); $this->manager->setAttribute(Doctrine::ATTR_CACHE_DIR,"%ROOT%".DIRECTORY_SEPARATOR."cache"); $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_CACHE_DIR),$this->manager->getRoot().DIRECTORY_SEPARATOR."cache"); - + */ $this->manager->setAttribute(Doctrine::ATTR_FETCHMODE,Doctrine::FETCH_LAZY); $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_FETCHMODE),Doctrine::FETCH_LAZY); @@ -29,6 +29,7 @@ class Doctrine_ConfigurableTestCase extends Doctrine_UnitTestCase { $this->assertEqual($this->manager->getAttribute(Doctrine::ATTR_LOCKMODE), Doctrine::LOCK_PESSIMISTIC); // test invalid arguments + /** try { $this->manager->setAttribute(Doctrine::ATTR_CACHE_TTL,-12); } catch(Exception $e) { @@ -44,7 +45,7 @@ class Doctrine_ConfigurableTestCase extends Doctrine_UnitTestCase { } catch(Exception $e) { $this->assertTrue($e instanceof Exception); } - + */ try { $this->connection->beginTransaction(); $this->manager->setAttribute(Doctrine::ATTR_LOCKMODE, Doctrine::LOCK_OPTIMISTIC); diff --git a/tests/DBTestCase.php b/tests/DBTestCase.php index 15c2898bc..08b0b5776 100644 --- a/tests/DBTestCase.php +++ b/tests/DBTestCase.php @@ -197,7 +197,7 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { } - public function testListeningEventsWithListenerChain() { + public function testListeningQueryEventsWithListenerChain() { $this->dbh->query('DROP TABLE entity'); $this->dbh->addListener(new Doctrine_Db_TestLogger()); @@ -212,10 +212,12 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { $this->assertEqual($listener2->pop(), 'onQuery'); $this->assertEqual($listener2->pop(), 'onPreQuery'); - + } + public function testListeningPrepareEventsWithListenerChain() { $stmt = $this->dbh->prepare('INSERT INTO entity (id) VALUES(?)'); - + $listener = $this->dbh->getListener()->get(0); + $listener2 = $this->dbh->getListener()->get(1); $this->assertEqual($listener->pop(), 'onPrepare'); $this->assertEqual($listener->pop(), 'onPrePrepare'); @@ -226,20 +228,24 @@ class Doctrine_Db_TestCase extends Doctrine_UnitTestCase { $this->assertEqual($listener->pop(), 'onExecute'); $this->assertEqual($listener->pop(), 'onPreExecute'); - + $this->assertEqual($listener2->pop(), 'onExecute'); $this->assertEqual($listener2->pop(), 'onPreExecute'); - + } + public function testListeningExecEventsWithListenerChain() { $this->dbh->exec('DELETE FROM entity'); - + $listener = $this->dbh->getListener()->get(0); + $listener2 = $this->dbh->getListener()->get(1); $this->assertEqual($listener->pop(), 'onExec'); $this->assertEqual($listener->pop(), 'onPreExec'); $this->assertEqual($listener2->pop(), 'onExec'); $this->assertEqual($listener2->pop(), 'onPreExec'); - + } + public function testListeningTransactionEventsWithListenerChain() { $this->dbh->beginTransaction(); - + $listener = $this->dbh->getListener()->get(0); + $listener2 = $this->dbh->getListener()->get(1); $this->assertEqual($listener->pop(), 'onBeginTransaction'); $this->assertEqual($listener->pop(), 'onPreBeginTransaction'); diff --git a/tests/run.php b/tests/run.php index cddc7d3ff..08e7ea02c 100644 --- a/tests/run.php +++ b/tests/run.php @@ -111,7 +111,6 @@ $test->addTestCase(new Doctrine_PessimisticLockingTestCase()); $test->addTestCase(new Doctrine_ViewTestCase()); -$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase()); $test->addTestCase(new Doctrine_CustomPrimaryKeyTestCase()); @@ -161,6 +160,7 @@ $test->addTestCase(new Doctrine_Query_Select_TestCase()); +//$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase()); //$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_SqliteTestCase());