From 5e2b7f8959794e97d9fc653da5d61358b708095a Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 26 Dec 2017 21:19:27 -0800 Subject: [PATCH 01/14] Added visibility for interface methods as required by the coding standard --- lib/Doctrine/DBAL/Driver/Connection.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/Connection.php b/lib/Doctrine/DBAL/Driver/Connection.php index 833b2430c47..d70837a70bd 100644 --- a/lib/Doctrine/DBAL/Driver/Connection.php +++ b/lib/Doctrine/DBAL/Driver/Connection.php @@ -36,14 +36,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. @@ -53,7 +53,7 @@ function query(); * * @return mixed */ - function quote($input, $type=\PDO::PARAM_STR); + public function quote($input, $type = \PDO::PARAM_STR); /** * Executes an SQL statement and return the number of affected rows. @@ -62,7 +62,7 @@ function quote($input, $type=\PDO::PARAM_STR); * * @return int */ - function exec($statement); + public function exec($statement); /** * Returns the ID of the last inserted row or sequence value. @@ -71,40 +71,40 @@ function exec($statement); * * @return string */ - function lastInsertId($name = null); + public function lastInsertId($name = null); /** * Initiates a transaction. * * @return bool TRUE on success or FALSE on failure. */ - function beginTransaction(); + public function beginTransaction(); /** * Commits a transaction. * * @return bool TRUE on success or FALSE on failure. */ - function commit(); + public function commit(); /** * Rolls back the current transaction, as initiated by beginTransaction(). * * @return bool 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(); } From 99356c28c52e300a3af42d393e6e41470e6bea38 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 12 Jan 2018 18:04:30 -0800 Subject: [PATCH 02/14] Removed HydratorMockStatement since it's not used anywhere since 2.0 --- .../Tests/Mocks/HydratorMockStatement.php | 101 ------------------ 1 file changed, 101 deletions(-) delete mode 100644 tests/Doctrine/Tests/Mocks/HydratorMockStatement.php diff --git a/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php b/tests/Doctrine/Tests/Mocks/HydratorMockStatement.php deleted file mode 100644 index 00967829bd9..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 bool - */ - 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 From 9ca04dd8724b49d7f8dece9ec8ed27dfeaad63fe Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 11 Dec 2017 19:54:45 -0800 Subject: [PATCH 03/14] Introduced new constants --- lib/Doctrine/DBAL/ColumnCase.php | 30 +++++++++++ lib/Doctrine/DBAL/Driver/Statement.php | 9 ++-- lib/Doctrine/DBAL/FetchMode.php | 69 ++++++++++++++++++++++++++ lib/Doctrine/DBAL/ParameterType.php | 51 +++++++++++++++++++ 4 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 lib/Doctrine/DBAL/ColumnCase.php create mode 100644 lib/Doctrine/DBAL/FetchMode.php create mode 100644 lib/Doctrine/DBAL/ParameterType.php diff --git a/lib/Doctrine/DBAL/ColumnCase.php b/lib/Doctrine/DBAL/ColumnCase.php new file mode 100644 index 00000000000..90ad11864e2 --- /dev/null +++ b/lib/Doctrine/DBAL/ColumnCase.php @@ -0,0 +1,30 @@ + Date: Mon, 25 Dec 2017 11:36:49 -0800 Subject: [PATCH 04/14] Replaced PDO::FETCH_* and PDO::PARAM_* constants --- .../data-retrieval-and-manipulation.rst | 18 ++- docs/en/reference/known-vendor-issues.rst | 2 +- docs/en/reference/security.rst | 4 +- lib/Doctrine/DBAL/Cache/ArrayStatement.php | 43 +++--- .../DBAL/Cache/ResultCacheStatement.php | 28 ++-- lib/Doctrine/DBAL/Connection.php | 11 +- lib/Doctrine/DBAL/Driver/Connection.php | 4 +- .../Driver/DrizzlePDOMySql/Connection.php | 6 +- .../DBAL/Driver/IBMDB2/DB2Connection.php | 6 +- .../DBAL/Driver/IBMDB2/DB2Statement.php | 39 +++--- .../DBAL/Driver/Mysqli/MysqliConnection.php | 3 +- .../DBAL/Driver/Mysqli/MysqliStatement.php | 35 ++--- .../DBAL/Driver/OCI8/OCI8Connection.php | 9 +- .../DBAL/Driver/OCI8/OCI8Statement.php | 30 +++-- lib/Doctrine/DBAL/Driver/PDOConnection.php | 3 +- .../DBAL/Driver/PDOSqlsrv/Connection.php | 3 +- .../DBAL/Driver/PDOSqlsrv/Statement.php | 7 +- lib/Doctrine/DBAL/Driver/PDOStatement.php | 6 +- lib/Doctrine/DBAL/Driver/ResultStatement.php | 30 ++--- .../SQLAnywhere/SQLAnywhereConnection.php | 3 +- .../SQLAnywhere/SQLAnywhereStatement.php | 53 +++++--- .../DBAL/Driver/SQLSrv/SQLSrvConnection.php | 3 +- .../DBAL/Driver/SQLSrv/SQLSrvStatement.php | 33 ++--- lib/Doctrine/DBAL/Driver/Statement.php | 15 ++- lib/Doctrine/DBAL/Id/TableGenerator.php | 3 +- lib/Doctrine/DBAL/Portability/Statement.php | 29 +++-- lib/Doctrine/DBAL/Query/QueryBuilder.php | 11 +- lib/Doctrine/DBAL/SQLParserUtils.php | 6 +- .../DBAL/Schema/SqliteSchemaManager.php | 5 +- lib/Doctrine/DBAL/Statement.php | 7 +- lib/Doctrine/DBAL/Types/BigIntType.php | 3 +- lib/Doctrine/DBAL/Types/BinaryType.php | 3 +- lib/Doctrine/DBAL/Types/BlobType.php | 3 +- lib/Doctrine/DBAL/Types/BooleanType.php | 3 +- lib/Doctrine/DBAL/Types/IntegerType.php | 3 +- lib/Doctrine/DBAL/Types/SmallIntType.php | 3 +- lib/Doctrine/DBAL/Types/Type.php | 11 +- .../DBAL/Cache/QueryCacheProfileTest.php | 10 +- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 54 +++++--- .../Tests/DBAL/Functional/BlobTest.php | 10 +- .../Tests/DBAL/Functional/ConnectionTest.php | 6 +- .../Tests/DBAL/Functional/DataAccessTest.php | 72 ++++++---- .../Driver/PDOPgsqlConnectionTest.php | 7 +- .../DBAL/Functional/NamedParametersTest.php | 31 +++-- .../Tests/DBAL/Functional/PortabilityTest.php | 19 +-- .../Tests/DBAL/Functional/ResultCacheTest.php | 41 +++--- .../Tests/DBAL/Functional/StatementTest.php | 10 +- .../DBAL/Functional/Ticket/DBAL630Test.php | 15 ++- .../Tests/DBAL/Functional/WriteTest.php | 15 ++- .../Tests/DBAL/Portability/StatementTest.php | 10 +- .../Tests/DBAL/Query/QueryBuilderTest.php | 23 ++-- .../Tests/DBAL/SQLParserUtilsTest.php | 123 +++++++++++------- tests/Doctrine/Tests/DBAL/StatementTest.php | 21 +-- .../Doctrine/Tests/DBAL/Types/BinaryTest.php | 3 +- .../DBAL/Types/DateImmutableTypeTest.php | 3 +- .../DBAL/Types/DateTimeImmutableTypeTest.php | 3 +- .../Types/DateTimeTzImmutableTypeTest.php | 3 +- .../Tests/DBAL/Types/JsonArrayTest.php | 3 +- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 3 +- .../DBAL/Types/TimeImmutableTypeTest.php | 3 +- .../Types/VarDateTimeImmutableTypeTest.php | 3 +- .../Tests/Mocks/DriverConnectionMock.php | 10 +- 62 files changed, 599 insertions(+), 386 deletions(-) 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/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 2e1cba9fe68..fab2f18772c 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -20,7 +20,7 @@ namespace Doctrine\DBAL\Cache; use Doctrine\DBAL\Driver\ResultStatement; -use PDO; +use Doctrine\DBAL\FetchMode; class ArrayStatement implements \IteratorAggregate, ResultStatement { @@ -42,7 +42,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement /** * @var int */ - private $defaultFetchMode = PDO::FETCH_BOTH; + private $defaultFetchMode = FetchMode::MIXED; /** * @param array $data @@ -100,23 +100,30 @@ public function getIterator() */ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { - 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; } - 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); + } + + 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."); } /** @@ -137,7 +144,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); // TODO: verify that return false is the correct behavior return $row[$columnIndex] ?? false; diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index c36c60e6c49..83c6a1660e7 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -22,7 +22,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. @@ -80,7 +80,7 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement /** * @var int */ - private $defaultFetchMode = PDO::FETCH_BOTH; + private $defaultFetchMode = FetchMode::MIXED; /** * @param \Doctrine\DBAL\Driver\Statement $stmt @@ -153,24 +153,32 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $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; @@ -194,7 +202,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); // TODO: verify that return false is the correct behavior return $row[$columnIndex] ?? false; diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 8b7e69f611e..71053321c21 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -21,7 +21,6 @@ use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Exception\InvalidArgumentException; -use PDO; use Closure; use Exception; use Doctrine\DBAL\Types\Type; @@ -195,7 +194,7 @@ class Connection implements DriverConnection /** * @var int */ - protected $defaultFetchMode = PDO::FETCH_ASSOC; + protected $defaultFetchMode = FetchMode::ASSOCIATIVE; /** * Initializes a new instance of the Connection class. @@ -563,7 +562,7 @@ public function setFetchMode($fetchMode) */ public function fetchAssoc($statement, array $params = [], array $types = []) { - return $this->executeQuery($statement, $params, $types)->fetch(PDO::FETCH_ASSOC); + return $this->executeQuery($statement, $params, $types)->fetch(FetchMode::ASSOCIATIVE); } /** @@ -578,7 +577,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); } /** @@ -808,7 +807,7 @@ private function extractTypeValues(array $columnList, array $types) $typeValues = []; foreach ($columnList as $columnIndex => $columnName) { - $typeValues[] = $types[$columnName] ?? \PDO::PARAM_STR; + $typeValues[] = $types[$columnName] ?? ParameterType::STRING; } return $typeValues; @@ -1592,7 +1591,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 d70837a70bd..773407510a6 100644 --- a/lib/Doctrine/DBAL/Driver/Connection.php +++ b/lib/Doctrine/DBAL/Driver/Connection.php @@ -19,6 +19,8 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\ParameterType; + /** * Connection interface. * Driver connections must implement this interface. @@ -53,7 +55,7 @@ public function query(); * * @return mixed */ - public 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. diff --git a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php index 61a23e772dd..bfc61acf9b8 100644 --- a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php +++ b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php @@ -19,6 +19,8 @@ namespace Doctrine\DBAL\Driver\DrizzlePDOMySql; +use Doctrine\DBAL\ParameterType; + /** * @author Kim Hemsø Rasmussen */ @@ -27,9 +29,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) { return $value ? 'true' : 'false'; } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index b538a2f240f..5aef861c497 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -21,6 +21,7 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; +use Doctrine\DBAL\ParameterType; class DB2Connection implements Connection, ServerInfoAwareConnection { @@ -98,10 +99,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 21f341a8e8f..874c6a30a01 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -21,6 +21,8 @@ use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; class DB2Statement implements \IteratorAggregate, Statement { @@ -35,19 +37,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 int */ - private $_defaultFetchMode = \PDO::FETCH_BOTH; + private $_defaultFetchMode = FetchMode::MIXED; /** * Indicates whether the statement is in the state when fetching results is possible @@ -62,8 +64,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, ]; /** @@ -77,7 +79,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); } @@ -85,7 +87,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; @@ -216,14 +218,16 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $fetchMode = $fetchMode ?: $this->_defaultFetchMode; switch ($fetchMode) { - case \PDO::FETCH_COLUMN: + case FetchMode::COLUMN: return $this->fetchColumn(); - 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; @@ -240,10 +244,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.'); } @@ -257,12 +264,12 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n $rows = []; switch ($fetchMode) { - case \PDO::FETCH_CLASS: + case FetchMode::CUSTOM_OBJECT: while ($row = call_user_func_array([$this, 'fetch'], func_get_args())) { $rows[] = $row; } break; - case \PDO::FETCH_COLUMN: + case FetchMode::COLUMN: while ($row = $this->fetchColumn()) { $rows[] = $row; } @@ -281,7 +288,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 182fd5817fb..b3314b46dfb 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -22,6 +22,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 @@ -145,7 +146,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 e27951cccaa..d08f2fe427f 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -21,7 +21,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 @@ -32,11 +33,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. ]; /** @@ -79,7 +80,7 @@ class MysqliStatement implements \IteratorAggregate, Statement /** * @var int */ - protected $_defaultFetchMode = PDO::FETCH_BOTH; + protected $_defaultFetchMode = FetchMode::MIXED; /** * Indicates whether the statement is in the state when fetching results is possible @@ -112,7 +113,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'; @@ -133,7 +134,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'; @@ -274,7 +275,7 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $fetchMode = $fetchMode ?: $this->_defaultFetchMode; - if ($fetchMode === PDO::FETCH_COLUMN) { + if ($fetchMode === FetchMode::COLUMN) { return $this->fetchColumn(); } @@ -288,19 +289,19 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE } 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(); @@ -323,7 +324,8 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n $fetchMode = $fetchMode ?: $this->_defaultFetchMode; $rows = []; - if (PDO::FETCH_COLUMN == $fetchMode) { + + if ($fetchMode === FetchMode::COLUMN) { while (($row = $this->fetchColumn()) !== false) { $rows[] = $row; } @@ -341,7 +343,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; } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index 95898aa8b4c..9d68bea7de1 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -21,6 +21,7 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; +use Doctrine\DBAL\ParameterType; /** * OCI8 implementation of the Connection interface. @@ -120,7 +121,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; @@ -152,13 +153,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 09770e05b0d..e4c513849f7 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -21,8 +21,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. @@ -56,16 +57,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 int */ - protected $_defaultFetchMode = PDO::FETCH_BOTH; + protected $_defaultFetchMode = FetchMode::MIXED; /** * @var array @@ -254,7 +255,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); } @@ -262,11 +263,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); @@ -387,11 +388,11 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $fetchMode = $fetchMode ?: $this->_defaultFetchMode; - if ($fetchMode === PDO::FETCH_COLUMN) { + if ($fetchMode === FetchMode::COLUMN) { return $this->fetchColumn(); } - if (PDO::FETCH_OBJ == $fetchMode) { + if ($fetchMode === FetchMode::STANDARD_OBJECT) { return oci_fetch_object($this->_sth); } @@ -414,7 +415,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n $result = []; - if (PDO::FETCH_OBJ == $fetchMode) { + if ($fetchMode == FetchMode::STANDARD_OBJECT) { while ($row = $this->fetch($fetchMode)) { $result[] = $row; } @@ -432,7 +433,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; } @@ -445,7 +447,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 cb47c3e9a86..91629f65bdb 100644 --- a/lib/Doctrine/DBAL/Driver/PDOConnection.php +++ b/lib/Doctrine/DBAL/Driver/PDOConnection.php @@ -19,6 +19,7 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\ParameterType; use PDO; /** @@ -110,7 +111,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); } diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php index 8c561555cff..36747110109 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php @@ -20,6 +20,7 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv; use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\ParameterType; /** * Sqlsrv Connection implementation. @@ -55,7 +56,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 3d1b22a656e..82e2c3e3565 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php @@ -20,6 +20,7 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv; use Doctrine\DBAL\Driver\PDOStatement; +use Doctrine\DBAL\ParameterType; use PDO; /** @@ -30,9 +31,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; } @@ -42,7 +43,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 deb35de0162..6c0455c65a0 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -19,6 +19,8 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\ParameterType; + /** * The PDO implementation of the Statement interface. * Used by all PDO-based drivers. @@ -61,7 +63,7 @@ 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) { try { return parent::bindValue($param, $value, $type); @@ -73,7 +75,7 @@ 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) { try { return parent::bindParam($column, $variable, $type, $length, $driverOptions); diff --git a/lib/Doctrine/DBAL/Driver/ResultStatement.php b/lib/Doctrine/DBAL/Driver/ResultStatement.php index 92b9de7d0b3..b03862ff6e3 100644 --- a/lib/Doctrine/DBAL/Driver/ResultStatement.php +++ b/lib/Doctrine/DBAL/Driver/ResultStatement.php @@ -45,13 +45,11 @@ public function columnCount(); /** * Sets the fetch mode to use while iterating this statement. * - * @param int $fetchMode The fetch mode must be one of the PDO::FETCH_* constants. + * @param int $fetchMode The fetch mode must be one of the {@link \Doctrine\DBAL\FetchMode} constants. * @param mixed $arg2 * @param mixed $arg3 * * @return bool - * - * @see PDO::FETCH_* constants. */ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null); @@ -59,8 +57,8 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null); * 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. + * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants, + * defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}. * @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, @@ -79,8 +77,6 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null); * * @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); @@ -88,21 +84,21 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE * 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. + * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants, + * defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}. * @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. + * * {@link \Doctrine\DBAL\FetchMode::COLUMN}: + * Returns the indicated 0-indexed column. + * * {@link \Doctrine\DBAL\FetchMode::CUSTOM_OBJECT}: + * 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. + * 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}. * * @return array - * - * @see \PDO::FETCH_* constants. */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null); diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php index 378f4e4144a..03be0576a7b 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php @@ -21,6 +21,7 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; +use Doctrine\DBAL\ParameterType; /** * SAP Sybase SQL Anywhere implementation of the Connection interface. @@ -172,7 +173,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 7d022b9afab..8a6b4a1176a 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -19,10 +19,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. @@ -39,19 +40,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. @@ -92,20 +93,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); } @@ -120,7 +124,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); } @@ -203,14 +207,16 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $fetchMode = $fetchMode ?: $this->defaultFetchMode; switch ($fetchMode) { - case PDO::FETCH_COLUMN: + case FetchMode::COLUMN: return $this->fetchColumn(); - 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; @@ -227,10 +233,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); } @@ -244,16 +253,18 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n $rows = []; switch ($fetchMode) { - case PDO::FETCH_CLASS: + case FetchMode::CUSTOM_OBJECT: while ($row = call_user_func_array([$this, 'fetch'], func_get_args())) { $rows[] = $row; } break; - case PDO::FETCH_COLUMN: + + case FetchMode::COLUMN: while ($row = $this->fetchColumn()) { $rows[] = $row; } break; + default: while ($row = $this->fetch($fetchMode)) { $rows[] = $row; @@ -268,7 +279,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/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index 6de138a4af5..52ad200cf7f 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -21,6 +21,7 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; +use Doctrine\DBAL\ParameterType; /** * SQL Server implementation for the Connection interface. @@ -102,7 +103,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 9c03f26ca7e..98fc5c4aee3 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -20,7 +20,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; @@ -73,20 +74,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 */ @@ -97,7 +98,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement * * @param int */ - private $defaultFetchMode = PDO::FETCH_BOTH; + private $defaultFetchMode = FetchMode::MIXED; /** * The last insert ID. @@ -139,7 +140,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( @@ -154,7 +155,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."); @@ -258,7 +259,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, @@ -315,7 +316,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX $args = func_get_args(); $fetchMode = $fetchMode ?: $this->defaultFetchMode; - if ($fetchMode === PDO::FETCH_COLUMN) { + if ($fetchMode === FetchMode::COLUMN) { return $this->fetchColumn(); } @@ -323,7 +324,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX 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; @@ -346,16 +347,18 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n $rows = []; switch ($fetchMode) { - case PDO::FETCH_CLASS: + case FetchMode::CUSTOM_OBJECT: while ($row = call_user_func_array([$this, 'fetch'], func_get_args())) { $rows[] = $row; } break; - case PDO::FETCH_COLUMN: + + case FetchMode::COLUMN: while ($row = $this->fetchColumn()) { $rows[] = $row; } break; + default: while ($row = $this->fetch($fetchMode)) { $rows[] = $row; @@ -370,7 +373,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 88e54068350..15b6bee1bae 100644 --- a/lib/Doctrine/DBAL/Driver/Statement.php +++ b/lib/Doctrine/DBAL/Driver/Statement.php @@ -19,6 +19,8 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\ParameterType; + /** * Statement interface. * Drivers must implement this interface. @@ -48,8 +50,7 @@ interface Statement extends ResultStatement * * @return bool 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 @@ -77,7 +78,7 @@ function bindValue($param, $value, $type = null); * * @return bool 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. @@ -86,7 +87,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. @@ -95,7 +96,7 @@ function errorCode(); * * @return array The error info array. */ - function errorInfo(); + public function errorInfo(); /** * Executes a prepared statement @@ -112,7 +113,7 @@ function errorInfo(); * * @return bool 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 @@ -125,5 +126,5 @@ function execute($params = null); * * @return int The number of rows. */ - function rowCount(); + public function rowCount(); } diff --git a/lib/Doctrine/DBAL/Id/TableGenerator.php b/lib/Doctrine/DBAL/Id/TableGenerator.php index 67705f54871..a6fa7e784a6 100644 --- a/lib/Doctrine/DBAL/Id/TableGenerator.php +++ b/lib/Doctrine/DBAL/Id/TableGenerator.php @@ -21,6 +21,7 @@ use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\FetchMode; /** * Table ID Generator for those poor languages that are missing sequences. @@ -124,7 +125,7 @@ public function nextValue($sequenceName) "WHERE sequence_name = ? " . $platform->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/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index 39d8d04b2d2..4b72dea79b0 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -19,7 +19,8 @@ namespace Doctrine\DBAL\Portability; -use PDO; +use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\ParameterType; /** * Portability wrapper for a Statement. @@ -48,7 +49,7 @@ class Statement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement /** * @var int */ - private $defaultFetchMode = PDO::FETCH_BOTH; + private $defaultFetchMode = FetchMode::MIXED; /** * Wraps Statement and applies portability measures. @@ -66,15 +67,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); } @@ -148,10 +149,11 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $row = $this->stmt->fetch($fetchMode); - $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) - ); + $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, $iterateRow, $fixCase); return $row; } @@ -170,12 +172,15 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n } $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]; } @@ -185,7 +190,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 5e0ce9118a1..d9d996f7fa4 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -19,6 +19,7 @@ namespace Doctrine\DBAL\Query; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\CompositeExpression; use Doctrine\DBAL\Connection; @@ -264,7 +265,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. */ @@ -1256,7 +1257,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++; @@ -1280,8 +1281,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 @@ -1289,7 +1290,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 afbb6aa4f10..d3b600c917a 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -139,7 +139,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) ); @@ -166,7 +168,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 9420bad888f..9f1adbd0f4e 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -20,6 +20,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; @@ -169,7 +170,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']) { @@ -200,7 +201,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 409d83fb79e..6469e501f0a 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -19,7 +19,6 @@ namespace Doctrine\DBAL; -use PDO; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Driver\Statement as DriverStatement; @@ -102,7 +101,7 @@ public function __construct($sql, Connection $conn) * * @return bool 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; @@ -114,7 +113,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); @@ -136,7 +135,7 @@ public function bindValue($name, $value, $type = null) * * @return bool 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; diff --git a/lib/Doctrine/DBAL/Types/BigIntType.php b/lib/Doctrine/DBAL/Types/BigIntType.php index c0ede8f5b12..9a2b42953ad 100644 --- a/lib/Doctrine/DBAL/Types/BigIntType.php +++ b/lib/Doctrine/DBAL/Types/BigIntType.php @@ -19,6 +19,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -50,7 +51,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 a22a4405425..a112e776a15 100644 --- a/lib/Doctrine/DBAL/Types/BinaryType.php +++ b/lib/Doctrine/DBAL/Types/BinaryType.php @@ -19,6 +19,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -73,6 +74,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 bd89301e21b..b0173e1a6d7 100644 --- a/lib/Doctrine/DBAL/Types/BlobType.php +++ b/lib/Doctrine/DBAL/Types/BlobType.php @@ -19,6 +19,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -72,6 +73,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 9fea80f10a2..748f7f52942 100644 --- a/lib/Doctrine/DBAL/Types/BooleanType.php +++ b/lib/Doctrine/DBAL/Types/BooleanType.php @@ -19,6 +19,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -65,6 +66,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 9e8d0da3799..3c83341ded0 100644 --- a/lib/Doctrine/DBAL/Types/IntegerType.php +++ b/lib/Doctrine/DBAL/Types/IntegerType.php @@ -19,6 +19,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -58,6 +59,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 4d7229c9be0..1a2abdbe062 100644 --- a/lib/Doctrine/DBAL/Types/SmallIntType.php +++ b/lib/Doctrine/DBAL/Types/SmallIntType.php @@ -19,6 +19,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -57,6 +58,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 7aa04f41360..eed08fc5a76 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -19,6 +19,7 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\DBALException; @@ -247,19 +248,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 int */ 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..5963962e651 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -11,10 +11,12 @@ 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; @@ -44,7 +46,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']) @@ -231,7 +235,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 +257,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 +277,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 +297,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 +492,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 +528,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 +564,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 +572,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 +624,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 +776,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/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 d35e9baf5c6..716513168f3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -3,10 +3,11 @@ 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\Platforms\TrimMode; use Doctrine\DBAL\Types\Type; -use PDO; class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase { @@ -42,7 +43,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); } @@ -60,7 +61,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); } @@ -78,7 +79,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]); } @@ -99,7 +100,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]); } @@ -135,7 +136,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); } @@ -165,7 +166,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); @@ -193,8 +194,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); @@ -226,7 +228,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); @@ -262,8 +264,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); @@ -302,8 +305,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); @@ -346,8 +350,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); @@ -393,8 +403,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); @@ -430,14 +448,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); } @@ -614,8 +632,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); @@ -641,7 +659,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."); @@ -659,7 +677,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]); @@ -691,7 +709,7 @@ public function testFetchAllSupportFetchClass() $stmt->execute(); $results = $stmt->fetchAll( - \PDO::FETCH_CLASS, + FetchMode::CUSTOM_OBJECT, __NAMESPACE__.'\\MyFetchClass' ); @@ -715,7 +733,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); } @@ -730,7 +748,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(); @@ -752,7 +770,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()) { @@ -786,7 +804,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 539f0503b30..dc8e667e149 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 ac4b7ef18b9..47b91dd4eac 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -4,8 +4,8 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Portability\Connection as ConnectionPortability; -use PDO; /** * @group DBAL-56 @@ -64,19 +64,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 +87,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,7 +123,7 @@ 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() @@ -153,7 +156,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 +179,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 be100f47a49..e6f9d4473b1 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(); @@ -287,7 +289,7 @@ public function testFetchInColumnMode() : void { $platform = $this->_conn->getDatabasePlatform(); $query = $platform->getDummySelectSQL(); - $result = $this->_conn->executeQuery($query)->fetch(\PDO::FETCH_COLUMN); + $result = $this->_conn->executeQuery($query)->fetch(FetchMode::COLUMN); self::assertEquals(1, $result); } 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/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 +} From c2a4ae07a71d1f07cff2250b089793dbedbd98d4 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 25 Dec 2017 12:51:45 -0800 Subject: [PATCH 05/14] Replaced PDO::CASE_* constants --- docs/en/reference/portability.rst | 12 ++++++++---- lib/Doctrine/DBAL/Portability/Connection.php | 4 +++- .../Tests/DBAL/Functional/PortabilityTest.php | 15 ++++++++++----- 3 files changed, 21 insertions(+), 10 deletions(-) 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/lib/Doctrine/DBAL/Portability/Connection.php b/lib/Doctrine/DBAL/Portability/Connection.php index 67dd70b83b1..ff42a0a12d4 100644 --- a/lib/Doctrine/DBAL/Portability/Connection.php +++ b/lib/Doctrine/DBAL/Portability/Connection.php @@ -20,6 +20,7 @@ namespace Doctrine\DBAL\Portability; use Doctrine\DBAL\Cache\QueryCacheProfile; +use Doctrine\DBAL\ColumnCase; /** * Portability wrapper for a Connection. @@ -83,12 +84,13 @@ public function connect() } $this->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/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php index 47b91dd4eac..595bbed1125 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional; +use Doctrine\DBAL\ColumnCase; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\FetchMode; @@ -28,13 +29,17 @@ protected function tearDown() * @param int $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 { From b24fe9773892e57ce8c318c3f541b7e3d4ff692a Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 30 Dec 2017 20:29:33 -0800 Subject: [PATCH 06/14] Reworked tests to avoid hard dependency on PDO --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 4 ++ .../Doctrine/Tests/DBAL/DriverManagerTest.php | 39 +++++++++++++++---- .../Tests/DBAL/Functional/PortabilityTest.php | 5 ++- .../SingleDatabaseSynchronizerTest.php | 3 ++ .../Sharding/PoolingShardConnectionTest.php | 3 ++ tests/Doctrine/Tests/Mocks/PDOMock.php | 10 ----- tests/Doctrine/Tests/TestUtil.php | 8 +++- 7 files changed, 52 insertions(+), 20 deletions(-) delete mode 100644 tests/Doctrine/Tests/Mocks/PDOMock.php diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 5963962e651..ef20791120d 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -20,6 +20,9 @@ use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock; +/** + * @requires extension pdo_mysql + */ class ConnectionTest extends \Doctrine\Tests\DbalTestCase { /** @@ -157,6 +160,7 @@ public function testEventManagerPassedToPlatform() } /** + * @requires extension pdo_sqlite * @expectedException \Doctrine\DBAL\DBALException * @dataProvider getQueryMethods */ 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/PortabilityTest.php b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php index 595bbed1125..6037d8055c4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -131,7 +131,10 @@ public function assertFetchResultRow($row) 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( diff --git a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php index 06b30e08d28..0071d217280 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php @@ -23,6 +23,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 ae3e05b0e14..22cbcd6c066 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -22,6 +22,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/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 From 4c80584356f3a1a41725f19f914c1cf9b4709390 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 31 Dec 2017 19:11:53 -0800 Subject: [PATCH 07/14] Added conversion of DBAL constants to PDO ones for PDOStatement --- lib/Doctrine/DBAL/Driver/PDOStatement.php | 69 +++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index 6c0455c65a0..38d3576affb 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -19,7 +19,9 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; +use PDO; /** * The PDO implementation of the Statement interface. @@ -29,6 +31,29 @@ */ class PDOStatement extends \PDOStatement implements Statement { + /** + * @var int[] + */ + 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, + ]; + /** * Protected constructor. */ @@ -41,6 +66,8 @@ protected function __construct() */ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) { + $fetchMode = $this->convertFetchMode($fetchMode); + // 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 @@ -65,6 +92,8 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) */ public function bindValue($param, $value, $type = ParameterType::STRING) { + $type = $this->convertParamType($type); + try { return parent::bindValue($param, $value, $type); } catch (\PDOException $exception) { @@ -77,6 +106,8 @@ public function bindValue($param, $value, $type = ParameterType::STRING) */ 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); } catch (\PDOException $exception) { @@ -115,6 +146,8 @@ public function execute($params = null) */ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { + $fetchMode = $this->convertFetchMode($fetchMode); + try { if ($fetchMode === null && \PDO::FETCH_ORI_NEXT === $cursorOrientation && 0 === $cursorOffset) { return parent::fetch(); @@ -139,6 +172,8 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { + $fetchMode = $this->convertFetchMode($fetchMode); + try { if ($fetchMode === null && null === $fetchArgument && null === $ctorArgs) { return parent::fetchAll(); @@ -169,4 +204,38 @@ public function fetchColumn($columnIndex = 0) 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]; + } } From a979518cbbed3fef9bda43ee897a3ffbb4469b50 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 31 Dec 2017 19:26:15 -0800 Subject: [PATCH 08/14] Expressed PARAM_*_ARRAY through other constants to eliminate the dependency on the actual constant values --- lib/Doctrine/DBAL/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 71053321c21..28e3f168ba6 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -82,14 +82,14 @@ class Connection implements DriverConnection * * @var int */ - const PARAM_INT_ARRAY = 101; + const PARAM_INT_ARRAY = ParameterType::INTEGER + self::ARRAY_PARAM_OFFSET; /** * Represents an array of strings to be expanded by Doctrine SQL parsing. * * @var int */ - const PARAM_STR_ARRAY = 102; + const PARAM_STR_ARRAY = ParameterType::STRING + self::ARRAY_PARAM_OFFSET; /** * Offset by which PARAM_* constants are detected as arrays of the param type. From 8da47ffe324f57bdd966c167abac7b7dcdef66b1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 2 Jan 2018 23:04:47 -0800 Subject: [PATCH 09/14] Updated UPGRADE.md for 2.x --- UPGRADE.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 6336d81e8ac..cc238ee34ac 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -12,6 +12,15 @@ ``Doctrine\DBAL\Connection::TRANSACTION_*`` were moved into ``Doctrine\DBAL\TransactionIsolationLevel`` class without the ``TRANSACTION_`` prefix. +## 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` From 9694138378774d49ef6ae74bf85a2f41ae7f20d3 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 28 Jan 2018 10:33:35 -0800 Subject: [PATCH 10/14] Made enum classes final --- lib/Doctrine/DBAL/ColumnCase.php | 4 ++-- lib/Doctrine/DBAL/FetchMode.php | 4 ++-- lib/Doctrine/DBAL/ParameterType.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/DBAL/ColumnCase.php b/lib/Doctrine/DBAL/ColumnCase.php index 90ad11864e2..420d868f582 100644 --- a/lib/Doctrine/DBAL/ColumnCase.php +++ b/lib/Doctrine/DBAL/ColumnCase.php @@ -5,7 +5,7 @@ /** * Contains portable column case conversions. */ -class ColumnCase +final class ColumnCase { /** * Convert column names to upper case. @@ -24,7 +24,7 @@ class ColumnCase /** * This class cannot be instantiated. */ - final private function __construct() + private function __construct() { } } diff --git a/lib/Doctrine/DBAL/FetchMode.php b/lib/Doctrine/DBAL/FetchMode.php index 35007b208a2..a3e7f3ba601 100644 --- a/lib/Doctrine/DBAL/FetchMode.php +++ b/lib/Doctrine/DBAL/FetchMode.php @@ -5,7 +5,7 @@ /** * Contains statement fetch modes. */ -class FetchMode +final class FetchMode { /** * Specifies that the fetch method shall return each row as an array indexed @@ -63,7 +63,7 @@ class FetchMode /** * This class cannot be instantiated. */ - final private function __construct() + private function __construct() { } } diff --git a/lib/Doctrine/DBAL/ParameterType.php b/lib/Doctrine/DBAL/ParameterType.php index 2977d86137c..362a0514d23 100644 --- a/lib/Doctrine/DBAL/ParameterType.php +++ b/lib/Doctrine/DBAL/ParameterType.php @@ -5,7 +5,7 @@ /** * Contains statement parameter types. */ -class ParameterType +final class ParameterType { /** * Represents the SQL NULL data type. @@ -45,7 +45,7 @@ class ParameterType /** * This class cannot be instantiated. */ - final private function __construct() + private function __construct() { } } From 7dadba43dbc9305767d02d010e543c204b4d28b5 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 28 Jan 2018 10:34:42 -0800 Subject: [PATCH 11/14] Fixed mistake in documentation --- docs/en/reference/portability.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/reference/portability.rst b/docs/en/reference/portability.rst index ea1800b5875..6cd6388fbda 100644 --- a/docs/en/reference/portability.rst +++ b/docs/en/reference/portability.rst @@ -60,7 +60,7 @@ Using the following code block in your initialization will: //... 'wrapperClass' => PortableConnection::class, 'portability' => PortableConnection::PORTABILITY_ALL, - 'fetch_case' => PortableConnection::LOWER, + 'fetch_case' => ColumnCase::LOWER, ); This sort of portability handling is pretty expensive because all the result From 0e99c343ef364ee0ab2f0d5aceb18b8768045037 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 28 Jan 2018 10:36:16 -0800 Subject: [PATCH 12/14] Fixed code style --- lib/Doctrine/DBAL/Cache/ArrayStatement.php | 2 +- lib/Doctrine/DBAL/Cache/ResultCacheStatement.php | 8 ++++---- lib/Doctrine/DBAL/Connection.php | 4 ++-- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php | 2 +- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php | 2 +- .../DBAL/Driver/Mysqli/MysqliStatement.php | 12 +++++++----- lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php | 14 +++++++------- lib/Doctrine/DBAL/Driver/PDOStatement.php | 6 ++---- .../DBAL/Driver/SQLSrv/SQLSrvStatement.php | 4 ++-- tests/Doctrine/Tests/DBAL/DriverManagerTest.php | 2 +- tests/Doctrine/Tests/TestUtil.php | 2 +- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index fab2f18772c..f66b329b031 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -100,7 +100,7 @@ public function getIterator() */ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { - if ( ! isset($this->data[$this->num])) { + if (! isset($this->data[$this->num])) { return false; } diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 83c6a1660e7..cc5b4e3e941 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -160,19 +160,19 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $fetchMode = $fetchMode ?: $this->defaultFetchMode; - if ($fetchMode == FetchMode::ASSOCIATIVE) { + if ($fetchMode === FetchMode::ASSOCIATIVE) { return $row; } - if ($fetchMode == FetchMode::NUMERIC) { + if ($fetchMode === FetchMode::NUMERIC) { return array_values($row); } - if ($fetchMode == FetchMode::MIXED) { + if ($fetchMode === FetchMode::MIXED) { return array_merge($row, array_values($row)); } - if ($fetchMode == FetchMode::COLUMN) { + if ($fetchMode === FetchMode::COLUMN) { return reset($row); } diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 28e3f168ba6..53ed295ff97 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -82,14 +82,14 @@ class Connection implements DriverConnection * * @var int */ - const PARAM_INT_ARRAY = ParameterType::INTEGER + self::ARRAY_PARAM_OFFSET; + public const PARAM_INT_ARRAY = ParameterType::INTEGER + self::ARRAY_PARAM_OFFSET; /** * Represents an array of strings to be expanded by Doctrine SQL parsing. * * @var int */ - const PARAM_STR_ARRAY = ParameterType::STRING + self::ARRAY_PARAM_OFFSET; + public const PARAM_STR_ARRAY = ParameterType::STRING + self::ARRAY_PARAM_OFFSET; /** * Offset by which PARAM_* constants are detected as arrays of the param type. diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index 5aef861c497..be43fc5f88b 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -103,7 +103,7 @@ public function quote($input, $type = ParameterType::STRING) { $input = db2_escape_string($input); - if ($type == ParameterType::INTEGER) { + 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 874c6a30a01..9a8ba334db6 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -65,7 +65,7 @@ class DB2Statement implements \IteratorAggregate, Statement */ static private $_typeMap = [ ParameterType::INTEGER => DB2_LONG, - ParameterType::STRING => DB2_CHAR, + ParameterType::STRING => DB2_CHAR, ]; /** diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index d08f2fe427f..38b05e318b2 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -33,11 +33,13 @@ class MysqliStatement implements \IteratorAggregate, Statement * @var array */ protected static $_paramTypeMap = [ - ParameterType::STRING => 's', - ParameterType::BOOLEAN => 'i', - ParameterType::NULL => 's', - ParameterType::INTEGER => 'i', - ParameterType::LARGE_OBJECT => 's' // TODO Support LOB bigger then max package size. + ParameterType::STRING => 's', + ParameterType::BOOLEAN => 'i', + ParameterType::NULL => 's', + ParameterType::INTEGER => 'i', + + // TODO Support LOB bigger then max package size + ParameterType::LARGE_OBJECT => 's', ]; /** diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index e4c513849f7..66bedeab5a3 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -57,10 +57,10 @@ class OCI8Statement implements IteratorAggregate, Statement * @var array */ protected static $fetchModeMap = [ - FetchMode::MIXED => OCI_BOTH, + FetchMode::MIXED => OCI_BOTH, FetchMode::ASSOCIATIVE => OCI_ASSOC, - FetchMode::NUMERIC => OCI_NUM, - FetchMode::COLUMN => OCI_NUM, + FetchMode::NUMERIC => OCI_NUM, + FetchMode::COLUMN => OCI_NUM, ]; /** @@ -267,7 +267,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l { $column = $this->_paramMap[$column] ?? $column; - if ($type == ParameterType::LARGE_OBJECT) { + if ($type === ParameterType::LARGE_OBJECT) { $lob = oci_new_descriptor($this->_dbh, OCI_D_LOB); $lob->writeTemporary($variable, OCI_TEMP_BLOB); @@ -415,7 +415,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n $result = []; - if ($fetchMode == FetchMode::STANDARD_OBJECT) { + if ($fetchMode === FetchMode::STANDARD_OBJECT) { while ($row = $this->fetch($fetchMode)) { $result[] = $row; } @@ -434,7 +434,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n } else { $fetchStructure = OCI_FETCHSTATEMENT_BY_ROW; - if ($fetchMode == FetchMode::COLUMN) { + if ($fetchMode === FetchMode::COLUMN) { $fetchStructure = OCI_FETCHSTATEMENT_BY_COLUMN; } @@ -447,7 +447,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 == FetchMode::COLUMN) { + if ($fetchMode === FetchMode::COLUMN) { $result = $result[0]; } } diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index 38d3576affb..9e45eb9ba29 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -209,11 +209,10 @@ public function fetchColumn($columnIndex = 0) * 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])) { + if (! isset(self::PARAM_TYPE_MAP[$type])) { throw new \InvalidArgumentException('Invalid parameter type: ' . $type); } @@ -224,7 +223,6 @@ private function convertParamType(int $type) : int * Converts DBAL fetch mode to PDO fetch mode * * @param int|null $fetchMode Fetch mode - * @return int|null */ private function convertFetchMode(?int $fetchMode) : ?int { @@ -232,7 +230,7 @@ private function convertFetchMode(?int $fetchMode) : ?int return null; } - if ( ! isset(self::FETCH_MODE_MAP[$fetchMode])) { + if (! isset(self::FETCH_MODE_MAP[$fetchMode])) { throw new \InvalidArgumentException('Invalid fetch mode: ' . $fetchMode); } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index 98fc5c4aee3..8b8749518e7 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -74,9 +74,9 @@ class SQLSrvStatement implements IteratorAggregate, Statement * @var array */ private static $fetchMap = [ - FetchMode::MIXED => SQLSRV_FETCH_BOTH, + FetchMode::MIXED => SQLSRV_FETCH_BOTH, FetchMode::ASSOCIATIVE => SQLSRV_FETCH_ASSOC, - FetchMode::NUMERIC => SQLSRV_FETCH_NUMERIC, + FetchMode::NUMERIC => SQLSRV_FETCH_NUMERIC, ]; /** diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index 84f23c0bd9b..b85587d8033 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -139,7 +139,7 @@ public function testDatabaseUrl($url, $expected) ); if (isset($options['pdo'])) { - if ( ! extension_loaded('pdo')) { + if (! extension_loaded('pdo')) { $this->markTestSkipped('PDO is not installed'); } diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index 7a3654f87b8..62ec5a14c17 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -113,7 +113,7 @@ private static function getSpecifiedConnectionParams() { private static function getFallbackConnectionParams() { - if ( ! extension_loaded('pdo_sqlite')) { + if (! extension_loaded('pdo_sqlite')) { Assert::markTestSkipped('PDO SQLite extension is not loaded'); } From 41906695d6aedfc71d50df97c18a68dff902c6bd Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 28 Jan 2018 18:28:06 -0800 Subject: [PATCH 13/14] Fixed some more code style --- lib/Doctrine/DBAL/Id/TableGenerator.php | 12 +- lib/Doctrine/DBAL/Portability/Connection.php | 2 +- lib/Doctrine/DBAL/Portability/Statement.php | 3 +- lib/Doctrine/DBAL/Query/QueryBuilder.php | 6 +- .../Tests/DBAL/Functional/BlobTest.php | 16 +- .../Tests/DBAL/Functional/ConnectionTest.php | 4 +- .../Tests/DBAL/Functional/DataAccessTest.php | 46 ++-- .../Driver/PDOPgsqlConnectionTest.php | 2 +- .../DBAL/Functional/NamedParametersTest.php | 253 ++++++++++-------- 9 files changed, 192 insertions(+), 152 deletions(-) diff --git a/lib/Doctrine/DBAL/Id/TableGenerator.php b/lib/Doctrine/DBAL/Id/TableGenerator.php index a6fa7e784a6..68039407206 100644 --- a/lib/Doctrine/DBAL/Id/TableGenerator.php +++ b/lib/Doctrine/DBAL/Id/TableGenerator.php @@ -22,6 +22,7 @@ use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Connection; use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\LockMode; /** * Table ID Generator for those poor languages that are missing sequences. @@ -120,12 +121,13 @@ public function nextValue($sequenceName) try { $platform = $this->conn->getDatabasePlatform(); - $sql = "SELECT sequence_value, sequence_increment_by " . - "FROM " . $platform->appendLockHint($this->generatorTableName, \Doctrine\DBAL\LockMode::PESSIMISTIC_WRITE) . " " . - "WHERE sequence_name = ? " . $platform->getWriteLockSQL(); - $stmt = $this->conn->executeQuery($sql, [$sequenceName]); + $sql = 'SELECT sequence_value, sequence_increment_by' + . ' FROM ' . $platform->appendLockHint($this->generatorTableName, LockMode::PESSIMISTIC_WRITE) + . ' WHERE sequence_name = ? ' . $platform->getWriteLockSQL(); + $stmt = $this->conn->executeQuery($sql, [$sequenceName]); + $row = $stmt->fetch(FetchMode::ASSOCIATIVE); - if ($row = $stmt->fetch(FetchMode::ASSOCIATIVE)) { + if ($row !== false) { $row = array_change_key_case($row, CASE_LOWER); $value = $row['sequence_value']; diff --git a/lib/Doctrine/DBAL/Portability/Connection.php b/lib/Doctrine/DBAL/Portability/Connection.php index ff42a0a12d4..d841d317879 100644 --- a/lib/Doctrine/DBAL/Portability/Connection.php +++ b/lib/Doctrine/DBAL/Portability/Connection.php @@ -90,7 +90,7 @@ public function connect() // make use of c-level support for case handling $this->_conn->setAttribute(\PDO::ATTR_CASE, $params['fetch_case']); } else { - $this->case = ($params['fetch_case'] == ColumnCase::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 4b72dea79b0..f36c365b4ea 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -150,7 +150,8 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $row = $this->stmt->fetch($fetchMode); $iterateRow = $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM); - $fixCase = ! is_null($this->case) && ($fetchMode == FetchMode::ASSOCIATIVE || $fetchMode == FetchMode::MIXED) + $fixCase = ! is_null($this->case) + && ($fetchMode === FetchMode::ASSOCIATIVE || $fetchMode === FetchMode::MIXED) && ($this->portability & Connection::PORTABILITY_FIX_CASE); $row = $this->fixRow($row, $iterateRow, $fixCase); diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index d9d996f7fa4..43f2d82c6b4 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -263,9 +263,9 @@ public function getSQL() * ->setParameter(':user_id', 1); * * - * @param string|integer $key The parameter position or name. - * @param mixed $value The parameter value. - * @param string|integer|null $type One of the {@link \Doctrine\DBAL\ParameterType} constants. + * @param string|int $key The parameter position or name. + * @param mixed $value The parameter value. + * @param string|int|null $type One of the {@link \Doctrine\DBAL\ParameterType} constants. * * @return $this This QueryBuilder instance. */ diff --git a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php index 11547b2e82f..1477c09d47a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php @@ -37,10 +37,18 @@ protected function setUp() public function testInsert() { - $ret = $this->_conn->insert('blob_table', - array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test', 'binaryfield' => 'test'), - array(ParameterType::INTEGER, ParameterType::STRING, ParameterType::LARGE_OBJECT, ParameterType::LARGE_OBJECT) - ); + $ret = $this->_conn->insert('blob_table', [ + 'id' => 1, + 'clobfield' => 'test', + 'blobfield' => 'test', + 'binaryfield' => 'test', + ], [ + ParameterType::INTEGER, + ParameterType::STRING, + ParameterType::LARGE_OBJECT, + ParameterType::LARGE_OBJECT, + ]); + self::assertEquals(1, $ret); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index e59a9520f29..e1b81198727 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -244,8 +244,8 @@ public function testTransactionalReturnValue() public function testQuote() { self::assertEquals( - $this->_conn->quote("foo", Type::STRING), - $this->_conn->quote("foo", ParameterType::STRING) + $this->_conn->quote('foo', Type::STRING), + $this->_conn->quote('foo', ParameterType::STRING) ); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index 716513168f3..503594d8ebf 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -195,8 +195,8 @@ 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(ParameterType::STRING, Type::DATETIME)); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + $data = $this->_conn->fetchAll($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); self::assertCount(1, $data); @@ -227,8 +227,8 @@ 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(FetchMode::MIXED); + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; + $row = $this->_conn->executeQuery($sql, [1, 'foo'])->fetch(FetchMode::MIXED); self::assertNotFalse($row); @@ -265,8 +265,8 @@ 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(ParameterType::STRING, Type::DATETIME)); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + $row = $this->_conn->fetchAssoc($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); self::assertNotFalse($row); @@ -306,8 +306,8 @@ 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(ParameterType::STRING, Type::DATETIME)); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + $row = $this->_conn->fetchArray($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); self::assertNotFalse($row); @@ -351,13 +351,8 @@ 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(ParameterType::STRING, Type::DATETIME) - ); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + $column = $this->_conn->fetchColumn($sql, [1, $datetime], 1, [ParameterType::STRING, Type::DATETIME]); self::assertNotFalse($column); @@ -402,18 +397,15 @@ public function testExecuteUpdateBindDateTimeType() $datetime = new \DateTime('2010-02-02 20:20:20'); $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 => ParameterType::INTEGER, - 2 => ParameterType::STRING, - 3 => Type::DATETIME, - ) - ); + $affectedRows = $this->_conn->executeUpdate($sql, [ + 1 => 50, + 2 => 'foo', + 3 => $datetime, + ], [ + 1 => ParameterType::INTEGER, + 2 => ParameterType::STRING, + 3 => Type::DATETIME, + ]); self::assertEquals(1, $affectedRows); self::assertEquals(1, $this->_conn->executeQuery( diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php index 4669df7c19c..1b7c9b587ce 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php @@ -43,7 +43,7 @@ public function testConnectsWithValidCharsetOption($charset) self::assertEquals( $charset, - $connection->query("SHOW client_encoding") + $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 dc8e667e149..6f99a44d17a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php @@ -5,151 +5,189 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Schema\Table; /** * @group DDC-1372 */ class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase { - public function ticketProvider() { - return array( - array( + return [ + [ 'SELECT * FROM ddc1372_foobar f WHERE f.foo = :foo AND f.bar IN (:bar)', - array('foo'=>1,'bar'=> array(1, 2, 3)), - array( + [ + 'foo' => 1, + 'bar' => [1, 2, 3], + ], + [ 'foo' => ParameterType::INTEGER, 'bar' => Connection::PARAM_INT_ARRAY, - ), - array( - array('id'=>1,'foo'=>1,'bar'=>1), - array('id'=>2,'foo'=>1,'bar'=>2), - array('id'=>3,'foo'=>1,'bar'=>3), - ) - ), - - array( + ], + [ + ['id' => 1, 'foo' => 1, 'bar' => 1], + ['id' => 2, 'foo' => 1, 'bar' => 2], + ['id' => 3, 'foo' => 1, 'bar' => 3], + ], + ], + + [ 'SELECT * FROM ddc1372_foobar f WHERE f.foo = :foo AND f.bar IN (:bar)', - array('foo'=>1,'bar'=> array(1, 2, 3)), - array( + [ + 'foo' => 1, + 'bar' => [1, 2, 3], + ], + [ 'bar' => Connection::PARAM_INT_ARRAY, 'foo' => ParameterType::INTEGER, - ), - array( - array('id'=>1,'foo'=>1,'bar'=>1), - array('id'=>2,'foo'=>1,'bar'=>2), - array('id'=>3,'foo'=>1,'bar'=>3), - ) - ), - - array( + ], + [ + ['id' => 1, 'foo' => 1, 'bar' => 1], + ['id' => 2, 'foo' => 1, 'bar' => 2], + ['id' => 3, 'foo' => 1, 'bar' => 3], + ], + ], + + [ 'SELECT * FROM ddc1372_foobar f WHERE f.bar IN (:bar) AND f.foo = :foo', - array('foo'=>1,'bar'=> array(1, 2, 3)), - array( + [ + 'foo' => 1, + 'bar' => [1, 2, 3], + ], + [ 'bar' => Connection::PARAM_INT_ARRAY, 'foo' => ParameterType::INTEGER, - ), - array( - array('id'=>1,'foo'=>1,'bar'=>1), - array('id'=>2,'foo'=>1,'bar'=>2), - array('id'=>3,'foo'=>1,'bar'=>3), - ) - ), - - array( + ], + [ + ['id' => 1, 'foo' => 1, 'bar' => 1], + ['id' => 2, 'foo' => 1, 'bar' => 2], + ['id' => 3, 'foo' => 1, 'bar' => 3], + ], + ], + + [ 'SELECT * FROM ddc1372_foobar f WHERE f.bar IN (:bar) AND f.foo = :foo', - array('foo'=>1,'bar'=> array('1', '2', '3')), - array( + [ + 'foo' => 1, + 'bar' => ['1', '2', '3'], + ], + [ 'bar' => Connection::PARAM_STR_ARRAY, 'foo' => ParameterType::INTEGER, - ), - array( - array('id'=>1,'foo'=>1,'bar'=>1), - array('id'=>2,'foo'=>1,'bar'=>2), - array('id'=>3,'foo'=>1,'bar'=>3), - ) - ), - - array( + ], + [ + ['id' => 1, 'foo' => 1, 'bar' => 1], + ['id' => 2, 'foo' => 1, 'bar' => 2], + ['id' => 3, 'foo' => 1, 'bar' => 3], + ], + ], + + [ 'SELECT * FROM ddc1372_foobar f WHERE f.bar IN (:bar) AND f.foo IN (:foo)', - array('foo'=>array('1'),'bar'=> array(1, 2, 3,4)), - array('bar'=> Connection::PARAM_STR_ARRAY,'foo'=>Connection::PARAM_INT_ARRAY), - array( - array('id'=>1,'foo'=>1,'bar'=>1), - array('id'=>2,'foo'=>1,'bar'=>2), - array('id'=>3,'foo'=>1,'bar'=>3), - array('id'=>4,'foo'=>1,'bar'=>4), - ) - ), - - array( + [ + 'foo' => ['1'], + 'bar' => [1, 2, 3, 4], + ], + [ + 'bar' => Connection::PARAM_STR_ARRAY, + 'foo' => Connection::PARAM_INT_ARRAY, + ], + [ + ['id' => 1, 'foo' => 1, 'bar' => 1], + ['id' => 2, 'foo' => 1, 'bar' => 2], + ['id' => 3, 'foo' => 1, 'bar' => 3], + ['id' => 4, 'foo' => 1, 'bar' => 4], + ], + ], + + [ 'SELECT * FROM ddc1372_foobar f WHERE f.bar IN (:bar) AND f.foo IN (:foo)', - array('foo'=>1,'bar'=> 2), - array('bar'=>ParameterType::INTEGER,'foo'=>ParameterType::INTEGER), - array( - array('id'=>2,'foo'=>1,'bar'=>2), - ) - ), - - array( + [ + 'foo' => 1, + 'bar' => 2, + ], + [ + 'bar' => ParameterType::INTEGER, + 'foo' => ParameterType::INTEGER, + ], + [ + ['id' => 2, 'foo' => 1, 'bar' => 2], + ], + ], + + [ 'SELECT * FROM ddc1372_foobar f WHERE f.bar = :arg AND f.foo <> :arg', - array('arg'=>'1'), - array( + ['arg' => '1'], + [ 'arg' => ParameterType::STRING, - ), - array( - array('id'=>5,'foo'=>2,'bar'=>1), - ) - ), + ], + [ + ['id' => 5, 'foo' => 2, 'bar' => 1], + ], + ], - array( + [ 'SELECT * FROM ddc1372_foobar f WHERE f.bar NOT IN (:arg) AND f.foo IN (:arg)', - array('arg'=>array(1, 2)), - array('arg'=>Connection::PARAM_INT_ARRAY), - array( - array('id'=>3,'foo'=>1,'bar'=>3), - array('id'=>4,'foo'=>1,'bar'=>4), - ) - ), - - ); + [ + 'arg' => [1, 2], + ], + [ + 'arg' => Connection::PARAM_INT_ARRAY, + ], + [ + ['id' => 3, 'foo' => 1, 'bar' => 3], + ['id' => 4, 'foo' => 1, 'bar' => 4], + ], + ], + ]; } protected function setUp() { parent::setUp(); - if (!$this->_conn->getSchemaManager()->tablesExist("ddc1372_foobar")) { + if (! $this->_conn->getSchemaManager()->tablesExist('ddc1372_foobar')) { try { - $table = new \Doctrine\DBAL\Schema\Table("ddc1372_foobar"); + $table = new Table('ddc1372_foobar'); $table->addColumn('id', 'integer'); - $table->addColumn('foo','string'); - $table->addColumn('bar','string'); - $table->setPrimaryKey(array('id')); - + $table->addColumn('foo', 'string'); + $table->addColumn('bar', 'string'); + $table->setPrimaryKey(['id']); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); - $this->_conn->insert('ddc1372_foobar', array( - 'id' => 1, 'foo' => 1, 'bar' => 1 - )); - $this->_conn->insert('ddc1372_foobar', array( - 'id' => 2, 'foo' => 1, 'bar' => 2 - )); - $this->_conn->insert('ddc1372_foobar', array( - 'id' => 3, 'foo' => 1, 'bar' => 3 - )); - $this->_conn->insert('ddc1372_foobar', array( - 'id' => 4, 'foo' => 1, 'bar' => 4 - )); - $this->_conn->insert('ddc1372_foobar', array( - 'id' => 5, 'foo' => 2, 'bar' => 1 - )); - $this->_conn->insert('ddc1372_foobar', array( - 'id' => 6, 'foo' => 2, 'bar' => 2 - )); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 1, + 'foo' => 1, + 'bar' => 1, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 2, + 'foo' => 1, + 'bar' => 2, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 3, + 'foo' => 1, + 'bar' => 3, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 4, + 'foo' => 1, + 'bar' => 4, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 5, + 'foo' => 2, + 'bar' => 1, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 6, + 'foo' => 2, + 'bar' => 2, + ]); } catch(\Exception $e) { $this->fail($e->getMessage()); } @@ -174,5 +212,4 @@ public function testTicket($query,$params,$types,$expected) self::assertEquals($result, $expected); } - } From be4253f568ab2961d5a609d7a1a50e7e58697c9c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 30 Jan 2018 23:26:41 -0800 Subject: [PATCH 14/14] More code style fixes --- lib/Doctrine/DBAL/Cache/ArrayStatement.php | 2 +- .../DBAL/Driver/SQLSrv/SQLSrvStatement.php | 2 +- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 24 +- .../Doctrine/Tests/DBAL/DriverManagerTest.php | 456 ++++++++++++------ .../Tests/DBAL/Functional/BlobTest.php | 45 +- .../Tests/DBAL/Functional/PortabilityTest.php | 2 +- .../Tests/DBAL/Functional/StatementTest.php | 4 +- .../DBAL/Functional/Ticket/DBAL630Test.php | 4 +- .../Tests/DBAL/Functional/WriteTest.php | 10 +- .../Tests/DBAL/Query/QueryBuilderTest.php | 5 +- 10 files changed, 371 insertions(+), 183 deletions(-) diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index f66b329b031..b77f85cacfe 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -123,7 +123,7 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE return reset($row); } - throw new \InvalidArgumentException("Invalid fetch-style given for fetching result."); + throw new \InvalidArgumentException('Invalid fetch-style given for fetching result.'); } /** diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index 8b8749518e7..ea601ed0e9b 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -96,7 +96,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement /** * The fetch style. * - * @param int + * @var int */ private $defaultFetchMode = FetchMode::MIXED; diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index ef20791120d..46a3c49df02 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -495,9 +495,9 @@ public function testDeleteWithIsNull() public function testFetchAssoc() { $statement = 'SELECT * FROM foo WHERE bar = ?'; - $params = array(666); - $types = array(ParameterType::INTEGER); - $result = array(); + $params = [666]; + $types = [ParameterType::INTEGER]; + $result = []; $driverMock = $this->createMock('Doctrine\DBAL\Driver'); @@ -531,9 +531,9 @@ public function testFetchAssoc() public function testFetchArray() { $statement = 'SELECT * FROM foo WHERE bar = ?'; - $params = array(666); - $types = array(ParameterType::INTEGER); - $result = array(); + $params = [666]; + $types = [ParameterType::INTEGER]; + $result = []; $driverMock = $this->createMock('Doctrine\DBAL\Driver'); @@ -567,10 +567,10 @@ public function testFetchArray() public function testFetchColumn() { $statement = 'SELECT * FROM foo WHERE bar = ?'; - $params = array(666); - $types = array(ParameterType::INTEGER); + $params = [666]; + $types = [ParameterType::INTEGER]; $column = 0; - $result = array(); + $result = []; $driverMock = $this->createMock('Doctrine\DBAL\Driver'); @@ -627,9 +627,9 @@ public function testConnectionIsClosedButNotUnset() public function testFetchAll() { $statement = 'SELECT * FROM foo WHERE bar = ?'; - $params = array(666); - $types = array(ParameterType::INTEGER); - $result = array(); + $params = [666]; + $types = [ParameterType::INTEGER]; + $result = []; $driverMock = $this->createMock('Doctrine\DBAL\Driver'); diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index b85587d8033..473c0ac0206 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -3,8 +3,18 @@ namespace Doctrine\Tests\DBAL; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver as DrizzlePDOMySqlDriver; +use Doctrine\DBAL\Driver\PDOMySQL\Driver as PDOMySQLDriver; +use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSqliteDriver; +use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; +use Doctrine\DBAL\DriverManager; +use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; +use Doctrine\Tests\Mocks\ConnectionMock; +use Doctrine\Tests\Mocks\DriverMock; +use stdClass; -class DriverManagerTest extends \Doctrine\Tests\DbalTestCase +class DriverManagerTest extends DbalTestCase { /** * @requires extension pdo_sqlite @@ -12,10 +22,7 @@ class DriverManagerTest extends \Doctrine\Tests\DbalTestCase */ public function testInvalidPdoInstance() { - $options = array( - 'pdo' => 'test' - ); - $test = \Doctrine\DBAL\DriverManager::getConnection($options); + DriverManager::getConnection(['pdo' => 'test']); } /** @@ -23,10 +30,10 @@ public function testInvalidPdoInstance() */ public function testValidPdoInstance() { - $options = array( - 'pdo' => new \PDO('sqlite::memory:') - ); - $conn = \Doctrine\DBAL\DriverManager::getConnection($options); + $conn = DriverManager::getConnection([ + 'pdo' => new \PDO('sqlite::memory:'), + ]); + self::assertEquals('sqlite', $conn->getDatabasePlatform()->getName()); } @@ -38,11 +45,9 @@ public function testPdoInstanceSetErrorMode() { $pdo = new \PDO('sqlite::memory:'); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT); - $options = array( - 'pdo' => $pdo - ); + $options = ['pdo' => $pdo]; - $conn = \Doctrine\DBAL\DriverManager::getConnection($options); + DriverManager::getConnection($options); self::assertEquals(\PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(\PDO::ATTR_ERRMODE)); } @@ -51,7 +56,7 @@ public function testPdoInstanceSetErrorMode() */ public function testCheckParams() { - $conn = \Doctrine\DBAL\DriverManager::getConnection(array()); + DriverManager::getConnection([]); } /** @@ -59,7 +64,7 @@ public function testCheckParams() */ public function testInvalidDriver() { - $conn = \Doctrine\DBAL\DriverManager::getConnection(array('driver' => 'invalid_driver')); + DriverManager::getConnection(['driver' => 'invalid_driver']); } /** @@ -67,13 +72,13 @@ public function testInvalidDriver() */ public function testCustomPlatform() { - $mockPlatform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform(); - $options = array( - 'pdo' => new \PDO('sqlite::memory:'), - 'platform' => $mockPlatform - ); + $mockPlatform = new MockPlatform(); + $options = [ + 'pdo' => new \PDO('sqlite::memory:'), + 'platform' => $mockPlatform, + ]; - $conn = \Doctrine\DBAL\DriverManager::getConnection($options); + $conn = DriverManager::getConnection($options); self::assertSame($mockPlatform, $conn->getDatabasePlatform()); } @@ -82,14 +87,14 @@ public function testCustomPlatform() */ public function testCustomWrapper() { - $wrapperClass = 'Doctrine\Tests\Mocks\ConnectionMock'; + $wrapperClass = ConnectionMock::class; - $options = array( + $options = [ 'pdo' => new \PDO('sqlite::memory:'), 'wrapperClass' => $wrapperClass, - ); + ]; - $conn = \Doctrine\DBAL\DriverManager::getConnection($options); + $conn = DriverManager::getConnection($options); self::assertInstanceOf($wrapperClass, $conn); } @@ -100,33 +105,29 @@ public function testInvalidWrapperClass() { $this->expectException(DBALException::class); - $options = array( + $options = [ 'pdo' => new \PDO('sqlite::memory:'), - 'wrapperClass' => 'stdClass', - ); + 'wrapperClass' => stdClass::class, + ]; - $conn = \Doctrine\DBAL\DriverManager::getConnection($options); + DriverManager::getConnection($options); } public function testInvalidDriverClass() { $this->expectException(DBALException::class); - $options = array( - 'driverClass' => 'stdClass' - ); + $options = ['driverClass' => stdClass::class]; - $conn = \Doctrine\DBAL\DriverManager::getConnection($options); + DriverManager::getConnection($options); } public function testValidDriverClass() { - $options = array( - 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', - ); + $options = ['driverClass' => PDOMySQLDriver::class]; - $conn = \Doctrine\DBAL\DriverManager::getConnection($options); - self::assertInstanceOf('Doctrine\DBAL\Driver\PDOMySql\Driver', $conn->getDriver()); + $conn = DriverManager::getConnection($options); + self::assertInstanceOf(PDOMySQLDriver::class, $conn->getDriver()); } /** @@ -134,9 +135,7 @@ public function testValidDriverClass() */ public function testDatabaseUrl($url, $expected) { - $options = is_array($url) ? $url : array( - 'url' => $url, - ); + $options = is_array($url) ? $url : ['url' => $url]; if (isset($options['pdo'])) { if (! extension_loaded('pdo')) { @@ -146,19 +145,17 @@ public function testDatabaseUrl($url, $expected) $options['pdo'] = $this->createMock(\PDO::class); } - $options = is_array($url) ? $url : array( - 'url' => $url, - ); + $options = is_array($url) ? $url : ['url' => $url]; if ($expected === false) { $this->expectException(DBALException::class); } - $conn = \Doctrine\DBAL\DriverManager::getConnection($options); + $conn = DriverManager::getConnection($options); $params = $conn->getParams(); foreach ($expected as $key => $value) { - if (in_array($key, array('pdo', 'driver', 'driverClass'), true)) { + if (in_array($key, ['pdo', 'driver', 'driverClass'], true)) { self::assertInstanceOf($value, $conn->getDriver()); } else { self::assertEquals($value, $params[$key]); @@ -168,121 +165,294 @@ public function testDatabaseUrl($url, $expected) public function databaseUrls() { - return array( - 'simple URL' => array( + return [ + 'simple URL' => [ 'mysql://foo:bar@localhost/baz', - array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), - ), - 'simple URL with port' => array( + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'simple URL with port' => [ 'mysql://foo:bar@localhost:11211/baz', - array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'port' => 11211, 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), - ), - 'sqlite relative URL with host' => array( + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'port' => 11211, + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'sqlite relative URL with host' => [ 'sqlite://localhost/foo/dbname.sqlite', - array('path' => 'foo/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'), - ), - 'sqlite absolute URL with host' => array( + [ + 'path' => 'foo/dbname.sqlite', + 'driver' => PDOSqliteDriver::class, + ], + ], + 'sqlite absolute URL with host' => [ 'sqlite://localhost//tmp/dbname.sqlite', - array('path' => '/tmp/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'), - ), - 'sqlite relative URL without host' => array( + [ + 'path' => '/tmp/dbname.sqlite', + 'driver' => PDOSqliteDriver::class, + ], + ], + 'sqlite relative URL without host' => [ 'sqlite:///foo/dbname.sqlite', - array('path' => 'foo/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'), - ), - 'sqlite absolute URL without host' => array( + [ + 'path' => 'foo/dbname.sqlite', + 'driver' => PDOSqliteDriver::class, + ], + ], + 'sqlite absolute URL without host' => [ 'sqlite:////tmp/dbname.sqlite', - array('path' => '/tmp/dbname.sqlite', 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'), - ), - 'sqlite memory' => array( + [ + 'path' => '/tmp/dbname.sqlite', + 'driver' => PDOSqliteDriver::class, + ], + ], + 'sqlite memory' => [ 'sqlite:///:memory:', - array('memory' => true, 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'), - ), - 'sqlite memory with host' => array( + [ + 'memory' => true, + 'driver' => PDOSqliteDriver::class, + ], + ], + 'sqlite memory with host' => [ 'sqlite://localhost/:memory:', - array('memory' => true, 'driver' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver'), - ), - 'params parsed from URL override individual params' => array( - array('url' => 'mysql://foo:bar@localhost/baz', 'password' => 'lulz'), - array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), - ), - 'params not parsed from URL but individual params are preserved' => array( - array('url' => 'mysql://foo:bar@localhost/baz', 'port' => 1234), - array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'port' => 1234, 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), - ), - 'query params from URL are used as extra params' => array( + [ + 'memory' => true, + 'driver' => PDOSqliteDriver::class, + ], + ], + 'params parsed from URL override individual params' => [ + [ + 'url' => 'mysql://foo:bar@localhost/baz', + 'password' => 'lulz', + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'params not parsed from URL but individual params are preserved' => [ + [ + 'url' => 'mysql://foo:bar@localhost/baz', + 'port' => 1234, + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'port' => 1234, + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'query params from URL are used as extra params' => [ 'url' => 'mysql://foo:bar@localhost/dbname?charset=UTF-8', - array('charset' => 'UTF-8'), - ), - 'simple URL with fallthrough scheme not defined in map' => array( + ['charset' => 'UTF-8'], + ], + 'simple URL with fallthrough scheme not defined in map' => [ 'sqlsrv://foo:bar@localhost/baz', - array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\SQLSrv\Driver'), - ), - 'simple URL with fallthrough scheme containing underscores fails' => array( + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => SQLSrvDriver::class, + ], + ], + 'simple URL with fallthrough scheme containing underscores fails' => [ 'drizzle_pdo_mysql://foo:bar@localhost/baz', false, - ), - 'simple URL with fallthrough scheme containing dashes works' => array( + ], + 'simple URL with fallthrough scheme containing dashes works' => [ 'drizzle-pdo-mysql://foo:bar@localhost/baz', - array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver'), - ), - 'simple URL with percent encoding' => array( + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => DrizzlePDOMySqlDriver::class, + ], + ], + 'simple URL with percent encoding' => [ 'mysql://foo%3A:bar%2F@localhost/baz+baz%40', - array('user' => 'foo:', 'password' => 'bar/', 'host' => 'localhost', 'dbname' => 'baz+baz@', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), - ), - 'simple URL with percent sign in password' => array( + [ + 'user' => 'foo:', + 'password' => 'bar/', + 'host' => 'localhost', + 'dbname' => 'baz+baz@', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'simple URL with percent sign in password' => [ 'mysql://foo:bar%25bar@localhost/baz', - array('user' => 'foo', 'password' => 'bar%bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), - ), + [ + 'user' => 'foo', + 'password' => 'bar%bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], // DBAL-1234 - 'URL without scheme and without any driver information' => array( - array('url' => '//foo:bar@localhost/baz'), + 'URL without scheme and without any driver information' => [ + ['url' => '//foo:bar@localhost/baz'], false, - ), - 'URL without scheme but default PDO driver' => array( - array('url' => '//foo:bar@localhost/baz', 'pdo' => true), + ], + 'URL without scheme but default PDO driver' => [ + [ + 'url' => '//foo:bar@localhost/baz', + 'pdo' => true, + ], false, - ), - 'URL without scheme but default driver' => array( - array('url' => '//foo:bar@localhost/baz', 'driver' => 'pdo_mysql'), - array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), - ), - 'URL without scheme but custom driver' => array( - array('url' => '//foo:bar@localhost/baz', 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock'), - 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' => 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( - array('url' => '//foo:bar@localhost/baz', 'driver' => 'pdo_mysql', 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock'), - 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' => true), - array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), - ), - 'URL with default driver' => array( - array('url' => 'mysql://foo:bar@localhost/baz', 'driver' => 'sqlite'), - array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), - ), - 'URL with default custom driver' => array( - array('url' => 'mysql://foo:bar@localhost/baz', 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock'), - 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' => 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( - array('url' => 'mysql://foo:bar@localhost/baz', 'driver' => 'sqlite', 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock'), - 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' => true, 'driver' => 'sqlite', 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock'), - array('user' => 'foo', 'password' => 'bar', 'host' => 'localhost', 'dbname' => 'baz', 'driver' => 'Doctrine\DBAL\Driver\PDOMySQL\Driver'), - ), - ); + ], + 'URL without scheme but default driver' => [ + [ + 'url' => '//foo:bar@localhost/baz', + 'driver' => 'pdo_mysql', + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'URL without scheme but custom driver' => [ + [ + 'url' => '//foo:bar@localhost/baz', + 'driverClass' => DriverMock::class, + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driverClass' => DriverMock::class, + ], + ], + 'URL without scheme but default PDO driver and default driver' => [ + [ + 'url' => '//foo:bar@localhost/baz', + 'pdo' => true, + 'driver' => 'pdo_mysql', + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'URL without scheme but driver and custom driver' => [ + [ + 'url' => '//foo:bar@localhost/baz', + 'driver' => 'pdo_mysql', + 'driverClass' => DriverMock::class, + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driverClass' => DriverMock::class, + ], + ], + 'URL with default PDO driver' => [ + [ + 'url' => 'mysql://foo:bar@localhost/baz', + 'pdo' => true, + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'URL with default driver' => [ + [ + 'url' => 'mysql://foo:bar@localhost/baz', + 'driver' => 'sqlite', + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'URL with default custom driver' => [ + [ + 'url' => 'mysql://foo:bar@localhost/baz', + 'driverClass' => DriverMock::class, + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'URL with default PDO driver and default driver' => [ + [ + 'url' => 'mysql://foo:bar@localhost/baz', + 'pdo' => true, + 'driver' => 'sqlite', + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'URL with default driver and default custom driver' => [ + [ + 'url' => 'mysql://foo:bar@localhost/baz', + 'driver' => 'sqlite', + 'driverClass' => DriverMock::class, + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + 'URL with default PDO driver and default driver and default custom driver' => [ + [ + 'url' => 'mysql://foo:bar@localhost/baz', + 'pdo' => true, + 'driver' => 'sqlite', + 'driverClass' => DriverMock::class, + ], + [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'dbname' => 'baz', + 'driver' => PDOMySQLDriver::class, + ], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php index 1477c09d47a..ebbff67bcef 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php @@ -54,26 +54,43 @@ public function testInsert() public function testSelect() { - $this->_conn->insert('blob_table', - array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test', 'binaryfield' => 'test'), - array(ParameterType::INTEGER, ParameterType::STRING, ParameterType::LARGE_OBJECT, ParameterType::LARGE_OBJECT) - ); + $this->_conn->insert('blob_table', [ + 'id' => 1, + 'clobfield' => 'test', + 'blobfield' => 'test', + 'binaryfield' => 'test', + ], [ + ParameterType::INTEGER, + ParameterType::STRING, + ParameterType::LARGE_OBJECT, + ParameterType::LARGE_OBJECT, + ]); $this->assertBlobContains('test'); } public function testUpdate() { - $this->_conn->insert('blob_table', - array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test', 'binaryfield' => 'test'), - 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(ParameterType::LARGE_OBJECT, ParameterType::LARGE_OBJECT, ParameterType::INTEGER) - ); + $this->_conn->insert('blob_table', [ + 'id' => 1, + 'clobfield' => 'test', + 'blobfield' => 'test', + 'binaryfield' => 'test', + ], [ + ParameterType::INTEGER, + ParameterType::STRING, + ParameterType::LARGE_OBJECT, + ParameterType::LARGE_OBJECT, + ]); + + $this->_conn->update('blob_table', [ + 'blobfield' => 'test2', + 'binaryfield' => 'test2', + ], ['id' => 1], [ + ParameterType::LARGE_OBJECT, + ParameterType::LARGE_OBJECT, + ParameterType::INTEGER, + ]); $this->assertBlobContains('test2'); $this->assertBinaryContains('test2'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php index 6037d8055c4..d76abdaca29 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -128,7 +128,7 @@ 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, "The row should not contain numerical keys."); + self::assertArrayNotHasKey(0, $row, 'The row should not contain numerical keys.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php index e6f9d4473b1..824ba65ad74 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php @@ -104,9 +104,7 @@ public function testFetchLongBlob() EOF ); - $this->_conn->insert('stmt_long_blob', array( - 'contents' => $contents, - ), array(ParameterType::LARGE_OBJECT)); + $this->_conn->insert('stmt_long_blob', ['contents' => $contents], [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 9a96ad2fb96..a0816b35303 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -55,8 +55,8 @@ public function testBooleanConversionBoolParamRealPrepares() { $this->_conn->executeUpdate( 'INSERT INTO dbal630 (bool_col) VALUES(?)', - array('false'), - array(ParameterType::BOOLEAN) + ['false'], + [ParameterType::BOOLEAN] ); $id = $this->_conn->lastInsertId('dbal630_id_seq'); self::assertNotEmpty($id); diff --git a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php index 54f4b6a9837..c7241592169 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php @@ -32,10 +32,10 @@ protected function setUp() public function testExecuteUpdateFirstTypeIsNull() { $sql = "INSERT INTO write_table (test_string, test_int) VALUES (?, ?)"; - $this->_conn->executeUpdate($sql, array("text", 1111), array(null, ParameterType::INTEGER)); + $this->_conn->executeUpdate($sql, ['text', 1111], [null, ParameterType::INTEGER]); $sql = "SELECT * FROM write_table WHERE test_string = ? AND test_int = ?"; - self::assertTrue((bool)$this->_conn->fetchColumn($sql, array("text", 1111))); + self::assertTrue((bool) $this->_conn->fetchColumn($sql, ['text', 1111])); } public function testExecuteUpdate() @@ -51,8 +51,8 @@ public function testExecuteUpdateWithTypes() $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; $affected = $this->_conn->executeUpdate( $sql, - array(1, 'foo'), - array(ParameterType::INTEGER, ParameterType::STRING) + [1, 'foo'], + [ParameterType::INTEGER, ParameterType::STRING] ); self::assertEquals(1, $affected, "executeUpdate() should return the number of affected rows!"); @@ -76,7 +76,7 @@ public function testPrepareWithPdoTypes() $stmt = $this->_conn->prepare($sql); $stmt->bindValue(1, 1, ParameterType::INTEGER); - $stmt->bindValue(2, "foo", ParameterType::STRING); + $stmt->bindValue(2, 'foo', ParameterType::STRING); $stmt->execute(); self::assertEquals(1, $stmt->rowCount()); diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php index 33263984161..26058b25942 100644 --- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php @@ -874,7 +874,10 @@ public function testGetParameterTypes() $qb->where('is_active = :isActive'); $qb->setParameter('isActive', true, ParameterType::BOOLEAN); - self::assertSame(array('name' => ParameterType::STRING, 'isActive' => ParameterType::BOOLEAN), $qb->getParameterTypes()); + self::assertSame([ + 'name' => ParameterType::STRING, + 'isActive' => ParameterType::BOOLEAN, + ], $qb->getParameterTypes()); } /**