Skip to content

Commit f3b4c93

Browse files
authored
Merge pull request #6395 from doctrine/4.0.x
Merge 4.0.x up into 4.1.x
2 parents d3ae200 + 7300b42 commit f3b4c93

12 files changed

+154
-64
lines changed

.github/dependabot.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
labels:
8+
- "CI"
9+
target-branch: "3.8.x"

.github/workflows/coding-standards.yml

Lines changed: 1 addition & 1 deletion
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@4.0.0"
28+
uses: "doctrine/.github/.github/workflows/coding-standards.yml@5.0.0"

.github/workflows/continuous-integration.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
ini-values: "zend.assertions=1"
6969

7070
- name: "Install dependencies with Composer"
71-
uses: "ramsey/composer-install@v2"
71+
uses: "ramsey/composer-install@v3"
7272
with:
7373
composer-options: "--ignore-platform-req=php+"
7474
dependency-versions: "${{ matrix.dependencies }}"
@@ -136,7 +136,7 @@ jobs:
136136
ini-values: "zend.assertions=1"
137137

138138
- name: "Install dependencies with Composer"
139-
uses: "ramsey/composer-install@v2"
139+
uses: "ramsey/composer-install@v3"
140140
with:
141141
composer-options: "--ignore-platform-req=php+"
142142

@@ -193,7 +193,7 @@ jobs:
193193
ini-values: "zend.assertions=1"
194194

195195
- name: "Install dependencies with Composer"
196-
uses: "ramsey/composer-install@v2"
196+
uses: "ramsey/composer-install@v3"
197197
with:
198198
composer-options: "--ignore-platform-req=php+"
199199

@@ -257,7 +257,7 @@ jobs:
257257
ini-values: "zend.assertions=1"
258258

259259
- name: "Install dependencies with Composer"
260-
uses: "ramsey/composer-install@v2"
260+
uses: "ramsey/composer-install@v3"
261261
with:
262262
composer-options: "--ignore-platform-req=php+"
263263

@@ -328,7 +328,7 @@ jobs:
328328
extensions: "${{ matrix.extension }}"
329329

330330
- name: "Install dependencies with Composer"
331-
uses: "ramsey/composer-install@v2"
331+
uses: "ramsey/composer-install@v3"
332332
with:
333333
composer-options: "--ignore-platform-req=php+"
334334

@@ -399,7 +399,7 @@ jobs:
399399
extensions: "${{ matrix.extension }}"
400400

401401
- name: "Install dependencies with Composer"
402-
uses: "ramsey/composer-install@v2"
402+
uses: "ramsey/composer-install@v3"
403403
with:
404404
composer-options: "--ignore-platform-req=php+"
405405

@@ -470,7 +470,7 @@ jobs:
470470
extensions: "${{ matrix.extension }}-5.10.0beta1"
471471

472472
- name: "Install dependencies with Composer"
473-
uses: "ramsey/composer-install@v2"
473+
uses: "ramsey/composer-install@v3"
474474
with:
475475
composer-options: "--ignore-platform-req=php+"
476476

@@ -541,7 +541,7 @@ jobs:
541541
IBM_DB2_CONFIGURE_OPTS: "--with-IBM_DB2=/tmp/clidriver"
542542

543543
- name: "Install dependencies with Composer"
544-
uses: "ramsey/composer-install@v2"
544+
uses: "ramsey/composer-install@v3"
545545
with:
546546
composer-options: "--ignore-platform-req=php+"
547547

@@ -576,7 +576,7 @@ jobs:
576576
run: "composer config minimum-stability dev"
577577

578578
- name: "Install development dependencies with Composer"
579-
uses: "ramsey/composer-install@v2"
579+
uses: "ramsey/composer-install@v3"
580580
with:
581581
composer-options: "--prefer-dist"
582582

@@ -612,6 +612,9 @@ jobs:
612612
working-directory: reports
613613

614614
- name: "Upload to Codecov"
615-
uses: "codecov/codecov-action@v3"
615+
uses: "codecov/codecov-action@v4"
616616
with:
617617
directory: reports
618+
fail_ci_if_error: true
619+
env:
620+
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}"

.github/workflows/lock-closed-issues.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
lock:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: dessant/lock-threads@v3
11+
- uses: dessant/lock-threads@v5
1212
with:
1313
github-token: '${{ github.token }}'
1414
issue-inactive-days: 30

.github/workflows/static-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
tools: "cs2pr"
4949

