Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl. escape long string literal for Oracle #1201

Merged
merged 2 commits into from
Apr 21, 2024
Merged
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
17 changes: 17 additions & 0 deletions src/Persistence/Sql/Oracle/ExpressionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ trait ExpressionTrait
#[\Override]
protected function escapeStringLiteral(string $value): string
{
// Oracle (multibyte) string literal is limited to 1332 bytes
$parts = $this->splitLongString($value, 1000);
if (count($parts) > 1) {
$buildConcatExprFx = function (array $parts) use (&$buildConcatExprFx): string {
if (count($parts) > 1) {
$partsLeft = array_slice($parts, 0, intdiv(count($parts), 2));
$partsRight = array_slice($parts, count($partsLeft));

return 'concat(' . $buildConcatExprFx($partsLeft) . ', ' . $buildConcatExprFx($partsRight) . ')';
}

return 'TO_CLOB(' . $this->escapeStringLiteral(reset($parts)) . ')';
};

return $buildConcatExprFx($parts);
}

$parts = [];
foreach (preg_split('~(\x00+)~', $value, -1, \PREG_SPLIT_DELIM_CAPTURE) as $i => $v) {
if (($i % 2) === 1) {
Expand Down
6 changes: 3 additions & 3 deletions tests/Persistence/Sql/WithDb/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,9 @@ public function testEscapeStringLiteral(): void
$str = mb_convert_encoding($str, 'UTF-8', 'UTF-8');
}

// Oracle string literal is limited to 4000 bytes
if ($this->getDatabasePlatform() instanceof OraclePlatform) {
$str = substr($str, 0, 4000);
// remove once https://github.com/php/php-src/issues/8928 is fixed
if (str_starts_with($_ENV['DB_DSN'], 'oci8')) {
$str = substr($str, 0, 1000);
}

// PostgreSQL does not support \0 character
Expand Down
Loading