Skip to content

Double a quote character inside an identifier instead of replacing it - #43

Open
simon-mundy wants to merge 1 commit into
php-db:0.3.xfrom
simon-mundy:fix/quote-identifier-escape
Open

simon-mundy wants to merge 1 commit into
php-db:0.3.xfrom
simon-mundy:fix/quote-identifier-escape

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Problem

AdapterPlatform set $quoteIdentifierTo to a single quote, so an embedded " was rewritten instead of escaped:

$platform->quoteIdentifier('my"col');   // "my'col"  (names a different column)

Fix

SQLite escapes a quote inside a delimited identifier by doubling it, so the value is now '""':

$platform->quoteIdentifier('my"col');   // "my""col"

The core default has the same fix in php-db/phpdb#250. This package sets the value itself, so it doesn't depend on that PR.

Tests

A new data-provider test in AdapterPlatformTest covers a quote inside a name, a lone quote, adjacent quotes, and a single quote left alone. It fails without the fix.

  • mago format --check and mago lint are clean.
  • Unit tests pass (102), and so do integration tests (18).
  • mago analyze reports 8 errors in src/Pdo/Driver.php, src/Pdo/Feature/SqliteRowCounter.php and src/Metadata/Source.php. The same errors appear on unchanged 0.3.x, and this PR doesn't touch those files.

AdapterPlatform set $quoteIdentifierTo to a single quote, so
quoteIdentifier('my"col') rendered "my'col" and named a different
column. SQLite escapes an embedded identifier quote by doubling it, so
the value is now '""' and the same name renders "my""col".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant