Skip to content

Commit c79f853

Browse files
committed
Merge branch '3.7.x' into 4.0.x
* 3.7.x: Run tests against Postgres 16 (doctrine#6154) PHPStan 1.10.34, PHPUnit 9.6.12 (doctrine#6151) Bump CI workflows (doctrine#6152) Add a configuration setting to disable generating type comments (doctrine#6150) Fix invalid SQL in the document docs: link to the testing guidelines in CONTRIBUTING.md Fix IBM DB2 tests Implement binary array parameter type Document `driverOptions` for SQL Server connections (doctrine#6140)
2 parents 9128251 + f29467a commit c79f853

17 files changed

+466
-24
lines changed

.github/workflows/coding-standards.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ on:
2525
jobs:
2626
coding-standards:
2727
name: "Coding Standards"
28-
uses: "doctrine/.github/.github/workflows/coding-standards.yml@3.0.0"
28+
uses: "doctrine/.github/.github/workflows/coding-standards.yml@3.1.0"

.github/workflows/continuous-integration.yml

+13-12
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656

5757
steps:
5858
- name: "Checkout"
59-
uses: "actions/checkout@v3"
59+
uses: "actions/checkout@v4"
6060
with:
6161
fetch-depth: 2
6262

@@ -122,7 +122,7 @@ jobs:
122122
123123
steps:
124124
- name: "Checkout"
125-
uses: "actions/checkout@v3"
125+
uses: "actions/checkout@v4"
126126
with:
127127
fetch-depth: 2
128128

@@ -178,7 +178,7 @@ jobs:
178178
179179
steps:
180180
- name: "Checkout"
181-
uses: "actions/checkout@v3"
181+
uses: "actions/checkout@v4"
182182
with:
183183
fetch-depth: 2
184184

@@ -216,15 +216,16 @@ jobs:
216216
postgres-version:
217217
- "10"
218218
- "15"
219+
- "16"
219220
extension:
220221
- "pgsql"
221222
- "pdo_pgsql"
222223
include:
223224
- php-version: "8.2"
224-
postgres-version: "15"
225+
postgres-version: "16"
225226
extension: "pgsql"
226227
- php-version: "8.3"
227-
postgres-version: "15"
228+
postgres-version: "16"
228229
extension: "pdo_pgsql"
229230

230231
services:
@@ -241,7 +242,7 @@ jobs:
241242

242243
steps:
243244
- name: "Checkout"
244-
uses: "actions/checkout@v3"
245+
uses: "actions/checkout@v4"
245246
with:
246247
fetch-depth: 2
247248

@@ -310,7 +311,7 @@ jobs:
310311

311312
steps:
312313
- name: "Checkout"
313-
uses: "actions/checkout@v3"
314+
uses: "actions/checkout@v4"
314315
with:
315316
fetch-depth: 2
316317

@@ -381,7 +382,7 @@ jobs:
381382

382383
steps:
383384
- name: "Checkout"
384-
uses: "actions/checkout@v3"
385+
uses: "actions/checkout@v4"
385386
with:
386387
fetch-depth: 2
387388

@@ -451,7 +452,7 @@ jobs:
451452

452453
steps:
453454
- name: "Checkout"
454-
uses: "actions/checkout@v3"
455+
uses: "actions/checkout@v4"
455456
with:
456457
fetch-depth: 2
457458

@@ -511,7 +512,7 @@ jobs:
511512
run: "docker exec ${{ job.services.ibm_db2.id }} su - db2inst1 -c 'db2 -t CONNECT TO doctrine; db2 -t CREATE USER TEMPORARY TABLESPACE doctrine_tbsp PAGESIZE 4 K;'"
512513

513514
- name: "Checkout"
514-
uses: "actions/checkout@v3"
515+
uses: "actions/checkout@v4"
515516
with:
516517
fetch-depth: 2
517518

@@ -557,7 +558,7 @@ jobs:
557558

558559
steps:
559560
- name: "Checkout"
560-
uses: "actions/checkout@v3"
561+
uses: "actions/checkout@v4"
561562

562563
- name: "Install PHP"
563564
uses: "shivammathur/setup-php@v2"
@@ -590,7 +591,7 @@ jobs:
590591

591592
steps:
592593
- name: "Checkout"
593-
uses: "actions/checkout@v3"
594+
uses: "actions/checkout@v4"
594595
with:
595596
fetch-depth: 2
596597

.github/workflows/release-on-milestone-closed.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
steps:
1414
- name: "Checkout"
15-
uses: "actions/checkout@v3"
15+
uses: "actions/checkout@v4"
1616

1717
- name: "Release"
1818
uses: "laminas/[email protected]"

.github/workflows/static-analysis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
steps:
4040
- name: "Checkout code"
41-
uses: "actions/checkout@v3"
41+
uses: "actions/checkout@v4"
4242

4343
- name: "Install PHP"
4444
uses: "shivammathur/setup-php@v2"
@@ -64,7 +64,7 @@ jobs:
6464

6565
steps:
6666
- name: Checkout code
67-
uses: actions/checkout@v3
67+
uses: actions/checkout@v4
6868

6969
- name: Install PHP
7070
uses: shivammathur/setup-php@v2

CONTRIBUTING.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
This repository has [guidelines specific to testing][testing guidelines], and
12
Doctrine has [general contributing guidelines][contributor workflow], make
2-
sure you follow them.
3+
sure you follow both.
34

45
[contributor workflow]: https://www.doctrine-project.org/contribute/index.html
6+
[testing guidelines]: https://www.doctrine-project.org/projects/doctrine-dbal/en/stable/reference/testing.html

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"doctrine/coding-standard": "12.0.0",
4242
"fig/log-test": "^1",
4343
"jetbrains/phpstorm-stubs": "2023.2",
44-
"phpstan/phpstan": "1.10.32",
44+
"phpstan/phpstan": "1.10.34",
4545
"phpstan/phpstan-phpunit": "1.3.14",
4646
"phpstan/phpstan-strict-rules": "^1.5",
4747
"phpunit/phpunit": "10.2.2",

docs/en/reference/configuration.rst

+1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ pdo_sqlsrv / sqlsrv
330330
- ``host`` (string): Hostname of the database to connect to.
331331
- ``port`` (integer): Port of the database to connect to.
332332
- ``dbname`` (string): Name of the database/schema to connect to.
333+
- ``driverOptions`` (array): Any supported options found on `https://learn.microsoft.com/en-us/sql/connect/php/connection-options`
333334

334335
ibm_db2
335336
^^^^^^^

docs/en/reference/data-retrieval-and-manipulation.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,12 @@ SQL injection possibilities if not handled carefully.
253253
Doctrine DBAL implements a very powerful parsing process that will make this kind of prepared
254254
statement possible natively in the binding type system.
255255
The parsing necessarily comes with a performance overhead, but only if you really use a list of parameters.
256-
There are two special binding types that describe a list of integers or strings:
256+
There are four special binding types that describe a list of integers, regular, ascii or binary strings:
257257

258258
- ``\Doctrine\DBAL\ArrayParameterType::INTEGER``
259259
- ``\Doctrine\DBAL\ArrayParameterType::STRING``
260+
- ``\Doctrine\DBAL\ArrayParameterType::ASCII``
261+
- ``\Doctrine\DBAL\ArrayParameterType::BINARY``
260262

261263
Using one of these constants as a type you can activate the SQLParser inside Doctrine that rewrites
262264
the SQL and flattens the specified values into the set of parameters. Consider our previous example:
@@ -538,4 +540,4 @@ given data.
538540
539541
<?php
540542
$conn->update('user', ['username' => 'jwage'], ['id' => 1]);
541-
// UPDATE user (username) VALUES (?) WHERE id = ? (jwage, 1)
543+
// UPDATE user SET username = ? WHERE id = ? (jwage, 1)

phpstan.neon.dist

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ parameters:
100100
# Ignore the possible false return value of db2_num_rows().
101101
- '~^Method Doctrine\\DBAL\\Driver\\IBMDB2\\Connection\:\:exec\(\) should return int but returns int<0, max>\|false\.$~'
102102
- '~^Method Doctrine\\DBAL\\Driver\\IBMDB2\\Result\:\:rowCount\(\) should return int but returns int<0, max>\|false\.$~'
103+
104+
# TODO
105+
-
106+
message: '~^Property Doctrine\\DBAL\\Platforms\\AbstractPlatform\:\:\$disableTypeComments is never read, only written\.$~'
107+
path: src/Platforms/AbstractPlatform.php
103108
includes:
104109
- vendor/phpstan/phpstan-phpunit/extension.neon
105110
- vendor/phpstan/phpstan-phpunit/rules.neon

psalm.xml.dist

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@
115115
<file name="tests/Platforms/AbstractPlatformTestCase.php"/>
116116
</errorLevel>
117117
</InvalidArgument>
118+
<InvalidArrayOffset>
119+
<errorLevel type="suppress">
120+
<!-- https://github.com/vimeo/psalm/issues/10213 -->
121+
<file name="tests/Functional/BinaryDataAccessTest.php"/>
122+
</errorLevel>
123+
</InvalidArrayOffset>
118124
<InvalidDocblock>
119125
<errorLevel type="suppress">
120126
<!-- See https://github.com/vimeo/psalm/issues/5472 -->

src/ArrayParameterType.php

+6
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@ enum ArrayParameterType
2121
*/
2222
case ASCII;
2323

24+
/**
25+
* Represents an array of ascii strings to be expanded by Doctrine SQL parsing.
26+
*/
27+
case BINARY;
28+
2429
/** @internal */
2530
public static function toElementParameterType(self $type): ParameterType
2631
{
2732
return match ($type) {
2833
self::INTEGER => ParameterType::INTEGER,
2934
self::STRING => ParameterType::STRING,
3035
self::ASCII => ParameterType::ASCII,
36+
self::BINARY => ParameterType::BINARY,
3137
};
3238
}
3339
}

