Skip to content

Commit bca1228

Browse files
Ocramiusmorozov
authored andcommitted
Merge pull request #3488 from morozov/quote-only-string
Connection::quote() can only quote strings
2 parents cb8bf18 + f5f5c7e commit bca1228

24 files changed

+63
-105
lines changed

UPGRADE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Upgrade to 3.0
22

3+
## BC BREAK `Statement::quote()` only accepts strings.
4+
5+
`Statement::quote()` and `ExpressionBuilder::literal()` no longer accept arguments of an arbitrary type and and don't implement type-specific handling. Only strings can be quoted.
6+
37
## BC BREAK `Statement` and `Connection` methods return `void`.
48

59
`Connection::connect()`, `Statement::bindParam()`, `::bindValue()`, `::execute()`, `ResultStatement::setFetchMode()` and `::closeCursor()` no longer return a boolean value. They will throw an exception in case of failure.

lib/Doctrine/DBAL/Connection.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,9 @@ public function quoteIdentifier($str)
808808
/**
809809
* {@inheritDoc}
810810
*/
811-
public function quote($input, $type = null)
811+
public function quote(string $input) : string
812812
{
813-
$connection = $this->getWrappedConnection();
814-
815-
[$value, $bindingType] = $this->getBindingInfo($input, $type);
816-
817-
return $connection->quote($value, $bindingType);
813+
return $this->getWrappedConnection()->quote($input);
818814
}
819815

820816
/**

lib/Doctrine/DBAL/Driver/Connection.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Doctrine\DBAL\Driver;
44

55
use Doctrine\DBAL\DBALException;
6-
use Doctrine\DBAL\ParameterType;
76

87
/**
98
* Connection interface.
@@ -27,13 +26,8 @@ public function query(string $sql) : ResultStatement;
2726

2827
/**
2928
* Quotes a string for use in a query.
30-
*
31-
* @param mixed $input
32-
* @param int $type
33-
*
34-
* @return mixed
3529
*/
36-
public function quote($input, $type = ParameterType::STRING);
30+
public function quote(string $input) : string;
3731

3832
/**
3933
* Executes an SQL statement and return the number of affected rows.

lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Doctrine\DBAL\Driver\ResultStatement;
77
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
88
use Doctrine\DBAL\Driver\Statement as DriverStatement;
9-
use Doctrine\DBAL\ParameterType;
109
use stdClass;
1110
use const DB2_AUTOCOMMIT_OFF;
1211
use const DB2_AUTOCOMMIT_ON;
@@ -101,15 +100,9 @@ public function query(string $sql) : ResultStatement
101100
/**
102101
* {@inheritdoc}
103102
*/
104-
public function quote($input, $type = ParameterType::STRING)
103+
public function quote(string $input) : string
105104
{
106-
$input = db2_escape_string($input);
107-
108-
if ($type === ParameterType::INTEGER) {
109-
return $input;
110-
}
111-
112-
return "'" . $input . "'";
105+
return "'" . db2_escape_string($input) . "'";
113106
}
114107

115108
/**

lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Doctrine\DBAL\Driver\ResultStatement;
88
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
99
use Doctrine\DBAL\Driver\Statement as DriverStatement;
10-
use Doctrine\DBAL\ParameterType;
1110
use mysqli;
1211
use const MYSQLI_INIT_COMMAND;
1312
use const MYSQLI_OPT_CONNECT_TIMEOUT;
@@ -146,7 +145,7 @@ public function query(string $sql) : ResultStatement
146145
/**
147146
* {@inheritdoc}
148147
*/
149-
public function quote($input, $type = ParameterType::STRING)
148+
public function quote(string $input) : string
150149
{
151150
return "'" . $this->conn->escape_string($input) . "'";
152151
}

lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66
use Doctrine\DBAL\Driver\ResultStatement;
77
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
88
use Doctrine\DBAL\Driver\Statement as DriverStatement;
9-
use Doctrine\DBAL\ParameterType;
109
use UnexpectedValueException;
1110
use const OCI_COMMIT_ON_SUCCESS;
1211
use const OCI_DEFAULT;
1312
use const OCI_NO_AUTO_COMMIT;
1413
use function addcslashes;
15-
use function is_float;
16-
use function is_int;
1714
use function oci_commit;
1815
use function oci_connect;
1916
use function oci_error;
@@ -123,14 +120,9 @@ public function query(string $sql) : ResultStatement
123120
/**
124121
* {@inheritdoc}
125122
*/
126-
public function quote($value, $type = ParameterType::STRING)
123+
public function quote(string $input) : string
127124
{
128-
if (is_int($value) || is_float($value)) {
129-
return $value;
130-
}
131-
$value = str_replace("'", "''", $value);
132-
133-
return "'" . addcslashes($value, "\000\n\r\\\032") . "'";
125+
return "'" . addcslashes(str_replace("'", "''", $input), "\000\n\r\\\032") . "'";
134126
}
135127

