From 4d7b8838cca6359b4db3f331a5645f48a205d01d Mon Sep 17 00:00:00 2001 From: romanb Date: Fri, 12 Sep 2008 08:51:56 +0000 Subject: [PATCH] Intermediate checkin. Refactoring towards namespaced structure. --- lib/Doctrine/Adapter/Db2.php | 3 +- lib/Doctrine/Adapter/Exception.php | 5 +- lib/Doctrine/Adapter/Interface.php | 3 +- lib/Doctrine/Adapter/Mock.php | 3 +- lib/Doctrine/Adapter/Mysqli.php | 1 + lib/Doctrine/Adapter/Resource.php | 4 +- lib/Doctrine/Adapter/Statement/Interface.php | 3 +- lib/Doctrine/Association/ManyToMany.php | 2 +- lib/Doctrine/Association/OneToMany.php | 2 +- lib/Doctrine/Cache/Apc.php | 9 +- lib/Doctrine/Cache/Array.php | 6 +- lib/Doctrine/Cache/Driver.php | 4 +- lib/Doctrine/Cache/Memcache.php | 4 +- lib/Doctrine/Cache/Xcache.php | 4 +- lib/Doctrine/ClassMetadata/CodeDriver.php | 4 +- lib/Doctrine/ClassMetadata/Exception.php | 2 +- lib/Doctrine/Collection.php | 2 +- lib/Doctrine/Collection/Exception.php | 3 +- lib/Doctrine/Collection/Iterator.php | 3 +- .../Collection/Iterator/Expandable.php | 5 +- lib/Doctrine/Collection/Iterator/Normal.php | 5 +- lib/Doctrine/Collection/Iterator/Offset.php | 5 +- lib/Doctrine/Collection/Offset.php | 3 +- lib/Doctrine/Compiler/Exception.php | 3 +- lib/Doctrine/Connection.php | 431 +--- lib/Doctrine/Connection/Common.php | 3 +- lib/Doctrine/Connection/Db2.php | 3 +- lib/Doctrine/Connection/Exception.php | 5 +- lib/Doctrine/Connection/Firebird.php | 3 +- lib/Doctrine/Connection/Informix.php | 3 +- lib/Doctrine/Connection/Module.php | 3 +- lib/Doctrine/Connection/Mssql.php | 3 +- lib/Doctrine/Connection/Mysql.php | 3 +- lib/Doctrine/Connection/Oracle.php | 3 +- lib/Doctrine/Connection/Pgsql.php | 3 +- lib/Doctrine/Connection/Profiler.php | 6 +- .../Connection/Profiler/Exception.php | 5 +- lib/Doctrine/Connection/Sqlite.php | 3 +- lib/Doctrine/Connection/Statement.php | 2 + lib/Doctrine/Connection/UnitOfWork.php | 4 +- lib/Doctrine/DBAL/Connection.php | 36 + lib/Doctrine/DBAL/Driver.php | 38 + .../DBAL/Driver/PDOMsSql/Connection.php | 89 + lib/Doctrine/DBAL/Driver/PDOMsSql/Driver.php | 39 + .../DBAL/Driver/PDOMySql/Connection.php | 57 + lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php | 53 + lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php | 37 + lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php | 40 + lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php | 45 + .../DBAL/Platforms/AbstractPlatform.php | 1822 +++++++++++++++++ lib/Doctrine/DBAL/Platforms/Db2Platform.php | 15 + .../Platforms}/FirebirdPlatform.php | 2 +- .../Platforms}/InformixPlatform.php | 2 +- .../Platforms}/MockPlatform.php | 3 +- .../Platforms}/MsSqlPlatform.php | 34 +- .../Platforms}/MySqlPlatform.php | 4 +- .../Platforms}/OraclePlatform.php | 4 +- .../Platforms}/PostgreSqlPlatform.php | 3 +- .../Platforms}/SqlitePlatform.php | 2 +- lib/Doctrine/DBAL/Statement.php | 297 +++ .../{DataType => DBAL/Types}/ArrayType.php | 2 +- .../{DataType => DBAL/Types}/BooleanType.php | 2 +- .../{DataType => DBAL/Types}/DateTimeType.php | 2 +- .../{DataType => DBAL/Types}/DecimalType.php | 2 +- .../{DataType => DBAL/Types}/IntegerType.php | 2 +- .../{DataType => DBAL/Types}/StringType.php | 2 +- .../{DataType => DBAL/Types}/TextType.php | 2 +- lib/Doctrine/DatabasePlatform.php | 12 + lib/Doctrine/Hydrator/ArrayDriver.php | 2 + lib/Doctrine/Schema/MySqlSchemaManger.php | 11 +- lib/Doctrine/Transaction.php | 67 +- lib/Doctrine/Transaction/Exception.php | 3 +- lib/Doctrine/Transaction/Firebird.php | 3 +- lib/Doctrine/Transaction/Informix.php | 3 +- lib/Doctrine/Transaction/Mock.php | 3 +- lib/Doctrine/Transaction/Mssql.php | 3 +- lib/Doctrine/Transaction/Mysql.php | 3 +- lib/Doctrine/Transaction/Oracle.php | 3 +- lib/Doctrine/Transaction/Pgsql.php | 3 +- lib/Doctrine/Transaction/Sqlite.php | 3 +- 80 files changed, 2863 insertions(+), 463 deletions(-) create mode 100644 lib/Doctrine/DBAL/Connection.php create mode 100644 lib/Doctrine/DBAL/Driver.php create mode 100644 lib/Doctrine/DBAL/Driver/PDOMsSql/Connection.php create mode 100644 lib/Doctrine/DBAL/Driver/PDOMsSql/Driver.php create mode 100644 lib/Doctrine/DBAL/Driver/PDOMySql/Connection.php create mode 100644 lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php create mode 100644 lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php create mode 100644 lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php create mode 100644 lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php create mode 100644 lib/Doctrine/DBAL/Platforms/AbstractPlatform.php create mode 100644 lib/Doctrine/DBAL/Platforms/Db2Platform.php rename lib/Doctrine/{DatabasePlatform => DBAL/Platforms}/FirebirdPlatform.php (98%) rename lib/Doctrine/{DatabasePlatform => DBAL/Platforms}/InformixPlatform.php (97%) rename lib/Doctrine/{DatabasePlatform => DBAL/Platforms}/MockPlatform.php (50%) rename lib/Doctrine/{DatabasePlatform => DBAL/Platforms}/MsSqlPlatform.php (89%) rename lib/Doctrine/{DatabasePlatform => DBAL/Platforms}/MySqlPlatform.php (99%) rename lib/Doctrine/{DatabasePlatform => DBAL/Platforms}/OraclePlatform.php (98%) rename lib/Doctrine/{DatabasePlatform => DBAL/Platforms}/PostgreSqlPlatform.php (99%) rename lib/Doctrine/{DatabasePlatform => DBAL/Platforms}/SqlitePlatform.php (99%) create mode 100644 lib/Doctrine/DBAL/Statement.php rename lib/Doctrine/{DataType => DBAL/Types}/ArrayType.php (70%) rename lib/Doctrine/{DataType => DBAL/Types}/BooleanType.php (88%) rename lib/Doctrine/{DataType => DBAL/Types}/DateTimeType.php (89%) rename lib/Doctrine/{DataType => DBAL/Types}/DecimalType.php (52%) rename lib/Doctrine/{DataType => DBAL/Types}/IntegerType.php (75%) rename lib/Doctrine/{DataType => DBAL/Types}/StringType.php (88%) rename lib/Doctrine/{DataType => DBAL/Types}/TextType.php (86%) diff --git a/lib/Doctrine/Adapter/Db2.php b/lib/Doctrine/Adapter/Db2.php index 3483d8276..c7000084f 100644 --- a/lib/Doctrine/Adapter/Db2.php +++ b/lib/Doctrine/Adapter/Db2.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Adapter'); + /** * Doctrine_Adapter_Db2 * IBM DB2 Adapter [BORROWED FROM ZEND FRAMEWORK] @@ -30,6 +30,7 @@ Doctrine::autoload('Doctrine_Adapter'); * @link www.phpdoctrine.org * @since 1.0 * @version $Revision: 1080 $ + * @deprecated */ class Doctrine_Adapter_Db2 extends Doctrine_Adapter { diff --git a/lib/Doctrine/Adapter/Exception.php b/lib/Doctrine/Adapter/Exception.php index 9dbacf002..134d99895 100644 --- a/lib/Doctrine/Adapter/Exception.php +++ b/lib/Doctrine/Adapter/Exception.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Exception'); + /** * Doctrine_Adapter_Exception * @@ -28,7 +28,8 @@ Doctrine::autoload('Doctrine_Exception'); * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Adapter_Exception extends Doctrine_Exception { } diff --git a/lib/Doctrine/Adapter/Interface.php b/lib/Doctrine/Adapter/Interface.php index ea91e3e77..9bb8427c3 100644 --- a/lib/Doctrine/Adapter/Interface.php +++ b/lib/Doctrine/Adapter/Interface.php @@ -29,7 +29,8 @@ * @subpackage Adapter * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @deprecated */ interface Doctrine_Adapter_Interface { public function prepare($prepareString); diff --git a/lib/Doctrine/Adapter/Mock.php b/lib/Doctrine/Adapter/Mock.php index 0c097cf56..c27ab9cef 100644 --- a/lib/Doctrine/Adapter/Mock.php +++ b/lib/Doctrine/Adapter/Mock.php @@ -29,7 +29,8 @@ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @deprecated */ class Doctrine_Adapter_Mock implements Doctrine_Adapter_Interface, Countable { diff --git a/lib/Doctrine/Adapter/Mysqli.php b/lib/Doctrine/Adapter/Mysqli.php index ccffbfead..d5ec741c4 100644 --- a/lib/Doctrine/Adapter/Mysqli.php +++ b/lib/Doctrine/Adapter/Mysqli.php @@ -30,6 +30,7 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision: 1080 $ + * @deprecated */ class Doctrine_Adapter_Mysqli extends Doctrine_Adapter { diff --git a/lib/Doctrine/Adapter/Resource.php b/lib/Doctrine/Adapter/Resource.php index 15d89c483..3ce42ef23 100644 --- a/lib/Doctrine/Adapter/Resource.php +++ b/lib/Doctrine/Adapter/Resource.php @@ -28,7 +28,9 @@ * @subpackage Adapter * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision: 2702 $ + * @version $Revision: 2702 $ + * @deprecated + * @todo Remove */ class Doctrine_Adapter_Resource implements Doctrine_Adapter_Interface { diff --git a/lib/Doctrine/Adapter/Statement/Interface.php b/lib/Doctrine/Adapter/Statement/Interface.php index 3f8f897e1..50aee68d1 100644 --- a/lib/Doctrine/Adapter/Statement/Interface.php +++ b/lib/Doctrine/Adapter/Statement/Interface.php @@ -28,7 +28,8 @@ * @subpackage Adapter * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @deprecated */ interface Doctrine_Adapter_Statement_Interface { diff --git a/lib/Doctrine/Association/ManyToMany.php b/lib/Doctrine/Association/ManyToMany.php index 7e8121f7d..afc1faf8e 100644 --- a/lib/Doctrine/Association/ManyToMany.php +++ b/lib/Doctrine/Association/ManyToMany.php @@ -1,6 +1,6 @@ . */ -#namespace Doctrine::ORM::Mappings; +#namespace Doctrine::ORM::Mapping; /** * Represents a one-to-many mapping. diff --git a/lib/Doctrine/Cache/Apc.php b/lib/Doctrine/Cache/Apc.php index 4bcf520f3..49bbe8cc3 100644 --- a/lib/Doctrine/Cache/Apc.php +++ b/lib/Doctrine/Cache/Apc.php @@ -19,19 +19,16 @@ * . */ -#namespace Doctrine::Common::Cache; +#namespace Doctrine::ORM::Cache; /** - * Doctrine_Cache_Apc + * APC cache driver. * - * @package Doctrine - * @subpackage Cache * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen - * @todo Rename to ApcCache + * @author Konsta Vesterinen */ class Doctrine_Cache_Apc extends Doctrine_Cache_Driver { diff --git a/lib/Doctrine/Cache/Array.php b/lib/Doctrine/Cache/Array.php index 9a7b10eab..3cec54cad 100644 --- a/lib/Doctrine/Cache/Array.php +++ b/lib/Doctrine/Cache/Array.php @@ -20,17 +20,15 @@ */ /** - * Doctrine_Cache_Interface + * Array cache driver. * - * @package Doctrine - * @subpackage Cache * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ * @author Konsta Vesterinen */ -class Doctrine_Cache_Array implements Countable, Doctrine_Cache_Interface +class Doctrine_Cache_Array implements Doctrine_Cache_Interface { /** * @var array $data an array of cached data diff --git a/lib/Doctrine/Cache/Driver.php b/lib/Doctrine/Cache/Driver.php index 60f636eb7..fff7b6a2d 100644 --- a/lib/Doctrine/Cache/Driver.php +++ b/lib/Doctrine/Cache/Driver.php @@ -20,10 +20,8 @@ */ /** - * Doctrine_Cache_Driver + * Base class for cache drivers. * - * @package Doctrine - * @subpackage Cache * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 diff --git a/lib/Doctrine/Cache/Memcache.php b/lib/Doctrine/Cache/Memcache.php index 2c287b67f..1a03980f1 100644 --- a/lib/Doctrine/Cache/Memcache.php +++ b/lib/Doctrine/Cache/Memcache.php @@ -20,10 +20,8 @@ */ /** - * Doctrine_Cache_Memcache + * Memcache cache driver. * - * @package Doctrine - * @subpackage Cache * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 diff --git a/lib/Doctrine/Cache/Xcache.php b/lib/Doctrine/Cache/Xcache.php index 798c5d315..e8b35fa58 100644 --- a/lib/Doctrine/Cache/Xcache.php +++ b/lib/Doctrine/Cache/Xcache.php @@ -20,10 +20,8 @@ */ /** - * Doctrine_Cache_Xcache + * Xcache cache driver. * - * @package Doctrine - * @subpackage Cache * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 diff --git a/lib/Doctrine/ClassMetadata/CodeDriver.php b/lib/Doctrine/ClassMetadata/CodeDriver.php index 426e85644..46e440f83 100644 --- a/lib/Doctrine/ClassMetadata/CodeDriver.php +++ b/lib/Doctrine/ClassMetadata/CodeDriver.php @@ -19,14 +19,14 @@ * . */ +#namespace Doctrine::ORM::Internal; + /** * The code metadata driver loads the metadata of the classes through invoking * a static callback method that needs to be implemented when using this driver. * * @author Konsta Vesterinen * @author Roman Borschel - * @package Doctrine - * @subpackage ClassMetadata * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version $Revision$ * @link www.phpdoctrine.org diff --git a/lib/Doctrine/ClassMetadata/Exception.php b/lib/Doctrine/ClassMetadata/Exception.php index 29f2b1163..3ce8efe5f 100644 --- a/lib/Doctrine/ClassMetadata/Exception.php +++ b/lib/Doctrine/ClassMetadata/Exception.php @@ -1,3 +1,3 @@ + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Collection_Exception extends Doctrine_Exception { } \ No newline at end of file diff --git a/lib/Doctrine/Collection/Iterator.php b/lib/Doctrine/Collection/Iterator.php index 5b6325a49..99834b577 100644 --- a/lib/Doctrine/Collection/Iterator.php +++ b/lib/Doctrine/Collection/Iterator.php @@ -29,7 +29,8 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ abstract class Doctrine_Collection_Iterator implements Iterator { diff --git a/lib/Doctrine/Collection/Iterator/Expandable.php b/lib/Doctrine/Collection/Iterator/Expandable.php index 70562e5a0..96d1a312f 100644 --- a/lib/Doctrine/Collection/Iterator/Expandable.php +++ b/lib/Doctrine/Collection/Iterator/Expandable.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Collection_Iterator'); + /** * Doctrine_Collection_Iterator_Normal * @@ -28,7 +28,8 @@ Doctrine::autoload('Doctrine_Collection_Iterator'); * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterator { diff --git a/lib/Doctrine/Collection/Iterator/Normal.php b/lib/Doctrine/Collection/Iterator/Normal.php index 3306c784f..68c591223 100644 --- a/lib/Doctrine/Collection/Iterator/Normal.php +++ b/lib/Doctrine/Collection/Iterator/Normal.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Collection_Iterator'); + /** * Doctrine_Collection_Iterator_Normal * @@ -28,7 +28,8 @@ Doctrine::autoload('Doctrine_Collection_Iterator'); * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Collection_Iterator_Normal extends Doctrine_Collection_Iterator { diff --git a/lib/Doctrine/Collection/Iterator/Offset.php b/lib/Doctrine/Collection/Iterator/Offset.php index 28dd40499..9133f4ec3 100644 --- a/lib/Doctrine/Collection/Iterator/Offset.php +++ b/lib/Doctrine/Collection/Iterator/Offset.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Collection_Iterator'); + /** * Doctrine_Collection_Iterator_Normal * @@ -28,7 +28,8 @@ Doctrine::autoload('Doctrine_Collection_Iterator'); * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Collection_Iterator_Offset extends Doctrine_Collection_Iterator { diff --git a/lib/Doctrine/Collection/Offset.php b/lib/Doctrine/Collection/Offset.php index 195151ad5..1470eb10b 100644 --- a/lib/Doctrine/Collection/Offset.php +++ b/lib/Doctrine/Collection/Offset.php @@ -28,7 +28,8 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Collection_Offset extends Doctrine_Collection { diff --git a/lib/Doctrine/Compiler/Exception.php b/lib/Doctrine/Compiler/Exception.php index c16b1b362..bc84956a3 100644 --- a/lib/Doctrine/Compiler/Exception.php +++ b/lib/Doctrine/Compiler/Exception.php @@ -28,7 +28,8 @@ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @deprecated */ class Doctrine_Compiler_Exception extends Doctrine_Exception { } \ No newline at end of file diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 2e0e2c76f..a9b9def14 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -19,27 +19,15 @@ * . */ -#namespace Doctrine::DBAL::Connections; +#namespace Doctrine::DBAL; #use Doctrine::Common::Configuration; #use Doctrine::Common::EventManager; #use Doctrine::DBAL::Exceptions::ConnectionException; /** - * A thin wrapper on top of the PDO class. - * - * 1. Event listeners - * An easy to use, pluggable eventlistener architecture. Aspects such as - * logging, query profiling and caching can be easily implemented through - * the use of these listeners - * - * 2. Lazy-connecting - * Creating an instance of Doctrine_Connection does not connect - * to database. Connecting to database is only invoked when actually needed - * (for example when query() is being called) - * - * 3. Convenience methods - * Doctrine_Connection provides many convenience methods such as fetchAll(), fetchOne() etc. + * A wrapper around a Doctrine::DBAL::Connection that adds features like + * events, configuration, emulated transaction nesting and more. * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @since 1.0 @@ -64,8 +52,9 @@ * * Doctrine::DBAL could ship with a simple standard broker that uses a primitive * round-robin approach to distribution. User can provide its own brokers. + * @todo Rename to ConnectionWrapper */ -abstract class Doctrine_Connection +class Doctrine_Connection { /** * The PDO database handle. @@ -114,6 +103,13 @@ abstract class Doctrine_Connection */ protected $_serverInfo = array(); + /** + * The transaction nesting level. + * + * @var integer + */ + protected $_transactionNestingLevel = 0; + /** * The parameters used during creation of the Connection. * @@ -183,11 +179,33 @@ abstract class Doctrine_Connection } // create platform - $class = "Doctrine_DatabasePlatform_" . $this->_driverName . "Platform"; + $class = "Doctrine_DBAL_Platforms_" . $this->_driverName . "Platform"; $this->_platform = new $class(); $this->_platform->setQuoteIdentifiers($this->_config->getQuoteIdentifiers()); } + public function __construct2(array $params, Doctrine_DBAL_Driver $driver, + Doctrine_Configuration $config = null, Doctrine_EventManager $eventManager = null) + { + $this->_driver = $driver; + $this->_params = $params; + + if (isset($params['pdo'])) { + $this->_pdo = $params['pdo']; + $this->_isConnected = true; + } + + // Create default config and event manager if none given + if ( ! $config) { + $this->_config = new Doctrine_Configuration(); + } + if ( ! $eventManager) { + $this->_eventManager = new Doctrine_EventManager(); + } + + $this->_platform = $driver->getDatabasePlatform(); + } + /** * Gets the Configuration used by the Connection. * @@ -232,27 +250,6 @@ abstract class Doctrine_Connection { return PDO::getAvailableDrivers(); } - - /** - * returns the name of this driver - * - * @return string the name of this driver - */ - public function getName() - { - return $this->_name; - } - - /** - * Sets the name of the connection - * - * @param string $name - * @return void - */ - public function setName($name) - { - $this->_name = $name; - } /** * Gets the name of the instance driver @@ -286,9 +283,6 @@ abstract class Doctrine_Connection return false; } - //$event = new Doctrine_Event($this, Doctrine_Event::CONN_CONNECT); - //$this->getListener()->preConnect($event); - // TODO: the extension_loaded check can happen earlier, maybe in the factory if ( ! extension_loaded('pdo')) { throw new Doctrine_Connection_Exception("Couldn't locate driver named " . $e[0]); @@ -309,18 +303,36 @@ abstract class Doctrine_Connection $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->_pdo->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); - // attach the pending attributes to adapter - /*foreach($this->pendingAttributes as $attr => $value) { - // some drivers don't support setting this so we just skip it - if ($attr == Doctrine::ATTR_DRIVER_NAME) { - continue; - } - $this->_pdo->setAttribute($attr, $value); - }*/ + $this->_isConnected = true; + + return true; + } + + /** + * Establishes the connection with the database. + * + * @return boolean + */ + public function connect2() + { + if ($this->_isConnected) { + return false; + } + + $driverOptions = isset($this->_params['driverOptions']) ? + $this->_params['driverOptions'] : array(); + $user = isset($this->_params['user']) ? + $this->_params['user'] : null; + $password = isset($this->_params['password']) ? + $this->_params['password'] : null; + + $this->_pdo = $this->_driver->connect($this->_params, $user, $password, $driverOptions); + + $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->_pdo->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); $this->_isConnected = true; - //$this->getListener()->postConnect($event); return true; } @@ -337,70 +349,6 @@ abstract class Doctrine_Connection { throw Doctrine_Exception::notImplemented('_constructPdoDsn', get_class($this)); } - - /** - * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT - * query, except that if there is already a row in the table with the same - * key field values, the REPLACE query just updates its values instead of - * inserting a new row. - * - * The REPLACE type of query does not make part of the SQL standards. Since - * practically only MySQL and SQLite implement it natively, this type of - * query is emulated through this method for other DBMS using standard types - * of queries inside a transaction to assure the atomicity of the operation. - * - * @param string name of the table on which the REPLACE query will - * be executed. - * - * @param array an associative array that describes the fields and the - * values that will be inserted or updated in the specified table. The - * indexes of the array are the names of all the fields of the table. - * - * The values of the array are values to be assigned to the specified field. - * - * @param array $keys an array containing all key fields (primary key fields - * or unique index fields) for this table - * - * the uniqueness of a row will be determined according to - * the provided key fields - * - * this method will fail if no key fields are specified - * - * @throws Doctrine_Connection_Exception if this driver doesn't support replace - * @throws Doctrine_Connection_Exception if some of the key values was null - * @throws Doctrine_Connection_Exception if there were no key fields - * @throws PDOException if something fails at PDO level - * @return integer number of rows affected - */ - public function replace($tableName, array $data, array $keys) - { - if (empty($keys)) { - throw new Doctrine_Connection_Exception('Not specified which fields are keys'); - } - $condition = $values = array(); - - foreach ($data as $columnName => $value) { - $values[$columnName] = $value; - - if (in_array($columnName, $keys)) { - if ($value === null) - throw new Doctrine_Connection_Exception('key value '.$columnName.' may not be null'); - - $condition[] = $columnName . ' = ?'; - $conditionValues[] = $value; - } - } - - $query = 'DELETE FROM ' . $this->quoteIdentifier($tableName) - . ' WHERE ' . implode(' AND ', $condition); - $affectedRows = $this->exec($query, $conditionValues); - - $this->insert($table, $values); - - $affectedRows++; - - return $affectedRows; - } /** * Deletes table row(s) matching the specified identifier. @@ -502,7 +450,7 @@ abstract class Doctrine_Connection */ public function setCharset($charset) { - return true; + $this->exec($this->_platform->getSetCharsetSql($charset)); } /** @@ -541,52 +489,7 @@ abstract class Doctrine_Connection */ public function quoteIdentifier($str) { - /*if (is_null($this->_quoteIdentifiers)) { - $this->_quoteIdentifiers = $this->_config->get('quoteIdentifiers'); - } - if ( ! $this->_quoteIdentifiers) { - return $str; - } - - // quick fix for the identifiers that contain a dot - if (strpos($str, '.')) { - $e = explode('.', $str); - return $this->quoteIdentifier($e[0]) - . '.' - . $this->quoteIdentifier($e[1]); - } - - $c = $this->_platform->getIdentifierQuoteCharacter(); - $str = str_replace($c, $c . $c, $str); - - return $c . $str . $c;*/ - return $this->getDatabasePlatform()->quoteIdentifier($str); - } - - /** - * Some drivers need the boolean values to be converted into integers - * when using DQL API. - * - * This method takes care of that conversion - * - * @param array $item - * @return void - * @deprecated Moved to DatabasePlatform - */ - public function convertBooleans($item) - { - if (is_array($item)) { - foreach ($item as $k => $value) { - if (is_bool($value)) { - $item[$k] = (int) $value; - } - } - } else { - if (is_bool($item)) { - $item = (int) $item; - } - } - return $item; + return $this->_platform->quoteIdentifier($str); } /** @@ -601,17 +504,6 @@ abstract class Doctrine_Connection return $this->_pdo->quote($input, $type); } - /** - * Set the date/time format for the current connection - * - * @param string time format - * - * @return void - */ - public function setDateFormat($format = null) - { - } - /** * fetchAll * @@ -706,19 +598,8 @@ abstract class Doctrine_Connection public function prepare($statement) { $this->connect(); - try { - //$event = new Doctrine_Event($this, Doctrine_Event::CONN_PREPARE, $statement); - //$this->getAttribute(Doctrine::ATTR_LISTENER)->prePrepare($event); - - $stmt = false; - - //if ( ! $event->skipOperation) { - $stmt = $this->_pdo->prepare($statement); - //} - - //$this->getAttribute(Doctrine::ATTR_LISTENER)->postPrepare($event); - + $stmt = $this->_pdo->prepare($statement); return new Doctrine_Connection_Statement($this, $stmt); } catch (PDOException $e) { $this->rethrowException($e, $this); @@ -742,19 +623,6 @@ abstract class Doctrine_Connection return $this->execute($query); } - /** - * standaloneQuery - * - * @param string $query sql query - * @param array $params query parameters - * - * @return PDOStatement|Doctrine_Adapter_Statement - */ - public function standaloneQuery($query, $params = array()) - { - return $this->execute($query, $params); - } - /** * Executes an SQL SELECT query with the given parameters. * @@ -766,22 +634,14 @@ abstract class Doctrine_Connection public function execute($query, array $params = array()) { $this->connect(); - try { if ( ! empty($params)) { $stmt = $this->prepare($query); $stmt->execute($params); return $stmt; } else { - //$event = new Doctrine_Event($this, Doctrine_Event::CONN_QUERY, $query, $params); - //$this->getAttribute(Doctrine::ATTR_LISTENER)->preQuery($event); - - //if ( ! $event->skipOperation) { - $stmt = $this->_pdo->query($query); - $this->_queryCount++; - //} - //$this->getAttribute(Doctrine::ATTR_LISTENER)->postQuery($event); - + $stmt = $this->_pdo->query($query); + $this->_queryCount++; return $stmt; } } catch (PDOException $e) { @@ -800,23 +660,14 @@ abstract class Doctrine_Connection */ public function exec($query, array $params = array()) { $this->connect(); - try { if ( ! empty($params)) { $stmt = $this->prepare($query); $stmt->execute($params); - return $stmt->rowCount(); } else { - //$event = new Doctrine_Event($this, Doctrine_Event::CONN_EXEC, $query, $params); - //$this->getAttribute(Doctrine::ATTR_LISTENER)->preExec($event); - - //if ( ! $event->skipOperation) { - $count = $this->_pdo->exec($query); - $this->_queryCount++; - //} - //$this->getAttribute(Doctrine::ATTR_LISTENER)->postExec($event); - + $count = $this->_pdo->exec($query); + $this->_queryCount++; return $count; } } catch (PDOException $e) { @@ -830,13 +681,7 @@ abstract class Doctrine_Connection * @throws Doctrine_Connection_Exception */ public function rethrowException(Exception $e, $invoker) - { - $name = 'Doctrine_Connection_' . $this->_driverName . '_Exception'; - $exc = new $name($e->getMessage(), (int) $e->getCode()); - if ( ! is_array($e->errorInfo)) { - $e->errorInfo = array(null, null, null, null); - } - $exc->processErrorInfo($e->errorInfo); + { throw $exc; } @@ -858,14 +703,9 @@ abstract class Doctrine_Connection */ public function close() { - //$event = new Doctrine_Event($this, Doctrine_Event::CONN_CLOSE); - //this->getAttribute(Doctrine::ATTR_LISTENER)->preClose($event); - $this->clear(); unset($this->_pdo); $this->_isConnected = false; - - //$this->getAttribute(Doctrine::ATTR_LISTENER)->postClose($event); } /** @@ -875,7 +715,7 @@ abstract class Doctrine_Connection */ public function getTransactionLevel() { - return $this->transaction->getTransactionLevel(); + return $this->_transaction->getTransactionLevel(); } /** @@ -886,7 +726,6 @@ abstract class Doctrine_Connection public function errorCode() { $this->connect(); - return $this->_pdo->errorCode(); } @@ -898,7 +737,6 @@ abstract class Doctrine_Connection public function errorInfo() { $this->connect(); - return $this->_pdo->errorInfo(); } @@ -921,17 +759,19 @@ abstract class Doctrine_Connection * Start a transaction or set a savepoint. * * if trying to set a savepoint and there is no active transaction - * a new transaction is being started - * - * Listeners: onPreTransactionBegin, onTransactionBegin + * a new transaction is being started. * * @param string $savepoint name of a savepoint to set * @throws Doctrine_Transaction_Exception if the transaction fails at database level * @return integer current transaction nesting level */ - public function beginTransaction($savepoint = null) + public function beginTransaction() { - return $this->_transaction->beginTransaction($savepoint); + if ($this->_transactionNestingLevel == 0) { + return $this->_pdo->beginTransaction(); + } + ++$this->_transactionNestingLevel; + return true; } /** @@ -939,16 +779,25 @@ abstract class Doctrine_Connection * progress or release a savepoint. This function may only be called when * auto-committing is disabled, otherwise it will fail. * - * Listeners: onPreTransactionCommit, onTransactionCommit - * * @param string $savepoint name of a savepoint to release * @throws Doctrine_Transaction_Exception if the transaction fails at PDO level * @throws Doctrine_Validator_Exception if the transaction fails due to record validations * @return boolean false if commit couldn't be performed, true otherwise */ - public function commit($savepoint = null) + public function commit() { - return $this->_transaction->commit($savepoint); + if ($this->_transactionNestingLevel == 0) { + throw new Doctrine_Exception("Commit failed. There is no active transaction."); + } + + $this->connect(); + + if ($this->_transactionNestingLevel == 1) { + return $this->_pdo->commit(); + } + --$this->_transactionNestingLevel; + + return true; } /** @@ -964,73 +813,22 @@ abstract class Doctrine_Connection * @throws Doctrine_Transaction_Exception If the rollback operation fails at database level. * @return boolean FALSE if rollback couldn't be performed, TRUE otherwise. */ - public function rollback($savepoint = null) + public function rollback() { - $this->_transaction->rollback($savepoint); - } - - /** - * Creates the database for the connection instance. - * - * @return mixed Will return an instance of the exception thrown if the - * create database fails, otherwise it returns a string - * detailing the success. - */ - public function createDatabase() - { - try { - if ( ! $dsn = $this->getOption('dsn')) { - throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality'); - } - - $manager = $this->getManager(); - - $info = $manager->parsePdoDsn($dsn); - $username = $this->getOption('username'); - $password = $this->getOption('password'); - - // Make connection without database specified so we can create it - $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false); - - // Create database - $connect->export->createDatabase($info['dbname']); - - // Close the tmp connection with no database - $manager->closeConnection($connect); - - // Close original connection - $manager->closeConnection($this); - - // Reopen original connection with newly created database - $manager->openConnection(new PDO($info['dsn'], $username, $password), $this->getName(), true); - - return 'Successfully created database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; - } catch (Exception $e) { - return $e; + if ($this->_transactionNestingLevel == 0) { + throw new Doctrine_Exception("Rollback failed. There is no active transaction."); } - } + + $this->connect(); - /** - * Method for dropping the database for the connection instance - * - * @return mixed Will return an instance of the exception thrown if the drop - * database fails, otherwise it returns a string detailing the success. - */ - public function dropDatabase() - { - try { - if ( ! $dsn = $this->getOption('dsn')) { - throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality'); - } - - $info = $this->getManager()->parsePdoDsn($dsn); - - $this->export->dropDatabase($info['dbname']); - - return 'Successfully dropped database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; - } catch (Exception $e) { - return $e; - } + if ($this->_transactionNestingLevel == 1) { + $this->_transactionNestingLevel = 0; + return $this->_pdo->rollback(); + + } + --$this->_transactionNestingLevel; + + return true; } /** @@ -1048,19 +846,6 @@ abstract class Doctrine_Connection protected function _escapePattern($text) { return $text; - /*if ( ! $this->string_quoting['escape_pattern']) { - return $text; - } - $tmp = $this->conn->string_quoting; - - $text = str_replace($tmp['escape_pattern'], - $tmp['escape_pattern'] . - $tmp['escape_pattern'], $text); - - foreach ($this->wildcards as $wildcard) { - $text = str_replace($wildcard, $tmp['escape_pattern'] . $wildcard, $text); - } - return $text;*/ } /** @@ -1157,4 +942,12 @@ abstract class Doctrine_Connection } return $this->_schemaManager; } + + public function getSchemaManager2() + { + if ( ! $this->_schemaManager) { + $this->_schemaManager = $this->_driver->getSchemaManager(); + } + return $this->_schemaManager; + } } diff --git a/lib/Doctrine/Connection/Common.php b/lib/Doctrine/Connection/Common.php index 876d9b306..322166c5c 100644 --- a/lib/Doctrine/Connection/Common.php +++ b/lib/Doctrine/Connection/Common.php @@ -29,7 +29,8 @@ * @since 1.0 * @version $Revision$ * @author Konsta Vesterinen - * @TODO Remove this class and move the modifyLimitQuery implementation to Connection. + * @TODO Remove this class and move the modifyLimitQuery implementation to Connection. + * @deprecated */ class Doctrine_Connection_Common extends Doctrine_Connection { diff --git a/lib/Doctrine/Connection/Db2.php b/lib/Doctrine/Connection/Db2.php index 21a5e3c6d..08416c51c 100644 --- a/lib/Doctrine/Connection/Db2.php +++ b/lib/Doctrine/Connection/Db2.php @@ -28,7 +28,8 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Connection_Db2 extends Doctrine_Connection { diff --git a/lib/Doctrine/Connection/Exception.php b/lib/Doctrine/Connection/Exception.php index 0039a5d8a..41b3003dc 100644 --- a/lib/Doctrine/Connection/Exception.php +++ b/lib/Doctrine/Connection/Exception.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Exception'); + /** * Doctrine_Exception * @@ -28,7 +28,8 @@ Doctrine::autoload('Doctrine_Exception'); * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Connection_Exception extends Doctrine_Exception { diff --git a/lib/Doctrine/Connection/Firebird.php b/lib/Doctrine/Connection/Firebird.php index aca434bde..914d90e5d 100644 --- a/lib/Doctrine/Connection/Firebird.php +++ b/lib/Doctrine/Connection/Firebird.php @@ -30,7 +30,8 @@ * @author Lorenzo Alberton (PEAR MDB2 Interbase driver) * @version $Revision$ * @link www.phpdoctrine.org - * @since 1.0 + * @since 1.0 + * @deprecated */ class Doctrine_Connection_Firebird extends Doctrine_Connection { diff --git a/lib/Doctrine/Connection/Informix.php b/lib/Doctrine/Connection/Informix.php index 2aae945b9..8e72eab5b 100644 --- a/lib/Doctrine/Connection/Informix.php +++ b/lib/Doctrine/Connection/Informix.php @@ -28,7 +28,8 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Connection_Informix extends Doctrine_Connection { diff --git a/lib/Doctrine/Connection/Module.php b/lib/Doctrine/Connection/Module.php index ae2faebb8..365f16b4f 100644 --- a/lib/Doctrine/Connection/Module.php +++ b/lib/Doctrine/Connection/Module.php @@ -28,7 +28,8 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Connection_Module { diff --git a/lib/Doctrine/Connection/Mssql.php b/lib/Doctrine/Connection/Mssql.php index 0cf4d580b..55d5d6b96 100644 --- a/lib/Doctrine/Connection/Mssql.php +++ b/lib/Doctrine/Connection/Mssql.php @@ -29,7 +29,8 @@ * @author Lukas Smith (PEAR MDB2 library) * @version $Revision$ * @link www.phpdoctrine.org - * @since 1.0 + * @since 1.0 + * @deprecated */ class Doctrine_Connection_Mssql extends Doctrine_Connection { diff --git a/lib/Doctrine/Connection/Mysql.php b/lib/Doctrine/Connection/Mysql.php index 5161b220a..bea2cb944 100644 --- a/lib/Doctrine/Connection/Mysql.php +++ b/lib/Doctrine/Connection/Mysql.php @@ -29,7 +29,8 @@ * @author Lukas Smith (PEAR MDB2 library) * @version $Revision$ * @link www.phpdoctrine.org - * @since 1.0 + * @since 1.0 + * @deprecated */ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { diff --git a/lib/Doctrine/Connection/Oracle.php b/lib/Doctrine/Connection/Oracle.php index d4180f9e1..2bc79c936 100644 --- a/lib/Doctrine/Connection/Oracle.php +++ b/lib/Doctrine/Connection/Oracle.php @@ -26,7 +26,8 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Connection_Oracle extends Doctrine_Connection { diff --git a/lib/Doctrine/Connection/Pgsql.php b/lib/Doctrine/Connection/Pgsql.php index 566923b4b..393ef9d48 100644 --- a/lib/Doctrine/Connection/Pgsql.php +++ b/lib/Doctrine/Connection/Pgsql.php @@ -29,7 +29,8 @@ * @author Lukas Smith (PEAR MDB2 library) * @version $Revision$ * @link www.phpdoctrine.org - * @since 1.0 + * @since 1.0 + * @deprecated */ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { diff --git a/lib/Doctrine/Connection/Profiler.php b/lib/Doctrine/Connection/Profiler.php index 6a474445f..6c9b51c4d 100644 --- a/lib/Doctrine/Connection/Profiler.php +++ b/lib/Doctrine/Connection/Profiler.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Overloadable'); + /** * Doctrine_Connection_Profiler * @@ -28,7 +28,9 @@ Doctrine::autoload('Doctrine_Overloadable'); * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @deprecated + * @todo remove */ class Doctrine_Connection_Profiler implements Doctrine_Overloadable, IteratorAggregate, Countable { diff --git a/lib/Doctrine/Connection/Profiler/Exception.php b/lib/Doctrine/Connection/Profiler/Exception.php index d2945c158..9eab3c125 100644 --- a/lib/Doctrine/Connection/Profiler/Exception.php +++ b/lib/Doctrine/Connection/Profiler/Exception.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Connection_Profiler_Exception'); + /** * Doctrine_Connection_Profiler_Exception * @@ -28,7 +28,8 @@ Doctrine::autoload('Doctrine_Connection_Profiler_Exception'); * @link www.phpdoctrine.org * @since 1.0 * @version $Revision: 1345 $ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @deprecated */ class Doctrine_Connection_Profiler_Exception extends Doctrine_Exception { diff --git a/lib/Doctrine/Connection/Sqlite.php b/lib/Doctrine/Connection/Sqlite.php index 9147b643d..27386cfca 100644 --- a/lib/Doctrine/Connection/Sqlite.php +++ b/lib/Doctrine/Connection/Sqlite.php @@ -31,7 +31,8 @@ * @author Lukas Smith (PEAR MDB2 library) * @version $Revision$ * @link www.phpdoctrine.org - * @since 1.0 + * @since 1.0 + * @deprecated */ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common { diff --git a/lib/Doctrine/Connection/Statement.php b/lib/Doctrine/Connection/Statement.php index 29604bf9f..7ed5d14d7 100644 --- a/lib/Doctrine/Connection/Statement.php +++ b/lib/Doctrine/Connection/Statement.php @@ -18,6 +18,8 @@ * and is licensed under the LGPL. For more information, see * . */ + +#namespace Doctrine::DBAL; /** * A thin wrapper around PDOStatement. diff --git a/lib/Doctrine/Connection/UnitOfWork.php b/lib/Doctrine/Connection/UnitOfWork.php index 765e779f1..0b8c0e640 100644 --- a/lib/Doctrine/Connection/UnitOfWork.php +++ b/lib/Doctrine/Connection/UnitOfWork.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine::ORM::Internal; +#namespace Doctrine::ORM; #use Doctrine::ORM::Entity; #use Doctrine::ORM::EntityManager; @@ -36,7 +36,7 @@ * @version $Revision$ * @author Konsta Vesterinen * @author Roman Borschel - * @todo Rename: Doctrine::ORM::(Internal::)UnitOfWork. + * @todo Rename: Doctrine::ORM::UnitOfWork. * @todo Turn connection exceptions into UnitOfWorkExceptions. */ class Doctrine_Connection_UnitOfWork diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php new file mode 100644 index 000000000..2b920b560 --- /dev/null +++ b/lib/Doctrine/DBAL/Connection.php @@ -0,0 +1,36 @@ + \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver.php b/lib/Doctrine/DBAL/Driver.php new file mode 100644 index 000000000..0e663e391 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver.php @@ -0,0 +1,38 @@ + \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/PDOMsSql/Connection.php b/lib/Doctrine/DBAL/Driver/PDOMsSql/Connection.php new file mode 100644 index 000000000..f6b739bf1 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/PDOMsSql/Connection.php @@ -0,0 +1,89 @@ +_isolationLevel = $level; + $this->exec('SET TRANSACTION ISOLATION LEVEL ' . $sql); + } + + public function getTransactionIsolation() + { + return $this->_isolationLevel; + } + + /** + * Performs the rollback. + * + * @override + */ + public function rollback() + { + $this->exec('ROLLBACK TRANSACTION'); + } + + /** + * Performs the commit. + * + * @override + */ + public function commit() + { + $this->exec('COMMIT TRANSACTION'); + } + + /** + * Begins a database transaction. + * + * @override + */ + public function beginTransaction() + { + $this->exec('BEGIN TRANSACTION'); + } +} + +?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/PDOMsSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMsSql/Driver.php new file mode 100644 index 000000000..c81fc74a1 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/PDOMsSql/Driver.php @@ -0,0 +1,39 @@ +_constructPdoDsn($params), $username, $password, $driverOptions); + } + + /** + * Constructs the MySql PDO DSN. + * + * Overrides Connection#_constructPdoDsn(). + * + * @return string The DSN. + */ + private function _constructPdoDsn(array $params) + { + //TODO + } + + public function getDatabasePlatform() + { + return new Doctrine_DatabasePlatform_MySqlPlatform(); + } + + public function getSchemaManager(Doctrine_Connection $conn) + { + return new Doctrine_Schema_MySqlSchemaManager($conn); + } + +} + +?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/PDOMySql/Connection.php b/lib/Doctrine/DBAL/Driver/PDOMySql/Connection.php new file mode 100644 index 000000000..19e204f28 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/PDOMySql/Connection.php @@ -0,0 +1,57 @@ +_isolationLevel = $level; + + return $this->exec('SET SESSION TRANSACTION ISOLATION LEVEL ' . $sql); + } + + /** + * getTransactionIsolation + * + * @return string returns the current session transaction isolation level + */ + public function getTransactionIsolation() + { + return $this->_isolationLevel; + } + +} + +?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php new file mode 100644 index 000000000..776c5841f --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php @@ -0,0 +1,53 @@ +_constructPdoDsn($params), $username, $password, $driverOptions); + } + + /** + * Constructs the MySql PDO DSN. + * + * Overrides Connection#_constructPdoDsn(). + * + * @return string The DSN. + */ + private function _constructPdoDsn(array $params) + { + $dsn = 'mysql:'; + if (isset($params['host'])) { + $dsn .= 'host=' . $params['host'] . ';'; + } + if (isset($params['port'])) { + $dsn .= 'port=' . $params['port'] . ';'; + } + if (isset($params['dbname'])) { + $dsn .= 'dbname=' . $params['dbname'] . ';'; + } + if (isset($params['unix_socket'])) { + $dsn .= 'unix_socket=' . $params['unix_socket'] . ';'; + } + + return $dsn; + } + + public function getDatabasePlatform() + { + return new Doctrine_DatabasePlatform_MySqlPlatform(); + } + + public function getSchemaManager(Doctrine_Connection $conn) + { + return new Doctrine_Schema_MySqlSchemaManager($conn); + } + +} + +?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php new file mode 100644 index 000000000..0cc558928 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php @@ -0,0 +1,37 @@ +_constructPdoDsn($params), $username, $password, $driverOptions); + } + + /** + * Constructs the Oracle PDO DSN. + * + * @return string The DSN. + */ + private function _constructPdoDsn(array $params) + { + //TODO + } + + public function getDatabasePlatform() + { + return new Doctrine_DatabasePlatform_OraclePlatform(); + } + + public function getSchemaManager(Doctrine_Connection $conn) + { + return new Doctrine_Schema_OracleSchemaManager($conn); + } + +} + +?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php new file mode 100644 index 000000000..0051961d0 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php @@ -0,0 +1,40 @@ +_constructPdoDsn($params), $username, $password, $driverOptions); + } + + /** + * Constructs the Postgres PDO DSN. + * + * @return string The DSN. + */ + private function _constructPdoDsn(array $params) + { + //TODO + } + + public function getDatabasePlatform() + { + return new Doctrine_DatabasePlatform_PostgreSqlPlatform(); + } + + public function getSchemaManager(Doctrine_Connection $conn) + { + return new Doctrine_Schema_PostgreSqlSchemaManager($conn); + } + +} + +?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php new file mode 100644 index 000000000..67ac60f2f --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -0,0 +1,45 @@ +_constructPdoDsn($params), $username, $password, $driverOptions); + } + + /** + * Constructs the Sqlite PDO DSN. + * + * @return string The DSN. + * @override + */ + protected function _constructPdoDsn(array $params) + { + $dsn = 'sqlite:'; + if (isset($params['path'])) { + $dsn .= $params['path']; + } else if (isset($params['memory'])) { + $dsn .= ':memory:'; + } + + return $dsn; + } + + public function getDatabasePlatform() + { + return new Doctrine_DatabasePlatform_SqlitePlatform(); + } + + public function getSchemaManager(Doctrine_Connection $conn) + { + return new Doctrine_Schema_SqliteSchemaManager($conn); + } + +} + +?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php new file mode 100644 index 000000000..fadf89505 --- /dev/null +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -0,0 +1,1822 @@ +. + */ + +#namespace Doctrine::DBAL::Platforms; + +/** + * Base class for all DatabasePlatforms. The DatabasePlatforms are the central + * point of abstraction of platform-specific behaviors, features and SQL dialects. + * They are a passive source of information. + * + * @since 2.0 + * @author Roman Borschel + * @author Lukas Smith (PEAR MDB2 library) + */ +abstract class Doctrine_DBAL_Platforms_AbstractPlatform +{ + protected $_quoteIdentifiers = false; + + protected $valid_default_values = array( + 'text' => '', + 'boolean' => true, + 'integer' => 0, + 'decimal' => 0.0, + 'float' => 0.0, + 'timestamp' => '1970-01-01 00:00:00', + 'time' => '00:00:00', + 'date' => '1970-01-01', + 'clob' => '', + 'blob' => '', + 'string' => '' + ); + + /** + * Constructor. + */ + public function __construct() {} + + public function setQuoteIdentifiers($bool) + { + $this->_quoteIdentifiers = (bool)$bool; + } + + public function getQuoteIdentifiers() + { + return $this->_quoteIdentifiers; + } + + /** + * Gets the character used for identifier quoting. + * + * @return string + */ + public function getIdentifierQuoteCharacter() + { + return '"'; + } + + /** + * Gets the string portion that starts an SQL comment. + * + * @return string + */ + public function getSqlCommentStartString() + { + return "--"; + } + + /** + * Gets the string portion that starts an SQL comment. + * + * @return string + */ + public function getSqlCommentEndString() + { + return "\n"; + } + + /** + * Gets the maximum length of a varchar field. + * + * @return integer + */ + public function getVarcharMaxLength() + { + return 255; + } + + /** + * Gets all SQL wildcard characters of the platform. + * + * @return array + */ + public function getWildcards() + { + return array('%', '_'); + } + + /** + * Returns the regular expression operator. + * + * @return string + */ + public function getRegexpExpression() + { + throw new Doctrine_Expression_Exception('Regular expression operator is not supported by this database driver.'); + } + + /** + * Returns the average value of a column + * + * @param string $column the column to use + * @return string generated sql including an AVG aggregate function + */ + public function getAvgExpression($column) + { + $column = $this->getIdentifier($column); + return 'AVG(' . $column . ')'; + } + + /** + * Returns the number of rows (without a NULL value) of a column + * + * If a '*' is used instead of a column the number of selected rows + * is returned. + * + * @param string|integer $column the column to use + * @return string generated sql including a COUNT aggregate function + */ + public function getCountExpression($column) + { + $column = $this->getIdentifier($column); + return 'COUNT(' . $column . ')'; + } + + /** + * Returns the highest value of a column + * + * @param string $column the column to use + * @return string generated sql including a MAX aggregate function + */ + public function getMaxExpression($column) + { + $column = $this->getIdentifier($column); + return 'MAX(' . $column . ')'; + } + + /** + * Returns the lowest value of a column + * + * @param string $column the column to use + * @return string + */ + public function getMinExpression($column) + { + $column = $this->getIdentifier($column); + return 'MIN(' . $column . ')'; + } + + /** + * Returns the total sum of a column + * + * @param string $column the column to use + * @return string + */ + public function getSumExpression($column) + { + $column = $this->getIdentifier($column); + return 'SUM(' . $column . ')'; + } + + // scalar functions + + /** + * Returns the md5 sum of a field. + * + * Note: Not SQL92, but common functionality + * + * @return string + */ + public function getMd5Expression($column) + { + $column = $this->getIdentifier($column); + return 'MD5(' . $column . ')'; + } + + /** + * Returns the length of a text field. + * + * @param string $expression1 + * @param string $expression2 + * @return string + */ + public function getLengthExpression($column) + { + $column = $this->getIdentifier($column); + return 'LENGTH(' . $column . ')'; + } + + /** + * Rounds a numeric field to the number of decimals specified. + * + * @param string $expression1 + * @param string $expression2 + * @return string + */ + public function getRoundExpression($column, $decimals = 0) + { + $column = $this->getIdentifier($column); + + return 'ROUND(' . $column . ', ' . $decimals . ')'; + } + + /** + * Returns the remainder of the division operation + * $expression1 / $expression2. + * + * @param string $expression1 + * @param string $expression2 + * @return string + */ + public function getModExpression($expression1, $expression2) + { + $expression1 = $this->getIdentifier($expression1); + $expression2 = $this->getIdentifier($expression2); + return 'MOD(' . $expression1 . ', ' . $expression2 . ')'; + } + + /** + * trim + * returns the string $str with leading and proceeding space characters removed + * + * @param string $str literal string or column name + * @return string + */ + public function getTrimExpression($str) + { + return 'TRIM(' . $str . ')'; + } + + /** + * rtrim + * returns the string $str with proceeding space characters removed + * + * @param string $str literal string or column name + * @return string + */ + public function getRtrimExpression($str) + { + return 'RTRIM(' . $str . ')'; + } + + /** + * ltrim + * returns the string $str with leading space characters removed + * + * @param string $str literal string or column name + * @return string + */ + public function getLtrimExpression($str) + { + return 'LTRIM(' . $str . ')'; + } + + /** + * upper + * Returns the string $str with all characters changed to + * uppercase according to the current character set mapping. + * + * @param string $str literal string or column name + * @return string + */ + public function getUpperExpression($str) + { + return 'UPPER(' . $str . ')'; + } + + /** + * lower + * Returns the string $str with all characters changed to + * lowercase according to the current character set mapping. + * + * @param string $str literal string or column name + * @return string + */ + public function getLowerExpression($str) + { + return 'LOWER(' . $str . ')'; + } + + /** + * locate + * returns the position of the first occurrence of substring $substr in string $str + * + * @param string $substr literal string to find + * @param string $str literal string + * @return integer + */ + public function getLocateExpression($str, $substr) + { + return 'LOCATE(' . $str . ', ' . $substr . ')'; + } + + /** + * Returns the current system date. + * + * @return string + */ + public function getNowExpression() + { + return 'NOW()'; + } + + /** + * soundex + * Returns a string to call a function to compute the + * soundex encoding of a string + * + * The string "?000" is returned if the argument is NULL. + * + * @param string $value + * @return string SQL soundex function with given parameter + */ + public function getSoundexExpression($value) + { + throw new Doctrine_Expression_Exception('SQL soundex function not supported by this driver.'); + } + + /** + * return string to call a function to get a substring inside an SQL statement + * + * Note: Not SQL92, but common functionality. + * + * SQLite only supports the 2 parameter variant of this function + * + * @param string $value an sql string literal or column name/alias + * @param integer $position where to start the substring portion + * @param integer $length the substring portion length + * @return string SQL substring function with given parameters + */ + public function getSubstringExpression($value, $from, $len = null) + { + $value = $this->getIdentifier($value); + if ($len === null) + return 'SUBSTRING(' . $value . ' FROM ' . $from . ')'; + else { + $len = $this->getIdentifier($len); + return 'SUBSTRING(' . $value . ' FROM ' . $from . ' FOR ' . $len . ')'; + } + } + + /** + * Returns a series of strings concatinated + * + * concat() accepts an arbitrary number of parameters. Each parameter + * must contain an expression + * + * @param string $arg1, $arg2 ... $argN strings that will be concatinated. + * @return string + */ + public function getConcatExpression() + { + $args = func_get_args(); + + return join(' || ' , $args); + } + + /** + * Returns the SQL for a logical not. + * + * Example: + * + * $q = new Doctrine_Query(); + * $e = $q->expr; + * $q->select('*')->from('table') + * ->where($e->eq('id', $e->not('null')); + * + * + * @return string a logical expression + */ + public function getNotExpression($expression) + { + $expression = $this->getIdentifier($expression); + return 'NOT(' . $expression . ')'; + } + + /** + * Returns the SQL to perform the same mathematical operation over an array + * of values or expressions. + * + * basicMath() accepts an arbitrary number of parameters. Each parameter + * must contain a value or an expression or an array with values or + * expressions. + * + * @param string $type the type of operation, can be '+', '-', '*' or '/'. + * @param string|array(string) + * @return string an expression + */ + private function getBasicMathExpression($type, array $args) + { + $elements = $this->getIdentifiers($args); + if (count($elements) < 1) { + return ''; + } + if (count($elements) == 1) { + return $elements[0]; + } else { + return '(' . implode(' ' . $type . ' ', $elements) . ')'; + } + } + + /** + * Returns the SQL to add values or expressions together. + * + * add() accepts an arbitrary number of parameters. Each parameter + * must contain a value or an expression or an array with values or + * expressions. + * + * Example: + * + * $q = new Doctrine_Query(); + * $e = $q->expr; + * + * $q->select('u.*') + * ->from('User u') + * ->where($e->eq($e->add('id', 2), 12)); + * + * + * @param string|array(string) + * @return string an expression + */ + public function getAddExpression(array $args) + { + return $this->basicMath('+', $args); + } + + /** + * Returns the SQL to subtract values or expressions from eachother. + * + * subtract() accepts an arbitrary number of parameters. Each parameter + * must contain a value or an expression or an array with values or + * expressions. + * + * Example: + * + * $q = new Doctrine_Query(); + * $e = $q->expr; + * + * $q->select('u.*') + * ->from('User u') + * ->where($e->eq($e->sub('id', 2), 12)); + * + * + * @param string|array(string) + * @return string an expression + */ + public function getSubExpression(array $args) + { + return $this->basicMath('-', $args ); + } + + /** + * Returns the SQL to multiply values or expressions by eachother. + * + * multiply() accepts an arbitrary number of parameters. Each parameter + * must contain a value or an expression or an array with values or + * expressions. + * + * Example: + * + * $q = new Doctrine_Query(); + * $e = $q->expr; + * + * $q->select('u.*') + * ->from('User u') + * ->where($e->eq($e->mul('id', 2), 12)); + * + * + * @param string|array(string) + * @return string an expression + */ + public function getMulExpression(array $args) + { + return $this->basicMath('*', $args); + } + + /** + * Returns the SQL to divide values or expressions by eachother. + * + * divide() accepts an arbitrary number of parameters. Each parameter + * must contain a value or an expression or an array with values or + * expressions. + * + * Example: + * + * $q = new Doctrine_Query(); + * $e = $q->expr; + * + * $q->select('u.*') + * ->from('User u') + * ->where($e->eq($e->div('id', 2), 12)); + * + * + * @param string|array(string) + * @return string an expression + */ + public function getDivExpression(array $args) + { + return $this->basicMath('/', $args); + } + + /** + * Returns the SQL to check if two values are equal. + * + * Example: + * + * $q = new Doctrine_Query(); + * $q->select('u.*') + * ->from('User u') + * ->where($q->expr->eq('id', 1)); + * + * + * @param string $value1 logical expression to compare + * @param string $value2 logical expression to compare with + * @return string logical expression + */ + public function getEqExpression($value1, $value2) + { + $value1 = $this->getIdentifier($value1); + $value2 = $this->getIdentifier($value2); + return $value1 . ' = ' . $value2; + } + + /** + * Returns the SQL to check if two values are unequal. + * + * Example: + * + * $q = new Doctrine_Query(); + * $q->select('u.*') + * ->from('User u') + * ->where($q->expr->neq('id', 1)); + * + * + * @param string $value1 logical expression to compare + * @param string $value2 logical expression to compare with + * @return string logical expression + */ + public function getNeqExpression($value1, $value2) + { + $value1 = $this->getIdentifier($value1); + $value2 = $this->getIdentifier($value2); + return $value1 . ' <> ' . $value2; + } + + /** + * Returns the SQL to check if one value is greater than another value. + * + * Example: + * + * $q = new Doctrine_Query(); + * $q->select('u.*') + * ->from('User u') + * ->where($q->expr->gt('id', 1)); + * + * + * @param string $value1 logical expression to compare + * @param string $value2 logical expression to compare with + * @return string logical expression + */ + public function getGtExpression($value1, $value2) + { + $value1 = $this->getIdentifier($value1); + $value2 = $this->getIdentifier($value2); + return $value1 . ' > ' . $value2; + } + + /** + * Returns the SQL to check if one value is greater than or equal to + * another value. + * + * Example: + * + * $q = new Doctrine_Query(); + * $q->select('u.*') + * ->from('User u') + * ->where($q->expr->gte('id', 1)); + * + * + * @param string $value1 logical expression to compare + * @param string $value2 logical expression to compare with + * @return string logical expression + */ + public function getGteExpression($value1, $value2) + { + $value1 = $this->getIdentifier($value1); + $value2 = $this->getIdentifier($value2); + return $value1 . ' >= ' . $value2; + } + + /** + * Returns the SQL to check if one value is less than another value. + * + * Example: + * + * $q = new Doctrine_Query(); + * $q->select('u.*') + * ->from('User u') + * ->where($q->expr->lt('id', 1)); + * + * + * @param string $value1 logical expression to compare + * @param string $value2 logical expression to compare with + * @return string logical expression + */ + public function getLtExpression($value1, $value2) + { + $value1 = $this->getIdentifier($value1); + $value2 = $this->getIdentifier($value2); + return $value1 . ' < ' . $value2; + } + + /** + * Returns the SQL to check if one value is less than or equal to + * another value. + * + * Example: + * + * $q = new Doctrine_Query(); + * $q->select('u.*') + * ->from('User u') + * ->where($q->expr->lte('id', 1)); + * + * + * @param string $value1 logical expression to compare + * @param string $value2 logical expression to compare with + * @return string logical expression + */ + public function getLteExpression($value1, $value2) + { + $value1 = $this->getIdentifier($value1); + $value2 = $this->getIdentifier($value2); + return $value1 . ' <= ' . $value2; + } + + /** + * Returns the SQL to check if a value is one in a set of + * given values.. + * + * in() accepts an arbitrary number of parameters. The first parameter + * must always specify the value that should be matched against. Successive + * must contain a logical expression or an array with logical expressions. + * These expressions will be matched against the first parameter. + * + * Example: + * + * $q = new Doctrine_Query(); + * $q->select('u.*') + * ->from('User u') + * ->where($q->expr->in( 'id', array(1,2,3))); + * + * + * @param string $column the value that should be matched against + * @param string|array(string) values that will be matched against $column + * @return string logical expression + */ + public function getInExpression($column, $values) + { + if ( ! is_array($values)) { + $values = array($values); + } + $values = $this->getIdentifiers($values); + $column = $this->getIdentifier($column); + + if (count($values) == 0) { + throw new Doctrine_Expression_Exception('Values array for IN operator should not be empty.'); + } + return $column . ' IN (' . implode(', ', $values) . ')'; + } + + /** + * Returns SQL that checks if a expression is null. + * + * Example: + * + * $q = new Doctrine_Query(); + * $q->select('u.*') + * ->from('User u') + * ->where($q->expr->isNull('id')); + * + * + * @param string $expression the expression that should be compared to null + * @return string logical expression + */ + public function getIsNullExpression($expression) + { + $expression = $this->getIdentifier($expression); + return $expression . ' IS NULL'; + } + + /** + * Returns SQL that checks if a expression is not null. + * + * Example: + * + * $q = new Doctrine_Query(); + * $q->select('u.*') + * ->from('User u') + * ->where($q->expr->isNotNull('id')); + * + * + * @param string $expression the expression that should be compared to null + * @return string logical expression + */ + public function getIsNotNullExpression($expression) + { + $expression = $this->getIdentifier($expression); + return $expression . ' IS NOT NULL'; + } + + /** + * Returns SQL that checks if an expression evaluates to a value between + * two values. + * + * The parameter $expression is checked if it is between $value1 and $value2. + * + * Note: There is a slight difference in the way BETWEEN works on some databases. + * http://www.w3schools.com/sql/sql_between.asp. If you want complete database + * independence you should avoid using between(). + * + * Example: + * + * $q = new Doctrine_Query(); + * $q->select('u.*') + * ->from('User u') + * ->where($q->expr->between('id', 1, 5)); + * + * + * @param string $expression the value to compare to + * @param string $value1 the lower value to compare with + * @param string $value2 the higher value to compare with + * @return string logical expression + */ + public function getBetweenExpression($expression, $value1, $value2) + { + $expression = $this->getIdentifier($expression); + $value1 = $this->getIdentifier($value1); + $value2 = $this->getIdentifier($value2); + return $expression . ' BETWEEN ' .$value1 . ' AND ' . $value2; + } + + /** + * Returns global unique identifier + * + * @return string to get global unique identifier + */ + public function getGuidExpression() + { + throw new Doctrine_Expression_Exception('method not implemented'); + } + + /** + * returns arcus cosine SQL string + * + * @return string + */ + public function getAcosExpression($value) + { + return 'ACOS(' . $value . ')'; + } + + /** + * sin + * + * @param string $value + * @return void + */ + public function getSinExpression($value) + { + return 'SIN(' . $value . ')'; + } + + /** + * pi + * + * @return void + */ + public function getPiExpression() + { + return 'PI()'; + } + + /** + * cos + * + * @param string $value + * @return void + * @author Jonathan H. Wage + */ + public function getCosExpression($value) + { + return 'COS(' . $value . ')'; + } + + /** + * Enter description here... + * + * @return string + */ + public function getForUpdateSql() + { + return 'FOR UPDATE'; + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getListDatabasesSql() + { + throw new Doctrine_Export_Exception('List databases not supported by this driver.'); + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getListFunctionsSql() + { + throw new Doctrine_Export_Exception('List functions not supported by this driver.'); + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getListTriggersSql() + { + throw new Doctrine_Export_Exception('List triggers not supported by this driver.'); + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getListSequencesSql() + { + throw new Doctrine_Export_Exception('List sequences not supported by this driver.'); + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getListTableConstraintsSql() + { + throw new Doctrine_Export_Exception('List table constraints not supported by this driver.'); + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getListTableColumnsSql() + { + throw new Doctrine_Export_Exception('List table columns not supported by this driver.'); + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getListTablesSql() + { + throw new Doctrine_Export_Exception('List tables not supported by this driver.'); + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getListUsersSql() + { + throw new Doctrine_Export_Exception('List users not supported by this driver.'); + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getListViewsSql() + { + throw new Doctrine_Export_Exception('List views not supported by this driver.'); + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getDropDatabaseSql($database) + { + return 'DROP DATABASE ' . $database; + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getDropTableSql($table) + { + return 'DROP TABLE ' . $table; + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getDropIndexSql($index, $name) + { + return 'DROP INDEX ' . $index; + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getDropSequenceSql() + { + throw new Doctrine_Export_Exception('Drop sequence not supported by this driver.'); + } + + /** + * Gets the SQL for acquiring the next value from a sequence. + */ + public function getSequenceNextValSql($sequenceName) + { + throw new Doctrine_Export_Exception('Sequences not supported by this driver.'); + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getCreateDatabaseSql($database) + { + throw new Doctrine_Export_Exception('Create database not supported by this driver.'); + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getCreateTableSql($table, array $columns, array $options = array()) + { + if ( ! $table) { + throw new Doctrine_Export_Exception('no valid table name specified'); + } + if (empty($columns)) { + throw new Doctrine_Export_Exception('no fields specified for table ' . $name); + } + + $queryFields = $this->getFieldDeclarationList($columns); + + if (isset($options['primary']) && ! empty($options['primary'])) { + $queryFields .= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')'; + } + + if (isset($options['indexes']) && ! empty($options['indexes'])) { + foreach($options['indexes'] as $index => $definition) { + $queryFields .= ', ' . $this->getIndexDeclaration($index, $definition); + } + } + + $query = 'CREATE TABLE ' . $this->conn->quoteIdentifier($name, true) . ' (' . $queryFields; + + $check = $this->getCheckDeclaration($columns); + + if ( ! empty($check)) { + $query .= ', ' . $check; + } + + $query .= ')'; + + $sql[] = $query; + + if (isset($options['foreignKeys'])) { + foreach ((array) $options['foreignKeys'] as $k => $definition) { + if (is_array($definition)) { + $sql[] = $this->getCreateForeignKeySql($name, $definition); + } + } + } + return $sql; + } + + /** + * Enter description here... + * + * @todo Throw exception by default? + */ + public function getCreateSequenceSql($sequenceName, $start = 1, array $options) + { + throw new Doctrine_Export_Exception('Create sequence not supported by this driver.'); + } + + /** + * create a constraint on a table + * + * @param string $table name of the table on which the constraint is to be created + * @param string $name name of the constraint to be created + * @param array $definition associative array that defines properties of the constraint to be created. + * Currently, only one property named FIELDS is supported. This property + * is also an associative with the names of the constraint fields as array + * constraints. Each entry of this array is set to another type of associative + * array that specifies properties of the constraint that are specific to + * each field. + * + * Example + * array( + * 'fields' => array( + * 'user_name' => array(), + * 'last_login' => array() + * ) + * ) + * @return void + */ + public function getCreateConstraintSql($table, $name, $definition) + { + $query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $name; + + if (isset($definition['primary']) && $definition['primary']) { + $query .= ' PRIMARY KEY'; + } elseif (isset($definition['unique']) && $definition['unique']) { + $query .= ' UNIQUE'; + } + + $fields = array(); + foreach (array_keys($definition['fields']) as $field) { + $fields[] = $field; + } + $query .= ' ('. implode(', ', $fields) . ')'; + + return $query; + } + + /** + * Get the stucture of a field into an array + * + * @param string $table name of the table on which the index is to be created + * @param string $name name of the index to be created + * @param array $definition associative array that defines properties of the index to be created. + * @see Doctrine_Export::createIndex() + * @return string + */ + public function getCreateIndexSql($table, $name, array $definition) + { + $type = ''; + if (isset($definition['type'])) { + switch (strtolower($definition['type'])) { + case 'unique': + $type = strtoupper($definition['type']) . ' '; + break; + default: + throw new Doctrine_Export_Exception('Unknown index type ' . $definition['type']); + } + } + + $query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table; + + $fields = array(); + foreach ($definition['fields'] as $field) { + $fields[] = $field; + } + $query .= ' (' . implode(', ', $fields) . ')'; + + return $query; + } + + /** + * Quote a string so it can be safely used as a table or column name. + * + * Delimiting style depends on which database driver is being used. + * + * NOTE: just because you CAN use delimited identifiers doesn't mean + * you SHOULD use them. In general, they end up causing way more + * problems than they solve. + * + * Portability is broken by using the following characters inside + * delimited identifiers: + * + backtick (`) -- due to MySQL + * + double quote (") -- due to Oracle + * + brackets ([ or ]) -- due to Access + * + * Delimited identifiers are known to generally work correctly under + * the following drivers: + * + mssql + * + mysql + * + mysqli + * + oci8 + * + pgsql + * + sqlite + * + * InterBase doesn't seem to be able to use delimited identifiers + * via PHP 4. They work fine under PHP 5. + * + * @param string $str identifier name to be quoted + * @param bool $checkOption check the 'quote_identifier' option + * + * @return string quoted identifier string + */ + public function quoteIdentifier($str) + { + if ( ! $this->_quoteIdentifiers) { + return $str; + } + + // quick fix for the identifiers that contain a dot + if (strpos($str, '.')) { + $e = explode('.', $str); + return $this->quoteIdentifier($e[0]) + . '.' + . $this->quoteIdentifier($e[1]); + } + + $c = $this->getIdentifierQuoteCharacter(); + $str = str_replace($c, $c . $c, $str); + + return $c . $str . $c; + } + + /** + * createForeignKeySql + * + * @param string $table name of the table on which the foreign key is to be created + * @param array $definition associative array that defines properties of the foreign key to be created. + * @return string + */ + public function getCreateForeignKeySql($table, array $definition) + { + $table = $this->quoteIdentifier($table); + $query = 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSql($definition); + + return $query; + } + + /** + * generates the sql for altering an existing table + * (this method is implemented by the drivers) + * + * @param string $name name of the table that is intended to be changed. + * @param array $changes associative array that contains the details of each type * + * @param boolean $check indicates whether the function should just check if the DBMS driver + * can perform the requested table alterations if the value is true or + * actually perform them otherwise. + * @see Doctrine_Export::alterTable() + * @return string + */ + public function getAlterTableSql($name, array $changes, $check = false) + { + throw new Doctrine_Export_Exception('Alter table not supported by this driver.'); + } + + /** + * Get declaration of a number of field in bulk + * + * @param array $fields a multidimensional associative array. + * The first dimension determines the field name, while the second + * dimension is keyed with the name of the properties + * of the field being declared as array indexes. Currently, the types + * of supported field properties are as follows: + * + * length + * Integer value that determines the maximum length of the text + * field. If this argument is missing the field should be + * declared to have the longest length allowed by the DBMS. + * + * default + * Text value to be used as default for this field. + * + * notnull + * Boolean flag that indicates whether this field is constrained + * to not be set to null. + * charset + * Text value with the default CHARACTER SET for this field. + * collation + * Text value with the default COLLATION for this field. + * unique + * unique constraint + * + * @return string + */ + public function getFieldDeclarationListSql(array $fields) + { + foreach ($fields as $fieldName => $field) { + $query = $this->getDeclarationSql($fieldName, $field); + + $queryFields[] = $query; + } + return implode(', ', $queryFields); + } + + /** + * Obtain DBMS specific SQL code portion needed to declare a generic type + * field to be used in statements like CREATE TABLE. + * + * @param string $name name the field to be declared. + * @param array $field associative array with the name of the properties + * of the field being declared as array indexes. Currently, the types + * of supported field properties are as follows: + * + * length + * Integer value that determines the maximum length of the text + * field. If this argument is missing the field should be + * declared to have the longest length allowed by the DBMS. + * + * default + * Text value to be used as default for this field. + * + * notnull + * Boolean flag that indicates whether this field is constrained + * to not be set to null. + * charset + * Text value with the default CHARACTER SET for this field. + * collation + * Text value with the default COLLATION for this field. + * unique + * unique constraint + * check + * column check constraint + * + * @return string DBMS specific SQL code portion that should be used to + * declare the specified field. + */ + public function getDeclarationSql($name, array $field) + { + $default = $this->getDefaultFieldDeclarationSql($field); + + $charset = (isset($field['charset']) && $field['charset']) ? + ' ' . $this->getCharsetFieldDeclarationSql($field['charset']) : ''; + + $collation = (isset($field['collation']) && $field['collation']) ? + ' ' . $this->getCollationFieldDeclarationSql($field['collation']) : ''; + + $notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : ''; + + $unique = (isset($field['unique']) && $field['unique']) ? + ' ' . $this->getUniqueFieldDeclarationSql() : ''; + + $check = (isset($field['check']) && $field['check']) ? + ' ' . $field['check'] : ''; + + $method = 'get' . $field['type'] . 'Declaration'; + + if (method_exists($this, $method)) { + return $this->$method($name, $field); + } else { + $dec = $this->getNativeDeclaration($field); + } + + return $this->quoteIdentifier($name, true) . ' ' . $dec . $charset . $default . $notnull . $unique . $check . $collation; + } + + /** + * getDefaultDeclaration + * Obtain DBMS specific SQL code portion needed to set a default value + * declaration to be used in statements like CREATE TABLE. + * + * @param array $field field definition array + * @return string DBMS specific SQL code portion needed to set a default value + */ + public function getDefaultFieldDeclarationSql($field) + { + $default = ''; + if (isset($field['default'])) { + if ($field['default'] === '') { + $field['default'] = empty($field['notnull']) + ? null : $this->valid_default_values[$field['type']]; + + if ($field['default'] === '' && + ($this->_conn->getAttribute(Doctrine::ATTR_PORTABILITY) & Doctrine::PORTABILITY_EMPTY_TO_NULL)) { + $field['default'] = null; + } + } + + if ($field['type'] === 'boolean') { + $field['default'] = $this->convertBooleans($field['default']); + } + $default = ' DEFAULT ' . $this->quote($field['default'], $field['type']); + } + return $default; + } + + /** + * Obtain DBMS specific SQL code portion needed to set a CHECK constraint + * declaration to be used in statements like CREATE TABLE. + * + * @param array $definition check definition + * @return string DBMS specific SQL code portion needed to set a CHECK constraint + */ + public function getCheckDeclarationSql(array $definition) + { + $constraints = array(); + foreach ($definition as $field => $def) { + if (is_string($def)) { + $constraints[] = 'CHECK (' . $def . ')'; + } else { + if (isset($def['min'])) { + $constraints[] = 'CHECK (' . $field . ' >= ' . $def['min'] . ')'; + } + + if (isset($def['max'])) { + $constraints[] = 'CHECK (' . $field . ' <= ' . $def['max'] . ')'; + } + } + } + + return implode(', ', $constraints); + } + + /** + * Obtain DBMS specific SQL code portion needed to set an index + * declaration to be used in statements like CREATE TABLE. + * + * @param string $name name of the index + * @param array $definition index definition + * @return string DBMS specific SQL code portion needed to set an index + */ + public function getIndexDeclarationSql($name, array $definition) + { + $name = $this->quoteIdentifier($name); + $type = ''; + + if (isset($definition['type'])) { + if (strtolower($definition['type']) == 'unique') { + $type = strtoupper($definition['type']) . ' '; + } else { + throw new Doctrine_Export_Exception('Unknown index type ' . $definition['type']); + } + } + + if ( ! isset($definition['fields']) || ! is_array($definition['fields'])) { + throw new Doctrine_Export_Exception('No index columns given.'); + } + + $query = $type . 'INDEX ' . $name; + + $query .= ' (' . $this->getIndexFieldDeclarationListSql($definition['fields']) . ')'; + + return $query; + } + + /** + * getIndexFieldDeclarationList + * Obtain DBMS specific SQL code portion needed to set an index + * declaration to be used in statements like CREATE TABLE. + * + * @return string + */ + public function getIndexFieldDeclarationListSql(array $fields) + { + $ret = array(); + foreach ($fields as $field => $definition) { + if (is_array($definition)) { + $ret[] = $this->quoteIdentifier($field); + } else { + $ret[] = $this->quoteIdentifier($definition); + } + } + return implode(', ', $ret); + } + + /** + * A method to return the required SQL string that fits between CREATE ... TABLE + * to create the table as a temporary table. + * + * Should be overridden in driver classes to return the correct string for the + * specific database type. + * + * The default is to return the string "TEMPORARY" - this will result in a + * SQL error for any database that does not support temporary tables, or that + * requires a different SQL command from "CREATE TEMPORARY TABLE". + * + * @return string The string required to be placed between "CREATE" and "TABLE" + * to generate a temporary table, if possible. + */ + public function getTemporaryTableSql() + { + return 'TEMPORARY'; + } + + /** + * Enter description here... + * + * @return unknown + */ + public function getShowDatabasesSql() + { + throw new Doctrine_Export_Exception('Show databases not supported by this driver.'); + } + + /** + * getForeignKeyDeclaration + * Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint + * of a field declaration to be used in statements like CREATE TABLE. + * + * @param array $definition an associative array with the following structure: + * name optional constraint name + * + * local the local field(s) + * + * foreign the foreign reference field(s) + * + * foreignTable the name of the foreign table + * + * onDelete referential delete action + * + * onUpdate referential update action + * + * deferred deferred constraint checking + * + * The onDelete and onUpdate keys accept the following values: + * + * CASCADE: Delete or update the row from the parent table and automatically delete or + * update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported. + * Between two tables, you should not define several ON UPDATE CASCADE clauses that act on the same column + * in the parent table or in the child table. + * + * SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the + * child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier + * specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported. + * + * NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary + * key value is not allowed to proceed if there is a related foreign key value in the referenced table. + * + * RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION and RESTRICT are the same as + * omitting the ON DELETE or ON UPDATE clause. + * + * SET DEFAULT + * + * @return string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint + * of a field declaration. + */ + public function getForeignKeyDeclarationSql(array $definition) + { + $sql = $this->getForeignKeyBaseDeclarationSql($definition); + $sql .= $this->getAdvancedForeignKeyOptionsSql($definition); + + return $sql; + } + + /** + * getAdvancedForeignKeyOptions + * Return the FOREIGN KEY query section dealing with non-standard options + * as MATCH, INITIALLY DEFERRED, ON UPDATE, ... + * + * @param array $definition foreign key definition + * @return string + */ + public function getAdvancedForeignKeyOptionsSql(array $definition) + { + $query = ''; + if ( ! empty($definition['onUpdate'])) { + $query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSql($definition['onUpdate']); + } + if ( ! empty($definition['onDelete'])) { + $query .= ' ON DELETE ' . $this->getForeignKeyReferentialActionSql($definition['onDelete']); + } + return $query; + } + + /** + * returns given referential action in uppercase if valid, otherwise throws + * an exception + * + * @throws Doctrine_Exception_Exception if unknown referential action given + * @param string $action foreign key referential action + * @param string foreign key referential action in uppercase + */ + public function getForeignKeyReferentialActionSql($action) + { + $upper = strtoupper($action); + switch ($upper) { + case 'CASCADE': + case 'SET NULL': + case 'NO ACTION': + case 'RESTRICT': + case 'SET DEFAULT': + return $upper; + break; + default: + throw new Doctrine_Export_Exception('Unknown foreign key referential action \'' . $upper . '\' given.'); + } + } + + /** + * Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint + * of a field declaration to be used in statements like CREATE TABLE. + * + * @param array $definition + * @return string + */ + public function getForeignKeyBaseDeclarationSql(array $definition) + { + $sql = ''; + if (isset($definition['name'])) { + $sql .= ' CONSTRAINT ' . $this->quoteIdentifier($definition['name']) . ' '; + } + $sql .= 'FOREIGN KEY ('; + + if ( ! isset($definition['local'])) { + throw new Doctrine_Export_Exception('Local reference field missing from definition.'); + } + if ( ! isset($definition['foreign'])) { + throw new Doctrine_Export_Exception('Foreign reference field missing from definition.'); + } + if ( ! isset($definition['foreignTable'])) { + throw new Doctrine_Export_Exception('Foreign reference table missing from definition.'); + } + + if ( ! is_array($definition['local'])) { + $definition['local'] = array($definition['local']); + } + if ( ! is_array($definition['foreign'])) { + $definition['foreign'] = array($definition['foreign']); + } + + $sql .= implode(', ', array_map(array($this, 'quoteIdentifier'), $definition['local'])) + . ') REFERENCES ' + . $this->_conn->quoteIdentifier($definition['foreignTable']) . '(' + . implode(', ', array_map(array($this, 'quoteIdentifier'), $definition['foreign'])) . ')'; + + return $sql; + } + + /** + * Obtain DBMS specific SQL code portion needed to set the UNIQUE constraint + * of a field declaration to be used in statements like CREATE TABLE. + * + * @return string DBMS specific SQL code portion needed to set the UNIQUE constraint + * of a field declaration. + */ + public function getUniqueFieldDeclarationSql() + { + return 'UNIQUE'; + } + + /** + * Obtain DBMS specific SQL code portion needed to set the CHARACTER SET + * of a field declaration to be used in statements like CREATE TABLE. + * + * @param string $charset name of the charset + * @return string DBMS specific SQL code portion needed to set the CHARACTER SET + * of a field declaration. + */ + public function getCharsetFieldDeclarationSql($charset) + { + return ''; + } + + /** + * Obtain DBMS specific SQL code portion needed to set the COLLATION + * of a field declaration to be used in statements like CREATE TABLE. + * + * @param string $collation name of the collation + * @return string DBMS specific SQL code portion needed to set the COLLATION + * of a field declaration. + */ + public function getCollationFieldDeclarationSql($collation) + { + return ''; + } + + /** + * build a pattern matching string + * + * EXPERIMENTAL + * + * WARNING: this function is experimental and may change signature at + * any time until labelled as non-experimental + * + * @access public + * + * @param array $pattern even keys are strings, odd are patterns (% and _) + * @param string $operator optional pattern operator (LIKE, ILIKE and maybe others in the future) + * @param string $field optional field name that is being matched against + * (might be required when emulating ILIKE) + * + * @return string SQL pattern + */ + public function getMatchPatternExpression($pattern, $operator = null, $field = null) + { + throw new Doctrine_Expression_Exception("Method not implemented."); + } + + /** + * Obtain DBMS specific SQL code portion needed to declare an text type + * field to be used in statements like CREATE TABLE. + * + * @param array $field associative array with the name of the properties + * of the field being declared as array indexes. Currently, the types + * of supported field properties are as follows: + * + * length + * Integer value that determines the maximum length of the text + * field. If this argument is missing the field should be + * declared to have the longest length allowed by the DBMS. + * + * default + * Text value to be used as default for this field. + * + * notnull + * Boolean flag that indicates whether this field is constrained + * to not be set to null. + * + * @return string DBMS specific SQL code portion that should be used to + * declare the specified field. + */ + abstract public function getNativeDeclaration(array $field); + + /** + * Maps a native array description of a field to a Doctrine datatype and length + * + * @param array $field native field description + * @return array containing the various possible types, length, sign, fixed + */ + abstract public function getPortableDeclaration(array $field); + + /** + * Whether the platform prefers sequences for ID generation. + * Subclasses should override this method to return TRUE if they prefer sequences. + * + * @return boolean + */ + public function prefersSequences() + { + return false; + } + + /** + * Whether the platform prefers identity columns (eg. autoincrement) for ID generation. + * Subclasses should override this method to return TRUE if they prefer identity columns. + * + * @return boolean + */ + public function prefersIdentityColumns() + { + return false; + } + + /** + * Adds a LIMIT/OFFSET clause to the query. + * This default implementation writes the syntax "LIMIT x OFFSET y" to the + * query which is supported by MySql, PostgreSql and Sqlite. + * Any database platforms that do not support this syntax should override + * this implementation and provide their own. + * + * @param string $query The SQL string to write to / append to. + * @param mixed $limit + * @param mixed $offset + */ + public function writeLimitClause($query, $limit = false, $offset = false) + { + $limit = (int) $limit; + $offset = (int) $offset; + + if ($limit && $offset) { + $query .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } elseif ($limit && ! $offset) { + $query .= ' LIMIT ' . $limit; + } elseif ( ! $limit && $offset) { + $query .= ' LIMIT 999999999999 OFFSET ' . $offset; + } + + return $query; + } + + /** + * Creates DBMS specific LIMIT/OFFSET SQL for the subqueries that are used in the + * context of the limit-subquery construction. + * This default implementation uses the normal LIMIT/OFFSET creation of the + * platform as provided by {@see modifyLimitQuery()}. This means LIMIT/OFFSET + * in subqueries don't get any special treatment. Most of the time this is not + * sufficient (eg. MySql does not allow LIMIT in subqueries) and the concrete + * platforms should provide their own implementation. + * + * @param string $query The SQL string to write to / append to. + * @return string + * @todo Remove the ORM dependency + */ + public function writeLimitClauseInSubquery(Doctrine_ClassMetadata $rootClass, + $query, $limit = false, $offset = false) + { + return $this->modifyLimitQuery($query, $limit, $offset); + } + + /** + * Enter description here... + * + * @param unknown_type $name + * @return unknown + * @todo Remove. Move properties to DatabasePlatform. + */ + public function getProperty($name) + { + if ( ! isset($this->_properties[$name])) { + throw Doctrine_Connection_Exception::unknownProperty($name); + } + return $this->_properties[$name]; + } + + /** + * Some platforms need the boolean values to be converted. + * Default conversion defined here converts to integers. + * + * @param array $item + * @return void + */ + public function convertBooleans($item) + { + if (is_array($item)) { + foreach ($item as $k => $value) { + if (is_bool($value)) { + $item[$k] = (int) $value; + } + } + } else { + if (is_bool($item)) { + $item = (int) $item; + } + } + return $item; + } + + /** + * Enter description here... + * + * @param unknown_type $charset + * @return string + */ + public function getSetCharsetSql($charset) + { + return 'SET NAMES ' . $this->quote($charset); + } + + + /* supports*() metods */ + + public function supportsSequences() + { + return false; + } + + public function supportsIdentityColumns() + { + return false; + } + + public function supportsIndexes() + { + return true; + } + + public function supportsTransactions() + { + return true; + } + + public function supportsSavepoints() + { + return true; + } + + public function supportsPrimaryConstraints() + { + return true; + } + + public function supportsForeignKeyConstraints() + { + return true; + } + + public function supportsGettingAffectedRows() + { + return true; + } +} + + +?> \ No newline at end of file diff --git a/lib/Doctrine/DBAL/Platforms/Db2Platform.php b/lib/Doctrine/DBAL/Platforms/Db2Platform.php new file mode 100644 index 000000000..90e5899c5 --- /dev/null +++ b/lib/Doctrine/DBAL/Platforms/Db2Platform.php @@ -0,0 +1,15 @@ +quoteIdentifier($sequenceName) + . ' FROM SYSIBM.SYSDUMMY1'; + } + +} + +?> \ No newline at end of file diff --git a/lib/Doctrine/DatabasePlatform/FirebirdPlatform.php b/lib/Doctrine/DBAL/Platforms/FirebirdPlatform.php similarity index 98% rename from lib/Doctrine/DatabasePlatform/FirebirdPlatform.php rename to lib/Doctrine/DBAL/Platforms/FirebirdPlatform.php index a06266a67..5ed5e6a5e 100644 --- a/lib/Doctrine/DatabasePlatform/FirebirdPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/FirebirdPlatform.php @@ -7,7 +7,7 @@ * * @since 2.0 */ -class Doctrine_DatabasePlatform_FirebirdPlatform extends Doctrine_DatabasePlatform +class Doctrine_DBAL_Platforms_FirebirdPlatform extends Doctrine_DBAL_Platforms_AbstractPlatform { /** diff --git a/lib/Doctrine/DatabasePlatform/InformixPlatform.php b/lib/Doctrine/DBAL/Platforms/InformixPlatform.php similarity index 97% rename from lib/Doctrine/DatabasePlatform/InformixPlatform.php rename to lib/Doctrine/DBAL/Platforms/InformixPlatform.php index b2a66ae1e..43b935c98 100644 --- a/lib/Doctrine/DatabasePlatform/InformixPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/InformixPlatform.php @@ -7,7 +7,7 @@ * * @since 2.0 */ -class Doctrine_DatabasePlatform_InformixPlatform extends Doctrine_DatabasePlatform +class Doctrine_DBAL_Platforms_InformixPlatform extends Doctrine_DBAL_Platforms_AbstractPlatform { public function __construct() diff --git a/lib/Doctrine/DatabasePlatform/MockPlatform.php b/lib/Doctrine/DBAL/Platforms/MockPlatform.php similarity index 50% rename from lib/Doctrine/DatabasePlatform/MockPlatform.php rename to lib/Doctrine/DBAL/Platforms/MockPlatform.php index a00a6ded5..5d65d8658 100644 --- a/lib/Doctrine/DatabasePlatform/MockPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MockPlatform.php @@ -1,6 +1,7 @@ $fixed); } + /** + * Quote a string so it can be safely used as a table / column name + * + * Quoting style depends on which database driver is being used. + * + * @param string $identifier identifier name to be quoted + * @param bool $checkOption check the 'quote_identifier' option + * + * @return string quoted identifier string + * @override + */ + public function quoteIdentifier($identifier, $checkOption = false) + { + if ($checkOption && ! $this->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) { + return $identifier; + } + + if (strpos($identifier, '.') !== false) { + $parts = explode('.', $identifier); + $quotedParts = array(); + foreach ($parts as $p) { + $quotedParts[] = $this->quoteIdentifier($p); + } + + return implode('.', $quotedParts); + } + + return '[' . str_replace(']', ']]', $identifier) . ']'; + } + } ?> \ No newline at end of file diff --git a/lib/Doctrine/DatabasePlatform/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php similarity index 99% rename from lib/Doctrine/DatabasePlatform/MySqlPlatform.php rename to lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 8cdddeddc..82288884c 100644 --- a/lib/Doctrine/DatabasePlatform/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::DBAL::Platforms; + /** * The MySqlPlatform provides the behavior, features and SQL dialect of the * MySQL database platform. @@ -26,7 +28,7 @@ * @since 2.0 * @author Roman Borschel */ -class Doctrine_DatabasePlatform_MySqlPlatform extends Doctrine_DatabasePlatform +class Doctrine_DBAL_Platforms_MySqlPlatform extends Doctrine_DBAL_Platforms_AbstractPlatform { /** * MySql reserved words. diff --git a/lib/Doctrine/DatabasePlatform/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php similarity index 98% rename from lib/Doctrine/DatabasePlatform/OraclePlatform.php rename to lib/Doctrine/DBAL/Platforms/OraclePlatform.php index e932af3e4..228250f17 100644 --- a/lib/Doctrine/DatabasePlatform/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::DBAL::Platforms; + /** * Base class for all DatabasePlatforms. The DatabasePlatforms are the central * point of abstraction of platform-specific behaviors, features and SQL dialects. @@ -28,7 +30,7 @@ * @author Roman Borschel * @author Lukas Smith (PEAR MDB2 library) */ -class Doctrine_DatabasePlatform_OraclePlatform extends Doctrine_DatabasePlatform +class Doctrine_DBAL_Platforms_OraclePlatform extends Doctrine_DBAL_Platforms_AbstractPlatform { /** * Constructor. diff --git a/lib/Doctrine/DatabasePlatform/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php similarity index 99% rename from lib/Doctrine/DatabasePlatform/PostgreSqlPlatform.php rename to lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 8fafe54ee..fee5913e6 100644 --- a/lib/Doctrine/DatabasePlatform/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -1,7 +1,8 @@ . + */ + +#namespace Doctrine::DBAL; + +/** + * Statement interface. + * Drivers must implement this interface. + * + * This includes the full PDOStatement interface as well as custom extensions of + * Doctrine's DBAL. + * + * @author Konsta Vesterinen + * @author Roman Borschel + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.0 + * @version $Revision$ + */ +interface Doctrine_DBAL_Statement +{ + /** + * Bind a column to a PHP variable + * + * @param mixed $column Number of the column (1-indexed) or name of the column in the result set. + * If using the column name, be aware that the name should match + * the case of the column, as returned by the driver. + * @param string $param Name of the PHP variable to which the column will be bound. + * @param integer $type Data type of the parameter, specified by the Doctrine::PARAM_* constants. + * @return boolean Returns TRUE on success or FALSE on failure + */ + public function bindColumn($column, $param, $type = null); + + /** + * bindValue + * Binds a value to a corresponding named or question mark + * placeholder in the SQL statement that was use to prepare the statement. + * + * @param mixed $param Parameter identifier. For a prepared statement using named placeholders, + * this will be a parameter name of the form :name. For a prepared statement + * using question mark placeholders, this will be the 1-indexed position of the parameter + * + * @param mixed $value The value to bind to the parameter. + * @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants. + * + * @return boolean Returns TRUE on success or FALSE on failure. + */ + public function bindValue($param, $value, $type = null); + + /** + * bindParam + * Binds a PHP variable to a corresponding named or question mark placeholder in the + * SQL statement that was use to prepare the statement. Unlike Doctrine_Adapter_Statement_Interface->bindValue(), + * the variable is bound as a reference and will only be evaluated at the time + * that Doctrine_Adapter_Statement_Interface->execute() is called. + * + * Most parameters are input parameters, that is, parameters that are + * used in a read-only fashion to build up the query. Some drivers support the invocation + * of stored procedures that return data as output parameters, and some also as input/output + * parameters that both send in data and are updated to receive it. + * + * @param mixed $param Parameter identifier. For a prepared statement using named placeholders, + * this will be a parameter name of the form :name. For a prepared statement + * using question mark placeholders, this will be the 1-indexed position of the parameter + * + * @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter. + * + * @param integer $type Explicit data type for the parameter using the Doctrine::PARAM_* constants. To return + * an INOUT parameter from a stored procedure, use the bitwise OR operator to set the + * Doctrine::PARAM_INPUT_OUTPUT bits for the data_type parameter. + * + * @param integer $length Length of the data type. To indicate that a parameter is an OUT parameter + * from a stored procedure, you must explicitly set the length. + * @param mixed $driverOptions + * @return boolean Returns TRUE on success or FALSE on failure. + */ + public function bindParam($column, &$variable, $type = null, $length = null, $driverOptions = array()); + + /** + * closeCursor + * Closes the cursor, enabling the statement to be executed again. + * + * @return boolean Returns TRUE on success or FALSE on failure. + */ + public function closeCursor(); + + /** + * columnCount + * Returns the number of columns in the result set + * + * @return integer Returns the number of columns in the result set represented + * by the Doctrine_Adapter_Statement_Interface object. If there is no result set, + * this method should return 0. + */ + public function columnCount(); + + /** + * errorCode + * Fetch the SQLSTATE associated with the last operation on the statement handle + * + * @see Doctrine_Adapter_Interface::errorCode() + * @return string error code string + */ + public function errorCode(); + + /** + * errorInfo + * Fetch extended error information associated with the last operation on the statement handle + * + * @see Doctrine_Adapter_Interface::errorInfo() + * @return array error info array + */ + public function errorInfo(); + + /** + * execute + * Executes a prepared statement + * + * If the prepared statement included parameter markers, you must either: + * call PDOStatement->bindParam() to bind PHP variables to the parameter markers: + * bound variables pass their value as input and receive the output value, + * if any, of their associated parameter markers or pass an array of input-only + * parameter values + * + * + * @param array $params An array of values with as many elements as there are + * bound parameters in the SQL statement being executed. + * @return boolean Returns TRUE on success or FALSE on failure. + */ + public function execute($params = null); + + /** + * fetch + * + * @see Doctrine::FETCH_* constants + * @param integer $fetchStyle Controls how the next row will be returned to the caller. + * This value must be one of the Doctrine::FETCH_* constants, + * defaulting to Doctrine::FETCH_BOTH + * + * @param integer $cursorOrientation For a PDOStatement object representing a scrollable cursor, + * this value determines which row will be returned to the caller. + * This value must be one of the Doctrine::FETCH_ORI_* constants, defaulting to + * Doctrine::FETCH_ORI_NEXT. To request a scrollable cursor for your + * Doctrine_Adapter_Statement_Interface object, + * you must set the Doctrine::ATTR_CURSOR attribute to Doctrine::CURSOR_SCROLL when you + * prepare the SQL statement with Doctrine_Adapter_Interface->prepare(). + * + * @param integer $cursorOffset For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for which the + * $cursorOrientation parameter is set to Doctrine::FETCH_ORI_ABS, this value specifies + * the absolute number of the row in the result set that shall be fetched. + * + * For a Doctrine_Adapter_Statement_Interface object representing a scrollable cursor for + * which the $cursorOrientation parameter is set to Doctrine::FETCH_ORI_REL, this value + * specifies the row to fetch relative to the cursor position before + * Doctrine_Adapter_Statement_Interface->fetch() was called. + * + * @return mixed + */ + public function fetch($fetchStyle = Doctrine::FETCH_BOTH, + $cursorOrientation = Doctrine::FETCH_ORI_NEXT, + $cursorOffset = null); + + /** + * fetchAll + * Returns an array containing all of the result set rows + * + * @param integer $fetchStyle Controls how the next row will be returned to the caller. + * This value must be one of the Doctrine::FETCH_* constants, + * defaulting to Doctrine::FETCH_BOTH + * + * @param integer $columnIndex Returns the indicated 0-indexed column when the value of $fetchStyle is + * Doctrine::FETCH_COLUMN. Defaults to 0. + * + * @return array + */ + public function fetchAll($fetchStyle = Doctrine::FETCH_BOTH); + + /** + * fetchColumn + * Returns a single column from the next row of a + * result set or FALSE if there are no more rows. + * + * @param integer $columnIndex 0-indexed number of the column you wish to retrieve from the row. If no + * value is supplied, Doctrine_Adapter_Statement_Interface->fetchColumn() + * fetches the first column. + * + * @return string returns a single column in the next row of a result set. + */ + public function fetchColumn($columnIndex = 0); + + /** + * fetchObject + * Fetches the next row and returns it as an object. + * + * Fetches the next row and returns it as an object. This function is an alternative to + * Doctrine_Adapter_Statement_Interface->fetch() with Doctrine::FETCH_CLASS or Doctrine::FETCH_OBJ style. + * + * @param string $className Name of the created class, defaults to stdClass. + * @param array $args Elements of this array are passed to the constructor. + * + * @return mixed an instance of the required class with property names that correspond + * to the column names or FALSE in case of an error. + */ + public function fetchObject($className = 'stdClass', $args = array()); + + /** + * getAttribute + * Retrieve a statement attribute + * + * @param integer $attribute + * @see Doctrine::ATTR_* constants + * @return mixed the attribute value + */ + public function getAttribute($attribute); + + /** + * getColumnMeta + * Returns metadata for a column in a result set + * + * @param integer $column The 0-indexed column in the result set. + * + * @return array Associative meta data array with the following structure: + * + * native_type The PHP native type used to represent the column value. + * driver:decl_ type The SQL type used to represent the column value in the database. If the column in the result set is the result of a function, this value is not returned by PDOStatement->getColumnMeta(). + * flags Any flags set for this column. + * name The name of this column as returned by the database. + * len The length of this column. Normally -1 for types other than floating point decimals. + * precision The numeric precision of this column. Normally 0 for types other than floating point decimals. + * pdo_type The type of this column as represented by the PDO::PARAM_* constants. + */ + public function getColumnMeta($column); + + /** + * nextRowset + * Advances to the next rowset in a multi-rowset statement handle + * + * Some database servers support stored procedures that return more than one rowset + * (also known as a result set). The nextRowset() method enables you to access the second + * and subsequent rowsets associated with a PDOStatement object. Each rowset can have a + * different set of columns from the preceding rowset. + * + * @return boolean Returns TRUE on success or FALSE on failure. + */ + public function nextRowset(); + + /** + * rowCount + * rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement + * executed by the corresponding object. + * + * If the last SQL statement executed by the associated Statement object was a SELECT statement, + * some databases may return the number of rows returned by that statement. However, + * this behaviour is not guaranteed for all databases and should not be + * relied on for portable applications. + * + * @return integer Returns the number of rows. + */ + public function rowCount(); + + /** + * setAttribute + * Set a statement attribute + * + * @param integer $attribute + * @param mixed $value the value of given attribute + * @return boolean Returns TRUE on success or FALSE on failure. + */ + public function setAttribute($attribute, $value); + + /** + * setFetchMode + * Set the default fetch mode for this statement + * + * @param integer $mode The fetch mode must be one of the Doctrine::FETCH_* constants. + * @return boolean Returns 1 on success or FALSE on failure. + */ + public function setFetchMode($mode, $arg1 = null, $arg2 = null); +} diff --git a/lib/Doctrine/DataType/ArrayType.php b/lib/Doctrine/DBAL/Types/ArrayType.php similarity index 70% rename from lib/Doctrine/DataType/ArrayType.php rename to lib/Doctrine/DBAL/Types/ArrayType.php index 4a218b2c4..f1a847628 100644 --- a/lib/Doctrine/DataType/ArrayType.php +++ b/lib/Doctrine/DBAL/Types/ArrayType.php @@ -5,7 +5,7 @@ * * @since 2.0 */ -class Doctrine_DataType_ArrayType extends Doctrine_DataType +class Doctrine_DBAL_Types_ArrayType extends Doctrine_DBAL_Types_Type { diff --git a/lib/Doctrine/DataType/BooleanType.php b/lib/Doctrine/DBAL/Types/BooleanType.php similarity index 88% rename from lib/Doctrine/DataType/BooleanType.php rename to lib/Doctrine/DBAL/Types/BooleanType.php index 82b127452..22e3e6ec2 100644 --- a/lib/Doctrine/DataType/BooleanType.php +++ b/lib/Doctrine/DBAL/Types/BooleanType.php @@ -4,7 +4,7 @@ * Type that maps an SQL boolean to a PHP boolean. * */ -class Doctrine_DataType_BooleanType extends Doctrine_DataType +class Doctrine_DBAL_Types_BooleanType extends Doctrine_DBAL_Types_Type { /** * Enter description here... diff --git a/lib/Doctrine/DataType/DateTimeType.php b/lib/Doctrine/DBAL/Types/DateTimeType.php similarity index 89% rename from lib/Doctrine/DataType/DateTimeType.php rename to lib/Doctrine/DBAL/Types/DateTimeType.php index 40ddecab3..7e49b4370 100644 --- a/lib/Doctrine/DataType/DateTimeType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeType.php @@ -5,7 +5,7 @@ * * @since 2.0 */ -class Doctrine_DataType_DateTimeType extends Doctrine_DataType +class Doctrine_DBAL_Types_DateTimeType extends Doctrine_DBAL_Types_Type { /** * Enter description here... diff --git a/lib/Doctrine/DataType/DecimalType.php b/lib/Doctrine/DBAL/Types/DecimalType.php similarity index 52% rename from lib/Doctrine/DataType/DecimalType.php rename to lib/Doctrine/DBAL/Types/DecimalType.php index c7ffd766f..2209a3978 100644 --- a/lib/Doctrine/DataType/DecimalType.php +++ b/lib/Doctrine/DBAL/Types/DecimalType.php @@ -4,7 +4,7 @@ * Type that maps an SQL DECIMAL to a PHP double. * */ -class Doctrine_DataType_DecimalType extends Doctrine_DataType +class Doctrine_DBAL_Types_DecimalType extends Doctrine_DBAL_Types_Type { } diff --git a/lib/Doctrine/DataType/IntegerType.php b/lib/Doctrine/DBAL/Types/IntegerType.php similarity index 75% rename from lib/Doctrine/DataType/IntegerType.php rename to lib/Doctrine/DBAL/Types/IntegerType.php index 5de7624b9..e4886358f 100644 --- a/lib/Doctrine/DataType/IntegerType.php +++ b/lib/Doctrine/DBAL/Types/IntegerType.php @@ -4,7 +4,7 @@ * Type that maps an SQL INT/MEDIUMINT/BIGINT to a PHP integer. * */ -class Doctrine_DataType_IntegerType extends Doctrine_DataType +class Doctrine_DBAL_Types_IntegerType extends Doctrine_DBAL_Types_Type { diff --git a/lib/Doctrine/DataType/StringType.php b/lib/Doctrine/DBAL/Types/StringType.php similarity index 88% rename from lib/Doctrine/DataType/StringType.php rename to lib/Doctrine/DBAL/Types/StringType.php index 1f1f566d6..a919688c4 100644 --- a/lib/Doctrine/DataType/StringType.php +++ b/lib/Doctrine/DBAL/Types/StringType.php @@ -7,7 +7,7 @@ * * @since 2.0 */ -class Doctrine_DataType_StringType extends Doctrine_DataType +class Doctrine_DBAL_Types_StringType extends Doctrine_DBAL_Types_Type { public function getSqlDeclaration(array $fieldDeclaration, Doctrine_DatabasePlatform $platform) { diff --git a/lib/Doctrine/DataType/TextType.php b/lib/Doctrine/DBAL/Types/TextType.php similarity index 86% rename from lib/Doctrine/DataType/TextType.php rename to lib/Doctrine/DBAL/Types/TextType.php index 51cd9ad57..d31da7496 100644 --- a/lib/Doctrine/DataType/TextType.php +++ b/lib/Doctrine/DBAL/Types/TextType.php @@ -5,7 +5,7 @@ * * @since 2.0 */ -class Doctrine_DataType_TextType extends Doctrine_DataType +class Doctrine_DBAL_Types_TextType extends Doctrine_DBAL_Types_Type { /** * Enter description here... diff --git a/lib/Doctrine/DatabasePlatform.php b/lib/Doctrine/DatabasePlatform.php index 2e0566eb8..b83b50b8c 100644 --- a/lib/Doctrine/DatabasePlatform.php +++ b/lib/Doctrine/DatabasePlatform.php @@ -1762,6 +1762,18 @@ abstract class Doctrine_DatabasePlatform } return $item; } + + /** + * Enter description here... + * + * @param unknown_type $charset + * @return string + */ + public function getSetCharsetSql($charset) + { + return 'SET NAMES ' . $this->quote($charset); + } + /* supports*() metods */ diff --git a/lib/Doctrine/Hydrator/ArrayDriver.php b/lib/Doctrine/Hydrator/ArrayDriver.php index 77f8d81f3..f5dfcde0a 100644 --- a/lib/Doctrine/Hydrator/ArrayDriver.php +++ b/lib/Doctrine/Hydrator/ArrayDriver.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::ORM::Internal; + /** * Defines an array hydration strategy. * diff --git a/lib/Doctrine/Schema/MySqlSchemaManger.php b/lib/Doctrine/Schema/MySqlSchemaManger.php index 9e33d99e9..658bf173d 100644 --- a/lib/Doctrine/Schema/MySqlSchemaManger.php +++ b/lib/Doctrine/Schema/MySqlSchemaManger.php @@ -31,16 +31,7 @@ * @since 2.0 */ class Doctrine_Schema_MySqlSchemaManager extends Doctrine_Schema_SchemaManager -{ - /*protected $_sql = array( - 'showDatabases' => 'SHOW DATABASES', - 'listTableFields' => 'DESCRIBE %s', - 'listSequences' => 'SHOW TABLES', - 'listTables' => 'SHOW TABLES', - 'listUsers' => 'SELECT DISTINCT USER FROM USER', - 'listViews' => "SHOW FULL TABLES %s WHERE Table_type = 'VIEW'", - );*/ - +{ public function __construct(Doctrine_Connection $conn) { $this->_conn = $conn; diff --git a/lib/Doctrine/Transaction.php b/lib/Doctrine/Transaction.php index 612bb0f50..ed204fee1 100644 --- a/lib/Doctrine/Transaction.php +++ b/lib/Doctrine/Transaction.php @@ -30,7 +30,8 @@ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @deprecated */ class Doctrine_Transaction extends Doctrine_Connection_Module { @@ -110,29 +111,17 @@ class Doctrine_Transaction extends Doctrine_Connection_Module public function begin($savepoint = null) { $this->conn->connect(); - //$listener = $this->conn->getAttribute(Doctrine::ATTR_LISTENER); if ( ! is_null($savepoint)) { $this->savePoints[] = $savepoint; - //$event = new Doctrine_Event($this, Doctrine_Event::SAVEPOINT_CREATE); - //$listener->preSavepointCreate($event); - //if ( ! $event->skipOperation) { - $this->createSavePoint($savepoint); - //} - //$listener->postSavepointCreate($event); + $this->createSavePoint($savepoint); } else { if ($this->_nestingLevel == 0) { - //$event = new Doctrine_Event($this, Doctrine_Event::TX_BEGIN); - //$listener->preTransactionBegin($event); - - //if ( ! $event->skipOperation) { - try { - $this->_doBeginTransaction(); - } catch (Exception $e) { - throw new Doctrine_Transaction_Exception($e->getMessage()); - } - //} - //$listener->postTransactionBegin($event); + try { + $this->_doBeginTransaction(); + } catch (Exception $e) { + throw new Doctrine_Transaction_Exception($e->getMessage()); + } } } @@ -161,24 +150,12 @@ class Doctrine_Transaction extends Doctrine_Connection_Module $this->conn->connect(); - //$listener = $this->conn->getAttribute(Doctrine::ATTR_LISTENER); - if ( ! is_null($savepoint)) { $this->_nestingLevel -= $this->removeSavePoints($savepoint); - //$event = new Doctrine_Event($this, Doctrine_Event::SAVEPOINT_COMMIT); - //$listener->preSavepointCommit($event); - //if ( ! $event->skipOperation) { - $this->releaseSavePoint($savepoint); - //} - //$listener->postSavepointCommit($event); + $this->releaseSavePoint($savepoint); } else { if ($this->_nestingLevel == 1) { - //$event = new Doctrine_Event($this, Doctrine_Event::TX_COMMIT); - //$listener->preTransactionCommit($event); - //if ( ! $event->skipOperation) { - $this->_doCommit(); - //} - //$listener->postTransactionCommit($event); + $this->_doCommit(); } if ($this->_nestingLevel > 0) { @@ -219,24 +196,14 @@ class Doctrine_Transaction extends Doctrine_Connection_Module if ( ! is_null($savepoint)) { $this->_nestingLevel -= $this->removeSavePoints($savepoint); - //$event = new Doctrine_Event($this, Doctrine_Event::SAVEPOINT_ROLLBACK); - //$listener->preSavepointRollback($event); - //if ( ! $event->skipOperation) { - $this->rollbackSavePoint($savepoint); - //} - //$listener->postSavepointRollback($event); + $this->rollbackSavePoint($savepoint); } else { - //$event = new Doctrine_Event($this, Doctrine_Event::TX_ROLLBACK); - //$listener->preTransactionRollback($event); - //if ( ! $event->skipOperation) { - $this->_nestingLevel = 0; - try { - $this->_doRollback(); - } catch (Exception $e) { - throw new Doctrine_Transaction_Exception($e->getMessage()); - } - //} - //$listener->postTransactionRollback($event); + $this->_nestingLevel = 0; + try { + $this->_doRollback(); + } catch (Exception $e) { + throw new Doctrine_Transaction_Exception($e->getMessage()); + } } return true; diff --git a/lib/Doctrine/Transaction/Exception.php b/lib/Doctrine/Transaction/Exception.php index 1d4609a50..362380157 100644 --- a/lib/Doctrine/Transaction/Exception.php +++ b/lib/Doctrine/Transaction/Exception.php @@ -28,7 +28,8 @@ Doctrine::autoload('Doctrine_Exception'); * @author Konsta Vesterinen * @since 1.0 * @version $Revision$ - * @link www.phpdoctrine.org + * @link www.phpdoctrine.org + * @todo remove */ class Doctrine_Transaction_Exception extends Doctrine_Exception { } \ No newline at end of file diff --git a/lib/Doctrine/Transaction/Firebird.php b/lib/Doctrine/Transaction/Firebird.php index c00e14861..ff01d190d 100644 --- a/lib/Doctrine/Transaction/Firebird.php +++ b/lib/Doctrine/Transaction/Firebird.php @@ -28,7 +28,8 @@ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @todo remove */ class Doctrine_Transaction_Firebird extends Doctrine_Transaction { diff --git a/lib/Doctrine/Transaction/Informix.php b/lib/Doctrine/Transaction/Informix.php index 670c5ad42..465cde5e1 100644 --- a/lib/Doctrine/Transaction/Informix.php +++ b/lib/Doctrine/Transaction/Informix.php @@ -26,7 +26,8 @@ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @todo remove */ class Doctrine_Transaction_Informix extends Doctrine_Transaction { } \ No newline at end of file diff --git a/lib/Doctrine/Transaction/Mock.php b/lib/Doctrine/Transaction/Mock.php index 5c93754b8..27d3ec893 100644 --- a/lib/Doctrine/Transaction/Mock.php +++ b/lib/Doctrine/Transaction/Mock.php @@ -30,7 +30,8 @@ Doctrine::autoload('Doctrine_Transaction'); * @subpackage Transaction * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @todo remove */ class Doctrine_Transaction_Mock extends Doctrine_Transaction { } \ No newline at end of file diff --git a/lib/Doctrine/Transaction/Mssql.php b/lib/Doctrine/Transaction/Mssql.php index 3df13bf6d..d3f0f9b7b 100644 --- a/lib/Doctrine/Transaction/Mssql.php +++ b/lib/Doctrine/Transaction/Mssql.php @@ -28,7 +28,8 @@ * @subpackage Transaction * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @todo remove */ class Doctrine_Transaction_Mssql extends Doctrine_Transaction { diff --git a/lib/Doctrine/Transaction/Mysql.php b/lib/Doctrine/Transaction/Mysql.php index 268358e31..0109a29f0 100644 --- a/lib/Doctrine/Transaction/Mysql.php +++ b/lib/Doctrine/Transaction/Mysql.php @@ -28,7 +28,8 @@ * @subpackage Transaction * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @todo remove */ class Doctrine_Transaction_Mysql extends Doctrine_Transaction { diff --git a/lib/Doctrine/Transaction/Oracle.php b/lib/Doctrine/Transaction/Oracle.php index 68bdb178c..d9b9bd1e6 100644 --- a/lib/Doctrine/Transaction/Oracle.php +++ b/lib/Doctrine/Transaction/Oracle.php @@ -28,7 +28,8 @@ * @subpackage Transaction * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @todo remove */ class Doctrine_Transaction_Oracle extends Doctrine_Transaction { diff --git a/lib/Doctrine/Transaction/Pgsql.php b/lib/Doctrine/Transaction/Pgsql.php index 29330b92c..8310a398b 100644 --- a/lib/Doctrine/Transaction/Pgsql.php +++ b/lib/Doctrine/Transaction/Pgsql.php @@ -29,7 +29,8 @@ * @subpackage Transaction * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @todo remove */ class Doctrine_Transaction_Pgsql extends Doctrine_Transaction { diff --git a/lib/Doctrine/Transaction/Sqlite.php b/lib/Doctrine/Transaction/Sqlite.php index f0ef280b1..fe642cf23 100644 --- a/lib/Doctrine/Transaction/Sqlite.php +++ b/lib/Doctrine/Transaction/Sqlite.php @@ -28,7 +28,8 @@ * @subpackage Transaction * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @todo remove */ class Doctrine_Transaction_Sqlite extends Doctrine_Transaction {