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
6 changes: 2 additions & 4 deletions src/AdapterPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ class AdapterPlatform extends AbstractPlatform

protected PdoDriverInterface|PDO|null $resource = null;

/**
* {@inheritDoc}
*/
protected string $quoteIdentifierTo = '\'';
/** Replacement for a quote character inside an identifier; SQLite doubles it */
protected string $quoteIdentifierTo = '""';

public function __construct(
protected readonly PdoDriverInterface|PDO|null $driver = null,
Expand Down
22 changes: 22 additions & 0 deletions test/unit/AdapterPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,35 @@
use PhpDb\Sqlite\AdapterPlatform;
use PhpDb\Sqlite\Sql\Platform as SqlPlatformDecorator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

#[CoversClass(AdapterPlatform::class)]
final class AdapterPlatformTest extends TestCase
{
private AdapterPlatform $platform;

/**
* @return array<string, array{string, string}>
*/
public static function identifiersWithEmbeddedQuotes(): array
{
return [
'quote inside a name' => ['my"col', '"my""col"'],
'quote only' => ['"', '""""'],
'adjacent quotes' => ['a""b', '"a""""b"'],
'single quote unchanged' => ["it's", "\"it's\""],
];
}

#[DataProvider('identifiersWithEmbeddedQuotes')]
#[Test]
public function quoteIdentifierDoublesEmbeddedQuoteCharacters(string $identifier, string $expected): void
{
static::assertSame($expected, $this->platform->quoteIdentifier($identifier));
}

public function testConstructWithPdo(): void
{
$pdoMock = $this->createMock(PDO::class);
Expand Down
Loading