src/Configuration.php

+21
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ class Configuration
3333
*/
3434
protected bool $autoCommit = true;
3535

36+
/**
37+
* Whether type comments should be disabled to provide the same DB schema than
38+
* will be obtained with DBAL 4.x. This is useful when relying only on the
39+
* platform-aware schema comparison (which does not need those type comments)
40+
* rather than the deprecated legacy tooling.
41+
*/
42+
private bool $disableTypeComments = false;
43+
3644
private ?SchemaManagerFactory $schemaManagerFactory = null;
3745

3846
public function __construct()
@@ -132,4 +140,17 @@ public function setSchemaManagerFactory(SchemaManagerFactory $schemaManagerFacto
132140

133141
return $this;
134142
}
143+
144+
public function getDisableTypeComments(): bool
145+
{
146+
return $this->disableTypeComments;
147+
}
148+
149+
/** @return $this */
150+
public function setDisableTypeComments(bool $disableTypeComments): self
151+
{
152+
$this->disableTypeComments = $disableTypeComments;
153+
154+
return $this;
155+
}
135156
}

src/Connection.php

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public function getDatabasePlatform(): AbstractPlatform
188188
}
189189

190190
$this->platform = $this->driver->getDatabasePlatform($versionProvider);
191+
$this->platform->setDisableTypeComments($this->_config->getDisableTypeComments());
191192
}
192193

