Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/database/src/Config/DatabaseDialect.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function tableNotFoundCode(): string
public function quoteIdentifier(string $identifier): string
{
return match ($this) {
self::MYSQL, self::SQLITE => sprintf('`%s`', $identifier),
self::POSTGRESQL => sprintf('"%s"', $identifier),
self::MYSQL, self::SQLITE => sprintf('`%s`', str_replace('`', '``', $identifier)),
self::POSTGRESQL => sprintf('"%s"', str_replace('"', '""', $identifier)),
};
}

Expand Down
28 changes: 28 additions & 0 deletions packages/database/tests/Config/DatabaseDialectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Tempest\Database\Tests\Config;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
use Tempest\Database\Config\DatabaseDialect;

/**
* @internal
*/
final class DatabaseDialectTest extends TestCase
{
#[TestWith([DatabaseDialect::MYSQL, 'title', '`title`'])]
#[TestWith([DatabaseDialect::MYSQL, 'ti`tle', '`ti``tle`'])]
#[TestWith([DatabaseDialect::SQLITE, 'title', '`title`'])]
#[TestWith([DatabaseDialect::SQLITE, 'ti`tle', '`ti``tle`'])]
#[TestWith([DatabaseDialect::POSTGRESQL, 'title', '"title"'])]
#[TestWith([DatabaseDialect::POSTGRESQL, 'ti"tle', '"ti""tle"'])]
#[Test]
public function quote_identifier(DatabaseDialect $dialect, string $identifier, string $expected): void
{
$this->assertSame($expected, $dialect->quoteIdentifier($identifier));
}
}
Loading