Skip to content

Commit

Permalink
Remove Statement::bindParam()
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Aug 4, 2022
1 parent 7483ccf commit 6d2182b
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 369 deletions.
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ awareness about deprecated code.

# Upgrade to 4.0

## BC BREAK: removed wrapper- and driver-level `Statement::bindParam()` methods.

The following methods have been removed:

1. `Doctrine\DBAL\Statement::bindParam()`,
2. `Doctrine\DBAL\Driver\Statement::bindParam()`.

## BC BREAK: made parameter type in driver-level `Statement::bind*()` methods required.

The `$type` parameter of the driver-level `Statement::bindParam()` and `::bindValue()` has been made required.
Expand Down
24 changes: 3 additions & 21 deletions src/Driver/IBMDB2/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;

use function assert;
use function db2_bind_param;
Expand Down Expand Up @@ -55,34 +54,17 @@ public function bindValue(int|string $param, mixed $value, ParameterType $type):
{
assert(is_int($param));

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

/**
* @deprecated Use {@see bindValue()} instead.
*/
public function bindParam(int|string $param, mixed &$variable, ParameterType $type, ?int $length = null): void
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5563',
'%s is deprecated. Use bindValue() instead.',
__METHOD__
);

assert(is_int($param));

switch ($type) {
case ParameterType::INTEGER:
$this->bind($param, $variable, DB2_PARAM_IN, DB2_LONG);
$this->bind($param, $value, DB2_PARAM_IN, DB2_LONG);
break;

case ParameterType::LARGE_OBJECT:
$this->lobs[$param] = &$variable;
$this->lobs[$param] = &$value;
break;

default:
$this->bind($param, $variable, DB2_PARAM_IN, DB2_CHAR);
$this->bind($param, $value, DB2_PARAM_IN, DB2_CHAR);
break;
}
}
Expand Down
20 changes: 0 additions & 20 deletions src/Driver/Middleware/AbstractStatementMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;

abstract class AbstractStatementMiddleware implements Statement
{
Expand All @@ -20,25 +19,6 @@ public function bindValue(int|string $param, mixed $value, ParameterType $type):
$this->wrappedStatement->bindValue($param, $value, $type);
}

/**
* @deprecated Use {@see bindValue()} instead.
*/
public function bindParam(
int|string $param,
mixed &$variable,
ParameterType $type,
?int $length = null
): void {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5563',
'%s is deprecated. Use bindValue() instead.',
__METHOD__
);

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

public function execute(): Result
{
return $this->wrappedStatement->execute();
Expand Down
23 changes: 0 additions & 23 deletions src/Driver/Mysqli/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Doctrine\DBAL\Driver\Mysqli\Exception\StatementError;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;
use mysqli_sql_exception;
use mysqli_stmt;

Expand Down Expand Up @@ -52,28 +51,6 @@ public function __construct(private readonly mysqli_stmt $stmt)
$this->boundValues = array_fill(1, $paramCount, null);
}

/**
* @deprecated Use {@see bindValue()} instead.
*/
public function bindParam(
int|string $param,
mixed &$variable,
ParameterType $type,
?int $length = null
): void {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5563',
'%s is deprecated. Use bindValue() instead.',
__METHOD__
);

assert(is_int($param));

$this->types[$param - 1] = $this->convertParameterType($type);
$this->boundValues[$param] =& $variable;
}

public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
assert(is_int($param));
Expand Down
30 changes: 5 additions & 25 deletions src/Driver/OCI8/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\DBAL\Driver\OCI8\Exception\UnknownParameterIndex;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;

use function is_int;
use function oci_bind_by_name;
Expand Down Expand Up @@ -42,25 +41,6 @@ public function __construct(

public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
$this->bindParam($param, $value, $type);
}

/**
* @deprecated Use {@see bindValue()} instead.
*/
public function bindParam(
int|string $param,
mixed &$variable,
ParameterType $type,
?int $length = null
): void {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5563',
'%s is deprecated. Use bindValue() instead.',
__METHOD__
);

