Replaced PDO::FETCH_* and PDO::PARAM_* constants

parent 9ca04dd8
......@@ -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
<?php
use Doctrine\DBAL\ParameterType;
$quoted = $conn->quote('value');
$quoted = $conn->quote('1234', \PDO::PARAM_INT);
$quoted = $conn->quote('1234', ParameterType::INTEGER);
quoteIdentifier()
~~~~~~~~~~~~~~~~~
......
......@@ -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.
......@@ -151,7 +151,7 @@ the ``Connection#quote`` method:
<?php
// Parameter quoting
$sql = "SELECT * FROM users WHERE name = " . $connection->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.
......@@ -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 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
*/
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;
}
$row = $this->data[$this->num++];
$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) {
return reset($row);
} else {
throw new \InvalidArgumentException("Invalid fetch-style given for fetching result.");
}
if ($fetchMode === FetchMode::COLUMN) {
return reset($row);
}
return false;
throw new \InvalidArgumentException("Invalid fetch-style given for fetching result.");
}
/**
......@@ -137,7 +144,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
*/
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;
......
......@@ -22,7 +22,7 @@ namespace Doctrine\DBAL\Cache;
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 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
$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 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
*/
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;
......
......@@ -21,7 +21,6 @@ namespace Doctrine\DBAL;
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 @@ class Connection implements DriverConnection
*/
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 @@ class Connection implements DriverConnection
*/
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 @@ class Connection implements DriverConnection
$typeValues = [];
foreach ($columnList as $columnIndex => $columnName) {
$typeValues[] = $types[$columnName] ?? \PDO::PARAM_STR;
$typeValues[] = $types[$columnName] ?? ParameterType::STRING;
}
return $typeValues;
......@@ -1592,7 +1591,7 @@ class Connection implements DriverConnection
$value = $type->convertToDatabaseValue($value, $this->getDatabasePlatform());
$bindingType = $type->getBindingType();
} else {
$bindingType = $type; // PDO::PARAM_* constants
$bindingType = $type;
}
return [$value, $bindingType];
......
......@@ -19,6 +19,8 @@
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\ParameterType;
/**
* Connection interface.
* Driver connections must implement this interface.
......@@ -53,7 +55,7 @@ interface Connection
*
* @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.
......
......@@ -19,6 +19,8 @@
namespace Doctrine\DBAL\Driver\DrizzlePDOMySql;
use Doctrine\DBAL\ParameterType;
/**
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
......@@ -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';
}
......
......@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
class DB2Connection implements Connection, ServerInfoAwareConnection
{
......@@ -98,10 +99,11 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
/**
* {@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;
}
......
......@@ -21,6 +21,8 @@ namespace Doctrine\DBAL\Driver\IBMDB2;
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 @@ class DB2Statement implements \IteratorAggregate, Statement
/**
* {@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 @@ class DB2Statement implements \IteratorAggregate, Statement
/**
* {@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 @@ class DB2Statement implements \IteratorAggregate, Statement
$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 @@ class DB2Statement implements \IteratorAggregate, Statement
}
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 @@ class DB2Statement implements \IteratorAggregate, Statement
$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 @@ class DB2Statement implements \IteratorAggregate, Statement
*/
public function fetchColumn($columnIndex = 0)
{
$row = $this->fetch(\PDO::FETCH_NUM);
$row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) {
return false;
......
......@@ -22,6 +22,7 @@ namespace Doctrine\DBAL\Driver\Mysqli;
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 <kimhemsoe@gmail.com>
......@@ -145,7 +146,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
/**
* {@inheritdoc}
*/
public function quote($input, $type=\PDO::PARAM_STR)
public function quote($input, $type = ParameterType::STRING)
{
return "'". $this->_conn->escape_string($input) ."'";
}
......
......@@ -21,7 +21,8 @@ namespace Doctrine\DBAL\Driver\Mysqli;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator;
use PDO;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
/**
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
......@@ -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 @@ class MysqliStatement implements \IteratorAggregate, Statement
/**
* {@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 @@ class MysqliStatement implements \IteratorAggregate, Statement
/**
* {@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 @@ class MysqliStatement implements \IteratorAggregate, Statement
$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
if ($fetchMode === PDO::FETCH_COLUMN) {
if ($fetchMode === FetchMode::COLUMN) {
return $this->fetchColumn();
}
......@@ -288,19 +289,19 @@ class MysqliStatement implements \IteratorAggregate, Statement
}
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 @@ class MysqliStatement implements \IteratorAggregate, Statement
$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 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/
public function fetchColumn($columnIndex = 0)
{
$row = $this->fetch(PDO::FETCH_NUM);
$row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) {
return false;
}
......
......@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
/**
* OCI8 implementation of the Connection interface.
......@@ -120,7 +121,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
/**
* {@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 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
$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;
}
/**
......
......@@ -21,8 +21,9 @@ namespace Doctrine\DBAL\Driver\OCI8;
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 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@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 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@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 @@ class OCI8Statement implements IteratorAggregate, Statement
$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 @@ class OCI8Statement implements IteratorAggregate, Statement
$result = [];
if (PDO::FETCH_OBJ == $fetchMode) {
if ($fetchMode == FetchMode::STANDARD_OBJECT) {
while ($row = $this->fetch($fetchMode)) {
$result[] = $row;
}
......@@ -432,7 +433,8 @@ class OCI8Statement implements IteratorAggregate, Statement
}
} else {
$fetchStructure = OCI_FETCHSTATEMENT_BY_ROW;
if ($fetchMode == PDO::FETCH_COLUMN) {
if ($fetchMode == FetchMode::COLUMN) {
$fetchStructure = OCI_FETCHSTATEMENT_BY_COLUMN;
}
......@@ -445,7 +447,7 @@ class OCI8Statement implements IteratorAggregate, Statement
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];
}
}
......
......@@ -19,6 +19,7 @@
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\ParameterType;
use PDO;
/**
......@@ -110,7 +111,7 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
/**
* {@inheritdoc}
*/
public function quote($input, $type = \PDO::PARAM_STR)
public function quote($input, $type = ParameterType::STRING)
{
return parent::quote($input, $type);
}
......
......@@ -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 @@ class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connecti
/**
* {@inheritDoc}
*/
public function quote($value, $type=\PDO::PARAM_STR)
public function quote($value, $type = ParameterType::STRING)
{
$val = parent::quote($value, $type);
......
......@@ -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 @@ class Statement extends PDOStatement
/**
* {@inheritdoc}
*/
public function bindValue($param, $value, $type = PDO::PARAM_STR)
public function bindValue($param, $value, $type = ParameterType::STRING)
{
return $this->bindParam($param, $value, $type);
}
......
......@@ -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 @@ class PDOStatement extends \PDOStatement implements Statement
/**
* {@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 @@ class PDOStatement extends \PDOStatement implements Statement
/**
* {@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);
......
......@@ -45,13 +45,11 @@ interface ResultStatement extends \Traversable
/**
* 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 @@ interface ResultStatement extends \Traversable
* 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 @@ interface ResultStatement extends \Traversable
*
* @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 @@ interface ResultStatement extends \Traversable
* 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.
* @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);
......
......@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere;
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 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
/**
* {@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;
......
......@@ -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 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*
* @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 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
/**
* {@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 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
$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 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
}
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 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
$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 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/
public function fetchColumn($columnIndex = 0)
{
$row = $this->fetch(PDO::FETCH_NUM);
$row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) {
return false;
......
......@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Driver\SQLSrv;
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 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
* {@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;
......
......@@ -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 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* {@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 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* {@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 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$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 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$args = func_get_args();
$fetchMode = $fetchMode ?: $this->defaultFetchMode;
if ($fetchMode === PDO::FETCH_COLUMN) {
if ($fetchMode === FetchMode::COLUMN) {
return $this->fetchColumn();
}
......@@ -323,7 +324,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
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 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$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 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/
public function fetchColumn($columnIndex = 0)
{
$row = $this->fetch(PDO::FETCH_NUM);
$row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) {
return false;
......
......@@ -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 @@ interface Statement extends ResultStatement
*
* @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 @@ interface Statement extends ResultStatement
*
* @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 @@ interface Statement extends ResultStatement
*
* @return array The error info array.
*/
function errorInfo();
public function errorInfo();
/**
* Executes a prepared statement
......@@ -112,7 +113,7 @@ interface Statement extends ResultStatement
*
* @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 @@ interface Statement extends ResultStatement
*
* @return int The number of rows.
*/
function rowCount();
public function rowCount();
}
......@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Id;
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 @@ class TableGenerator
"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'];
......
......@@ -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 <tt>Statement</tt> and applies portability measures.
......@@ -66,15 +67,15 @@ class Statement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement
/**
* {@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 @@ class Statement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement
$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 @@ class Statement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement
}
$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 @@ class Statement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement
$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];
}
......
......@@ -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 @@ class QueryBuilder
*
* @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 @@ class QueryBuilder
*
* @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 @@ class QueryBuilder
* $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))
* </code>
*
* @param mixed $value
......@@ -1289,7 +1290,7 @@ class QueryBuilder
*
* @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);
......
......@@ -139,7 +139,9 @@ class SQLParserUtils
$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 @@ class SQLParserUtils
$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;
......
......@@ -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 @@ class SqliteSchemaManager extends AbstractSchemaManager
// 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 @@ class SqliteSchemaManager extends AbstractSchemaManager
$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'];
......
......@@ -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 @@ class Statement implements \IteratorAggregate, DriverStatement
*
* @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 @@ class Statement implements \IteratorAggregate, DriverStatement
$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 @@ class Statement implements \IteratorAggregate, DriverStatement
*
* @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;
......
......@@ -19,6 +19,7 @@
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
......@@ -50,7 +51,7 @@ class BigIntType extends Type implements PhpIntegerMappingType
*/
public function getBindingType()
{
return \PDO::PARAM_STR;
return ParameterType::STRING;
}
/**
......
......@@ -19,6 +19,7 @@
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
......@@ -73,6 +74,6 @@ class BinaryType extends Type
*/
public function getBindingType()
{
return \PDO::PARAM_LOB;
return ParameterType::LARGE_OBJECT;
}
}
......@@ -19,6 +19,7 @@
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
......@@ -72,6 +73,6 @@ class BlobType extends Type
*/
public function getBindingType()
{
return \PDO::PARAM_LOB;
return ParameterType::LARGE_OBJECT;
}
}
......@@ -19,6 +19,7 @@
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
......@@ -65,6 +66,6 @@ class BooleanType extends Type
*/
public function getBindingType()
{
return \PDO::PARAM_BOOL;
return ParameterType::BOOLEAN;
}
}
......@@ -19,6 +19,7 @@
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
......@@ -58,6 +59,6 @@ class IntegerType extends Type implements PhpIntegerMappingType
*/
public function getBindingType()
{
return \PDO::PARAM_INT;
return ParameterType::INTEGER;
}
}
......@@ -19,6 +19,7 @@
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
......@@ -57,6 +58,6 @@ class SmallIntType extends Type implements PhpIntegerMappingType
*/
public function getBindingType()
{
return \PDO::PARAM_INT;
return ParameterType::INTEGER;
}
}
......@@ -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 @@ abstract class Type
* 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;
}
/**
......
......@@ -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 @@ class QueryCacheProfileTest extends DbalTestCase
{
$query = 'SELECT * FROM foo WHERE bar = ?';
$params = [666];
$types = [PDO::PARAM_INT];
$types = [ParameterType::INTEGER];
$connectionParams = array(
'dbname' => 'database_name',
......@@ -47,7 +47,7 @@ class QueryCacheProfileTest extends DbalTestCase
{
$query = 'SELECT * FROM foo WHERE bar = ?';
$params = [666];
$types = [PDO::PARAM_INT];
$types = [ParameterType::INTEGER];
$connectionParams = array(
'dbname' => 'database_name',
......@@ -79,7 +79,7 @@ class QueryCacheProfileTest extends DbalTestCase
{
$query = 'SELECT * FROM foo WHERE bar = ?';
$params = [666];
$types = [PDO::PARAM_INT];
$types = [ParameterType::INTEGER];
$connectionParams = array(
'dbname' => 'database_name',
......@@ -114,7 +114,7 @@ class QueryCacheProfileTest extends DbalTestCase
{
$query = 'SELECT * FROM foo WHERE bar = ?';
$params = [666];
$types = [PDO::PARAM_INT];
$types = [ParameterType::INTEGER];
$connectionParams = array(
'dbname' => 'database_name',
......
......@@ -11,10 +11,12 @@ use Doctrine\DBAL\Connection;
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 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
$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 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
$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 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
$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 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
$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 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
$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 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
{
$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 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
{
$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 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
{
$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 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
$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 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
{
$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 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
$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);
......
......@@ -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 @@ class BlobTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$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 @@ class BlobTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$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 @@ class BlobTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$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');
......
......@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Functional;
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 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
*/
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()
......
......@@ -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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$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));
$data = $this->_conn->fetchAll($sql, array(1, $datetime), array(ParameterType::STRING, Type::DATETIME));
self::assertCount(1, $data);
......@@ -226,7 +228,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$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));
$column = $this->_conn->fetchColumn(
$sql,
array(1, $datetime),
1,
array(ParameterType::STRING, Type::DATETIME)
);
self::assertNotFalse($column);
......@@ -393,8 +403,16 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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);
}
......@@ -615,7 +633,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$sql[] = 'FROM fetch_table';
$stmt = $this->_conn->executeQuery(implode(PHP_EOL, $sql));
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$data = $stmt->fetchAll(FetchMode::ASSOCIATIVE);
self::assertCount(4, $data);
......@@ -641,7 +659,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$stmt->execute();
$results = $stmt->fetchAll(
\PDO::FETCH_CLASS,
FetchMode::CUSTOM_OBJECT,
__NAMESPACE__.'\\MyFetchClass'
);
......@@ -715,7 +733,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$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();
......
......@@ -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 @@ class PDOPgsqlConnectionTest extends DbalFunctionalTestCase
$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)
);
}
/**
......
......@@ -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 @@ class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase
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);
......
......@@ -4,8 +4,8 @@ namespace Doctrine\Tests\DBAL\Functional;
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 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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);
}
}
<?php
namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use PDO;
use Doctrine\DBAL\FetchMode;
/**
* @group DDC-217
......@@ -44,7 +45,10 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testCacheFetchAssoc()
{
self::assertCacheNonCacheSelectSameFetchModeAreEqual($this->expectedResult, \PDO::FETCH_ASSOC);
self::assertCacheNonCacheSelectSameFetchModeAreEqual(
$this->expectedResult,
FetchMode::ASSOCIATIVE
);
}
public function testFetchNum()
......@@ -53,7 +57,8 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
$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 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$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 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
return $data;
}
private function hydrateStmtIterator($stmt, $fetchMode = \PDO::FETCH_ASSOC)
private function hydrateStmtIterator($stmt, $fetchMode = FetchMode::ASSOCIATIVE)
{
$data = array();
$stmt->setFetchMode($fetchMode);
......
......@@ -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 @@ class StatementTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class StatementTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ EOF
$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 @@ EOF
{
$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);
}
......
......@@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Functional\Ticket;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\ParameterType;
use PDO;
/**
......@@ -52,7 +53,11 @@ class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase
$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 @@ class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase
$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');
......
<?php
namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Types\Type;
use PDO;
class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
......@@ -31,7 +32,7 @@ class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testExecuteUpdateFirstTypeIsNull()
{
$sql = "INSERT INTO write_table (test_string, test_int) VALUES (?, ?)";
$this->_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 @@ class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase
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 @@ class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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());
......
......@@ -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 @@ class StatementTest extends \Doctrine\Tests\DbalTestCase
{
$column = 'mycolumn';
$variable = 'myvalue';
$type = \PDO::PARAM_STR;
$type = ParameterType::STRING;
$length = 666;
$this->wrappedStmt->expects($this->once())
......@@ -54,7 +56,7 @@ class StatementTest extends \Doctrine\Tests\DbalTestCase
{
$param = 'myparam';
$value = 'myvalue';
$type = \PDO::PARAM_STR;
$type = ParameterType::STRING;
$this->wrappedStmt->expects($this->once())
->method('bindValue')
......@@ -123,7 +125,7 @@ class StatementTest extends \Doctrine\Tests\DbalTestCase
public function testSetFetchMode()
{
$fetchMode = \PDO::FETCH_CLASS;
$fetchMode = FetchMode::CUSTOM_OBJECT;
$arg1 = 'MyClass';
$arg2 = array(1, 2);
......@@ -132,7 +134,7 @@ class StatementTest extends \Doctrine\Tests\DbalTestCase
->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);
}
......
......@@ -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 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$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 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$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 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$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 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
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 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
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());
}
/**
......
......@@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\SQLParserUtils;
/**
......@@ -95,34 +96,40 @@ SQLDATA
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 @@ SQLDATA
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 @@ SQLDATA
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 @@ SQLDATA
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 @@ SQLDATA
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 @@ SQLDATA
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 @@ SQLDATA
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 @@ SQLDATA
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 @@ SQLDATA
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 @@ SQLDATA
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)
),
);
}
......
......@@ -2,6 +2,7 @@
namespace Doctrine\Tests\DBAL;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Statement;
use Doctrine\DBAL\Logging\SQLLogger;
......@@ -64,9 +65,9 @@ class StatementTest extends \Doctrine\Tests\DbalTestCase
{
$name = 'foo';
$var = 'bar';
$type = \PDO::PARAM_STR;
$values = array($name => $var);
$types = array($name => $type);
$type = ParameterType::STRING;
$values = [$name => $var];
$types = [$name => $type];
$sql = '';
$logger = $this->createMock('\Doctrine\DBAL\Logging\SQLLogger');
......@@ -109,7 +110,7 @@ class StatementTest extends \Doctrine\Tests\DbalTestCase
$name = 'foo';
$var = 'bar';
$values = [$name => $var];
$types = [$name => \PDO::PARAM_STR];
$types = [$name => ParameterType::STRING];
$sql = '';
$logger = $this->createMock(SQLLogger::class);
......
......@@ -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 @@ class BinaryTest extends \Doctrine\Tests\DbalTestCase
public function testReturnsBindingType()
{
self::assertSame(\PDO::PARAM_LOB, $this->type->getBindingType());
self::assertSame(ParameterType::LARGE_OBJECT, $this->type->getBindingType());
}
public function testReturnsName()
......
......@@ -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 @@ class DateImmutableTypeTest extends \PHPUnit\Framework\TestCase
public function testReturnsBindingType()
{
self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType());
self::assertSame(ParameterType::STRING, $this->type->getBindingType());
}
public function testConvertsDateTimeImmutableInstanceToDatabaseValue()
......
......@@ -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 @@ class DateTimeImmutableTypeTest extends \PHPUnit\Framework\TestCase
public function testReturnsBindingType()
{
self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType());
self::assertSame(ParameterType::STRING, $this->type->getBindingType());
}
public function testConvertsDateTimeImmutableInstanceToDatabaseValue()
......
......@@ -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 @@ class DateTimeTzImmutableTypeTest extends \PHPUnit\Framework\TestCase
public function testReturnsBindingType()
{
self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType());
self::assertSame(ParameterType::STRING, $this->type->getBindingType());
}
public function testConvertsDateTimeImmutableInstanceToDatabaseValue()
......
......@@ -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 @@ class JsonArrayTest extends \Doctrine\Tests\DbalTestCase
public function testReturnsBindingType()
{
self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType());
self::assertSame(ParameterType::STRING, $this->type->getBindingType());
}
public function testReturnsName()
......
......@@ -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 @@ class JsonTest extends \Doctrine\Tests\DbalTestCase
public function testReturnsBindingType()
{
self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType());
self::assertSame(ParameterType::STRING, $this->type->getBindingType());
}
public function testReturnsName()
......
......@@ -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 @@ class TimeImmutableTypeTest extends \PHPUnit\Framework\TestCase
public function testReturnsBindingType()
{
self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType());
self::assertSame(ParameterType::STRING, $this->type->getBindingType());
}
public function testConvertsDateTimeImmutableInstanceToDatabaseValue()
......
......@@ -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 @@ class VarDateTimeImmutableTypeTest extends \PHPUnit\Framework\TestCase
public function testReturnsBindingType()
{
self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType());
self::assertSame(ParameterType::STRING, $this->type->getBindingType());
}
public function testConvertsDateTimeImmutableInstanceToDatabaseValue()
......
......@@ -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() {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment