diff --git a/sources/Formatter/Formatter.php b/sources/Formatter/Formatter.php index 3d2399e6..77bdc5fa 100644 --- a/sources/Formatter/Formatter.php +++ b/sources/Formatter/Formatter.php @@ -111,7 +111,8 @@ public function formatName(string $name): string if ($name === '*') { return '*'; } - $quote = $this->session->getMode()->containsAny(SqlMode::ANSI_QUOTES) ? '"' : '`'; + $sqlMode = $this->session->getMode(); + $quote = $sqlMode->containsAny(SqlMode::ANSI_QUOTES) ? '"' : '`'; $name = str_replace($quote, $quote . $quote, $name); $needsQuoting = $this->quoteAllNames @@ -120,7 +121,7 @@ public function formatName(string $name): string || preg_match('~[\pC\pM\pS\pZ\p{Pd}\p{Pe}\p{Pf}\p{Pi}\p{Po}\p{Ps}]~u', ltrim($name, '@')) !== 0 // contains control, mark, symbols, whitespace, punctuation except _ || $this->session->getPlatform()->isReserved($name); - if ($needsQuoting && !$this->session->getMode()->containsAny(SqlMode::NO_BACKSLASH_ESCAPES)) { + if ($needsQuoting && !$sqlMode->containsAny(SqlMode::NO_BACKSLASH_ESCAPES)) { $name = str_replace($this->escapeKeys, $this->escapeValues, $name); } diff --git a/sources/Platform/Platform.php b/sources/Platform/Platform.php index 3a3d453f..cd6788b8 100644 --- a/sources/Platform/Platform.php +++ b/sources/Platform/Platform.php @@ -309,6 +309,8 @@ public function getFeatures(): array public function isReserved(string $word): bool { + $word = strtoupper($word); + return in_array($word, $this->getReserved(), true); } @@ -328,6 +330,8 @@ public function getReserved(): array public function isKeyword(string $word, int $version): bool { + $word = strtoupper($word); + return in_array($word, $this->getReserved(), true) || in_array($word, $this->getNonReserved(), true); } diff --git a/tests/Parser/ReservedWordsQuoting.phpt b/tests/Parser/ReservedWordsQuoting.phpt new file mode 100644 index 00000000..ea0f043e --- /dev/null +++ b/tests/Parser/ReservedWordsQuoting.phpt @@ -0,0 +1,13 @@ +