Repository: symfony/symfony
File: src/Symfony/Bridge/Doctrine/SchemaListener/AbstractSchemaListener.php (PHP)

Code before:
            $table->addColumn('key', Types::STRING)
                ->setLength(14)
                ->setNotNull(true)
            ;

            if (class_exists(PrimaryKeyConstraint::class)) {
                $table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted('id'))], true));
            } else {
                $table->setPrimaryKey(['id']);
            }

            try {
                $schemaManager->createTable($table);
            } catch (DatabaseObjectExistsException) {
            }

            $platform = $connection->getDatabasePlatform();
            $connection->executeStatement(\sprintf('INSERT INTO _schema_subscriber_check (%s) VALUES (%s)', $platform->quoteSingleIdentifier('key'), $platform->quoteStringLiteral($key)));

            try {
                $exec(\sprintf('DELETE FROM _schema_subscriber_check WHERE %s = %s', $platform->quoteSingleIdentifier('key'), $platform->quoteStringLiteral($key)));
            } catch (DatabaseObjectNotFoundException|ConnectionException) {
            }

            try {
                return !$connection->executeStatement(\sprintf('DELETE FROM _schema_subscriber_check WHERE %s = %s', $platform->quoteSingleIdentifier('key'), $platform->quoteStringLiteral($key)));
            } finally {
                if (!$connection->executeQuery('SELECT count(id) FROM _schema_subscriber_check')->fetchOne()) {
                    try {
                        $schemaManager->dropTable('_schema_subscriber_check');
                    } catch (DatabaseObjectNotFoundException) {
                    }
                }
            }
        };
    }
}


Review comment (suggestion):
as `$connection` is known to be a DBAL connection, we should keep using a prepared parameter for the value rather than concatenating a literal in the SQL here IMO.

Code after:
            $table->addColumn('random_key', Types::STRING)
                ->setLength(14)
                ->setNotNull(true)
            ;

            if (class_exists(PrimaryKeyConstraint::class)) {
                $table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted('id'))], true));
            } else {
                $table->setPrimaryKey(['id']);
            }

            try {
                $schemaManager->createTable($table);
            } catch (DatabaseObjectExistsException) {
            }

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

            try {
                $exec(\sprintf('DELETE FROM _schema_subscriber_check WHERE random_key = %s', $connection->getDatabasePlatform()->quoteStringLiteral($key)));
            } catch (DatabaseObjectNotFoundException|ConnectionException) {
            }

            try {
                return !$connection->executeStatement('DELETE FROM _schema_subscriber_check WHERE random_key = :key', ['key' => $key], ['key' => Types::STRING]);
            } finally {
                if (!$connection->executeQuery('SELECT count(id) FROM _schema_subscriber_check')->fetchOne()) {
                    try {
                        $schemaManager->dropTable('_schema_subscriber_check');
                    } catch (DatabaseObjectNotFoundException) {
                    }
                }
            }
        };
    }
}