Skip to content

Commit 8c082f6

Browse files
grossmannmartinvitek-rostislav
authored andcommitted
quoted generated SQL identifiers and literals
1 parent bbb88cc commit 8c082f6

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/Component/Doctrine/DatabaseSchemaFacade.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ public function __construct(
1717

1818
public function createSchema(string $schemaName): void
1919
{
20-
$this->em->getConnection()->executeStatement('CREATE SCHEMA ' . $schemaName);
20+
$connection = $this->em->getConnection();
21+
$databasePlatform = $connection->getDatabasePlatform();
22+
$connection->executeStatement('CREATE SCHEMA ' . $databasePlatform->quoteSingleIdentifier($schemaName));
2123
}
2224

2325
public function dropSchemaIfExists(string $schemaName): void
2426
{
25-
$this->em->getConnection()->executeStatement('DROP SCHEMA IF EXISTS ' . $schemaName . ' CASCADE');
27+
$connection = $this->em->getConnection();
28+
$databasePlatform = $connection->getDatabasePlatform();
29+
$connection->executeStatement(
30+
'DROP SCHEMA IF EXISTS ' . $databasePlatform->quoteSingleIdentifier($schemaName) . ' CASCADE',
31+
);
2632
}
2733

2834
public function importDefaultSchema(): void
@@ -48,10 +54,13 @@ public function importDefaultSchema(): void
4854
public function dropTables(): void
4955
{
5056
$connection = $this->em->getConnection();
57+
$databasePlatform = $connection->getDatabasePlatform();
5158
$tableNames = $connection->fetchAllAssociative('SELECT tablename FROM pg_tables WHERE schemaname = \'public\'');
5259

5360
foreach ($tableNames as $tableName) {
54-
$connection->executeStatement('DROP TABLE IF EXISTS ' . $tableName['tablename'] . ' CASCADE');
61+
$connection->executeStatement(
62+
'DROP TABLE IF EXISTS ' . $databasePlatform->quoteSingleIdentifier($tableName['tablename']) . ' CASCADE',
63+
);
5564
}
5665
}
5766
}

src/Component/Domain/DomainDbFunctionsFacade.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public function createDomainDbFunctions(): void
2020

2121
protected function createDomainIdsByLocaleFunction(): void
2222
{
23+
$connection = $this->em->getConnection();
24+
$databasePlatform = $connection->getDatabasePlatform();
2325
$domainsIdsByLocale = [];
2426

2527
foreach ($this->domain->getAllIncludingDomainConfigsWithoutDataCreated() as $domainConfig) {
@@ -29,15 +31,15 @@ protected function createDomainIdsByLocaleFunction(): void
2931
$domainIdsByLocaleSqlClauses = [];
3032

3133
foreach ($domainsIdsByLocale as $locale => $domainIds) {
32-
$sql = 'WHEN locale = \'' . $locale . '\' THEN ';
34+
$sql = 'WHEN locale = ' . $databasePlatform->quoteStringLiteral($locale) . ' THEN ';
3335

3436
foreach ($domainIds as $domainId) {
3537
$sql .= ' RETURN NEXT ' . $domainId . ';';
3638
}
3739
$domainIdsByLocaleSqlClauses[] = $sql;
3840
}
3941

40-
$this->em->getConnection()->executeStatement(
42+
$connection->executeStatement(
4143
'CREATE OR REPLACE FUNCTION get_domain_ids_by_locale(locale text) RETURNS SETOF integer AS $$
4244
BEGIN
4345
CASE
@@ -51,15 +53,17 @@ protected function createDomainIdsByLocaleFunction(): void
5153

5254
protected function createLocaleByDomainIdFunction(): void
5355
{
56+
$connection = $this->em->getConnection();
57+
$databasePlatform = $connection->getDatabasePlatform();
5458
$localeByDomainIdSqlClauses = [];
5559

5660
foreach ($this->domain->getAllIncludingDomainConfigsWithoutDataCreated() as $domainConfig) {
5761
$localeByDomainIdSqlClauses[] =
5862
'WHEN domain_id = ' . $domainConfig->getId()
59-
. ' THEN RETURN \'' . $domainConfig->getLocale() . '\';';
63+
. ' THEN RETURN ' . $databasePlatform->quoteStringLiteral($domainConfig->getLocale()) . ';';
6064
}
6165

62-
$this->em->getConnection()->executeStatement(
66+
$connection->executeStatement(
6367
'CREATE OR REPLACE FUNCTION get_domain_locale(domain_id integer) RETURNS text AS $$
6468
BEGIN
6569
CASE

0 commit comments

Comments
 (0)