193194
return $this->platform;

src/Platforms/AbstractPlatform.php

+8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ abstract class AbstractPlatform
7979
*/
8080
protected ?KeywordList $_keywords = null;
8181

82+
private bool $disableTypeComments = false;
83+
84+
/** @internal */
85+
final public function setDisableTypeComments(bool $value): void
86+
{
87+
$this->disableTypeComments = $value;
88+
}
89+
8290
/**
8391
* Returns the SQL snippet that declares a boolean column.
8492
*

tests/Connection/ExpandArrayParametersTest.php

+32-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Doctrine\DBAL\Types\Type;
1515
use PHPUnit\Framework\TestCase;
1616

17+
use function hex2bin;
18+
1719
/** @psalm-import-type WrapperParameterTypeArray from Connection */
1820
class ExpandArrayParametersTest extends TestCase
1921
{
@@ -107,16 +109,24 @@ public static function dataExpandListParameters(): iterable
107109
[1 => ParameterType::STRING, 2 => ParameterType::STRING],
108110
],
109111
'Positional: explicit keys for array params and array types' => [
110-
'SELECT * FROM Foo WHERE foo IN (?) AND bar IN (?) AND baz = ? AND bax IN (?)',
111-
[1 => ['bar1', 'bar2'], 2 => true, 0 => [1, 2, 3], ['bax1', 'bax2']],
112+
'SELECT * FROM Foo WHERE foo IN (?) AND bar IN (?) AND baz = ? AND bax IN (?) AND bay IN (?)',
113+
[
114+
1 => ['bar1', 'bar2'],
115+
2 => true,
116+
0 => [1, 2, 3],
117+
['bax1', 'bax2'],
118+
4 => [hex2bin('DEADBEEF'), hex2bin('C0DEF00D')],
119+
],
112120
[
121+
4 => ArrayParameterType::BINARY,
113122
3 => ArrayParameterType::ASCII,
114123
2 => ParameterType::BOOLEAN,
115124
1 => ArrayParameterType::STRING,
116125
0 => ArrayParameterType::INTEGER,
117126
],
118-
'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND bar IN (?, ?) AND baz = ? AND bax IN (?, ?)',
119-
[1, 2, 3, 'bar1', 'bar2', true, 'bax1', 'bax2'],
127+
'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND bar IN (?, ?) AND baz = ? AND bax IN (?, ?) ' .
128+
'AND bay IN (?, ?)',
129+
[1, 2, 3, 'bar1', 'bar2', true, 'bax1', 'bax2', hex2bin('DEADBEEF'), hex2bin('C0DEF00D')],
120130
[
121131
ParameterType::INTEGER,
122132
ParameterType::INTEGER,
@@ -126,6 +136,8 @@ public static function dataExpandListParameters(): iterable
126136
ParameterType::BOOLEAN,
127137
ParameterType::ASCII,
128138
ParameterType::ASCII,
139+
ParameterType::BINARY,
140+
ParameterType::BINARY,
129141
],
130142
],
131143
'Named: Very simple with param int' => [
@@ -323,6 +335,22 @@ public static function dataExpandListParameters(): iterable
323335
['foo', 'bar', 'baz'],
324336
[1 => ParameterType::STRING, ParameterType::STRING],
325337
],
338+
'Named: Binary array with explicit types' => [
339+
'SELECT * FROM Foo WHERE foo IN (:foo) OR bar IN (:bar)',
340+
[
341+
'foo' => [hex2bin('DEADBEEF'), hex2bin('C0DEF00D')],
342+
'bar' => [hex2bin('DEADBEEF'), hex2bin('C0DEF00D')],
343+
],
344+
['foo' => ArrayParameterType::BINARY, 'bar' => ArrayParameterType::BINARY],
345+
'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar IN (?, ?)',
346+
[hex2bin('DEADBEEF'), hex2bin('C0DEF00D'), hex2bin('DEADBEEF'), hex2bin('C0DEF00D')],
347+
[
348+
ParameterType::BINARY,
349+
ParameterType::BINARY,
350+
ParameterType::BINARY,
351+
ParameterType::BINARY,
352+
],
353+
],
326354
];
327355
}
328356

0 commit comments

Comments
 (0)