Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate not passing parameter type to bindParam() and bindValue() #5558

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE.md
Expand Up @@ -8,6 +8,11 @@ awareness about deprecated code.

# Upgrade to 3.4

## Deprecated not passing parameter type to the driver-level `Statement::bind*()` methods.

Not passing `$type` to the driver-level `Statement::bindParam()` and `::bindValue()` is deprecated.
Pass the type corresponding to the parameter being bound.

## Deprecated passing `$params` to `Statement::execute*()` methods.

Passing `$params` to the driver-level `Statement::execute()` and the wrapper-level `Statement::executeQuery()`
Expand Down
10 changes: 6 additions & 4 deletions src/Connection.php
Expand Up @@ -1671,7 +1671,6 @@ private function bindParameters(DriverStatement $stmt, array $params, array $typ
if (isset($types[$key])) {
$type = $types[$key];
[$value, $bindingType] = $this->getBindingInfo($value, $type);
$stmt->bindValue($bindIndex, $value, $bindingType);
} else {
if (array_key_exists($key, $types)) {
Deprecation::trigger(
Expand All @@ -1682,9 +1681,11 @@ private function bindParameters(DriverStatement $stmt, array $params, array $typ
);
}

$stmt->bindValue($bindIndex, $value);
$bindingType = ParameterType::STRING;
}

$stmt->bindValue($bindIndex, $value, $bindingType);

++$bindIndex;
}
} else {
Expand All @@ -1693,7 +1694,6 @@ private function bindParameters(DriverStatement $stmt, array $params, array $typ
if (isset($types[$name])) {
$type = $types[$name];
[$value, $bindingType] = $this->getBindingInfo($value, $type);
$stmt->bindValue($name, $value, $bindingType);
} else {
if (array_key_exists($name, $types)) {
Deprecation::trigger(
Expand All @@ -1704,8 +1704,10 @@ private function bindParameters(DriverStatement $stmt, array $params, array $typ
);
}

$stmt->bindValue($name, $value);
$bindingType = ParameterType::STRING;
}

$stmt->bindValue($name, $value, $bindingType);
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/Driver/IBMDB2/Statement.php
Expand Up @@ -16,6 +16,7 @@
use function db2_execute;
use function error_get_last;
use function fclose;
use function func_num_args;
use function is_int;
use function is_resource;
use function stream_copy_to_stream;
Expand Down Expand Up @@ -61,6 +62,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool
{
assert(is_int($param));

if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindValue() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

return $this->bindParam($param, $value, $type);
}

Expand All @@ -71,6 +81,15 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le
{
assert(is_int($param));

if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindParam() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

switch ($type) {
case ParameterType::INTEGER:
$this->bind($param, $variable, DB2_PARAM_IN, DB2_LONG);
Expand Down
21 changes: 21 additions & 0 deletions src/Driver/Middleware/AbstractStatementMiddleware.php
Expand Up @@ -5,6 +5,9 @@
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;

use function func_num_args;

abstract class AbstractStatementMiddleware implements Statement
{
Expand All @@ -20,6 +23,15 @@ public function __construct(Statement $wrappedStatement)
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
{
if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindValue() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

return $this->wrappedStatement->bindValue($param, $value, $type);
}

Expand All @@ -28,6 +40,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING)
*/
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
{
if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindParam() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

return $this->wrappedStatement->bindParam($param, $variable, $type, $length);
}

Expand Down
19 changes: 19 additions & 0 deletions src/Driver/Mysqli/Statement.php
Expand Up @@ -19,6 +19,7 @@
use function count;
use function feof;
use function fread;
use function func_num_args;
use function get_resource_type;
use function is_int;
use function is_resource;
Expand Down Expand Up @@ -70,6 +71,15 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le
{
assert(is_int($param));

if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindParam() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

if (! isset(self::$paramTypeMap[$type])) {
throw UnknownParameterType::new($type);
}
Expand All @@ -87,6 +97,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool
{
assert(is_int($param));

if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindValue() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

if (! isset(self::$paramTypeMap[$type])) {
throw UnknownParameterType::new($type);
}
Expand Down
23 changes: 21 additions & 2 deletions src/Driver/OCI8/Statement.php
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;

use function func_num_args;
use function is_int;
use function oci_bind_by_name;
use function oci_execute;
Expand Down Expand Up @@ -55,6 +56,15 @@ public function __construct($connection, $statement, array $parameterMap, Execut
*/
public function bindValue($param, $value, $type = ParameterType::STRING): bool
{
if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindValue() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

return $this->bindParam($param, $value, $type);
}

Expand All @@ -63,6 +73,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool
*/
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool
{
if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindParam() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

if (is_int($param)) {
if (! isset($this->parameterMap[$param])) {
throw UnknownParameterIndex::new($param);
Expand Down Expand Up @@ -123,9 +142,9 @@ public function execute($params = null): ResultInterface

foreach ($params as $key => $val) {
if (is_int($key)) {
$this->bindValue($key + 1, $val);
$this->bindValue($key + 1, $val, ParameterType::STRING);
} else {
$this->bindValue($key, $val);
$this->bindValue($key, $val, ParameterType::STRING);
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/Driver/PDO/SQLSrv/Statement.php
Expand Up @@ -40,6 +40,15 @@ public function bindParam(
$length = null,
$driverOptions = null
): bool {
if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindParam() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

if (func_num_args() > 4) {
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
Expand Down Expand Up @@ -70,6 +79,15 @@ public function bindParam(
*/
public function bindValue($param, $value, $type = ParameterType::STRING): bool
{
if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindValue() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

return $this->bindParam($param, $value, $type);
}
}
18 changes: 18 additions & 0 deletions src/Driver/PDO/Statement.php
Expand Up @@ -43,6 +43,15 @@ public function __construct(PDOStatement $stmt)
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
{
if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindValue() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

$type = $this->convertParamType($type);

try {
Expand All @@ -68,6 +77,15 @@ public function bindParam(
$length = null,
$driverOptions = null
): bool {
if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindParam() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

if (func_num_args() > 4) {
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
Expand Down
23 changes: 21 additions & 2 deletions src/Driver/SQLSrv/Statement.php
Expand Up @@ -10,6 +10,7 @@
use Doctrine\Deprecations\Deprecation;

use function assert;
use function func_num_args;
use function is_int;
use function sqlsrv_execute;
use function SQLSRV_PHPTYPE_STREAM;
Expand Down Expand Up @@ -87,6 +88,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool
{
assert(is_int($param));

if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindValue() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

$this->variables[$param] = $value;
$this->types[$param] = $type;

Expand All @@ -100,6 +110,15 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le
{
assert(is_int($param));

if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindParam() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

$this->variables[$param] =& $variable;
$this->types[$param] = $type;

Expand All @@ -124,9 +143,9 @@ public function execute($params = null): ResultInterface

foreach ($params as $key => $val) {
if (is_int($key)) {
$this->bindValue($key + 1, $val);
$this->bindValue($key + 1, $val, ParameterType::STRING);
} else {
$this->bindValue($key, $val);
$this->bindValue($key, $val, ParameterType::STRING);
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/Logging/Statement.php
Expand Up @@ -8,10 +8,12 @@
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;
use Psr\Log\LoggerInterface;

use function array_slice;
use function func_get_args;
use function func_num_args;

final class Statement extends AbstractStatementMiddleware
{
Expand Down Expand Up @@ -40,6 +42,15 @@ public function __construct(StatementInterface $statement, LoggerInterface $logg
*/
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null)
{
if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindParam() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

$this->params[$param] = &$variable;
$this->types[$param] = $type;

Expand All @@ -51,6 +62,15 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
{
if (func_num_args() < 3) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5558',
'Not passing $type to Statement::bindValue() is deprecated.'
. ' Pass the type corresponding to the parameter being bound.'
);
}

$this->params[$param] = $value;
$this->types[$param] = $type;

Expand Down