136128
/**

lib/Doctrine/DBAL/Driver/PDOConnection.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Doctrine\DBAL\Driver;
44

5-
use Doctrine\DBAL\ParameterType;
65
use PDO;
76
use function assert;
87

@@ -86,9 +85,9 @@ public function query(string $sql) : ResultStatement
8685
/**
8786
* {@inheritdoc}
8887
*/
89-
public function quote($input, $type = ParameterType::STRING)
88+
public function quote(string $input) : string
9089
{
91-
return $this->connection->quote($input, $type);
90+
return $this->connection->quote($input);
9291
}
9392

9493
/**

lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Doctrine\DBAL\Driver\PDOConnection;
66
use Doctrine\DBAL\Driver\PDOStatement;
7-
use Doctrine\DBAL\ParameterType;
87
use function strpos;
98
use function substr;
109

@@ -31,9 +30,9 @@ public function lastInsertId($name = null)
3130
/**
3231
* {@inheritDoc}
3332
*/
34-
public function quote($value, $type = ParameterType::STRING)
33+
public function quote(string $input) : string
3534
{
36-
$val = parent::quote($value, $type);
35+
$val = parent::quote($input);
3736

3837
// Fix for a driver version terminating all values with null byte
3938
if (strpos($val, "\0") !== false) {

lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
use Doctrine\DBAL\Driver\ResultStatement;
77
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
88
use Doctrine\DBAL\Driver\Statement as DriverStatement;
9-
use Doctrine\DBAL\ParameterType;
109
use function assert;
11-
use function is_float;
12-
use function is_int;
1310
use function is_resource;
1411
use function is_string;
1512
use function sasql_affected_rows;
@@ -159,12 +156,8 @@ public function query(string $sql) : ResultStatement
159156
/**
160157
* {@inheritdoc}
161158
*/
162-
public function quote($input, $type = ParameterType::STRING)
159+
public function quote(string $input) : string
163160
{
164-
if (is_int($input) || is_float($input)) {
165-
return $input;
166-
}
167-
168161
return "'" . sasql_escape_string($this->connection, $input) . "'";
169162
}
170163

lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
use Doctrine\DBAL\Driver\ResultStatement;
77
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
88
use Doctrine\DBAL\Driver\Statement as DriverStatement;
9-
use Doctrine\DBAL\ParameterType;
109
use const SQLSRV_ERR_ERRORS;
11-
use function is_float;
12-
use function is_int;
13-
use function sprintf;
1410
use function sqlsrv_begin_transaction;
1511
use function sqlsrv_commit;
1612
use function sqlsrv_configure;
@@ -95,17 +91,9 @@ public function query(string $sql) : ResultStatement
9591
/**
9692
* {@inheritDoc}
9793
*/
98-
public function quote($value, $type = ParameterType::STRING)
94+
public function quote(string $input) : string
9995
{
100-
if (is_int($value)) {
101-
return $value;
102-
}
103-
104-
if (is_float($value)) {
105-
return sprintf('%F', $value);
106-
}
107-
108-
return "'" . str_replace("'", "''", $value) . "'";
96+
return "'" . str_replace("'", "''", $input) . "'";
10997
}
11098

11199
/**

lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,10 @@ public function notIn($x, $y)
284284
}
285285

286286
/**
287-
* Quotes a given input parameter.
288-
*
289-
* @param mixed $input The parameter to be quoted.
290-
* @param int|null $type The type of the parameter.
291-
*
292-
* @return string
287+
* Creates an SQL literal expression from the string.
293288
*/
294-
public function literal($input, $type = null)
289+
public function literal(string $input)
295290
{
296-
return $this->connection->quote($input, $type);
291+
return $this->connection->quote($input);
297292
}
298293
}

lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,12 +830,11 @@ abstract protected function _getPortableTableColumnDefinition($tableColumn);
830830
/**
831831
* Aggregates and groups the index results according to the required data result.
832832
*
833-
* @param mixed[][] $tableIndexRows
834-
* @param string|null $tableName
833+
* @param mixed[][] $tableIndexRows
835834
*
836835
* @return Index[]
837836
*/
838-
protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null)
837+
protected function _getPortableTableIndexesList(array $tableIndexRows, string $tableName) : array
839838
{
840839
$result = [];
841840
foreach ($tableIndexRows as $tableIndex) {

lib/Doctrine/DBAL/Schema/DB2SchemaManager.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Doctrine\DBAL\Types\Type;
66
use const CASE_LOWER;
77
use function array_change_key_case;
8+
use function assert;
89
use function is_resource;
10+
use function is_string;
911
use function strpos;
1012
use function strtolower;
1113
use function substr;
@@ -22,12 +24,14 @@ class DB2SchemaManager extends AbstractSchemaManager
2224
* Apparently creator is the schema not the user who created it:
2325
* {@link http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z_sysibmsystablestable.htm}
2426
*/
25-
public function listTableNames()
27+
public function listTableNames() : array
2628
{
27-
$sql = $this->_platform->getListTablesSQL();
28-
$sql .= ' AND CREATOR = UPPER(' . $this->_conn->quote($this->_conn->getUsername()) . ')';
29+
$username = $this->_conn->getUsername();
30+
assert(is_string($username));
2931

30-
$tables = $this->_conn->fetchAll($sql);
32+
$sql = $this->_platform->getListTablesSQL() . ' AND CREATOR = UPPER(?)';
33+
34+
$tables = $this->_conn->fetchAll($sql, [$username]);
3135

3236
return $this->filterAssetNames($this->_getPortableTablesList($tables));
3337
}
@@ -117,7 +121,7 @@ protected function _getPortableTablesList($tables)
117121
/**
118122
* {@inheritdoc}
119123
*/
120-
protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null)
124+
protected function _getPortableTableIndexesList(array $tableIndexRows, string $tableName) : array
121125
{
122126
foreach ($tableIndexRows as &$tableIndexRow) {
123127
$tableIndexRow = array_change_key_case($tableIndexRow, CASE_LOWER);

lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ protected function _getPortableUserDefinition($user)
5454
/**
5555
* {@inheritdoc}
5656
*/
57-
protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
57+
protected function _getPortableTableIndexesList(array $tableIndexRows, string $tableName) : array
5858
{
59-
foreach ($tableIndexes as $k => $v) {
59+
foreach ($tableIndexRows as $k => $v) {
6060
$v = array_change_key_case($v, CASE_LOWER);
6161
if ($v['key_name'] === 'PRIMARY') {
6262
$v['primary'] = true;
@@ -70,10 +70,10 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null
7070
}
7171
$v['length'] = isset($v['sub_part']) ? (int) $v['sub_part'] : null;
7272

73-
$tableIndexes[$k] = $v;
73+
$tableIndexRows[$k] = $v;
7474
}
7575

76-
return parent::_getPortableTableIndexesList($tableIndexes, $tableName);
76+
return parent::_getPortableTableIndexesList($tableIndexRows, $tableName);
7777
}
7878

7979
/**

lib/Doctrine/DBAL/Schema/OracleSchemaManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ protected function _getPortableTableDefinition($table)
8989
*
9090
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html
9191
*/
92-
protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
92+
protected function _getPortableTableIndexesList(array $tableIndexRows, string $tableName) : array
9393
{
9494
$indexBuffer = [];
95-
foreach ($tableIndexes as $tableIndex) {
95+
foreach ($tableIndexRows as $tableIndex) {
9696
$tableIndex = array_change_key_case($tableIndex, CASE_LOWER);
9797

9898
$keyName = strtolower($tableIndex['name']);

lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ protected function _getPortableTableDefinition($table)
209209
*
210210
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html
211211
*/
212-
protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
212+
protected function _getPortableTableIndexesList(array $tableIndexRows, string $tableName) : array
213213
{
214214
$buffer = [];
215-
foreach ($tableIndexes as $row) {
215+
foreach ($tableIndexRows as $row) {
216216
$colNumbers = array_map('intval', explode(' ', $row['indkey']));
217217
$columnNameSql = sprintf(
218218
'SELECT attnum, attname FROM pg_attribute WHERE attrelid=%d AND attnum IN (%s) ORDER BY attnum ASC',

lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys)
194194
/**
195195
* {@inheritdoc}
196196
*/
197-
protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null)
197+
protected function _getPortableTableIndexesList(array $tableIndexRows, string $tableName) : array
198198
{
199199
foreach ($tableIndexRows as &$tableIndex) {
200200
$tableIndex['primary'] = (bool) $tableIndex['primary'];

lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys)
168168
/**
169169
* {@inheritdoc}
170170
*/
171-
protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null)
171+
protected function _getPortableTableIndexesList(array $tableIndexRows, string $tableName) : array
172172
{
173173
foreach ($tableIndexRows as &$tableIndex) {
174174
$tableIndex['non_unique'] = (bool) $tableIndex['non_unique'];

lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ protected function _getPortableTableDefinition($table)
163163
*
164164
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html
165165
*/
166-
protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
166+
protected function _getPortableTableIndexesList(array $tableIndexRows, string $tableName) : array
167167
{
168168
$indexBuffer = [];
169169

@@ -195,7 +195,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null
195195
}
196196

197197
// fetch regular indexes
198-
foreach ($tableIndexes as $tableIndex) {
198+
foreach ($tableIndexRows as $tableIndex) {
199199
// Ignore indexes with reserved names, e.g. autoindexes
200200
if (strpos($tableIndex['name'], 'sqlite_') === 0) {
201201
continue;

lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function splitFederation($splitDistributionValue)
202202

203203
$sql = 'ALTER FEDERATION ' . $this->getFederationName() . ' ' .
204204
'SPLIT AT (' . $this->getDistributionKey() . ' = ' .
205-
$this->conn->quote($splitDistributionValue, $type->getBindingType()) . ')';
205+
$this->conn->quote($splitDistributionValue) . ')';
206206
$this->conn->exec($sql);
207207
}
208208
}

0 commit comments

Comments
 (0)