Skip to content

Commit be24a0e

Browse files
committed
bug symfony#61717 [DoctrineBridge] use non-reserved keyword as key column name, quote key value (xabbuh)
This PR was merged into the 7.4 branch. Discussion ---------- [DoctrineBridge] use non-reserved keyword as key column name, quote key value | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony#61699 | License | MIT Commits ------- 231ec3e use non-reserved keyword as key column name, quote key value
2 parents b875dfb + 231ec3e commit be24a0e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Symfony/Bridge/Doctrine/SchemaListener/AbstractSchemaListener.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ abstract class AbstractSchemaListener
2626
{
2727
abstract public function postGenerateSchema(GenerateSchemaEventArgs $event): void;
2828

29+
/**
30+
* @return \Closure(\Closure(string): mixed): bool
31+
*/
2932
protected function getIsSameDatabaseChecker(Connection $connection): \Closure
3033
{
3134
return static function (\Closure $exec) use ($connection): bool {
@@ -35,7 +38,7 @@ protected function getIsSameDatabaseChecker(Connection $connection): \Closure
3538
$table->addColumn('id', Types::INTEGER)
3639
->setAutoincrement(true)
3740
->setNotnull(true);
38-
$table->addColumn('key', Types::STRING)
41+
$table->addColumn('random_key', Types::STRING)
3942
->setLength(14)
4043
->setNotNull(true)
4144
;
@@ -51,15 +54,15 @@ protected function getIsSameDatabaseChecker(Connection $connection): \Closure
5154
} catch (DatabaseObjectExistsException) {
5255
}
5356

54-
$connection->executeStatement('INSERT INTO _schema_subscriber_check (key) VALUES (:key)', ['key' => $key], ['key' => Types::STRING]);
57+
$connection->executeStatement('INSERT INTO _schema_subscriber_check (random_key) VALUES (:key)', ['key' => $key], ['key' => Types::STRING]);
5558

5659
try {
57-
$exec('DELETE FROM _schema_subscriber_check WHERE key == :key', ['key' => $key], ['key' => Types::STRING]);
60+
$exec(\sprintf('DELETE FROM _schema_subscriber_check WHERE random_key = %s', $connection->getDatabasePlatform()->quoteStringLiteral($key)));
5861
} catch (DatabaseObjectNotFoundException|ConnectionException) {
5962
}
6063

6164
try {
62-
return !$connection->executeStatement('DELETE FROM _schema_subscriber_check WHERE key == :key', ['key' => $key], ['key' => Types::STRING]);
65+
return !$connection->executeStatement('DELETE FROM _schema_subscriber_check WHERE random_key = :key', ['key' => $key], ['key' => Types::STRING]);
6366
} finally {
6467
if (!$connection->executeQuery('SELECT count(id) FROM _schema_subscriber_check')->fetchOne()) {
6568
try {

0 commit comments

Comments
 (0)