diff --git a/UPGRADE.md b/UPGRADE.md index 2847c786413..50c03220e57 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,48 @@ +# Upgrade to DEVELOP + +## BC BREAK: the PDO symbols are no longer part of the DBAL API + +1. The support of `PDO::PARAM_*`, `PDO::FETCH_*`, `PDO::CASE_*` and `PDO::PARAM_INPUT_OUTPUT` constants in the DBAL API is removed. +2. `\Doctrine\DBAL\Driver\PDOStatement` does not extend `\PDOStatement` anymore. + +Before: + + use Doctrine\DBAL\Portability\Connection; + + $params = array( + 'wrapperClass' => Connection::class, + 'fetch_case' => PDO::CASE_LOWER, + ); + + $stmt->bindValue(1, 1, PDO::PARAM_INT); + $stmt->fetchAll(PDO::FETCH_COLUMN); + +After: + + use Doctrine\DBAL\ColumnCase; + use Doctrine\DBAL\FetchMode; + use Doctrine\DBAL\ParameterType; + use Doctrine\DBAL\Portability\Connection; + + $params = array( + 'wrapperClass' => Connection::class, + 'fetch_case' => ColumnCase::LOWER, + ); + + $stmt->bindValue(1, 1, ParameterType::INTEGER); + $stmt->fetchAll(FetchMode::COLUMN); + +# Upgrade to UNRELEASED + +## DEPRECATION: direct usage of the PDO APIs in the DBAL API + +1. When calling `Doctrine\DBAL\Driver\Statement` methods, instead of `PDO::PARAM_*` constants, `Doctrine\DBAL\ParameterType` constants should be used. +2. When calling `Doctrine\DBAL\Driver\ResultStatement` methods, instead of `PDO::FETCH_*` constants, `Doctrine\DBAL\FetchMode` constants should be used. +3. When configuring `Doctrine\DBAL\Portability\Connection`, instead of `PDO::CASE_*` constants, `Doctrine\DBAL\ColumnCase` constants should be used. +4. Usage of `PDO::PARAM_INPUT_OUTPUT` in `Doctrine\DBAL\Driver\Statement::bindValue()` is deprecated. +5. Usage of `PDO::FETCH_FUNC` in `Doctrine\DBAL\Driver\ResultStatement::fetch()` is deprecated. +6. Calls to `\PDOStatement` methods on a `\Doctrine\DBAL\Driver\PDOStatement` instance (e.g. `fetchObject()`) are deprecated. + # Upgrade to 2.6 ## MINOR BC BREAK: `fetch()` and `fetchAll()` method signatures in `Doctrine\DBAL\Driver\ResultStatement` diff --git a/composer.json b/composer.json index 53f02f1326e..bf21bda1c26 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,6 @@ ], "require": { "php": "^7.2", - "ext-pdo": "*", "doctrine/common": "^2.7.1" }, "require-dev": { diff --git a/docs/en/reference/data-retrieval-and-manipulation.rst b/docs/en/reference/data-retrieval-and-manipulation.rst index 404e8c47282..31397a532b9 100644 --- a/docs/en/reference/data-retrieval-and-manipulation.rst +++ b/docs/en/reference/data-retrieval-and-manipulation.rst @@ -180,13 +180,13 @@ Binding Types ------------- Doctrine DBAL extends PDOs handling of binding types in prepared statements -considerably. Besides the well known ``\PDO::PARAM_*`` constants you +considerably. Besides ``Doctrine\DBAL\ParameterType`` constants, you can make use of two very powerful additional features. Doctrine\DBAL\Types Conversion ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If you don't specify an integer (through a ``PDO::PARAM*`` constant) to +If you don't specify an integer (through one of ``Doctrine\DBAL\ParameterType`` constants) to any of the parameter binding methods but a string, Doctrine DBAL will ask the type abstraction layer to convert the passed value from its PHP to a database representation. This way you can pass ``\DateTime`` @@ -271,7 +271,14 @@ be specified as well: // Same SQL WITHOUT usage of Doctrine\DBAL\Connection::PARAM_INT_ARRAY $stmt = $conn->executeQuery('SELECT * FROM articles WHERE id IN (?, ?, ?, ?, ?, ?)', array(1, 2, 3, 4, 5, 6), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT) + array( + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ) ); This is much more complicated and is ugly to write generically. @@ -469,8 +476,11 @@ Quote a value: .. code-block:: php quote('value'); - $quoted = $conn->quote('1234', \PDO::PARAM_INT); + $quoted = $conn->quote('1234', ParameterType::INTEGER); quoteIdentifier() ~~~~~~~~~~~~~~~~~ diff --git a/docs/en/reference/known-vendor-issues.rst b/docs/en/reference/known-vendor-issues.rst index d27fe30789f..09c44aeb8f2 100644 --- a/docs/en/reference/known-vendor-issues.rst +++ b/docs/en/reference/known-vendor-issues.rst @@ -187,6 +187,6 @@ The ``PDO_SQLSRV`` driver currently has a bug when binding values to VARBINARY/BLOB columns with ``bindValue`` in prepared statements. This raises an implicit conversion from data type error as it tries to convert a character type value to a binary type value even if -you explicitly define the value as ``\PDO::PARAM_LOB`` type. +you explicitly define the value as ``ParameterType::LARGE_OBJECT`` type. Therefore it is highly encouraged to use the native ``sqlsrv`` driver instead which does not have this limitation. diff --git a/docs/en/reference/portability.rst b/docs/en/reference/portability.rst index a69b59f5bca..ea1800b5875 100644 --- a/docs/en/reference/portability.rst +++ b/docs/en/reference/portability.rst @@ -51,12 +51,16 @@ Using the following code block in your initialization will: .. code-block:: php 'Doctrine\DBAL\Portability\Connection', - 'portability' => \Doctrine\DBAL\Portability\Connection::PORTABILITY_ALL, - 'fetch_case' => \PDO::CASE_LOWER, + 'wrapperClass' => PortableConnection::class, + 'portability' => PortableConnection::PORTABILITY_ALL, + 'fetch_case' => PortableConnection::LOWER, ); This sort of portability handling is pretty expensive because all the result @@ -80,4 +84,4 @@ This functionality is only implemented with Doctrine 2.1 upwards. Doctrine ships with lists of keywords for every supported vendor. You can access a keyword list through the schema manager of the vendor you are currently using or just instantiating it from the ``Doctrine\DBAL\Platforms\Keywords`` -namespace. \ No newline at end of file +namespace. diff --git a/docs/en/reference/security.rst b/docs/en/reference/security.rst index e8a01f0b7ec..82f159c87fb 100644 --- a/docs/en/reference/security.rst +++ b/docs/en/reference/security.rst @@ -151,7 +151,7 @@ the ``Connection#quote`` method: quote($_GET['username'], \PDO::PARAM_STR); + $sql = "SELECT * FROM users WHERE name = " . $connection->quote($_GET['username']); This method is only available for SQL, not for DQL. For DQL you are always encouraged to use prepared -statements not only for security, but also for caching reasons. \ No newline at end of file +statements not only for security, but also for caching reasons. diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index 7e8a46766e6..d24e98bc96c 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -3,7 +3,7 @@ namespace Doctrine\DBAL\Cache; use Doctrine\DBAL\Driver\ResultStatement; -use PDO; +use Doctrine\DBAL\FetchMode; class ArrayStatement implements \IteratorAggregate, ResultStatement { @@ -25,7 +25,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement /** * @var integer */ - private $defaultFetchMode = PDO::FETCH_BOTH; + private $defaultFetchMode = FetchMode::MIXED; /** * @param array $data @@ -57,9 +57,9 @@ public function columnCount() /** * {@inheritdoc} */ - public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) + public function setFetchMode($fetchMode, ...$args) { - if ($arg2 !== null || $arg3 !== null) { + if (count($args) > 0) { throw new \InvalidArgumentException("Caching layer does not support 2nd/3rd argument to setFetchMode()"); } @@ -81,34 +81,41 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, ...$args) { - if (isset($this->data[$this->num])) { - $row = $this->data[$this->num++]; - $fetchMode = $fetchMode ?: $this->defaultFetchMode; - if ($fetchMode === PDO::FETCH_ASSOC) { - return $row; - } elseif ($fetchMode === PDO::FETCH_NUM) { - return array_values($row); - } elseif ($fetchMode === PDO::FETCH_BOTH) { - return array_merge($row, array_values($row)); - } elseif ($fetchMode === PDO::FETCH_COLUMN) { - return reset($row); - } else { - throw new \InvalidArgumentException("Invalid fetch-style given for fetching result."); - } + if ( ! isset($this->data[$this->num])) { + return false; + } + + $row = $this->data[$this->num++]; + $fetchMode = $fetchMode ?: $this->defaultFetchMode; + + if ($fetchMode === FetchMode::ASSOCIATIVE) { + return $row; + } + + if ($fetchMode === FetchMode::NUMERIC) { + return array_values($row); } - return false; + if ($fetchMode === FetchMode::MIXED) { + return array_merge($row, array_values($row)); + } + + if ($fetchMode === FetchMode::COLUMN) { + return reset($row); + } + + throw new \InvalidArgumentException("Invalid fetch-style given for fetching result."); } /** * {@inheritdoc} */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + public function fetchAll($fetchMode = null, ...$args) { $rows = []; - while ($row = $this->fetch($fetchMode)) { + while ($row = $this->fetch($fetchMode, ...$args)) { $rows[] = $row; } @@ -120,7 +127,8 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n */ public function fetchColumn($columnIndex = 0) { - $row = $this->fetch(PDO::FETCH_NUM); + $row = $this->fetch(FetchMode::NUMERIC); + if (!isset($row[$columnIndex])) { // TODO: verify this is correct behavior return false; diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 6f026bd3116..a0a4b5227a3 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -5,7 +5,7 @@ use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\Common\Cache\Cache; -use PDO; +use Doctrine\DBAL\FetchMode; /** * Cache statement for SQL results. @@ -63,7 +63,7 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement /** * @var integer */ - private $defaultFetchMode = PDO::FETCH_BOTH; + private $defaultFetchMode = FetchMode::MIXED; /** * @param \Doctrine\DBAL\Driver\Statement $stmt @@ -110,7 +110,7 @@ public function columnCount() /** * {@inheritdoc} */ - public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) + public function setFetchMode($fetchMode, ...$args) { $this->defaultFetchMode = $fetchMode; @@ -130,30 +130,38 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, ...$args) { if ($this->data === null) { $this->data = []; } - $row = $this->statement->fetch(PDO::FETCH_ASSOC); + $row = $this->statement->fetch(FetchMode::ASSOCIATIVE); + if ($row) { $this->data[] = $row; $fetchMode = $fetchMode ?: $this->defaultFetchMode; - if ($fetchMode == PDO::FETCH_ASSOC) { + if ($fetchMode == FetchMode::ASSOCIATIVE) { return $row; - } elseif ($fetchMode == PDO::FETCH_NUM) { + } + + if ($fetchMode == FetchMode::NUMERIC) { return array_values($row); - } elseif ($fetchMode == PDO::FETCH_BOTH) { + } + + if ($fetchMode == FetchMode::MIXED) { return array_merge($row, array_values($row)); - } elseif ($fetchMode == PDO::FETCH_COLUMN) { + } + + if ($fetchMode == FetchMode::COLUMN) { return reset($row); - } else { - throw new \InvalidArgumentException("Invalid fetch-style given for caching result."); } + + throw new \InvalidArgumentException('Invalid fetch-style given for caching result.'); } + $this->emptied = true; return false; @@ -162,10 +170,10 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE /** * {@inheritdoc} */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + public function fetchAll($fetchMode = null, ...$args) { $rows = []; - while ($row = $this->fetch($fetchMode)) { + while ($row = $this->fetch($fetchMode, ...$args)) { $rows[] = $row; } @@ -177,7 +185,8 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n */ public function fetchColumn($columnIndex = 0) { - $row = $this->fetch(PDO::FETCH_NUM); + $row = $this->fetch(FetchMode::NUMERIC); + if (!isset($row[$columnIndex])) { // TODO: verify this is correct behavior return false; diff --git a/lib/Doctrine/DBAL/ColumnCase.php b/lib/Doctrine/DBAL/ColumnCase.php new file mode 100644 index 00000000000..181e84429e5 --- /dev/null +++ b/lib/Doctrine/DBAL/ColumnCase.php @@ -0,0 +1,30 @@ +executeQuery($statement, $params, $types)->fetch(PDO::FETCH_ASSOC); + return $this->executeQuery($statement, $params, $types)->fetch(FetchMode::ASSOCIATIVE); } /** @@ -553,7 +552,7 @@ public function fetchAssoc($statement, array $params = [], array $types = []) */ public function fetchArray($statement, array $params = [], array $types = []) { - return $this->executeQuery($statement, $params, $types)->fetch(PDO::FETCH_NUM); + return $this->executeQuery($statement, $params, $types)->fetch(FetchMode::NUMERIC); } /** @@ -785,7 +784,7 @@ private function extractTypeValues(array $columnList, array $types) foreach ($columnList as $columnIndex => $columnName) { $typeValues[] = isset($types[$columnName]) ? $types[$columnName] - : \PDO::PARAM_STR; + : ParameterType::STRING; } return $typeValues; @@ -1569,7 +1568,7 @@ private function getBindingInfo($value, $type) $value = $type->convertToDatabaseValue($value, $this->getDatabasePlatform()); $bindingType = $type->getBindingType(); } else { - $bindingType = $type; // PDO::PARAM_* constants + $bindingType = $type; } return [$value, $bindingType]; diff --git a/lib/Doctrine/DBAL/Driver/Connection.php b/lib/Doctrine/DBAL/Driver/Connection.php index 3185741607c..ef6c9e4006b 100644 --- a/lib/Doctrine/DBAL/Driver/Connection.php +++ b/lib/Doctrine/DBAL/Driver/Connection.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\ParameterType; + /** * Connection interface. * Driver connections must implement this interface. @@ -19,14 +21,14 @@ interface Connection * * @return \Doctrine\DBAL\Driver\Statement */ - function prepare($prepareString); + public function prepare($prepareString); /** * Executes an SQL statement, returning a result set as a Statement object. * * @return \Doctrine\DBAL\Driver\Statement */ - function query(); + public function query(); /** * Quotes a string for use in a query. @@ -36,7 +38,7 @@ function query(); * * @return mixed */ - function quote($input, $type=\PDO::PARAM_STR); + public function quote($input, $type = ParameterType::STRING); /** * Executes an SQL statement and return the number of affected rows. @@ -45,7 +47,7 @@ function quote($input, $type=\PDO::PARAM_STR); * * @return integer */ - function exec($statement); + public function exec($statement); /** * Returns the ID of the last inserted row or sequence value. @@ -54,40 +56,40 @@ function exec($statement); * * @return string */ - function lastInsertId($name = null); + public function lastInsertId($name = null); /** * Initiates a transaction. * * @return boolean TRUE on success or FALSE on failure. */ - function beginTransaction(); + public function beginTransaction(); /** * Commits a transaction. * * @return boolean TRUE on success or FALSE on failure. */ - function commit(); + public function commit(); /** * Rolls back the current transaction, as initiated by beginTransaction(). * * @return boolean TRUE on success or FALSE on failure. */ - function rollBack(); + public function rollBack(); /** * Returns the error code associated with the last operation on the database handle. * * @return string|null The error code, or null if no operation has been run on the database handle. */ - function errorCode(); + public function errorCode(); /** * Returns extended error information associated with the last operation on the database handle. * * @return array */ - function errorInfo(); + public function errorInfo(); } diff --git a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php index 89a6f065eca..7adfeb5158c 100644 --- a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php +++ b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL\Driver\DrizzlePDOMySql; +use Doctrine\DBAL\ParameterType; + /** * @author Kim Hemsø Rasmussen */ @@ -10,9 +12,9 @@ class Connection extends \Doctrine\DBAL\Driver\PDOConnection /** * {@inheritdoc} */ - public function quote($value, $type = \PDO::PARAM_STR) + public function quote($value, $type = ParameterType::STRING) { - if (\PDO::PARAM_BOOL === $type) { + if ($type === ParameterType::BOOLEAN) { if ($value) { return 'true'; } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index 37b80d39c52..8feeb39fae0 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; +use Doctrine\DBAL\ParameterType; class DB2Connection implements Connection, ServerInfoAwareConnection { @@ -81,10 +82,11 @@ public function query() /** * {@inheritdoc} */ - public function quote($input, $type=\PDO::PARAM_STR) + public function quote($input, $type = ParameterType::STRING) { $input = db2_escape_string($input); - if ($type == \PDO::PARAM_INT) { + + if ($type == ParameterType::INTEGER) { return $input; } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index b92c323ba31..e9eff7fb607 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -4,6 +4,8 @@ use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; class DB2Statement implements \IteratorAggregate, Statement { @@ -18,19 +20,19 @@ class DB2Statement implements \IteratorAggregate, Statement private $_bindParam = []; /** - * @var string Name of the default class to instantiate when fetch mode is \PDO::FETCH_CLASS. + * @var string Name of the default class to instantiate when fetching class instances. */ private $defaultFetchClass = '\stdClass'; /** - * @var string Constructor arguments for the default class to instantiate when fetch mode is \PDO::FETCH_CLASS. + * @var string Constructor arguments for the default class to instantiate when fetching class instances. */ private $defaultFetchClassCtorArgs = []; /** * @var integer */ - private $_defaultFetchMode = \PDO::FETCH_BOTH; + private $_defaultFetchMode = FetchMode::MIXED; /** * Indicates whether the statement is in the state when fetching results is possible @@ -45,8 +47,8 @@ class DB2Statement implements \IteratorAggregate, Statement * @var array */ static private $_typeMap = [ - \PDO::PARAM_INT => DB2_LONG, - \PDO::PARAM_STR => DB2_CHAR, + ParameterType::INTEGER => DB2_LONG, + ParameterType::STRING => DB2_CHAR, ]; /** @@ -60,7 +62,7 @@ public function __construct($stmt) /** * {@inheritdoc} */ - public function bindValue($param, $value, $type = null) + public function bindValue($param, $value, $type = ParameterType::STRING) { return $this->bindParam($param, $value, $type); } @@ -68,7 +70,7 @@ public function bindValue($param, $value, $type = null) /** * {@inheritdoc} */ - public function bindParam($column, &$variable, $type = null, $length = null) + public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { $this->_bindParam[$column] =& $variable; @@ -169,11 +171,17 @@ public function execute($params = null) /** * {@inheritdoc} */ - public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) + public function setFetchMode($fetchMode, ...$args) { - $this->_defaultFetchMode = $fetchMode; - $this->defaultFetchClass = $arg2 ? $arg2 : $this->defaultFetchClass; - $this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs; + $this->_defaultFetchMode = $fetchMode; + + if (isset($args[0])) { + $this->defaultFetchClass = $args[0]; + } + + if (isset($args[1])) { + $this->defaultFetchClassCtorArgs = (array) $args[2]; + } return true; } @@ -189,7 +197,7 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, ...$args) { // do not try fetching from the statement if it's not expected to contain result // in order to prevent exceptional situation @@ -199,18 +207,19 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $fetchMode = $fetchMode ?: $this->_defaultFetchMode; switch ($fetchMode) { - case \PDO::FETCH_BOTH: + case FetchMode::MIXED: return db2_fetch_both($this->_stmt); - case \PDO::FETCH_ASSOC: + + case FetchMode::ASSOCIATIVE: return db2_fetch_assoc($this->_stmt); - case \PDO::FETCH_CLASS: + + case FetchMode::CUSTOM_OBJECT: $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; - if (func_num_args() >= 2) { - $args = func_get_args(); - $className = $args[1]; - $ctorArgs = $args[2] ?? []; + if (count($args) > 0) { + $className = $args[0]; + $ctorArgs = $args[1] ?? []; } $result = db2_fetch_object($this->_stmt); @@ -220,10 +229,13 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE } return $result; - case \PDO::FETCH_NUM: + + case FetchMode::NUMERIC: return db2_fetch_array($this->_stmt); - case \PDO::FETCH_OBJ: + + case FetchMode::STANDARD_OBJECT: return db2_fetch_object($this->_stmt); + default: throw new DB2Exception('Given Fetch-Style ' . $fetchMode . ' is not supported.'); } @@ -232,23 +244,23 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE /** * {@inheritdoc} */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + public function fetchAll($fetchMode = null, ...$args) { $rows = []; switch ($fetchMode) { - case \PDO::FETCH_CLASS: - while ($row = call_user_func_array([$this, 'fetch'], func_get_args())) { + case FetchMode::CUSTOM_OBJECT: + while (($row = $this->fetch($fetchMode, ...$args)) !== false) { $rows[] = $row; } break; - case \PDO::FETCH_COLUMN: - while ($row = $this->fetchColumn()) { + case FetchMode::COLUMN: + while (($row = $this->fetchColumn()) !== false) { $rows[] = $row; } break; default: - while ($row = $this->fetch($fetchMode)) { + while (($row = $this->fetch($fetchMode)) !== false) { $rows[] = $row; } } @@ -261,7 +273,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n */ public function fetchColumn($columnIndex = 0) { - $row = $this->fetch(\PDO::FETCH_NUM); + $row = $this->fetch(FetchMode::NUMERIC); if (false === $row) { return false; diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index bda4acfa133..fce1a44776b 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Driver\Connection as Connection; use Doctrine\DBAL\Driver\PingableConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; +use Doctrine\DBAL\ParameterType; /** * @author Kim Hemsø Rasmussen @@ -128,7 +129,7 @@ public function query() /** * {@inheritdoc} */ - public function quote($input, $type=\PDO::PARAM_STR) + public function quote($input, $type = ParameterType::STRING) { return "'". $this->_conn->escape_string($input) ."'"; } diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index a26c0bdd018..f0623e77b92 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -4,7 +4,8 @@ use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; -use PDO; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; /** * @author Kim Hemsø Rasmussen @@ -15,11 +16,11 @@ class MysqliStatement implements \IteratorAggregate, Statement * @var array */ protected static $_paramTypeMap = [ - PDO::PARAM_STR => 's', - PDO::PARAM_BOOL => 'i', - PDO::PARAM_NULL => 's', - PDO::PARAM_INT => 'i', - PDO::PARAM_LOB => 's' // TODO Support LOB bigger then max package size. + ParameterType::STRING => 's', + ParameterType::BOOLEAN => 'i', + ParameterType::NULL => 's', + ParameterType::INTEGER => 'i', + ParameterType::LARGE_OBJECT => 's' // TODO Support LOB bigger then max package size. ]; /** @@ -62,7 +63,7 @@ class MysqliStatement implements \IteratorAggregate, Statement /** * @var integer */ - protected $_defaultFetchMode = PDO::FETCH_BOTH; + protected $_defaultFetchMode = FetchMode::MIXED; /** * Indicates whether the statement is in the state when fetching results is possible @@ -95,7 +96,7 @@ public function __construct(\mysqli $conn, $prepareString) /** * {@inheritdoc} */ - public function bindParam($column, &$variable, $type = null, $length = null) + public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { if (null === $type) { $type = 's'; @@ -116,7 +117,7 @@ public function bindParam($column, &$variable, $type = null, $length = null) /** * {@inheritdoc} */ - public function bindValue($param, $value, $type = null) + public function bindValue($param, $value, $type = ParameterType::STRING) { if (null === $type) { $type = 's'; @@ -247,7 +248,7 @@ private function _fetch() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, ...$args) { // do not try fetching from the statement if it's not expected to contain result // in order to prevent exceptional situation @@ -267,19 +268,19 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $fetchMode = $fetchMode ?: $this->_defaultFetchMode; switch ($fetchMode) { - case PDO::FETCH_NUM: + case FetchMode::NUMERIC: return $values; - case PDO::FETCH_ASSOC: + case FetchMode::ASSOCIATIVE: return array_combine($this->_columnNames, $values); - case PDO::FETCH_BOTH: + case FetchMode::MIXED: $ret = array_combine($this->_columnNames, $values); $ret += $values; return $ret; - case PDO::FETCH_OBJ: + case FetchMode::STANDARD_OBJECT: $assoc = array_combine($this->_columnNames, $values); $ret = new \stdClass(); @@ -297,12 +298,13 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE /** * {@inheritdoc} */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + public function fetchAll($fetchMode = null, ...$args) { $fetchMode = $fetchMode ?: $this->_defaultFetchMode; $rows = []; - if (PDO::FETCH_COLUMN == $fetchMode) { + + if ($fetchMode === FetchMode::COLUMN) { while (($row = $this->fetchColumn()) !== false) { $rows[] = $row; } @@ -320,7 +322,8 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n */ public function fetchColumn($columnIndex = 0) { - $row = $this->fetch(PDO::FETCH_NUM); + $row = $this->fetch(FetchMode::NUMERIC); + if (false === $row) { return false; } @@ -378,7 +381,7 @@ public function columnCount() /** * {@inheritdoc} */ - public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) + public function setFetchMode($fetchMode, ...$args) { $this->_defaultFetchMode = $fetchMode; diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index e168d2d240b..928a140be6e 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; +use Doctrine\DBAL\ParameterType; /** * OCI8 implementation of the Connection interface. @@ -103,7 +104,7 @@ public function query() /** * {@inheritdoc} */ - public function quote($value, $type=\PDO::PARAM_STR) + public function quote($value, $type = ParameterType::STRING) { if (is_int($value) || is_float($value)) { return $value; @@ -135,13 +136,13 @@ public function lastInsertId($name = null) $sql = 'SELECT ' . $name . '.CURRVAL FROM DUAL'; $stmt = $this->query($sql); - $result = $stmt->fetch(\PDO::FETCH_ASSOC); + $result = $stmt->fetchColumn(); - if ($result === false || !isset($result['CURRVAL'])) { + if ($result === false) { throw new OCI8Exception("lastInsertId failed: Query was executed but no result was returned."); } - return (int) $result['CURRVAL']; + return (int) $result; } /** diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index bf50d62e245..64a714c0659 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -4,8 +4,9 @@ use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; use IteratorAggregate; -use PDO; /** * The OCI8 implementation of the Statement interface. @@ -39,16 +40,16 @@ class OCI8Statement implements IteratorAggregate, Statement * @var array */ protected static $fetchModeMap = [ - PDO::FETCH_BOTH => OCI_BOTH, - PDO::FETCH_ASSOC => OCI_ASSOC, - PDO::FETCH_NUM => OCI_NUM, - PDO::FETCH_COLUMN => OCI_NUM, + FetchMode::MIXED => OCI_BOTH, + FetchMode::ASSOCIATIVE => OCI_ASSOC, + FetchMode::NUMERIC => OCI_NUM, + FetchMode::COLUMN => OCI_NUM, ]; /** * @var integer */ - protected $_defaultFetchMode = PDO::FETCH_BOTH; + protected $_defaultFetchMode = FetchMode::MIXED; /** * @var array @@ -237,7 +238,7 @@ private static function findToken($statement, &$offset, $regex) /** * {@inheritdoc} */ - public function bindValue($param, $value, $type = null) + public function bindValue($param, $value, $type = ParameterType::STRING) { return $this->bindParam($param, $value, $type, null); } @@ -245,11 +246,11 @@ public function bindValue($param, $value, $type = null) /** * {@inheritdoc} */ - public function bindParam($column, &$variable, $type = null, $length = null) + public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { $column = $this->_paramMap[$column] ?? $column; - if ($type == \PDO::PARAM_LOB) { + if ($type == ParameterType::LARGE_OBJECT) { $lob = oci_new_descriptor($this->_dbh, OCI_D_LOB); $lob->writeTemporary($variable, OCI_TEMP_BLOB); @@ -342,7 +343,7 @@ public function execute($params = null) /** * {@inheritdoc} */ - public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) + public function setFetchMode($fetchMode, ...$args) { $this->_defaultFetchMode = $fetchMode; @@ -360,7 +361,7 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, ...$args) { // do not try fetching from the statement if it's not expected to contain result // in order to prevent exceptional situation @@ -370,7 +371,7 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $fetchMode = $fetchMode ?: $this->_defaultFetchMode; - if (PDO::FETCH_OBJ == $fetchMode) { + if ($fetchMode == FetchMode::STANDARD_OBJECT) { return oci_fetch_object($this->_sth); } @@ -387,13 +388,13 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE /** * {@inheritdoc} */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + public function fetchAll($fetchMode = null, ...$args) { $fetchMode = $fetchMode ?: $this->_defaultFetchMode; $result = []; - if (PDO::FETCH_OBJ == $fetchMode) { + if ($fetchMode == FetchMode::STANDARD_OBJECT) { while ($row = $this->fetch($fetchMode)) { $result[] = $row; } @@ -411,7 +412,8 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n } } else { $fetchStructure = OCI_FETCHSTATEMENT_BY_ROW; - if ($fetchMode == PDO::FETCH_COLUMN) { + + if ($fetchMode == FetchMode::COLUMN) { $fetchStructure = OCI_FETCHSTATEMENT_BY_COLUMN; } @@ -424,7 +426,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n oci_fetch_all($this->_sth, $result, 0, -1, self::$fetchModeMap[$fetchMode] | OCI_RETURN_NULLS | $fetchStructure | OCI_RETURN_LOBS); - if ($fetchMode == PDO::FETCH_COLUMN) { + if ($fetchMode == FetchMode::COLUMN) { $result = $result[0]; } } diff --git a/lib/Doctrine/DBAL/Driver/PDOConnection.php b/lib/Doctrine/DBAL/Driver/PDOConnection.php index 4c67c83fb51..24e369065d7 100644 --- a/lib/Doctrine/DBAL/Driver/PDOConnection.php +++ b/lib/Doctrine/DBAL/Driver/PDOConnection.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\ParameterType; use PDO; /** @@ -24,7 +25,6 @@ public function __construct($dsn, $user = null, $password = null, array $options { try { parent::__construct($dsn, $user, $password, $options); - $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, ['Doctrine\DBAL\Driver\PDOStatement', []]); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (\PDOException $exception) { throw new PDOException($exception); @@ -57,7 +57,9 @@ public function getServerVersion() public function prepare($prepareString, $driverOptions = []) { try { - return parent::prepare($prepareString, $driverOptions); + return $this->createStatement( + parent::prepare($prepareString, $driverOptions) + ); } catch (\PDOException $exception) { throw new PDOException($exception); } @@ -69,22 +71,11 @@ public function prepare($prepareString, $driverOptions = []) public function query() { $args = func_get_args(); - $argsCount = count($args); try { - if ($argsCount == 4) { - return parent::query($args[0], $args[1], $args[2], $args[3]); - } - - if ($argsCount == 3) { - return parent::query($args[0], $args[1], $args[2]); - } - - if ($argsCount == 2) { - return parent::query($args[0], $args[1]); - } - - return parent::query($args[0]); + return $this->createStatement( + parent::query(...$args) + ); } catch (\PDOException $exception) { throw new PDOException($exception); } @@ -93,7 +84,7 @@ public function query() /** * {@inheritdoc} */ - public function quote($input, $type = \PDO::PARAM_STR) + public function quote($input, $type = ParameterType::STRING) { return parent::quote($input, $type); } @@ -113,4 +104,15 @@ public function requiresQueryForServerVersion() { return false; } + + /** + * Creates a wrapped statement + * + * @param \PDOStatement $stmt + * @return PDOStatement + */ + private function createStatement(\PDOStatement $stmt) : PDOStatement + { + return new PDOStatement($stmt); + } } diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php index ea198c7033f..e7b7ed9b74e 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv; use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\ParameterType; /** * Sqlsrv Connection implementation. @@ -38,7 +39,7 @@ public function lastInsertId($name = null) /** * {@inheritDoc} */ - public function quote($value, $type=\PDO::PARAM_STR) + public function quote($value, $type = ParameterType::STRING) { $val = parent::quote($value, $type); diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php index d8538defde0..8af01d1fb51 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv; use Doctrine\DBAL\Driver\PDOStatement; +use Doctrine\DBAL\ParameterType; use PDO; /** @@ -13,9 +14,9 @@ class Statement extends PDOStatement /** * {@inheritdoc} */ - public function bindParam($column, &$variable, $type = PDO::PARAM_STR, $length = null, $driverOptions = null) + public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null) { - if ($type === PDO::PARAM_LOB && $driverOptions === null) { + if ($type === ParameterType::LARGE_OBJECT && $driverOptions === null) { $driverOptions = PDO::SQLSRV_ENCODING_BINARY; } @@ -25,7 +26,7 @@ public function bindParam($column, &$variable, $type = PDO::PARAM_STR, $length = /** * {@inheritdoc} */ - public function bindValue($param, $value, $type = PDO::PARAM_STR) + public function bindValue($param, $value, $type = ParameterType::STRING) { return $this->bindParam($param, $value, $type); } diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index 5a951700fcb..fb6ec3fc122 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -2,40 +2,61 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; +use IteratorAggregate; +use PDO; + /** * The PDO implementation of the Statement interface. * Used by all PDO-based drivers. * * @since 2.0 */ -class PDOStatement extends \PDOStatement implements Statement +class PDOStatement implements IteratorAggregate, Statement { /** - * Protected constructor. + * @var int[] */ - protected function __construct() + private const PARAM_TYPE_MAP = [ + ParameterType::NULL => PDO::PARAM_NULL, + ParameterType::INTEGER => PDO::PARAM_INT, + ParameterType::STRING => PDO::PARAM_STR, + ParameterType::LARGE_OBJECT => PDO::PARAM_LOB, + ParameterType::BOOLEAN => PDO::PARAM_BOOL, + ]; + + /** + * @var int[] + */ + private const FETCH_MODE_MAP = [ + FetchMode::ASSOCIATIVE => PDO::FETCH_ASSOC, + FetchMode::NUMERIC => PDO::FETCH_NUM, + FetchMode::MIXED => PDO::FETCH_BOTH, + FetchMode::STANDARD_OBJECT => PDO::FETCH_OBJ, + FetchMode::COLUMN => PDO::FETCH_COLUMN, + FetchMode::CUSTOM_OBJECT => PDO::FETCH_CLASS, + ]; + + /** + * @var \PDOStatement + */ + private $stmt; + + public function __construct(\PDOStatement $stmt) { + $this->stmt = $stmt; } /** * {@inheritdoc} */ - public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) + public function setFetchMode($fetchMode, ...$args) { - // This thin wrapper is necessary to shield against the weird signature - // of PDOStatement::setFetchMode(): even if the second and third - // parameters are optional, PHP will not let us remove it from this - // declaration. - try { - if ($arg2 === null && $arg3 === null) { - return parent::setFetchMode($fetchMode); - } - - if ($arg3 === null) { - return parent::setFetchMode($fetchMode, $arg2); - } + $fetchMode = $this->convertFetchMode($fetchMode); - return parent::setFetchMode($fetchMode, $arg2, $arg3); + try { + return $this->stmt->setFetchMode($fetchMode, ...$args); } catch (\PDOException $exception) { throw new PDOException($exception); } @@ -44,10 +65,12 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) /** * {@inheritdoc} */ - public function bindValue($param, $value, $type = \PDO::PARAM_STR) + public function bindValue($param, $value, $type = ParameterType::STRING) { + $type = $this->convertParamType($type); + try { - return parent::bindValue($param, $value, $type); + return $this->stmt->bindValue($param, $value, $type); } catch (\PDOException $exception) { throw new PDOException($exception); } @@ -56,10 +79,12 @@ public function bindValue($param, $value, $type = \PDO::PARAM_STR) /** * {@inheritdoc} */ - public function bindParam($column, &$variable, $type = \PDO::PARAM_STR, $length = null, $driverOptions = null) + public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null) { + $type = $this->convertParamType($type); + try { - return parent::bindParam($column, $variable, $type, $length, $driverOptions); + return $this->stmt->bindParam($column, $variable, $type, $length, $driverOptions); } catch (\PDOException $exception) { throw new PDOException($exception); } @@ -71,7 +96,7 @@ public function bindParam($column, &$variable, $type = \PDO::PARAM_STR, $length public function closeCursor() { try { - return parent::closeCursor(); + return $this->stmt->closeCursor(); } catch (\PDOException $exception) { // Exceptions not allowed by the interface. // In case driver implementations do not adhere to the interface, silence exceptions here. @@ -79,13 +104,37 @@ public function closeCursor() } } + /** + * {@inheritdoc} + */ + public function columnCount() + { + return $this->stmt->columnCount(); + } + + /** + * {@inheritdoc} + */ + public function errorCode() + { + return $this->stmt->errorCode(); + } + + /** + * {@inheritdoc} + */ + public function errorInfo() + { + return $this->stmt->errorInfo(); + } + /** * {@inheritdoc} */ public function execute($params = null) { try { - return parent::execute($params); + return $this->stmt->execute($params); } catch (\PDOException $exception) { throw new PDOException($exception); } @@ -94,22 +143,24 @@ public function execute($params = null) /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function rowCount() { - try { - if ($fetchMode === null && \PDO::FETCH_ORI_NEXT === $cursorOrientation && 0 === $cursorOffset) { - return parent::fetch(); - } + return $this->stmt->rowCount(); + } - if (\PDO::FETCH_ORI_NEXT === $cursorOrientation && 0 === $cursorOffset) { - return parent::fetch($fetchMode); - } + /** + * {@inheritdoc} + */ + public function fetch($fetchMode = null, ...$args) + { + $fetchMode = $this->convertFetchMode($fetchMode); - if (0 === $cursorOffset) { - return parent::fetch($fetchMode, $cursorOrientation); + try { + if ($fetchMode === null) { + return $this->stmt->fetch(); } - return parent::fetch($fetchMode, $cursorOrientation, $cursorOffset); + return $this->stmt->fetch($fetchMode, ...$args); } catch (\PDOException $exception) { throw new PDOException($exception); } @@ -118,22 +169,16 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE /** * {@inheritdoc} */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + public function fetchAll($fetchMode = null, ...$args) { - try { - if ($fetchMode === null && null === $fetchArgument && null === $ctorArgs) { - return parent::fetchAll(); - } + $fetchMode = $this->convertFetchMode($fetchMode); - if (null === $fetchArgument && null === $ctorArgs) { - return parent::fetchAll($fetchMode); - } - - if (null === $ctorArgs) { - return parent::fetchAll($fetchMode, $fetchArgument); + try { + if ($fetchMode === null) { + return $this->stmt->fetchAll(); } - return parent::fetchAll($fetchMode, $fetchArgument, $ctorArgs); + return $this->stmt->fetchAll($fetchMode, ...$args); } catch (\PDOException $exception) { throw new PDOException($exception); } @@ -145,9 +190,51 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n public function fetchColumn($columnIndex = 0) { try { - return parent::fetchColumn($columnIndex); + return $this->stmt->fetchColumn($columnIndex); } catch (\PDOException $exception) { throw new PDOException($exception); } } + + /** + * Converts DBAL parameter type to PDO parameter type + * + * @param int $type Parameter type + * @return int + */ + private function convertParamType(int $type) : int + { + if ( ! isset(self::PARAM_TYPE_MAP[$type])) { + throw new \InvalidArgumentException('Invalid parameter type: ' . $type); + } + + return self::PARAM_TYPE_MAP[$type]; + } + + /** + * Converts DBAL fetch mode to PDO fetch mode + * + * @param int|null $fetchMode Fetch mode + * @return int|null + */ + private function convertFetchMode(?int $fetchMode) : ?int + { + if ($fetchMode === null) { + return null; + } + + if ( ! isset(self::FETCH_MODE_MAP[$fetchMode])) { + throw new \InvalidArgumentException('Invalid fetch mode: ' . $fetchMode); + } + + return self::FETCH_MODE_MAP[$fetchMode]; + } + + /** + * {@inheritdoc} + */ + public function getIterator() + { + yield from $this->stmt; + } } diff --git a/lib/Doctrine/DBAL/Driver/ResultStatement.php b/lib/Doctrine/DBAL/Driver/ResultStatement.php index bd30e6ac311..f8715afd40e 100644 --- a/lib/Doctrine/DBAL/Driver/ResultStatement.php +++ b/lib/Doctrine/DBAL/Driver/ResultStatement.php @@ -28,66 +28,43 @@ public function columnCount(); /** * Sets the fetch mode to use while iterating this statement. * - * @param integer $fetchMode The fetch mode must be one of the PDO::FETCH_* constants. - * @param mixed $arg2 - * @param mixed $arg3 + * @param int $fetchMode Controls how the next row will be returned to the caller. + * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants. + * @param array $args Optional mode-specific arguments (see {@link self::fetchAll()}). * * @return boolean - * - * @see PDO::FETCH_* constants. */ - public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null); + public function setFetchMode($fetchMode, ...$args); /** * Returns the next row of a result set. * * @param int|null $fetchMode Controls how the next row will be returned to the caller. - * The value must be one of the \PDO::FETCH_* constants, - * defaulting to \PDO::FETCH_BOTH. - * @param int $cursorOrientation For a ResultStatement object representing a scrollable cursor, - * this value determines which row will be returned to the caller. - * This value must be one of the \PDO::FETCH_ORI_* constants, - * defaulting to \PDO::FETCH_ORI_NEXT. To request a scrollable - * cursor for your ResultStatement object, you must set the \PDO::ATTR_CURSOR - * attribute to \PDO::CURSOR_SCROLL when you prepare the SQL statement with - * \PDO::prepare(). - * @param int $cursorOffset For a ResultStatement object representing a scrollable cursor for which the - * cursorOrientation parameter is set to \PDO::FETCH_ORI_ABS, this value - * specifies the absolute number of the row in the result set that shall be - * fetched. - * For a ResultStatement object representing a scrollable cursor for which the - * cursorOrientation parameter is set to \PDO::FETCH_ORI_REL, this value - * specifies the row to fetch relative to the cursor position before - * ResultStatement::fetch() was called. + * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants, + * defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}. + * @param array $args Optional mode-specific arguments (see {@link self::fetchAll()}). * * @return mixed The return value of this method on success depends on the fetch mode. In all cases, FALSE is * returned on failure. - * - * @see PDO::FETCH_* constants. */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0); + public function fetch($fetchMode = null, ...$args); /** * Returns an array containing all of the result set rows. * * @param int|null $fetchMode Controls how the next row will be returned to the caller. - * The value must be one of the \PDO::FETCH_* constants, - * defaulting to \PDO::FETCH_BOTH. - * @param int|null $fetchArgument This argument has a different meaning depending on the value of the $fetchMode parameter: - * * \PDO::FETCH_COLUMN: Returns the indicated 0-indexed column. - * * \PDO::FETCH_CLASS: Returns instances of the specified class, mapping the columns of each - * row to named properties in the class. - * * \PDO::FETCH_FUNC: Returns the results of calling the specified function, using each row's - * columns as parameters in the call. - * @param array|null $ctorArgs Controls how the next row will be returned to the caller. - * The value must be one of the \PDO::FETCH_* constants, - * defaulting to \PDO::FETCH_BOTH. + * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants, + * defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}. + * @param array $args Optional mode-specific arguments. Supported modes: + * * {@link \Doctrine\DBAL\FetchMode::COLUMN} + * 1. The 0-indexed column to be returned. + * * {@link \Doctrine\DBAL\FetchMode::CUSTOM_OBJECT} + * 1. The class name of the object to be created, + * 2. Array of constructor arguments * * @return array - * - * @see \PDO::FETCH_* constants. */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null); + public function fetchAll($fetchMode = null, ...$args); /** * Returns a single column from the next row of a result set or FALSE if there are no more rows. diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php index dd8ced8aee3..dce6af30c72 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; +use Doctrine\DBAL\ParameterType; /** * SAP Sybase SQL Anywhere implementation of the Connection interface. @@ -155,7 +156,7 @@ public function query() /** * {@inheritdoc} */ - public function quote($input, $type = \PDO::PARAM_STR) + public function quote($input, $type = ParameterType::STRING) { if (is_int($input) || is_float($input)) { return $input; diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index ef2db942d84..80116eb24f8 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -2,10 +2,11 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere; +use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; use IteratorAggregate; -use PDO; -use Doctrine\DBAL\Driver\Statement; /** * SAP SQL Anywhere implementation of the Statement interface. @@ -22,19 +23,19 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement private $conn; /** - * @var string Name of the default class to instantiate when fetch mode is \PDO::FETCH_CLASS. + * @var string Name of the default class to instantiate when fetching class instances. */ private $defaultFetchClass = '\stdClass'; /** - * @var string Constructor arguments for the default class to instantiate when fetch mode is \PDO::FETCH_CLASS. + * @var string Constructor arguments for the default class to instantiate when fetching class instances. */ private $defaultFetchClassCtorArgs = []; /** * @var int Default fetch mode to use. */ - private $defaultFetchMode = PDO::FETCH_BOTH; + private $defaultFetchMode = FetchMode::MIXED; /** * @var resource The result set resource to fetch. @@ -75,20 +76,23 @@ public function __construct($conn, $sql) * * @throws SQLAnywhereException */ - public function bindParam($column, &$variable, $type = null, $length = null) + public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { switch ($type) { - case PDO::PARAM_INT: - case PDO::PARAM_BOOL: + case ParameterType::INTEGER: + case ParameterType::BOOLEAN: $type = 'i'; break; - case PDO::PARAM_LOB: + + case ParameterType::LARGE_OBJECT: $type = 'b'; break; - case PDO::PARAM_NULL: - case PDO::PARAM_STR: + + case ParameterType::NULL: + case ParameterType::STRING: $type = 's'; break; + default: throw new SQLAnywhereException('Unknown type: ' . $type); } @@ -103,7 +107,7 @@ public function bindParam($column, &$variable, $type = null, $length = null) /** * {@inheritdoc} */ - public function bindValue($param, $value, $type = null) + public function bindValue($param, $value, $type = ParameterType::STRING) { return $this->bindParam($param, $value, $type); } @@ -177,7 +181,7 @@ public function execute($params = null) * * @throws SQLAnywhereException */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, ...$args) { if ( ! is_resource($this->result)) { return false; @@ -186,18 +190,19 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $fetchMode = $fetchMode ?: $this->defaultFetchMode; switch ($fetchMode) { - case PDO::FETCH_ASSOC: + case FetchMode::ASSOCIATIVE: return sasql_fetch_assoc($this->result); - case PDO::FETCH_BOTH: + + case FetchMode::MIXED: return sasql_fetch_array($this->result, SASQL_BOTH); - case PDO::FETCH_CLASS: + + case FetchMode::CUSTOM_OBJECT: $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; - if (func_num_args() >= 2) { - $args = func_get_args(); - $className = $args[1]; - $ctorArgs = isset($args[2]) ? $args[2] : []; + if (count($args) > 0) { + $className = $args[0]; + $ctorArgs = $args[1] ?? []; } $result = sasql_fetch_object($this->result); @@ -207,10 +212,13 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE } return $result; - case PDO::FETCH_NUM: + + case FetchMode::NUMERIC: return sasql_fetch_row($this->result); - case PDO::FETCH_OBJ: + + case FetchMode::STANDARD_OBJECT: return sasql_fetch_object($this->result); + default: throw new SQLAnywhereException('Fetch mode is not supported: ' . $fetchMode); } @@ -219,23 +227,25 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE /** * {@inheritdoc} */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + public function fetchAll($fetchMode = null, ...$args) { $rows = []; switch ($fetchMode) { - case PDO::FETCH_CLASS: - while ($row = call_user_func_array([$this, 'fetch'], func_get_args())) { + case FetchMode::CUSTOM_OBJECT: + while (($row = $this->fetch($fetchMode, ...$args)) !== false) { $rows[] = $row; } break; - case PDO::FETCH_COLUMN: - while ($row = $this->fetchColumn()) { + + case FetchMode::COLUMN: + while (($row = $this->fetchColumn()) !== false) { $rows[] = $row; } break; + default: - while ($row = $this->fetch($fetchMode)) { + while (($row = $this->fetch($fetchMode)) !== false) { $rows[] = $row; } } @@ -248,7 +258,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n */ public function fetchColumn($columnIndex = 0) { - $row = $this->fetch(PDO::FETCH_NUM); + $row = $this->fetch(FetchMode::NUMERIC); if (false === $row) { return false; @@ -276,7 +286,7 @@ public function rowCount() /** * {@inheritdoc} */ - public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) + public function setFetchMode($fetchMode, ...$args) { $this->defaultFetchMode = $fetchMode; $this->defaultFetchClass = $arg2 ? $arg2 : $this->defaultFetchClass; diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index 3dc303babf3..3f3bc879bcd 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; +use Doctrine\DBAL\ParameterType; /** * SQL Server implementation for the Connection interface. @@ -85,7 +86,7 @@ public function query() * {@inheritDoc} * @license New BSD, code from Zend Framework */ - public function quote($value, $type=\PDO::PARAM_STR) + public function quote($value, $type = ParameterType::STRING) { if (is_int($value)) { return $value; diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index feb6cd69b28..841a79462b3 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -3,7 +3,8 @@ namespace Doctrine\DBAL\Driver\SQLSrv; use Doctrine\DBAL\Driver\StatementIterator; -use PDO; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; use IteratorAggregate; use Doctrine\DBAL\Driver\Statement; @@ -56,20 +57,20 @@ class SQLSrvStatement implements IteratorAggregate, Statement * @var array */ private static $fetchMap = [ - PDO::FETCH_BOTH => SQLSRV_FETCH_BOTH, - PDO::FETCH_ASSOC => SQLSRV_FETCH_ASSOC, - PDO::FETCH_NUM => SQLSRV_FETCH_NUMERIC, + FetchMode::MIXED => SQLSRV_FETCH_BOTH, + FetchMode::ASSOCIATIVE => SQLSRV_FETCH_ASSOC, + FetchMode::NUMERIC => SQLSRV_FETCH_NUMERIC, ]; /** - * The name of the default class to instantiate when fetch mode is \PDO::FETCH_CLASS. + * The name of the default class to instantiate when fetching class instances. * * @var string */ private $defaultFetchClass = '\stdClass'; /** - * The constructor arguments for the default class to instantiate when fetch mode is \PDO::FETCH_CLASS. + * The constructor arguments for the default class to instantiate when fetching class instances. * * @var string */ @@ -80,7 +81,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement * * @param integer */ - private $defaultFetchMode = PDO::FETCH_BOTH; + private $defaultFetchMode = FetchMode::MIXED; /** * The last insert ID. @@ -122,7 +123,7 @@ public function __construct($conn, $sql, LastInsertId $lastInsertId = null) /** * {@inheritdoc} */ - public function bindValue($param, $value, $type = null) + public function bindValue($param, $value, $type = ParameterType::STRING) { if (!is_numeric($param)) { throw new SQLSrvException( @@ -137,7 +138,7 @@ public function bindValue($param, $value, $type = null) /** * {@inheritdoc} */ - public function bindParam($column, &$variable, $type = null, $length = null) + public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { if (!is_numeric($column)) { throw new SQLSrvException("sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead."); @@ -241,7 +242,7 @@ private function prepare() $params = []; foreach ($this->variables as $column => &$variable) { - if (PDO::PARAM_LOB === $this->types[$column]) { + if ($this->types[$column] === ParameterType::LARGE_OBJECT) { $params[$column - 1] = [ &$variable, SQLSRV_PARAM_IN, @@ -265,11 +266,17 @@ private function prepare() /** * {@inheritdoc} */ - public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) + public function setFetchMode($fetchMode, ...$args) { - $this->defaultFetchMode = $fetchMode; - $this->defaultFetchClass = $arg2 ?: $this->defaultFetchClass; - $this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs; + $this->defaultFetchMode = $fetchMode; + + if (isset($args[0])) { + $this->defaultFetchClass = $args[0]; + } + + if (isset($args[1])) { + $this->defaultFetchClassCtorArgs = (array) $args[2]; + } return true; } @@ -287,7 +294,7 @@ public function getIterator() * * @throws SQLSrvException */ - public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, ...$args) { // do not try fetching from the statement if it's not expected to contain result // in order to prevent exceptional situation @@ -295,20 +302,19 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX return false; } - $args = func_get_args(); $fetchMode = $fetchMode ?: $this->defaultFetchMode; if (isset(self::$fetchMap[$fetchMode])) { return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchMode]) ?: false; } - if (in_array($fetchMode, [PDO::FETCH_OBJ, PDO::FETCH_CLASS], true)) { + if (in_array($fetchMode, [FetchMode::STANDARD_OBJECT, FetchMode::CUSTOM_OBJECT], true)) { $className = $this->defaultFetchClass; $ctorArgs = $this->defaultFetchClassCtorArgs; - if (count($args) >= 2) { - $className = $args[1]; - $ctorArgs = isset($args[2]) ? $args[2] : []; + if (count($args) > 0) { + $className = $args[0]; + $ctorArgs = $args[1] ?? []; } return sqlsrv_fetch_object($this->stmt, $className, $ctorArgs) ?: false; @@ -320,23 +326,25 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX /** * {@inheritdoc} */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + public function fetchAll($fetchMode = null, ...$args) { $rows = []; switch ($fetchMode) { - case PDO::FETCH_CLASS: - while ($row = call_user_func_array([$this, 'fetch'], func_get_args())) { + case FetchMode::CUSTOM_OBJECT: + while (($row = $this->fetch($fetchMode, $args)) !== false) { $rows[] = $row; } break; - case PDO::FETCH_COLUMN: - while ($row = $this->fetchColumn()) { + + case FetchMode::COLUMN: + while (($row = $this->fetchColumn()) !== false) { $rows[] = $row; } break; + default: - while ($row = $this->fetch($fetchMode)) { + while (($row = $this->fetch($fetchMode)) !== false) { $rows[] = $row; } } @@ -349,7 +357,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n */ public function fetchColumn($columnIndex = 0) { - $row = $this->fetch(PDO::FETCH_NUM); + $row = $this->fetch(FetchMode::NUMERIC); if (false === $row) { return false; diff --git a/lib/Doctrine/DBAL/Driver/Statement.php b/lib/Doctrine/DBAL/Driver/Statement.php index f9ee4d820a1..4f1655aa89e 100644 --- a/lib/Doctrine/DBAL/Driver/Statement.php +++ b/lib/Doctrine/DBAL/Driver/Statement.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\ParameterType; + /** * Statement interface. * Drivers must implement this interface. @@ -26,12 +28,12 @@ interface Statement extends ResultStatement * 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 PDO::PARAM_* constants. + * @param integer $type Explicit data type for the parameter using the {@link \Doctrine\DBAL\ParameterType} + * constants. * * @return boolean TRUE on success or FALSE on failure. */ - function bindValue($param, $value, $type = null); - + public function bindValue($param, $value, $type = ParameterType::STRING); /** * Binds a PHP variable to a corresponding named (not supported by mysqli driver, see comment below) or question @@ -51,15 +53,14 @@ function bindValue($param, $value, $type = null); * 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|null $type Explicit data type for the parameter using the PDO::PARAM_* constants. To return - * an INOUT parameter from a stored procedure, use the bitwise OR operator to set the - * PDO::PARAM_INPUT_OUTPUT bits for the data_type parameter. + * @param integer|null $type Explicit data type for the parameter using the {@link \Doctrine\DBAL\ParameterType} + * constants. * @param integer|null $length You must specify maxlength when using an OUT bind * so that PHP allocates enough memory to hold the returned value. * * @return boolean TRUE on success or FALSE on failure. */ - function bindParam($column, &$variable, $type = null, $length = null); + public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null); /** * Fetches the SQLSTATE associated with the last operation on the statement handle. @@ -68,7 +69,7 @@ function bindParam($column, &$variable, $type = null, $length = null); * * @return string The error code string. */ - function errorCode(); + public function errorCode(); /** * Fetches extended error information associated with the last operation on the statement handle. @@ -77,7 +78,7 @@ function errorCode(); * * @return array The error info array. */ - function errorInfo(); + public function errorInfo(); /** * Executes a prepared statement @@ -94,7 +95,7 @@ function errorInfo(); * * @return boolean TRUE on success or FALSE on failure. */ - function execute($params = null); + public function execute($params = null); /** * Returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement @@ -107,5 +108,5 @@ function execute($params = null); * * @return integer The number of rows. */ - function rowCount(); + public function rowCount(); } diff --git a/lib/Doctrine/DBAL/FetchMode.php b/lib/Doctrine/DBAL/FetchMode.php new file mode 100644 index 00000000000..ca5302ba531 --- /dev/null +++ b/lib/Doctrine/DBAL/FetchMode.php @@ -0,0 +1,69 @@ +getWriteLockSQL(); $stmt = $this->conn->executeQuery($sql, [$sequenceName]); - if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + if ($row = $stmt->fetch(FetchMode::ASSOCIATIVE)) { $row = array_change_key_case($row, CASE_LOWER); $value = $row['sequence_value']; diff --git a/lib/Doctrine/DBAL/ParameterType.php b/lib/Doctrine/DBAL/ParameterType.php new file mode 100644 index 00000000000..ac52bfcca8e --- /dev/null +++ b/lib/Doctrine/DBAL/ParameterType.php @@ -0,0 +1,51 @@ +portability = $params['portability']; } + if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) { if ($this->_conn instanceof \Doctrine\DBAL\Driver\PDOConnection) { // make use of c-level support for case handling $this->_conn->setAttribute(\PDO::ATTR_CASE, $params['fetch_case']); } else { - $this->case = ($params['fetch_case'] == \PDO::CASE_LOWER) ? CASE_LOWER : CASE_UPPER; + $this->case = ($params['fetch_case'] == ColumnCase::LOWER) ? CASE_LOWER : CASE_UPPER; } } } diff --git a/lib/Doctrine/DBAL/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index 752c3319c8c..8f97dd2e0f7 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -2,7 +2,8 @@ namespace Doctrine\DBAL\Portability; -use PDO; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; /** * Portability wrapper for a Statement. @@ -31,7 +32,7 @@ class Statement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement /** * @var integer */ - private $defaultFetchMode = PDO::FETCH_BOTH; + private $defaultFetchMode = FetchMode::MIXED; /** * Wraps Statement and applies portability measures. @@ -49,15 +50,15 @@ public function __construct($stmt, Connection $conn) /** * {@inheritdoc} */ - public function bindParam($column, &$variable, $type = null, $length = null) + public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { return $this->stmt->bindParam($column, $variable, $type, $length); } + /** * {@inheritdoc} */ - - public function bindValue($param, $value, $type = null) + public function bindValue($param, $value, $type = ParameterType::STRING) { return $this->stmt->bindValue($param, $value, $type); } @@ -105,11 +106,11 @@ public function execute($params = null) /** * {@inheritdoc} */ - public function setFetchMode($fetchMode, $arg1 = null, $arg2 = null) + public function setFetchMode($fetchMode, ...$args) { $this->defaultFetchMode = $fetchMode; - return $this->stmt->setFetchMode($fetchMode, $arg1, $arg2); + return $this->stmt->setFetchMode($fetchMode, ...$args); } /** @@ -125,16 +126,17 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, ...$args) { $fetchMode = $fetchMode ?: $this->defaultFetchMode; - $row = $this->stmt->fetch($fetchMode); + $row = $this->stmt->fetch($fetchMode, ...$args); + + $iterateRow = $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM); + $fixCase = ! is_null($this->case) && ($fetchMode == FetchMode::ASSOCIATIVE || $fetchMode == FetchMode::MIXED) + && ($this->portability & Connection::PORTABILITY_FIX_CASE); - $row = $this->fixRow($row, - $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM), - !is_null($this->case) && ($fetchMode == PDO::FETCH_ASSOC || $fetchMode == PDO::FETCH_BOTH) && ($this->portability & Connection::PORTABILITY_FIX_CASE) - ); + $row = $this->fixRow($row, $iterateRow, $fixCase); return $row; } @@ -142,23 +144,22 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE /** * {@inheritdoc} */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + public function fetchAll($fetchMode = null, ...$args) { $fetchMode = $fetchMode ?: $this->defaultFetchMode; - if ($fetchArgument) { - $rows = $this->stmt->fetchAll($fetchMode, $fetchArgument); - } else { - $rows = $this->stmt->fetchAll($fetchMode); - } + $rows = $this->stmt->fetchAll($fetchMode, ...$args); $iterateRow = $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM); - $fixCase = !is_null($this->case) && ($fetchMode == PDO::FETCH_ASSOC || $fetchMode == PDO::FETCH_BOTH) && ($this->portability & Connection::PORTABILITY_FIX_CASE); + $fixCase = ! is_null($this->case) + && ($fetchMode === FetchMode::ASSOCIATIVE || $fetchMode === FetchMode::MIXED) + && ($this->portability & Connection::PORTABILITY_FIX_CASE); + if ( ! $iterateRow && !$fixCase) { return $rows; } - if ($fetchMode === PDO::FETCH_COLUMN) { + if ($fetchMode === FetchMode::COLUMN) { foreach ($rows as $num => $row) { $rows[$num] = [$row]; } @@ -168,7 +169,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n $rows[$num] = $this->fixRow($row, $iterateRow, $fixCase); } - if ($fetchMode === PDO::FETCH_COLUMN) { + if ($fetchMode === FetchMode::COLUMN) { foreach ($rows as $num => $row) { $rows[$num] = $row[0]; } diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 9172ae7c645..8ab74b8d326 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Query; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\CompositeExpression; use Doctrine\DBAL\Connection; @@ -247,7 +248,7 @@ public function getSQL() * * @param string|integer $key The parameter position or name. * @param mixed $value The parameter value. - * @param string|integer|null $type One of the PDO::PARAM_* constants. + * @param string|integer|null $type One of the {@link \Doctrine\DBAL\ParameterType} constants. * * @return $this This QueryBuilder instance. */ @@ -1239,7 +1240,7 @@ public function __toString() * * @return string the placeholder name used. */ - public function createNamedParameter($value, $type = \PDO::PARAM_STR, $placeHolder = null) + public function createNamedParameter($value, $type = ParameterType::STRING, $placeHolder = null) { if ($placeHolder === null) { $this->boundCounter++; @@ -1263,8 +1264,8 @@ public function createNamedParameter($value, $type = \PDO::PARAM_STR, $placeHold * $qb = $conn->createQueryBuilder(); * $qb->select('u.*') * ->from('users', 'u') - * ->where('u.username = ' . $qb->createPositionalParameter('Foo', PDO::PARAM_STR)) - * ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', PDO::PARAM_STR)) + * ->where('u.username = ' . $qb->createPositionalParameter('Foo', ParameterType::STRING)) + * ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', ParameterType::STRING)) * * * @param mixed $value @@ -1272,7 +1273,7 @@ public function createNamedParameter($value, $type = \PDO::PARAM_STR, $placeHold * * @return string */ - public function createPositionalParameter($value, $type = \PDO::PARAM_STR) + public function createPositionalParameter($value, $type = ParameterType::STRING) { $this->boundCounter++; $this->setParameter($this->boundCounter, $value, $type); diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index d265d5a599f..eeac7a01067 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -122,7 +122,9 @@ public static function expandListParameters($query, $params, $types) $types = array_merge( array_slice($types, 0, $needle), $count ? - array_fill(0, $count, $types[$needle] - Connection::ARRAY_PARAM_OFFSET) : // array needles are at PDO::PARAM_* + 100 + // array needles are at {@link \Doctrine\DBAL\ParameterType} constants + // + {@link Doctrine\DBAL\Connection::ARRAY_PARAM_OFFSET} + array_fill(0, $count, $types[$needle] - Connection::ARRAY_PARAM_OFFSET) : [], array_slice($types, $needle + 1) ); @@ -149,7 +151,7 @@ public static function expandListParameters($query, $params, $types) $pos += $queryOffset; $queryOffset -= ($paramLen - 1); $paramsOrd[] = $value; - $typesOrd[] = static::extractParam($paramName, $types, false, \PDO::PARAM_STR); + $typesOrd[] = static::extractParam($paramName, $types, false, ParameterType::STRING); $query = substr($query, 0, $pos) . '?' . substr($query, ($pos + $paramLen)); continue; diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 63d46d11b0f..231ce0481a0 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Schema; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Types\StringType; use Doctrine\DBAL\Types\TextType; use Doctrine\DBAL\Types\Type; @@ -152,7 +153,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) // fetch primary $stmt = $this->_conn->executeQuery("PRAGMA TABLE_INFO ('$tableName')"); - $indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE); usort($indexArray, function($a, $b) { if ($a['pk'] == $b['pk']) { @@ -183,7 +184,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) $idx['non_unique'] = $tableIndex['unique']?false:true; $stmt = $this->_conn->executeQuery("PRAGMA INDEX_INFO ('{$keyName}')"); - $indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE); foreach ($indexArray as $indexColumnRow) { $idx['column_name'] = $indexColumnRow['name']; diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index c08a0b52866..c1f0b906dc6 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -2,7 +2,6 @@ namespace Doctrine\DBAL; -use PDO; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Driver\Statement as DriverStatement; @@ -85,7 +84,7 @@ public function __construct($sql, Connection $conn) * * @return boolean TRUE on success, FALSE on failure. */ - public function bindValue($name, $value, $type = null) + public function bindValue($name, $value, $type = ParameterType::STRING) { $this->params[$name] = $value; $this->types[$name] = $type; @@ -97,7 +96,7 @@ public function bindValue($name, $value, $type = null) $value = $type->convertToDatabaseValue($value, $this->platform); $bindingType = $type->getBindingType(); } else { - $bindingType = $type; // PDO::PARAM_* constants + $bindingType = $type; } return $this->stmt->bindValue($name, $value, $bindingType); @@ -119,7 +118,7 @@ public function bindValue($name, $value, $type = null) * * @return boolean TRUE on success, FALSE on failure. */ - public function bindParam($name, &$var, $type = PDO::PARAM_STR, $length = null) + public function bindParam($name, &$var, $type = ParameterType::STRING, $length = null) { $this->params[$name] = $var; $this->types[$name] = $type; @@ -213,15 +212,9 @@ public function errorInfo() /** * {@inheritdoc} */ - public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) + public function setFetchMode($fetchMode, ...$args) { - if ($arg2 === null) { - return $this->stmt->setFetchMode($fetchMode); - } elseif ($arg3 === null) { - return $this->stmt->setFetchMode($fetchMode, $arg2); - } - - return $this->stmt->setFetchMode($fetchMode, $arg2, $arg3); + return $this->stmt->setFetchMode($fetchMode, ...$args); } /** @@ -237,21 +230,17 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, ...$args) { - return $this->stmt->fetch($fetchMode); + return $this->stmt->fetch($fetchMode, ...$args); } /** * {@inheritdoc} */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + public function fetchAll($fetchMode = null, ...$args) { - if ($fetchArgument) { - return $this->stmt->fetchAll($fetchMode, $fetchArgument); - } - - return $this->stmt->fetchAll($fetchMode); + return $this->stmt->fetchAll($fetchMode, ...$args); } /** diff --git a/lib/Doctrine/DBAL/Types/BigIntType.php b/lib/Doctrine/DBAL/Types/BigIntType.php index d817344de4c..d579af34ad5 100644 --- a/lib/Doctrine/DBAL/Types/BigIntType.php +++ b/lib/Doctrine/DBAL/Types/BigIntType.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -33,7 +34,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function getBindingType() { - return \PDO::PARAM_STR; + return ParameterType::STRING; } /** diff --git a/lib/Doctrine/DBAL/Types/BinaryType.php b/lib/Doctrine/DBAL/Types/BinaryType.php index 64a32360967..e2c27876578 100644 --- a/lib/Doctrine/DBAL/Types/BinaryType.php +++ b/lib/Doctrine/DBAL/Types/BinaryType.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -56,6 +57,6 @@ public function getName() */ public function getBindingType() { - return \PDO::PARAM_LOB; + return ParameterType::LARGE_OBJECT; } } diff --git a/lib/Doctrine/DBAL/Types/BlobType.php b/lib/Doctrine/DBAL/Types/BlobType.php index dc831c4a3d9..816563f2fd3 100644 --- a/lib/Doctrine/DBAL/Types/BlobType.php +++ b/lib/Doctrine/DBAL/Types/BlobType.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -55,6 +56,6 @@ public function getName() */ public function getBindingType() { - return \PDO::PARAM_LOB; + return ParameterType::LARGE_OBJECT; } } diff --git a/lib/Doctrine/DBAL/Types/BooleanType.php b/lib/Doctrine/DBAL/Types/BooleanType.php index 099ff0595a3..77dc9eba617 100644 --- a/lib/Doctrine/DBAL/Types/BooleanType.php +++ b/lib/Doctrine/DBAL/Types/BooleanType.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -48,6 +49,6 @@ public function getName() */ public function getBindingType() { - return \PDO::PARAM_BOOL; + return ParameterType::BOOLEAN; } } diff --git a/lib/Doctrine/DBAL/Types/IntegerType.php b/lib/Doctrine/DBAL/Types/IntegerType.php index f99cf4fb55e..60b183a009a 100644 --- a/lib/Doctrine/DBAL/Types/IntegerType.php +++ b/lib/Doctrine/DBAL/Types/IntegerType.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -41,6 +42,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getBindingType() { - return \PDO::PARAM_INT; + return ParameterType::INTEGER; } } diff --git a/lib/Doctrine/DBAL/Types/SmallIntType.php b/lib/Doctrine/DBAL/Types/SmallIntType.php index 19e56966a93..4fc2ab96211 100644 --- a/lib/Doctrine/DBAL/Types/SmallIntType.php +++ b/lib/Doctrine/DBAL/Types/SmallIntType.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -40,6 +41,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform) */ public function getBindingType() { - return \PDO::PARAM_INT; + return ParameterType::INTEGER; } } diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 7f6cafd1057..ee4c92387c6 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\DBALException; @@ -230,19 +231,13 @@ public static function overrideType($name, $className) * Gets the (preferred) binding type for values of this type that * can be used when binding parameters to prepared statements. * - * This method should return one of the PDO::PARAM_* constants, that is, one of: - * - * PDO::PARAM_BOOL - * PDO::PARAM_NULL - * PDO::PARAM_INT - * PDO::PARAM_STR - * PDO::PARAM_LOB + * This method should return one of the {@link \Doctrine\DBAL\ParameterType} constants. * * @return integer */ public function getBindingType() { - return \PDO::PARAM_STR; + return ParameterType::STRING; } /** diff --git a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php index fcc46382d18..553af666784 100644 --- a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php +++ b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php @@ -3,8 +3,8 @@ namespace Doctrine\Tests\DBAL\Cache; use Doctrine\DBAL\Cache\QueryCacheProfile; +use Doctrine\DBAL\ParameterType; use Doctrine\Tests\DbalTestCase; -use PDO; class QueryCacheProfileTest extends DbalTestCase { @@ -23,7 +23,7 @@ public function testShouldUseTheGivenCacheKeyIfPresent() { $query = 'SELECT * FROM foo WHERE bar = ?'; $params = [666]; - $types = [PDO::PARAM_INT]; + $types = [ParameterType::INTEGER]; $connectionParams = array( 'dbname' => 'database_name', @@ -47,7 +47,7 @@ public function testShouldGenerateAnAutomaticKeyIfNoKeyHasBeenGiven() { $query = 'SELECT * FROM foo WHERE bar = ?'; $params = [666]; - $types = [PDO::PARAM_INT]; + $types = [ParameterType::INTEGER]; $connectionParams = array( 'dbname' => 'database_name', @@ -79,7 +79,7 @@ public function testShouldGenerateDifferentKeysForSameQueryAndParamsAndDifferent { $query = 'SELECT * FROM foo WHERE bar = ?'; $params = [666]; - $types = [PDO::PARAM_INT]; + $types = [ParameterType::INTEGER]; $connectionParams = array( 'dbname' => 'database_name', @@ -114,7 +114,7 @@ public function testShouldGenerateSameKeysIfNoneOfTheParamsChanges() { $query = 'SELECT * FROM foo WHERE bar = ?'; $params = [666]; - $types = [PDO::PARAM_INT]; + $types = [ParameterType::INTEGER]; $connectionParams = array( 'dbname' => 'database_name', diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 43ed2b214cb..ef20791120d 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -11,13 +11,18 @@ use Doctrine\DBAL\ConnectionException; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Events; use Doctrine\DBAL\Exception\InvalidArgumentException; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\Tests\Mocks\DriverConnectionMock; use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock; +/** + * @requires extension pdo_mysql + */ class ConnectionTest extends \Doctrine\Tests\DbalTestCase { /** @@ -44,7 +49,9 @@ public function getExecuteUpdateMockConnection() $driverMock->expects($this->any()) ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); + ->will($this->returnValue( + $this->createMock(DriverConnection::class) + )); $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeUpdate']) @@ -153,6 +160,7 @@ public function testEventManagerPassedToPlatform() } /** + * @requires extension pdo_sqlite * @expectedException \Doctrine\DBAL\DBALException * @dataProvider getQueryMethods */ @@ -231,7 +239,9 @@ public function testConnectStartsTransactionInNoAutoCommitMode() $driverMock = $this->createMock('Doctrine\DBAL\Driver'); $driverMock->expects($this->any()) ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); + ->will($this->returnValue( + $this->createMock(DriverConnection::class) + )); $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); $conn->setAutoCommit(false); @@ -251,7 +261,9 @@ public function testCommitStartsTransactionInNoAutoCommitMode() $driverMock = $this->createMock('Doctrine\DBAL\Driver'); $driverMock->expects($this->any()) ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); + ->will($this->returnValue( + $this->createMock(DriverConnection::class) + )); $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); $conn->setAutoCommit(false); @@ -269,7 +281,9 @@ public function testRollBackStartsTransactionInNoAutoCommitMode() $driverMock = $this->createMock('Doctrine\DBAL\Driver'); $driverMock->expects($this->any()) ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); + ->will($this->returnValue( + $this->createMock(DriverConnection::class) + )); $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); $conn->setAutoCommit(false); @@ -287,7 +301,9 @@ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() $driverMock = $this->createMock('Doctrine\DBAL\Driver'); $driverMock->expects($this->any()) ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); + ->will($this->returnValue( + $this->createMock(DriverConnection::class) + )); $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); $conn->connect(); @@ -480,20 +496,22 @@ public function testFetchAssoc() { $statement = 'SELECT * FROM foo WHERE bar = ?'; $params = array(666); - $types = array(\PDO::PARAM_INT); + $types = array(ParameterType::INTEGER); $result = array(); $driverMock = $this->createMock('Doctrine\DBAL\Driver'); $driverMock->expects($this->any()) ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); + ->will($this->returnValue( + $this->createMock(DriverConnection::class) + )); $driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock'); $driverStatementMock->expects($this->once()) ->method('fetch') - ->with(\PDO::FETCH_ASSOC) + ->with(FetchMode::ASSOCIATIVE) ->will($this->returnValue($result)); /** @var \PHPUnit_Framework_MockObject_MockObject|\Doctrine\DBAL\Connection $conn */ @@ -514,20 +532,22 @@ public function testFetchArray() { $statement = 'SELECT * FROM foo WHERE bar = ?'; $params = array(666); - $types = array(\PDO::PARAM_INT); + $types = array(ParameterType::INTEGER); $result = array(); $driverMock = $this->createMock('Doctrine\DBAL\Driver'); $driverMock->expects($this->any()) ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); + ->will($this->returnValue( + $this->createMock(DriverConnection::class) + )); $driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock'); $driverStatementMock->expects($this->once()) ->method('fetch') - ->with(\PDO::FETCH_NUM) + ->with(FetchMode::NUMERIC) ->will($this->returnValue($result)); /** @var \PHPUnit_Framework_MockObject_MockObject|\Doctrine\DBAL\Connection $conn */ @@ -548,7 +568,7 @@ public function testFetchColumn() { $statement = 'SELECT * FROM foo WHERE bar = ?'; $params = array(666); - $types = array(\PDO::PARAM_INT); + $types = array(ParameterType::INTEGER); $column = 0; $result = array(); @@ -556,7 +576,9 @@ public function testFetchColumn() $driverMock->expects($this->any()) ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); + ->will($this->returnValue( + $this->createMock(DriverConnection::class) + )); $driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock'); @@ -606,14 +628,16 @@ public function testFetchAll() { $statement = 'SELECT * FROM foo WHERE bar = ?'; $params = array(666); - $types = array(\PDO::PARAM_INT); + $types = array(ParameterType::INTEGER); $result = array(); $driverMock = $this->createMock('Doctrine\DBAL\Driver'); $driverMock->expects($this->any()) ->method('connect') - ->will($this->returnValue(new DriverConnectionMock())); + ->will($this->returnValue( + $this->createMock(DriverConnection::class) + )); $driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock'); @@ -756,7 +780,7 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach $query = 'SELECT * FROM foo WHERE bar = ?'; $params = [666]; - $types = [\PDO::PARAM_INT]; + $types = [ParameterType::INTEGER]; /* @var $queryCacheProfileMock QueryCacheProfile|\PHPUnit_Framework_MockObject_MockObject */ $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index d5155de2f73..84f23c0bd9b 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -3,11 +3,11 @@ namespace Doctrine\Tests\DBAL; use Doctrine\DBAL\DBALException; -use Doctrine\Tests\Mocks\PDOMock; class DriverManagerTest extends \Doctrine\Tests\DbalTestCase { /** + * @requires extension pdo_sqlite * @expectedException \Doctrine\DBAL\DBALException */ public function testInvalidPdoInstance() @@ -18,6 +18,9 @@ public function testInvalidPdoInstance() $test = \Doctrine\DBAL\DriverManager::getConnection($options); } + /** + * @requires extension pdo_sqlite + */ public function testValidPdoInstance() { $options = array( @@ -29,6 +32,7 @@ public function testValidPdoInstance() /** * @group DBAL-32 + * @requires extension pdo_sqlite */ public function testPdoInstanceSetErrorMode() { @@ -58,6 +62,9 @@ public function testInvalidDriver() $conn = \Doctrine\DBAL\DriverManager::getConnection(array('driver' => 'invalid_driver')); } + /** + * @requires extension pdo_sqlite + */ public function testCustomPlatform() { $mockPlatform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform(); @@ -70,6 +77,9 @@ public function testCustomPlatform() self::assertSame($mockPlatform, $conn->getDatabasePlatform()); } + /** + * @requires extension pdo_sqlite + */ public function testCustomWrapper() { $wrapperClass = 'Doctrine\Tests\Mocks\ConnectionMock'; @@ -83,6 +93,9 @@ public function testCustomWrapper() self::assertInstanceOf($wrapperClass, $conn); } + /** + * @requires extension pdo_sqlite + */ public function testInvalidWrapperClass() { $this->expectException(DBALException::class); @@ -125,6 +138,18 @@ public function testDatabaseUrl($url, $expected) 'url' => $url, ); + if (isset($options['pdo'])) { + if ( ! extension_loaded('pdo')) { + $this->markTestSkipped('PDO is not installed'); + } + + $options['pdo'] = $this->createMock(\PDO::class); + } + + $options = is_array($url) ? $url : array( + 'url' => $url, + ); + if ($expected === false) { $this->expectException(DBALException::class); } @@ -143,8 +168,6 @@ public function testDatabaseUrl($url, $expected) public function databaseUrls() { - $pdoMock = $this->createMock(PDOMock::class); - return array( 'simple URL' => array( 'mysql://foo:bar@localhost/baz', @@ -217,7 +240,7 @@ public function databaseUrls() false, ), 'URL without scheme but default PDO driver' => array( - array('url' => '//foo:bar@localhost/baz', 'pdo' => $pdoMock), + array('url' => '//foo:bar@localhost/baz', 'pdo' => true), false, ), 'URL without scheme but default driver' => array( @@ -229,7 +252,7 @@ public function databaseUrls() array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock'), ), 'URL without scheme but default PDO driver and default driver' => array( - array('url' => '//foo:bar@localhost/baz', 'pdo' => $pdoMock, 'driver' => 'pdo_mysql'), + array('url' => '//foo:bar@localhost/baz', 'pdo' => true, 'driver' => 'pdo_mysql'), array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), ), 'URL without scheme but driver and custom driver' => array( @@ -237,7 +260,7 @@ public function databaseUrls() array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock'), ), 'URL with default PDO driver' => array( - array('url' => 'mysql://foo:bar@localhost/baz', 'pdo' => $pdoMock), + array('url' => 'mysql://foo:bar@localhost/baz', 'pdo' => true), array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), ), 'URL with default driver' => array( @@ -249,7 +272,7 @@ public function databaseUrls() array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), ), 'URL with default PDO driver and default driver' => array( - array('url' => 'mysql://foo:bar@localhost/baz', 'pdo' => $pdoMock, 'driver' => 'sqlite'), + array('url' => 'mysql://foo:bar@localhost/baz', 'pdo' => true, 'driver' => 'sqlite'), array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), ), 'URL with default driver and default custom driver' => array( @@ -257,7 +280,7 @@ public function databaseUrls() array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), ), 'URL with default PDO driver and default driver and default custom driver' => array( - array('url' => 'mysql://foo:bar@localhost/baz', 'pdo' => $pdoMock, 'driver' => 'sqlite', 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock'), + array('url' => 'mysql://foo:bar@localhost/baz', 'pdo' => true, 'driver' => 'sqlite', 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock'), array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), ), ); diff --git a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php index 557974e4cdc..11547b2e82f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php @@ -2,8 +2,8 @@ namespace Doctrine\Tests\DBAL\Functional; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Type; -use PDO; /** * @group DBAL-6 @@ -39,7 +39,7 @@ public function testInsert() { $ret = $this->_conn->insert('blob_table', array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test', 'binaryfield' => 'test'), - array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB, \PDO::PARAM_LOB) + array(ParameterType::INTEGER, ParameterType::STRING, ParameterType::LARGE_OBJECT, ParameterType::LARGE_OBJECT) ); self::assertEquals(1, $ret); } @@ -48,7 +48,7 @@ public function testSelect() { $this->_conn->insert('blob_table', array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test', 'binaryfield' => 'test'), - array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB, \PDO::PARAM_LOB) + array(ParameterType::INTEGER, ParameterType::STRING, ParameterType::LARGE_OBJECT, ParameterType::LARGE_OBJECT) ); $this->assertBlobContains('test'); @@ -58,13 +58,13 @@ public function testUpdate() { $this->_conn->insert('blob_table', array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test', 'binaryfield' => 'test'), - array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB, \PDO::PARAM_LOB) + array(ParameterType::INTEGER, ParameterType::STRING, ParameterType::LARGE_OBJECT, ParameterType::LARGE_OBJECT) ); $this->_conn->update('blob_table', array('blobfield' => 'test2', 'binaryfield' => 'test2'), array('id' => 1), - array(\PDO::PARAM_LOB, \PDO::PARAM_LOB, \PDO::PARAM_INT) + array(ParameterType::LARGE_OBJECT, ParameterType::LARGE_OBJECT, ParameterType::INTEGER) ); $this->assertBlobContains('test2'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index a595d2d2a2d..e59a9520f29 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\ConnectionException; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; @@ -242,7 +243,10 @@ public function testTransactionalReturnValue() */ public function testQuote() { - self::assertEquals($this->_conn->quote("foo", Type::STRING), $this->_conn->quote("foo", \PDO::PARAM_STR)); + self::assertEquals( + $this->_conn->quote("foo", Type::STRING), + $this->_conn->quote("foo", ParameterType::STRING) + ); } public function testPingDoesTriggersConnect() diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index 6df4814f6e5..e465327a2e9 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -3,9 +3,10 @@ namespace Doctrine\Tests\DBAL\Functional; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; -use PDO; class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase { @@ -41,7 +42,7 @@ public function testPrepareWithBindValue() $stmt->bindValue(2, 'foo'); $stmt->execute(); - $row = $stmt->fetch(\PDO::FETCH_ASSOC); + $row = $stmt->fetch(FetchMode::ASSOCIATIVE); $row = array_change_key_case($row, \CASE_LOWER); self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); } @@ -59,7 +60,7 @@ public function testPrepareWithBindParam() $stmt->bindParam(2, $paramStr); $stmt->execute(); - $row = $stmt->fetch(\PDO::FETCH_ASSOC); + $row = $stmt->fetch(FetchMode::ASSOCIATIVE); $row = array_change_key_case($row, \CASE_LOWER); self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); } @@ -77,7 +78,7 @@ public function testPrepareWithFetchAll() $stmt->bindParam(2, $paramStr); $stmt->execute(); - $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $rows = $stmt->fetchAll(FetchMode::ASSOCIATIVE); $rows[0] = array_change_key_case($rows[0], \CASE_LOWER); self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $rows[0]); } @@ -98,7 +99,7 @@ public function testPrepareWithFetchAllBoth() $stmt->bindParam(2, $paramStr); $stmt->execute(); - $rows = $stmt->fetchAll(\PDO::FETCH_BOTH); + $rows = $stmt->fetchAll(FetchMode::MIXED); $rows[0] = array_change_key_case($rows[0], \CASE_LOWER); self::assertEquals(array('test_int' => 1, 'test_string' => 'foo', 0 => 1, 1 => 'foo'), $rows[0]); } @@ -134,7 +135,7 @@ public function testPrepareWithIterator() $stmt->execute(); $rows = array(); - $stmt->setFetchMode(\PDO::FETCH_ASSOC); + $stmt->setFetchMode(FetchMode::ASSOCIATIVE); foreach ($stmt as $row) { $rows[] = array_change_key_case($row, \CASE_LOWER); } @@ -164,7 +165,7 @@ public function testPrepareWithExecuteParams() self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); $stmt->execute(array($paramInt, $paramStr)); - $row = $stmt->fetch(\PDO::FETCH_ASSOC); + $row = $stmt->fetch(FetchMode::ASSOCIATIVE); self::assertNotFalse($row); $row = array_change_key_case($row, \CASE_LOWER); self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); @@ -192,8 +193,9 @@ public function testFetchAllWithTypes() { $datetimeString = '2010-01-01 10:10:10'; $datetime = new \DateTime($datetimeString); - $sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?"; - $data = $this->_conn->fetchAll($sql, array(1, $datetime), array(PDO::PARAM_STR, Type::DATETIME)); + + $sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?"; + $data = $this->_conn->fetchAll($sql, array(1, $datetime), array(ParameterType::STRING, Type::DATETIME)); self::assertCount(1, $data); @@ -225,7 +227,7 @@ public function testFetchAllWithMissingTypes() public function testFetchBoth() { $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; - $row = $this->_conn->executeQuery($sql, array(1, 'foo'))->fetch(\PDO::FETCH_BOTH); + $row = $this->_conn->executeQuery($sql, array(1, 'foo'))->fetch(FetchMode::MIXED); self::assertNotFalse($row); @@ -261,8 +263,9 @@ public function testFetchAssocWithTypes() { $datetimeString = '2010-01-01 10:10:10'; $datetime = new \DateTime($datetimeString); + $sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?"; - $row = $this->_conn->fetchAssoc($sql, array(1, $datetime), array(PDO::PARAM_STR, Type::DATETIME)); + $row = $this->_conn->fetchAssoc($sql, array(1, $datetime), array(ParameterType::STRING, Type::DATETIME)); self::assertNotFalse($row); @@ -301,8 +304,9 @@ public function testFetchArrayWithTypes() { $datetimeString = '2010-01-01 10:10:10'; $datetime = new \DateTime($datetimeString); + $sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?"; - $row = $this->_conn->fetchArray($sql, array(1, $datetime), array(PDO::PARAM_STR, Type::DATETIME)); + $row = $this->_conn->fetchArray($sql, array(1, $datetime), array(ParameterType::STRING, Type::DATETIME)); self::assertNotFalse($row); @@ -345,8 +349,14 @@ public function testFetchColumnWithTypes() { $datetimeString = '2010-01-01 10:10:10'; $datetime = new \DateTime($datetimeString); - $sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?"; - $column = $this->_conn->fetchColumn($sql, array(1, $datetime), 1, array(PDO::PARAM_STR, Type::DATETIME)); + + $sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?"; + $column = $this->_conn->fetchColumn( + $sql, + array(1, $datetime), + 1, + array(ParameterType::STRING, Type::DATETIME) + ); self::assertNotFalse($column); @@ -392,8 +402,16 @@ public function testExecuteUpdateBindDateTimeType() $sql = 'INSERT INTO fetch_table (test_int, test_string, test_datetime) VALUES (?, ?, ?)'; $affectedRows = $this->_conn->executeUpdate($sql, - array(1 => 50, 2 => 'foo', 3 => $datetime), - array(1 => PDO::PARAM_INT, 2 => PDO::PARAM_STR, 3 => Type::DATETIME) + array( + 1 => 50, + 2 => 'foo', + 3 => $datetime, + ), + array( + 1 => ParameterType::INTEGER, + 2 => ParameterType::STRING, + 3 => Type::DATETIME, + ) ); self::assertEquals(1, $affectedRows); @@ -429,14 +447,14 @@ public function testNativeArrayListSupport() $stmt = $this->_conn->executeQuery('SELECT test_int FROM fetch_table WHERE test_int IN (?)', array(array(100, 101, 102, 103, 104)), array(Connection::PARAM_INT_ARRAY)); - $data = $stmt->fetchAll(PDO::FETCH_NUM); + $data = $stmt->fetchAll(FetchMode::NUMERIC); self::assertCount(5, $data); self::assertEquals(array(array(100), array(101), array(102), array(103), array(104)), $data); $stmt = $this->_conn->executeQuery('SELECT test_int FROM fetch_table WHERE test_string IN (?)', array(array('foo100', 'foo101', 'foo102', 'foo103', 'foo104')), array(Connection::PARAM_STR_ARRAY)); - $data = $stmt->fetchAll(PDO::FETCH_NUM); + $data = $stmt->fetchAll(FetchMode::NUMERIC); self::assertCount(5, $data); self::assertEquals(array(array(100), array(101), array(102), array(103), array(104)), $data); } @@ -613,8 +631,8 @@ public function testBitComparisonExpressionSupport() $sql[] = $platform->getBitAndComparisonExpression('test_int', 2) . ' AS bit_and '; $sql[] = 'FROM fetch_table'; - $stmt = $this->_conn->executeQuery(implode(PHP_EOL, $sql)); - $data = $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt = $this->_conn->executeQuery(implode(PHP_EOL, $sql)); + $data = $stmt->fetchAll(FetchMode::ASSOCIATIVE); self::assertCount(4, $data); @@ -640,7 +658,7 @@ public function testBitComparisonExpressionSupport() public function testSetDefaultFetchMode() { $stmt = $this->_conn->query("SELECT * FROM fetch_table"); - $stmt->setFetchMode(\PDO::FETCH_NUM); + $stmt->setFetchMode(FetchMode::NUMERIC); $row = array_keys($stmt->fetch()); self::assertCount(0, array_filter($row, function($v) { return ! is_numeric($v); }), "should be no non-numerical elements in the result."); @@ -658,7 +676,7 @@ public function testFetchAllStyleObject() $stmt->execute(); - $results = $stmt->fetchAll(\PDO::FETCH_OBJ); + $results = $stmt->fetchAll(FetchMode::STANDARD_OBJECT); self::assertCount(1, $results); self::assertInstanceOf('stdClass', $results[0]); @@ -690,7 +708,7 @@ public function testFetchAllSupportFetchClass() $stmt->execute(); $results = $stmt->fetchAll( - \PDO::FETCH_CLASS, + FetchMode::CUSTOM_OBJECT, __NAMESPACE__.'\\MyFetchClass' ); @@ -714,7 +732,7 @@ public function testFetchAllStyleColumn() $this->_conn->insert('fetch_table', array('test_int' => 10, 'test_string' => 'foo')); $sql = "SELECT test_int FROM fetch_table"; - $rows = $this->_conn->query($sql)->fetchAll(\PDO::FETCH_COLUMN); + $rows = $this->_conn->query($sql)->fetchAll(FetchMode::COLUMN); self::assertEquals(array(1, 10), $rows); } @@ -729,7 +747,7 @@ public function testSetFetchModeClassFetchAll() $sql = "SELECT * FROM fetch_table"; $stmt = $this->_conn->query($sql); - $stmt->setFetchMode(\PDO::FETCH_CLASS, __NAMESPACE__ . '\\MyFetchClass'); + $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass'); $results = $stmt->fetchAll(); @@ -751,7 +769,7 @@ public function testSetFetchModeClassFetch() $sql = "SELECT * FROM fetch_table"; $stmt = $this->_conn->query($sql); - $stmt->setFetchMode(\PDO::FETCH_CLASS, __NAMESPACE__ . '\\MyFetchClass'); + $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass'); $results = array(); while ($row = $stmt->fetch()) { @@ -785,7 +803,7 @@ public function testSetFetchModeOnDbalStatement() { $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; $stmt = $this->_conn->executeQuery($sql, array(1, "foo")); - $stmt->setFetchMode(\PDO::FETCH_NUM); + $stmt->setFetchMode(FetchMode::NUMERIC); $row = $stmt->fetch(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php index c4d7382d525..4669df7c19c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\Tests\DbalFunctionalTestCase; @@ -40,7 +41,11 @@ public function testConnectsWithValidCharsetOption($charset) $this->_conn->getEventManager() ); - self::assertEquals($charset, $connection->query("SHOW client_encoding")->fetch(\PDO::FETCH_COLUMN)); + self::assertEquals( + $charset, + $connection->query("SHOW client_encoding") + ->fetch(FetchMode::COLUMN) + ); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php index 974cca52db7..e878a71d0fe 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php @@ -3,7 +3,8 @@ namespace Doctrine\Tests\DBAL\Functional\Ticket; use Doctrine\DBAL\Connection; -use PDO; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; /** * @group DDC-1372 @@ -17,7 +18,10 @@ public function ticketProvider() array( 'SELECT * FROM ddc1372_foobar f WHERE f.foo = :foo AND f.bar IN (:bar)', array('foo'=>1,'bar'=> array(1, 2, 3)), - array('foo'=>PDO::PARAM_INT,'bar'=> Connection::PARAM_INT_ARRAY,), + array( + 'foo' => ParameterType::INTEGER, + 'bar' => Connection::PARAM_INT_ARRAY, + ), array( array('id'=>1,'foo'=>1,'bar'=>1), array('id'=>2,'foo'=>1,'bar'=>2), @@ -28,7 +32,10 @@ public function ticketProvider() array( 'SELECT * FROM ddc1372_foobar f WHERE f.foo = :foo AND f.bar IN (:bar)', array('foo'=>1,'bar'=> array(1, 2, 3)), - array('bar'=> Connection::PARAM_INT_ARRAY,'foo'=>PDO::PARAM_INT), + array( + 'bar' => Connection::PARAM_INT_ARRAY, + 'foo' => ParameterType::INTEGER, + ), array( array('id'=>1,'foo'=>1,'bar'=>1), array('id'=>2,'foo'=>1,'bar'=>2), @@ -39,7 +46,10 @@ public function ticketProvider() array( 'SELECT * FROM ddc1372_foobar f WHERE f.bar IN (:bar) AND f.foo = :foo', array('foo'=>1,'bar'=> array(1, 2, 3)), - array('bar'=> Connection::PARAM_INT_ARRAY,'foo'=>PDO::PARAM_INT), + array( + 'bar' => Connection::PARAM_INT_ARRAY, + 'foo' => ParameterType::INTEGER, + ), array( array('id'=>1,'foo'=>1,'bar'=>1), array('id'=>2,'foo'=>1,'bar'=>2), @@ -50,7 +60,10 @@ public function ticketProvider() array( 'SELECT * FROM ddc1372_foobar f WHERE f.bar IN (:bar) AND f.foo = :foo', array('foo'=>1,'bar'=> array('1', '2', '3')), - array('bar'=> Connection::PARAM_STR_ARRAY,'foo'=>PDO::PARAM_INT), + array( + 'bar' => Connection::PARAM_STR_ARRAY, + 'foo' => ParameterType::INTEGER, + ), array( array('id'=>1,'foo'=>1,'bar'=>1), array('id'=>2,'foo'=>1,'bar'=>2), @@ -73,7 +86,7 @@ public function ticketProvider() array( 'SELECT * FROM ddc1372_foobar f WHERE f.bar IN (:bar) AND f.foo IN (:foo)', array('foo'=>1,'bar'=> 2), - array('bar'=>PDO::PARAM_INT,'foo'=>PDO::PARAM_INT), + array('bar'=>ParameterType::INTEGER,'foo'=>ParameterType::INTEGER), array( array('id'=>2,'foo'=>1,'bar'=>2), ) @@ -82,7 +95,9 @@ public function ticketProvider() array( 'SELECT * FROM ddc1372_foobar f WHERE f.bar = :arg AND f.foo <> :arg', array('arg'=>'1'), - array('arg'=>PDO::PARAM_STR), + array( + 'arg' => ParameterType::STRING, + ), array( array('id'=>5,'foo'=>2,'bar'=>1), ) @@ -151,7 +166,7 @@ protected function setUp() public function testTicket($query,$params,$types,$expected) { $stmt = $this->_conn->executeQuery($query, $params, $types); - $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $result = $stmt->fetchAll(FetchMode::ASSOCIATIVE); foreach ($result as $k => $v) { $result[$k] = array_change_key_case($v, CASE_LOWER); diff --git a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php index cbadf508a15..78d0a03f68b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -2,10 +2,11 @@ namespace Doctrine\Tests\DBAL\Functional; +use Doctrine\DBAL\ColumnCase; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Portability\Connection as ConnectionPortability; -use PDO; /** * @group DBAL-56 @@ -28,13 +29,17 @@ protected function tearDown() * @param integer $case * @return Connection */ - private function getPortableConnection($portabilityMode = \Doctrine\DBAL\Portability\Connection::PORTABILITY_ALL, $case = \PDO::CASE_LOWER) - { + private function getPortableConnection( + $portabilityMode = ConnectionPortability::PORTABILITY_ALL, + $case = ColumnCase::LOWER + ) { if (!$this->portableConnection) { $params = $this->_conn->getParams(); - $params['wrapperClass'] = 'Doctrine\DBAL\Portability\Connection'; - $params['portability'] = $portabilityMode; - $params['fetch_case'] = $case; + + $params['wrapperClass'] = ConnectionPortability::class; + $params['portability'] = $portabilityMode; + $params['fetch_case'] = $case; + $this->portableConnection = DriverManager::getConnection($params, $this->_conn->getConfiguration(), $this->_conn->getEventManager()); try { @@ -64,19 +69,22 @@ public function testFullFetchMode() $this->assertFetchResultRows($rows); $stmt = $this->getPortableConnection()->query('SELECT * FROM portability_table'); - $stmt->setFetchMode(\PDO::FETCH_ASSOC); + $stmt->setFetchMode(FetchMode::ASSOCIATIVE); + foreach ($stmt as $row) { $this->assertFetchResultRow($row); } $stmt = $this->getPortableConnection()->query('SELECT * FROM portability_table'); - while (($row = $stmt->fetch(\PDO::FETCH_ASSOC))) { + + while (($row = $stmt->fetch(FetchMode::ASSOCIATIVE))) { $this->assertFetchResultRow($row); } $stmt = $this->getPortableConnection()->prepare('SELECT * FROM portability_table'); $stmt->execute(); - while (($row = $stmt->fetch(\PDO::FETCH_ASSOC))) { + + while (($row = $stmt->fetch(FetchMode::ASSOCIATIVE))) { $this->assertFetchResultRow($row); } } @@ -84,7 +92,7 @@ public function testFullFetchMode() public function testConnFetchMode() { $conn = $this->getPortableConnection(); - $conn->setFetchMode(\PDO::FETCH_ASSOC); + $conn->setFetchMode(FetchMode::ASSOCIATIVE); $rows = $conn->fetchAll('SELECT * FROM portability_table'); $this->assertFetchResultRows($rows); @@ -120,10 +128,13 @@ public function assertFetchResultRow($row) self::assertArrayHasKey('test_string', $row, "Case should be lowered."); self::assertEquals(3, strlen($row['test_string']), "test_string should be rtrimed to length of three for CHAR(32) column."); self::assertNull($row['test_null']); - self::assertArrayNotHasKey(0, $row, "PDO::FETCH_ASSOC should not return numerical keys."); + self::assertArrayNotHasKey(0, $row, "The row should not contain numerical keys."); } - public function testPortabilitySqlServer() + /** + * @requires extension pdo + */ + public function testPortabilityPdoSqlServer() { $portability = ConnectionPortability::PORTABILITY_SQLSRV; $params = array( @@ -153,7 +164,7 @@ public function testFetchAllColumn($field, array $expected) $conn = $this->getPortableConnection(); $stmt = $conn->query('SELECT ' . $field . ' FROM portability_table'); - $column = $stmt->fetchAll(PDO::FETCH_COLUMN); + $column = $stmt->fetchAll(FetchMode::COLUMN); self::assertEquals($expected, $column); } @@ -176,7 +187,7 @@ public function testFetchAllNullColumn() $conn = $this->getPortableConnection(); $stmt = $conn->query('SELECT Test_Null FROM portability_table'); - $column = $stmt->fetchAll(PDO::FETCH_COLUMN); + $column = $stmt->fetchAll(FetchMode::COLUMN); self::assertSame(array(null, null), $column); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index 76c2c8424e4..367a09f9e35 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -1,8 +1,9 @@ expectedResult, \PDO::FETCH_ASSOC); + self::assertCacheNonCacheSelectSameFetchModeAreEqual( + $this->expectedResult, + FetchMode::ASSOCIATIVE + ); } public function testFetchNum() @@ -53,7 +57,8 @@ public function testFetchNum() foreach ($this->expectedResult as $v) { $expectedResult[] = array_values($v); } - self::assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_NUM); + + self::assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, FetchMode::NUMERIC); } public function testFetchBoth() @@ -62,7 +67,8 @@ public function testFetchBoth() foreach ($this->expectedResult as $v) { $expectedResult[] = array_merge($v, array_values($v)); } - self::assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_BOTH); + + self::assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, FetchMode::MIXED); } public function testFetchColumn() @@ -71,7 +77,8 @@ public function testFetchColumn() foreach ($this->expectedResult as $v) { $expectedResult[] = array_shift($v); } - self::assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_COLUMN); + + self::assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, FetchMode::COLUMN); } public function testMixingFetch() @@ -82,22 +89,22 @@ public function testMixingFetch() } $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); - $data = $this->hydrateStmt($stmt, \PDO::FETCH_ASSOC); + $data = $this->hydrateStmt($stmt, FetchMode::ASSOCIATIVE); self::assertEquals($this->expectedResult, $data); $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); - $data = $this->hydrateStmt($stmt, \PDO::FETCH_NUM); + $data = $this->hydrateStmt($stmt, FetchMode::NUMERIC); self::assertEquals($numExpectedResult, $data); } public function testIteratorFetch() { - self::assertStandardAndIteratorFetchAreEqual(\PDO::FETCH_BOTH); - self::assertStandardAndIteratorFetchAreEqual(\PDO::FETCH_ASSOC); - self::assertStandardAndIteratorFetchAreEqual(\PDO::FETCH_NUM); + self::assertStandardAndIteratorFetchAreEqual(FetchMode::MIXED); + self::assertStandardAndIteratorFetchAreEqual(FetchMode::ASSOCIATIVE); + self::assertStandardAndIteratorFetchAreEqual(FetchMode::NUMERIC); } public function assertStandardAndIteratorFetchAreEqual($fetchMode) @@ -116,14 +123,16 @@ public function testDontCloseNoCache() $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); $data = array(); - while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + + while ($row = $stmt->fetch(FetchMode::ASSOCIATIVE)) { $data[] = $row; } $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); $data = array(); - while ($row = $stmt->fetch(\PDO::FETCH_NUM)) { + + while ($row = $stmt->fetch(FetchMode::NUMERIC)) { $data[] = $row; } @@ -134,12 +143,12 @@ public function testDontFinishNoCache() { $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); - $row = $stmt->fetch(\PDO::FETCH_ASSOC); + $stmt->fetch(FetchMode::ASSOCIATIVE); $stmt->closeCursor(); $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); - $data = $this->hydrateStmt($stmt, \PDO::FETCH_NUM); + $this->hydrateStmt($stmt, FetchMode::NUMERIC); self::assertCount(2, $this->sqlLogger->queries); } @@ -184,7 +193,7 @@ public function testChangeCacheImpl() self::assertCount(1, $secondCache->fetch("emptycachekey")); } - private function hydrateStmt($stmt, $fetchMode = \PDO::FETCH_ASSOC) + private function hydrateStmt($stmt, $fetchMode = FetchMode::ASSOCIATIVE) { $data = array(); while ($row = $stmt->fetch($fetchMode)) { @@ -194,7 +203,7 @@ private function hydrateStmt($stmt, $fetchMode = \PDO::FETCH_ASSOC) return $data; } - private function hydrateStmtIterator($stmt, $fetchMode = \PDO::FETCH_ASSOC) + private function hydrateStmtIterator($stmt, $fetchMode = FetchMode::ASSOCIATIVE) { $data = array(); $stmt->setFetchMode($fetchMode); diff --git a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php index a6408071c2a..4ab6cf76c21 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php @@ -3,6 +3,8 @@ namespace Doctrine\Tests\DBAL\Functional; use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; @@ -57,7 +59,7 @@ public function testReuseStatementWithLongerResults() $stmt->execute(); self::assertArraySubset(array( array('param1', 'X'), - ), $stmt->fetchAll(\PDO::FETCH_NUM)); + ), $stmt->fetchAll(FetchMode::NUMERIC)); $row2 = array( 'param' => 'param2', @@ -69,7 +71,7 @@ public function testReuseStatementWithLongerResults() self::assertArraySubset(array( array('param1', 'X'), array('param2', 'A bit longer value'), - ), $stmt->fetchAll(\PDO::FETCH_NUM)); + ), $stmt->fetchAll(FetchMode::NUMERIC)); } public function testFetchLongBlob() @@ -104,7 +106,7 @@ public function testFetchLongBlob() $this->_conn->insert('stmt_long_blob', array( 'contents' => $contents, - ), array(\PDO::PARAM_LOB)); + ), array(ParameterType::LARGE_OBJECT)); $stmt = $this->_conn->prepare('SELECT contents FROM stmt_long_blob'); $stmt->execute(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php index 0d9eb3ea5d9..9a96ad2fb96 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Ticket; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\ParameterType; use PDO; /** @@ -52,7 +53,11 @@ public function testBooleanConversionSqlLiteral() public function testBooleanConversionBoolParamRealPrepares() { - $this->_conn->executeUpdate('INSERT INTO dbal630 (bool_col) VALUES(?)', array('false'), array(PDO::PARAM_BOOL)); + $this->_conn->executeUpdate( + 'INSERT INTO dbal630 (bool_col) VALUES(?)', + array('false'), + array(ParameterType::BOOLEAN) + ); $id = $this->_conn->lastInsertId('dbal630_id_seq'); self::assertNotEmpty($id); @@ -68,7 +73,7 @@ public function testBooleanConversionBoolParamEmulatedPrepares() $platform = $this->_conn->getDatabasePlatform(); $stmt = $this->_conn->prepare('INSERT INTO dbal630 (bool_col) VALUES(?)'); - $stmt->bindValue(1, $platform->convertBooleansToDatabaseValue('false'), PDO::PARAM_BOOL); + $stmt->bindValue(1, $platform->convertBooleansToDatabaseValue('false'), ParameterType::BOOLEAN); $stmt->execute(); $id = $this->_conn->lastInsertId('dbal630_id_seq'); @@ -116,7 +121,11 @@ public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInB $platform = $this->_conn->getDatabasePlatform(); $stmt = $this->_conn->prepare('INSERT INTO dbal630_allow_nulls (bool_col) VALUES(?)'); - $stmt->bindValue(1, $platform->convertBooleansToDatabaseValue($statementValue), PDO::PARAM_BOOL); + $stmt->bindValue( + 1, + $platform->convertBooleansToDatabaseValue($statementValue), + ParameterType::BOOLEAN + ); $stmt->execute(); $id = $this->_conn->lastInsertId('dbal630_allow_nulls_id_seq'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php index 7f072d26807..54f4b6a9837 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php @@ -1,8 +1,9 @@ _conn->executeUpdate($sql, array("text", 1111), array(null, PDO::PARAM_INT)); + $this->_conn->executeUpdate($sql, array("text", 1111), array(null, ParameterType::INTEGER)); $sql = "SELECT * FROM write_table WHERE test_string = ? AND test_int = ?"; self::assertTrue((bool)$this->_conn->fetchColumn($sql, array("text", 1111))); @@ -48,7 +49,11 @@ public function testExecuteUpdate() public function testExecuteUpdateWithTypes() { $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; - $affected = $this->_conn->executeUpdate($sql, array(1, 'foo'), array(\PDO::PARAM_INT, \PDO::PARAM_STR)); + $affected = $this->_conn->executeUpdate( + $sql, + array(1, 'foo'), + array(ParameterType::INTEGER, ParameterType::STRING) + ); self::assertEquals(1, $affected, "executeUpdate() should return the number of affected rows!"); } @@ -70,8 +75,8 @@ public function testPrepareWithPdoTypes() $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; $stmt = $this->_conn->prepare($sql); - $stmt->bindValue(1, 1, \PDO::PARAM_INT); - $stmt->bindValue(2, "foo", \PDO::PARAM_STR); + $stmt->bindValue(1, 1, ParameterType::INTEGER); + $stmt->bindValue(2, "foo", ParameterType::STRING); $stmt->execute(); self::assertEquals(1, $stmt->rowCount()); diff --git a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php index e369aab9286..2f35f0b64be 100644 --- a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\DBAL\Portability; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Portability\Connection; use Doctrine\DBAL\Portability\Statement; @@ -39,7 +41,7 @@ public function testBindParam() { $column = 'mycolumn'; $variable = 'myvalue'; - $type = \PDO::PARAM_STR; + $type = ParameterType::STRING; $length = 666; $this->wrappedStmt->expects($this->once()) @@ -54,7 +56,7 @@ public function testBindValue() { $param = 'myparam'; $value = 'myvalue'; - $type = \PDO::PARAM_STR; + $type = ParameterType::STRING; $this->wrappedStmt->expects($this->once()) ->method('bindValue') @@ -123,7 +125,7 @@ public function testExecute() public function testSetFetchMode() { - $fetchMode = \PDO::FETCH_CLASS; + $fetchMode = FetchMode::CUSTOM_OBJECT; $arg1 = 'MyClass'; $arg2 = array(1, 2); @@ -132,7 +134,7 @@ public function testSetFetchMode() ->with($fetchMode, $arg1, $arg2) ->will($this->returnValue(true)); - self::assertAttributeSame(\PDO::FETCH_BOTH, 'defaultFetchMode', $this->stmt); + self::assertAttributeSame(FetchMode::MIXED, 'defaultFetchMode', $this->stmt); self::assertTrue($this->stmt->setFetchMode($fetchMode, $arg1, $arg2)); self::assertAttributeSame($fetchMode, 'defaultFetchMode', $this->stmt); } diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php index 35c1b7e4f39..33263984161 100644 --- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Query; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Query\QueryBuilder; @@ -600,12 +601,12 @@ public function testCreateNamedParameter() $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where( - $qb->expr()->eq('u.name', $qb->createNamedParameter(10, \PDO::PARAM_INT)) + $qb->expr()->eq('u.name', $qb->createNamedParameter(10, ParameterType::INTEGER)) ); self::assertEquals('SELECT u.* FROM users u WHERE u.name = :dcValue1', (string)$qb); self::assertEquals(10, $qb->getParameter('dcValue1')); - self::assertEquals(\PDO::PARAM_INT, $qb->getParameterType('dcValue1')); + self::assertEquals(ParameterType::INTEGER, $qb->getParameterType('dcValue1')); } public function testCreateNamedParameterCustomPlaceholder() @@ -613,12 +614,12 @@ public function testCreateNamedParameterCustomPlaceholder() $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where( - $qb->expr()->eq('u.name', $qb->createNamedParameter(10, \PDO::PARAM_INT, ':test')) + $qb->expr()->eq('u.name', $qb->createNamedParameter(10, ParameterType::INTEGER, ':test')) ); self::assertEquals('SELECT u.* FROM users u WHERE u.name = :test', (string)$qb); self::assertEquals(10, $qb->getParameter('test')); - self::assertEquals(\PDO::PARAM_INT, $qb->getParameterType('test')); + self::assertEquals(ParameterType::INTEGER, $qb->getParameterType('test')); } public function testCreatePositionalParameter() @@ -626,12 +627,12 @@ public function testCreatePositionalParameter() $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where( - $qb->expr()->eq('u.name', $qb->createPositionalParameter(10, \PDO::PARAM_INT)) + $qb->expr()->eq('u.name', $qb->createPositionalParameter(10, ParameterType::INTEGER)) ); self::assertEquals('SELECT u.* FROM users u WHERE u.name = ?', (string)$qb); self::assertEquals(10, $qb->getParameter(1)); - self::assertEquals(\PDO::PARAM_INT, $qb->getParameterType(1)); + self::assertEquals(ParameterType::INTEGER, $qb->getParameterType(1)); } /** @@ -847,9 +848,9 @@ public function testGetParameterType() self::assertNull($qb->getParameterType('name')); - $qb->setParameter('name', 'foo', \PDO::PARAM_STR); + $qb->setParameter('name', 'foo', ParameterType::STRING); - self::assertSame(\PDO::PARAM_STR, $qb->getParameterType('name')); + self::assertSame(ParameterType::STRING, $qb->getParameterType('name')); } /** @@ -868,12 +869,12 @@ public function testGetParameterTypes() self::assertSame(array(), $qb->getParameterTypes()); - $qb->setParameter('name', 'foo', \PDO::PARAM_STR); + $qb->setParameter('name', 'foo', ParameterType::STRING); $qb->where('is_active = :isActive'); - $qb->setParameter('isActive', true, \PDO::PARAM_BOOL); + $qb->setParameter('isActive', true, ParameterType::BOOLEAN); - self::assertSame(array('name' => \PDO::PARAM_STR, 'isActive' => \PDO::PARAM_BOOL), $qb->getParameterTypes()); + self::assertSame(array('name' => ParameterType::STRING, 'isActive' => ParameterType::BOOLEAN), $qb->getParameterTypes()); } /** diff --git a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php index d284b107eb1..c357988bf6a 100644 --- a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php +++ b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\SQLParserUtils; /** @@ -95,34 +96,40 @@ public function dataExpandListParameters() array(Connection::PARAM_INT_ARRAY), 'SELECT * FROM Foo WHERE foo IN (?, ?, ?)', array(1, 2, 3), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT) + array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) ), // Positional: One non-list before d one after list-needle array( "SELECT * FROM Foo WHERE foo = ? AND bar IN (?)", array("string", array(1, 2, 3)), - array(\PDO::PARAM_STR, Connection::PARAM_INT_ARRAY), + array(ParameterType::STRING, Connection::PARAM_INT_ARRAY), 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?)', array("string", 1, 2, 3), - array(\PDO::PARAM_STR, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT) + array(ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) ), // Positional: One non-list after list-needle array( "SELECT * FROM Foo WHERE bar IN (?) AND baz = ?", array(array(1, 2, 3), "foo"), - array(Connection::PARAM_INT_ARRAY, \PDO::PARAM_STR), + array(Connection::PARAM_INT_ARRAY, ParameterType::STRING), 'SELECT * FROM Foo WHERE bar IN (?, ?, ?) AND baz = ?', array(1, 2, 3, "foo"), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR) + array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) ), // Positional: One non-list before and one after list-needle array( "SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ?", array(1, array(1, 2, 3), 4), - array(\PDO::PARAM_INT, Connection::PARAM_INT_ARRAY, \PDO::PARAM_INT), + array(ParameterType::INTEGER, Connection::PARAM_INT_ARRAY, ParameterType::INTEGER), 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ?', array(1, 1, 2, 3, 4), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT) + array( + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ) ), // Positional: Two lists array( @@ -131,7 +138,13 @@ public function dataExpandListParameters() array(Connection::PARAM_INT_ARRAY, Connection::PARAM_INT_ARRAY), 'SELECT * FROM Foo WHERE foo IN (?, ?, ?, ?, ?)', array(1, 2, 3, 4, 5), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT) + array( + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ) ), // Positional: Empty "integer" array DDC-1978 array( @@ -155,47 +168,67 @@ public function dataExpandListParameters() array( "SELECT * FROM Foo WHERE foo = ? AND bar = ? AND baz = ?", array(1 => 'bar', 2 => 'baz', 0 => 1), - array(2 => \PDO::PARAM_STR, 1 => \PDO::PARAM_STR), + array(2 => ParameterType::STRING, 1 => ParameterType::STRING), 'SELECT * FROM Foo WHERE foo = ? AND bar = ? AND baz = ?', array(1 => 'bar', 0 => 1, 2 => 'baz'), - array(1 => \PDO::PARAM_STR, 2 => \PDO::PARAM_STR) + array(1 => ParameterType::STRING, 2 => ParameterType::STRING), ), // Positional: explicit keys for array params and array types array( "SELECT * FROM Foo WHERE foo IN (?) AND bar IN (?) AND baz = ?", array(1 => array('bar1', 'bar2'), 2 => true, 0 => array(1, 2, 3)), - array(2 => \PDO::PARAM_BOOL, 1 => Connection::PARAM_STR_ARRAY, 0 => Connection::PARAM_INT_ARRAY), + array(2 => ParameterType::BOOLEAN, 1 => Connection::PARAM_STR_ARRAY, 0 => Connection::PARAM_INT_ARRAY), 'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND bar IN (?, ?) AND baz = ?', array(1, 2, 3, 'bar1', 'bar2', true), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_STR, \PDO::PARAM_BOOL) + array( + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::STRING, + ParameterType::STRING, + ParameterType::BOOLEAN, + ) ), // Positional starts from 1: One non-list before and one after list-needle array( "SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ? AND foo IN (?)", array(1 => 1, 2 => array(1, 2, 3), 3 => 4, 4 => array(5, 6)), - array(1 => \PDO::PARAM_INT, 2 => Connection::PARAM_INT_ARRAY, 3 => \PDO::PARAM_INT, 4 => Connection::PARAM_INT_ARRAY), + array( + 1 => ParameterType::INTEGER, + 2 => Connection::PARAM_INT_ARRAY, + 3 => ParameterType::INTEGER, + 4 => Connection::PARAM_INT_ARRAY, + ), 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ? AND foo IN (?, ?)', array(1, 1, 2, 3, 4, 5, 6), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT) + array( + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ParameterType::INTEGER, + ) ), // Named parameters : Very simple with param int array( "SELECT * FROM Foo WHERE foo = :foo", array('foo'=>1), - array('foo'=>\PDO::PARAM_INT), + array('foo' => ParameterType::INTEGER), 'SELECT * FROM Foo WHERE foo = ?', array(1), - array(\PDO::PARAM_INT) + array(ParameterType::INTEGER), ), // Named parameters : Very simple with param int and string array( "SELECT * FROM Foo WHERE foo = :foo AND bar = :bar", array('bar'=>'Some String','foo'=>1), - array('foo'=>\PDO::PARAM_INT,'bar'=>\PDO::PARAM_STR), + array('foo' => ParameterType::INTEGER, 'bar' => ParameterType::STRING), 'SELECT * FROM Foo WHERE foo = ? AND bar = ?', array(1,'Some String'), - array(\PDO::PARAM_INT, \PDO::PARAM_STR) + array(ParameterType::INTEGER, ParameterType::STRING) ), // Named parameters : Very simple with one needle array( @@ -204,34 +237,34 @@ public function dataExpandListParameters() array('foo'=>Connection::PARAM_INT_ARRAY), 'SELECT * FROM Foo WHERE foo IN (?, ?, ?)', array(1, 2, 3), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT) + array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER), ), // Named parameters: One non-list before d one after list-needle array( "SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar)", array('foo'=>"string", 'bar'=>array(1, 2, 3)), - array('foo'=>\PDO::PARAM_STR, 'bar'=>Connection::PARAM_INT_ARRAY), + array('foo' => ParameterType::STRING, 'bar' => Connection::PARAM_INT_ARRAY), 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?)', array("string", 1, 2, 3), - array(\PDO::PARAM_STR, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT) + array(ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) ), // Named parameters: One non-list after list-needle array( "SELECT * FROM Foo WHERE bar IN (:bar) AND baz = :baz", array('bar'=>array(1, 2, 3), 'baz'=>"foo"), - array('bar'=>Connection::PARAM_INT_ARRAY, 'baz'=>\PDO::PARAM_STR), + array('bar'=>Connection::PARAM_INT_ARRAY, 'baz'=>ParameterType::STRING), 'SELECT * FROM Foo WHERE bar IN (?, ?, ?) AND baz = ?', array(1, 2, 3, "foo"), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR) + array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) ), // Named parameters: One non-list before and one after list-needle array( "SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar) AND baz = :baz", array('bar'=>array(1, 2, 3),'foo'=>1, 'baz'=>4), - array('bar'=>Connection::PARAM_INT_ARRAY, 'foo'=>\PDO::PARAM_INT, 'baz'=>\PDO::PARAM_INT), + array('bar'=>Connection::PARAM_INT_ARRAY, 'foo'=>ParameterType::INTEGER, 'baz'=>ParameterType::INTEGER), 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ?', array(1, 1, 2, 3, 4), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT) + array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) ), // Named parameters: Two lists array( @@ -240,16 +273,16 @@ public function dataExpandListParameters() array('a'=>Connection::PARAM_INT_ARRAY, 'b'=>Connection::PARAM_INT_ARRAY), 'SELECT * FROM Foo WHERE foo IN (?, ?, ?, ?, ?)', array(1, 2, 3, 4, 5), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT) + array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) ), // Named parameters : With the same name arg type string array( "SELECT * FROM Foo WHERE foo <> :arg AND bar = :arg", array('arg'=>"Some String"), - array('arg'=>\PDO::PARAM_STR), + array('arg'=>ParameterType::STRING), 'SELECT * FROM Foo WHERE foo <> ? AND bar = ?', array("Some String","Some String"), - array(\PDO::PARAM_STR,\PDO::PARAM_STR,) + array(ParameterType::STRING,ParameterType::STRING,) ), // Named parameters : With the same name arg array( @@ -258,17 +291,17 @@ public function dataExpandListParameters() array('arg'=>Connection::PARAM_INT_ARRAY), 'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND NOT bar IN (?, ?, ?)', array(1, 2, 3, 1, 2, 3), - array(\PDO::PARAM_INT,\PDO::PARAM_INT, \PDO::PARAM_INT,\PDO::PARAM_INT,\PDO::PARAM_INT, \PDO::PARAM_INT) + array(ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER,ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER) ), // Named parameters : Same name, other name in between DBAL-299 array( "SELECT * FROM Foo WHERE (:foo = 2) AND (:bar = 3) AND (:foo = 2)", array('foo'=>2,'bar'=>3), - array('foo'=>\PDO::PARAM_INT,'bar'=>\PDO::PARAM_INT), + array('foo'=>ParameterType::INTEGER,'bar'=>ParameterType::INTEGER), 'SELECT * FROM Foo WHERE (? = 2) AND (? = 3) AND (? = 2)', array(2, 3, 2), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT) + array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) ), // Named parameters : Empty "integer" array DDC-1978 array( @@ -294,7 +327,7 @@ public function dataExpandListParameters() array('foo' => Connection::PARAM_INT_ARRAY, 'baz' => 'string'), 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ? OR baz = ?', array(1, 2, 'bar', 'baz'), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR, 'string') + array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING, 'string') ), array( "SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar", @@ -302,24 +335,24 @@ public function dataExpandListParameters() array('foo' => Connection::PARAM_INT_ARRAY), 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', array(1, 2, 'bar'), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR) + array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) ), // Params/types with colons array( "SELECT * FROM Foo WHERE foo = :foo OR bar = :bar", array(':foo' => 'foo', ':bar' => 'bar'), - array(':foo' => \PDO::PARAM_INT), + array(':foo' => ParameterType::INTEGER), 'SELECT * FROM Foo WHERE foo = ? OR bar = ?', array('foo', 'bar'), - array(\PDO::PARAM_INT, \PDO::PARAM_STR) + array(ParameterType::INTEGER, ParameterType::STRING) ), array( "SELECT * FROM Foo WHERE foo = :foo OR bar = :bar", array(':foo' => 'foo', ':bar' => 'bar'), - array(':foo' => \PDO::PARAM_INT, 'bar' => \PDO::PARAM_INT), + array(':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER), 'SELECT * FROM Foo WHERE foo = ? OR bar = ?', array('foo', 'bar'), - array(\PDO::PARAM_INT, \PDO::PARAM_INT) + array(ParameterType::INTEGER, ParameterType::INTEGER) ), array( "SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar", @@ -327,7 +360,7 @@ public function dataExpandListParameters() array('foo' => Connection::PARAM_INT_ARRAY), 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', array(1, 2, 'bar'), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR) + array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) ), array( "SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar", @@ -335,33 +368,33 @@ public function dataExpandListParameters() array(':foo' => Connection::PARAM_INT_ARRAY), 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', array(1, 2, 'bar'), - array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR) + array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) ), // DBAL-522 - null valued parameters are not considered array( 'INSERT INTO Foo (foo, bar) values (:foo, :bar)', array('foo' => 1, 'bar' => null), - array(':foo' => \PDO::PARAM_INT, ':bar' => \PDO::PARAM_NULL), + array(':foo' => ParameterType::INTEGER, ':bar' => ParameterType::NULL), 'INSERT INTO Foo (foo, bar) values (?, ?)', array(1, null), - array(\PDO::PARAM_INT, \PDO::PARAM_NULL) + array(ParameterType::INTEGER, ParameterType::NULL) ), array( 'INSERT INTO Foo (foo, bar) values (?, ?)', array(1, null), - array(\PDO::PARAM_INT, \PDO::PARAM_NULL), + array(ParameterType::INTEGER, ParameterType::NULL), 'INSERT INTO Foo (foo, bar) values (?, ?)', array(1, null), - array(\PDO::PARAM_INT, \PDO::PARAM_NULL) + array(ParameterType::INTEGER, ParameterType::NULL) ), // DBAL-1205 - Escaped single quotes SQL- and C-Style array( "SELECT * FROM Foo WHERE foo = :foo||''':not_a_param''\\'' OR bar = ''':not_a_param''\\'':bar", array(':foo' => 1, ':bar' => 2), - array(':foo' => \PDO::PARAM_INT, 'bar' => \PDO::PARAM_INT), + array(':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER), 'SELECT * FROM Foo WHERE foo = ?||\'\'\':not_a_param\'\'\\\'\' OR bar = \'\'\':not_a_param\'\'\\\'\'?', array(1, 2), - array(\PDO::PARAM_INT, \PDO::PARAM_INT) + array(ParameterType::INTEGER, ParameterType::INTEGER) ), ); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php index 9095a814c57..f1f8902a52d 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php @@ -6,6 +6,9 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer; +/** + * @requires extension pdo_sqlite + */ class SingleDatabaseSynchronizerTest extends \PHPUnit\Framework\TestCase { private $conn; diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php index 10fc3cfd24e..4b6bc232406 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -5,6 +5,9 @@ use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; +/** + * @requires extension pdo_sqlite + */ class PoolingShardConnectionTest extends \PHPUnit\Framework\TestCase { public function testConnect() diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index 3e05c5fb9c5..fa22536f2d4 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Statement; use Doctrine\DBAL\Logging\SQLLogger; @@ -62,12 +63,12 @@ protected function setUp() public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() { - $name = 'foo'; - $var = 'bar'; - $type = \PDO::PARAM_STR; - $values = array($name => $var); - $types = array($name => $type); - $sql = ''; + $name = 'foo'; + $var = 'bar'; + $type = ParameterType::STRING; + $values = [$name => $var]; + $types = [$name => $type]; + $sql = ''; $logger = $this->createMock('\Doctrine\DBAL\Logging\SQLLogger'); $logger->expects($this->once()) @@ -106,11 +107,11 @@ public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedTo public function testExecuteCallsStartQueryWithTheParametersBoundViaBindParam() { - $name = 'foo'; - $var = 'bar'; + $name = 'foo'; + $var = 'bar'; $values = [$name => $var]; - $types = [$name => \PDO::PARAM_STR]; - $sql = ''; + $types = [$name => ParameterType::STRING]; + $sql = ''; $logger = $this->createMock(SQLLogger::class); $logger->expects(self::once()) diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index a68bf692381..f260d57c9f5 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; @@ -28,7 +29,7 @@ protected function setUp() public function testReturnsBindingType() { - self::assertSame(\PDO::PARAM_LOB, $this->type->getBindingType()); + self::assertSame(ParameterType::LARGE_OBJECT, $this->type->getBindingType()); } public function testReturnsName() diff --git a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php index 9d32448be51..5051853eb2a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateImmutableType; @@ -37,7 +38,7 @@ public function testReturnsName() public function testReturnsBindingType() { - self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType()); + self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } public function testConvertsDateTimeImmutableInstanceToDatabaseValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php index a134180830c..b7c99825e0a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeImmutableType; @@ -37,7 +38,7 @@ public function testReturnsName() public function testReturnsBindingType() { - self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType()); + self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } public function testConvertsDateTimeImmutableInstanceToDatabaseValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php index 87d448ceab0..302aea26b7f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeTzImmutableType; @@ -37,7 +38,7 @@ public function testReturnsName() public function testReturnsBindingType() { - self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType()); + self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } public function testConvertsDateTimeImmutableInstanceToDatabaseValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index bbfc0365e30..211baeef101 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; @@ -28,7 +29,7 @@ protected function setUp() public function testReturnsBindingType() { - self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType()); + self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } public function testReturnsName() diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index 851b2e972b6..a92bf5f6c41 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; @@ -28,7 +29,7 @@ protected function setUp() public function testReturnsBindingType() { - self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType()); + self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } public function testReturnsName() diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php index 9bca6fa0c34..c1de23ac641 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\TimeImmutableType; @@ -37,7 +38,7 @@ public function testReturnsName() public function testReturnsBindingType() { - self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType()); + self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } public function testConvertsDateTimeImmutableInstanceToDatabaseValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php index 1ce9adfc029..ebf21284651 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\VarDateTimeImmutableType; @@ -36,7 +37,7 @@ public function testReturnsName() public function testReturnsBindingType() { - self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType()); + self::assertSame(ParameterType::STRING, $this->type->getBindingType()); } public function testConvertsDateTimeImmutableInstanceToDatabaseValue() diff --git a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php index 03d44caae48..760dbff40cf 100644 --- a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php @@ -2,11 +2,17 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\DBAL\ParameterType; + class DriverConnectionMock implements \Doctrine\DBAL\Driver\Connection { public function prepare($prepareString) {} public function query() {} - public function quote($input, $type=\PDO::PARAM_STR) {} + + public function quote($input, $type = ParameterType::STRING) + { + } + public function exec($statement) {} public function lastInsertId($name = null) {} public function beginTransaction() {} @@ -14,4 +20,4 @@ public function commit() {} public function rollBack() {} public function errorCode() {} public function errorInfo() {} -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php deleted file mode 100644 index 629352fbcc9..00000000000 --- a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php +++ /dev/null @@ -1,101 +0,0 @@ - - */ -class HydratorMockStatement implements \Doctrine\DBAL\Driver\Statement -{ - private $_resultSet; - - /** - * Creates a new mock statement that will serve the provided fake result set to clients. - * - * @param array $resultSet The faked SQL result set. - */ - public function __construct(array $resultSet) - { - $this->_resultSet = $resultSet; - } - - /** - * Fetches all rows from the result set. - * - * @return array - */ - public function fetchAll($fetchMode = null, $columnIndex = null, array $ctorArgs = null) - { - return $this->_resultSet; - } - - public function fetchColumn($columnNumber = 0) - { - $row = current($this->_resultSet); - if ( ! is_array($row)) return false; - $val = array_shift($row); - return $val !== null ? $val : false; - } - - /** - * Fetches the next row in the result set. - * - */ - public function fetch($fetchMode = null) - { - $current = current($this->_resultSet); - next($this->_resultSet); - return $current; - } - - /** - * Closes the cursor, enabling the statement to be executed again. - * - * @return boolean - */ - public function closeCursor() - { - return true; - } - - public function setResultSet(array $resultSet) - { - reset($resultSet); - $this->_resultSet = $resultSet; - } - - public function bindColumn($column, &$param, $type = null) - { - } - - public function bindValue($param, $value, $type = null) - { - } - - public function bindParam($column, &$variable, $type = null, $length = null, $driverOptions = array()) - { - } - - public function columnCount() - { - } - - public function errorCode() - { - } - - public function errorInfo() - { - } - - public function execute($params = array()) - { - } - - public function rowCount() - { - } -} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Mocks/PDOMock.php b/tests/Doctrine/Tests/Mocks/PDOMock.php deleted file mode 100644 index 0967c17b517..00000000000 --- a/tests/Doctrine/Tests/Mocks/PDOMock.php +++ /dev/null @@ -1,10 +0,0 @@ - 'pdo_sqlite', 'memory' => true