5050
- name: "Install dependencies with Composer"
51-
uses: "ramsey/composer-install@v2"
51+
uses: "ramsey/composer-install@v3"
5252

5353
- name: "Run a static analysis with phpstan/phpstan"
5454
run: "vendor/bin/phpstan --error-format=checkstyle | cs2pr"
@@ -74,7 +74,7 @@ jobs:
7474
tools: cs2pr
7575

7676
- name: Install dependencies with Composer
77-
uses: ramsey/composer-install@v2
77+
uses: ramsey/composer-install@v3
7878

7979
- name: Run static analysis with Vimeo Psalm
8080
run: vendor/bin/psalm --shepherd

src/Platforms/SQLServerPlatform.php

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@
3434
use function preg_match_all;
3535
use function sprintf;
3636
use function str_contains;
37+
use function str_ends_with;
3738
use function str_replace;
39+
use function str_starts_with;
3840
use function strtoupper;
41+
use function substr;
3942
use function substr_count;
4043

4144
use const PREG_OFFSET_CAPTURE;
@@ -256,6 +259,13 @@ public function getCreatePrimaryKeySQL(Index $index, string $table): string
256259
return $sql . ' (' . implode(', ', $index->getQuotedColumns($this)) . ')';
257260
}
258261

262+
private function unquoteSingleIdentifier(string $possiblyQuotedName): string
263+
{
264+
return str_starts_with($possiblyQuotedName, '[') && str_ends_with($possiblyQuotedName, ']')
265+
? substr($possiblyQuotedName, 1, -1)
266+
: $possiblyQuotedName;
267+
}
268+
259269
/**
260270
* Returns the SQL statement for creating a column comment.
261271
*
@@ -274,23 +284,20 @@ public function getCreatePrimaryKeySQL(Index $index, string $table): string
274284
protected function getCreateColumnCommentSQL(string $tableName, string $columnName, string $comment): string
275285
{
276286
if (str_contains($tableName, '.')) {
277-
[$schemaSQL, $tableSQL] = explode('.', $tableName);
278-
$schemaSQL = $this->quoteStringLiteral($schemaSQL);
279-
$tableSQL = $this->quoteStringLiteral($tableSQL);
287+
[$schemaName, $tableName] = explode('.', $tableName);
280288
} else {
281-
$schemaSQL = "'dbo'";
282-
$tableSQL = $this->quoteStringLiteral($tableName);
289+
$schemaName = 'dbo';
283290
}
284291

285292
return $this->getAddExtendedPropertySQL(
286293
'MS_Description',
287294
$comment,
288295
'SCHEMA',
289-
$schemaSQL,
296+
$this->quoteStringLiteral($this->unquoteSingleIdentifier($schemaName)),
290297
'TABLE',
291-
$tableSQL,
298+
$this->quoteStringLiteral($this->unquoteSingleIdentifier($tableName)),
292299
'COLUMN',
293-
$columnName,
300+
$this->quoteStringLiteral($this->unquoteSingleIdentifier($columnName)),
294301
);
295302
}
296303

@@ -568,23 +575,20 @@ private function alterColumnRequiresDropDefaultConstraint(ColumnDiff $columnDiff
568575
protected function getAlterColumnCommentSQL(string $tableName, string $columnName, string $comment): string
569576
{
570577
if (str_contains($tableName, '.')) {
571-
[$schemaSQL, $tableSQL] = explode('.', $tableName);
572-
$schemaSQL = $this->quoteStringLiteral($schemaSQL);
573-
$tableSQL = $this->quoteStringLiteral($tableSQL);
578+
[$schemaName, $tableName] = explode('.', $tableName);
574579
} else {
575-
$schemaSQL = "'dbo'";
576-
$tableSQL = $this->quoteStringLiteral($tableName);
580+
$schemaName = 'dbo';
577581
}
578582

579583
return $this->getUpdateExtendedPropertySQL(
580584
'MS_Description',
581585
$comment,
582586
'SCHEMA',
583-
$schemaSQL,
587+
$this->quoteStringLiteral($this->unquoteSingleIdentifier($schemaName)),
584588
'TABLE',
585-
$tableSQL,
589+
$this->quoteStringLiteral($this->unquoteSingleIdentifier($tableName)),
586590
'COLUMN',
587-
$columnName,
591+
$this->quoteStringLiteral($this->unquoteSingleIdentifier($columnName)),
588592
);
589593
}
590594

@@ -605,22 +609,19 @@ protected function getAlterColumnCommentSQL(string $tableName, string $columnNam
605609
protected function getDropColumnCommentSQL(string $tableName, string $columnName): string
606610
{
607611
if (str_contains($tableName, '.')) {
608-
[$schemaSQL, $tableSQL] = explode('.', $tableName);
609-
$schemaSQL = $this->quoteStringLiteral($schemaSQL);
610-
$tableSQL = $this->quoteStringLiteral($tableSQL);
612+
[$schemaName, $tableName] = explode('.', $tableName);
611613
} else {
612-
$schemaSQL = "'dbo'";
613-
$tableSQL = $this->quoteStringLiteral($tableName);
614+
$schemaName = 'dbo';
614615
}
615616

616617
return $this->getDropExtendedPropertySQL(
617618
'MS_Description',
618619
'SCHEMA',
619-
$schemaSQL,
620+
$this->quoteStringLiteral($this->unquoteSingleIdentifier($schemaName)),
620621
'TABLE',
621-
$tableSQL,
622+
$this->quoteStringLiteral($this->unquoteSingleIdentifier($tableName)),
622623
'COLUMN',
623-
$columnName,
624+
$this->quoteStringLiteral($this->unquoteSingleIdentifier($columnName)),
624625
);
625626
}
626627

@@ -663,10 +664,13 @@ protected function getAddExtendedPropertySQL(
663664
?string $level2Name = null,
664665
): string {
665666
return 'EXEC sp_addextendedproperty ' .
666-
'N' . $this->quoteStringLiteral($name) . ', N' . $this->quoteStringLiteral((string) $value) . ', ' .
667-
'N' . $this->quoteStringLiteral((string) $level0Type) . ', ' . $level0Name . ', ' .
668-
'N' . $this->quoteStringLiteral((string) $level1Type) . ', ' . $level1Name . ', ' .
669-
'N' . $this->quoteStringLiteral((string) $level2Type) . ', ' . $level2Name;
667+
'N' . $this->quoteStringLiteral($name) . ', N' . $this->quoteStringLiteral($value ?? '') . ', ' .
668+
'N' . $this->quoteStringLiteral($level0Type ?? '') . ', ' . $level0Name . ', ' .
669+
'N' . $this->quoteStringLiteral($level1Type ?? '') . ', ' . $level1Name .
670+
($level2Type !== null || $level2Name !== null
671+
? ', N' . $this->quoteStringLiteral($level2Type ?? '') . ', ' . $level2Name
672+
: ''
673+
);
670674
}
671675

672676
/**
@@ -693,9 +697,12 @@ protected function getDropExtendedPropertySQL(
693697
): string {
694698
return 'EXEC sp_dropextendedproperty ' .
695699
'N' . $this->quoteStringLiteral($name) . ', ' .
696-
'N' . $this->quoteStringLiteral((string) $level0Type) . ', ' . $level0Name . ', ' .
697-
'N' . $this->quoteStringLiteral((string) $level1Type) . ', ' . $level1Name . ', ' .
698-
'N' . $this->quoteStringLiteral((string) $level2Type) . ', ' . $level2Name;
700+
'N' . $this->quoteStringLiteral($level0Type ?? '') . ', ' . $level0Name . ', ' .
701+
'N' . $this->quoteStringLiteral($level1Type ?? '') . ', ' . $level1Name .
702+
($level2Type !== null || $level2Name !== null
703+
? ', N' . $this->quoteStringLiteral($level2Type ?? '') . ', ' . $level2Name
704+
: ''
705+
);
699706
}
700707

701708
/**
@@ -723,10 +730,13 @@ protected function getUpdateExtendedPropertySQL(
723730
?string $level2Name = null,
724731
): string {
725732
return 'EXEC sp_updateextendedproperty ' .
726-
'N' . $this->quoteStringLiteral($name) . ', N' . $this->quoteStringLiteral((string) $value) . ', ' .
727-
'N' . $this->quoteStringLiteral((string) $level0Type) . ', ' . $level0Name . ', ' .
728-
'N' . $this->quoteStringLiteral((string) $level1Type) . ', ' . $level1Name . ', ' .
729-
'N' . $this->quoteStringLiteral((string) $level2Type) . ', ' . $level2Name;
733+
'N' . $this->quoteStringLiteral($name) . ', N' . $this->quoteStringLiteral($value ?? '') . ', ' .
734+
'N' . $this->quoteStringLiteral($level0Type ?? '') . ', ' . $level0Name . ', ' .
735+
'N' . $this->quoteStringLiteral($level1Type ?? '') . ', ' . $level1Name .
736+
($level2Type !== null || $level2Name !== null
737+
? ', N' . $this->quoteStringLiteral($level2Type ?? '') . ', ' . $level2Name
738+
: ''
739+
);
730740
}
731741

732742
public function getEmptyIdentityInsertSQL(string $quotedTableName, string $quotedIdentifierColumnName): string
@@ -1168,15 +1178,13 @@ protected function getLikeWildcardCharacters(): string
11681178

11691179
protected function getCommentOnTableSQL(string $tableName, string $comment): string
11701180
{
1171-
return sprintf(
1172-
<<<'SQL'
1173-
EXEC sys.sp_addextendedproperty @name=N'MS_Description',
1174-
@value=N%s, @level0type=N'SCHEMA', @level0name=N'dbo',
1175-
@level1type=N'TABLE', @level1name=N%s
1176-
SQL
1177-
,
1178-
$this->quoteStringLiteral($comment),
1179-
$this->quoteStringLiteral($tableName),
1181+
return $this->getAddExtendedPropertySQL(
1182+
'MS_Description',
1183+
$comment,
1184+
'SCHEMA',
1185+
$this->quoteStringLiteral('dbo'),
1186+
'TABLE',
1187+
$this->quoteStringLiteral($this->unquoteSingleIdentifier($tableName)),
11801188
);
11811189
}
11821190

src/Platforms/SQLitePlatform.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use function str_replace;
3737
use function strpos;
3838
use function strtolower;
39+
use function substr;
3940
use function trim;
4041

4142
/**
@@ -674,7 +675,13 @@ public function getAlterTableSQL(TableDiff $diff): array
674675
$columns[strtolower($column->getName())] = $column;
675676
}
676677

677-
$dataTable = new Table('__temp__' . $table->getName());
678+
$tableName = $table->getName();
679+
$pos = strpos($tableName, '.');
680+
if ($pos !== false) {
681+
$tableName = substr($tableName, $pos + 1);
682+
}
683+
684+
$dataTable = new Table('__temp__' . $tableName);
678685

679686
$newTable = new Table(
680687
$table->getQuotedName($this),

src/Schema/SQLiteSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function listTableForeignKeys(string $table): array
7979
{
8080
$table = $this->normalizeName($table);
8181

82-
$columns = $this->selectForeignKeyColumns('', $table)
82+
$columns = $this->selectForeignKeyColumns('main', $table)
8383
->fetchAllAssociative();
8484

8585
if (count($columns) > 0) {

tests/Functional/Schema/SQLiteSchemaManagerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
use Doctrine\DBAL\Exception;
88
use Doctrine\DBAL\Platforms\AbstractPlatform;
99
use Doctrine\DBAL\Platforms\SQLitePlatform;
10+
use Doctrine\DBAL\Schema\Column;
1011
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
1112
use Doctrine\DBAL\Schema\Table;
13+
use Doctrine\DBAL\Schema\TableDiff;
1214
use Doctrine\DBAL\Types\BlobType;
1315
use Doctrine\DBAL\Types\Type;
1416
use Doctrine\DBAL\Types\Types;
1517

18+
use function array_keys;
1619
use function array_shift;
1720

1821
class SQLiteSchemaManagerTest extends SchemaManagerFunctionalTestCase
@@ -207,6 +210,24 @@ public function testNonSimpleAlterTableCreatedFromDDL(): void
207210
self::assertSame(['name'], $index->getColumns());
208211
}
209212

213+
public function testAlterTableWithSchema(): void
214+
{
215+
$this->dropTableIfExists('t');
216+
217+
$table = new Table('main.t');
218+
$table->addColumn('a', Types::INTEGER);
219+
$this->schemaManager->createTable($table);
220+
221+
self::assertSame(['a'], array_keys($this->schemaManager->listTableColumns('t')));
222+
223+
$tableDiff = new TableDiff($table, [], [], [], [
224+
'a' => new Column('b', Type::getType(Types::INTEGER)),
225+
], [], [], [], [], [], [], []);
226+
$this->schemaManager->alterTable($tableDiff);
227+
228+
self::assertSame(['b'], array_keys($this->schemaManager->listTableColumns('t')));
229+
}
230+
210231
public function testIntrospectMultipleAnonymousForeignKeyConstraints(): void
211232
{
212233
$this->dropTableIfExists('album');

0 commit comments

Comments
 (0)