if (is_int($param)) {
if (! isset($this->parameterMap[$param])) {
throw UnknownParameterIndex::new($param);
Expand All @@ -70,11 +50,11 @@ public function bindParam(
}

if ($type === ParameterType::LARGE_OBJECT) {
if ($variable !== null) {
if ($value !== null) {
$lob = oci_new_descriptor($this->connection, OCI_D_LOB);
$lob->writeTemporary($variable, OCI_TEMP_BLOB);
$lob->writeTemporary($value, OCI_TEMP_BLOB);

$variable =& $lob;
$value =& $lob;
} else {
$type = ParameterType::STRING;
}
Expand All @@ -84,8 +64,8 @@ public function bindParam(
! @oci_bind_by_name(
$this->statement,
$param,
$variable,
$length ?? -1,
$value,
-1,
$this->convertParameterType($type)
)
) {
Expand Down
32 changes: 5 additions & 27 deletions src/Driver/PDO/SQLSrv/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
use Doctrine\DBAL\Driver\PDO\Statement as PDOStatement;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;
use PDO;

final class Statement extends AbstractStatementMiddleware
Expand All @@ -24,51 +23,30 @@ public function __construct(PDOStatement $statement)
$this->statement = $statement;
}

/**
* @deprecated Use {@see bindValue()} instead.
*/
public function bindParam(
int|string $param,
mixed &$variable,
ParameterType $type,
?int $length = null
): void {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5563',
'%s is deprecated. Use bindValue() instead.',
__METHOD__
);

public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
switch ($type) {
case ParameterType::LARGE_OBJECT:
case ParameterType::BINARY:
$this->statement->bindParamWithDriverOptions(
$param,
$variable,
$value,
$type,
$length ?? 0,
PDO::SQLSRV_ENCODING_BINARY
);
break;

case ParameterType::ASCII:
$this->statement->bindParamWithDriverOptions(
$param,
$variable,
$value,
ParameterType::STRING,
$length ?? 0,
PDO::SQLSRV_ENCODING_SYSTEM
);
break;

default:
$this->statement->bindParam($param, $variable, $type, $length ?? 0);
$this->statement->bindValue($param, $value, $type);
}
}

public function bindValue(int|string $param, mixed $value, ParameterType $type): void
{
$this->bindParam($param, $value, $type);
}
}
31 changes: 1 addition & 30 deletions src/Driver/PDO/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\DBAL\Driver\Exception as ExceptionInterface;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;
use PDO;
use PDOException;
use PDOStatement;
Expand All @@ -32,33 +31,6 @@ public function bindValue(int|string $param, mixed $value, ParameterType $type):
}
}

/**
* @deprecated Use {@see bindValue()} instead.
*/
public function bindParam(
string|int $param,
mixed &$variable,
ParameterType $type,
?int $length = null
): void {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5563',
'%s is deprecated. Use bindValue() instead.',
__METHOD__
);

try {
if ($length === null) {
$this->stmt->bindParam($param, $variable, $this->convertParamType($type));
} else {
$this->stmt->bindParam($param, $variable, $this->convertParamType($type), $length);
}
} catch (PDOException $exception) {
throw Exception::new($exception);
}
}

/**
* @internal Driver options can be only specified by a PDO-based driver.
*
Expand All @@ -68,11 +40,10 @@ public function bindParamWithDriverOptions(
string|int $param,
mixed &$variable,
ParameterType $type,
int $length,
mixed $driverOptions
): void {
try {
$this->stmt->bindParam($param, $variable, $this->convertParamType($type), $length, $driverOptions);
$this->stmt->bindParam($param, $variable, $this->convertParamType($type), 0, $driverOptions);
} catch (PDOException $exception) {
throw Exception::new($exception);
}
Expand Down
26 changes: 0 additions & 26 deletions src/Driver/SQLSrv/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\DBAL\Driver\SQLSrv\Exception\Error;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;

use function assert;
use function is_int;
Expand Down Expand Up @@ -75,31 +74,6 @@ public function bindValue(int|string $param, mixed $value, ParameterType $type):
$this->types[$param] = $type;
}

/**
* @deprecated Use {@see bindValue()} instead.
*/
public function bindParam(
int|string $param,
mixed &$variable,
ParameterType $type,
?int $length = null
): void {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5563',
'%s is deprecated. Use bindValue() instead.',
__METHOD__
);

assert(is_int($param));

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

// unset the statement resource if it exists as the new one will need to be bound to the new variable
$this->stmt = null;
}

public function execute(): Result
{
$this->stmt ??= $this->prepare();
Expand Down
34 changes: 0 additions & 34 deletions src/Driver/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,6 @@ interface Statement
*/
public function bindValue(int|string $param, mixed $value, ParameterType $type): void;

/**
* Binds a PHP variable to a corresponding named (not supported by mysqli driver, see comment below) or question
* mark placeholder in the SQL statement that was use to prepare the statement. Unlike {@see bindValue()},
* the variable is bound as a reference and will only be evaluated at the time
* that PDOStatement->execute() is called.
*
* As mentioned above, the named parameters are not natively supported by the mysqli driver, use executeQuery(),
* fetchAll(), fetchArray(), fetchColumn(), fetchAssoc() methods to have the named parameter emulated by doctrine.
*
* Most parameters are input parameters, that is, parameters that are
* used in a read-only fashion to build up the query. Some drivers support the invocation
* of stored procedures that return data as output parameters, and some also as input/output
* parameters that both send in data and are updated to receive it.
*
* @deprecated Use {@see bindValue()} instead.
*
* @param int|string $param Parameter identifier. For a prepared statement using named placeholders,
* this will be a parameter name of the form :name. For a prepared statement using
* question mark placeholders, this will be the 1-indexed position of the parameter.
* @param mixed $variable The variable to bind to the parameter.
* @param ParameterType $type Explicit data type for the parameter using the {@see ParameterType}
* constants.
* @param int|null $length You must specify maxlength when using an OUT bind
* so that PHP allocates enough memory to hold the returned value.
*
* @throws Exception
*/
public function bindParam(
int|string $param,
mixed &$variable,
ParameterType $type,
?int $length = null
): void;

/**
* Executes a prepared statement
*
Expand Down
Loading

0 comments on commit 6d2182b

Please sign in to comment.