Skip to content

Commit

Permalink
optimize Oracle performance
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 15, 2024
1 parent 51b4afb commit 4a7e193
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Persistence/Sql/Oracle/ExpressionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ trait ExpressionTrait
protected function escapeStringLiteral(string $value): string
{
$parts = [];
foreach (explode("\0", $value) as $i => $v) {
if ($i > 0) {
$parts[] = 'chr(0)';
}

if ($v !== '') {
foreach (preg_split('~(\x00+)~', $value, -1, \PREG_SPLIT_DELIM_CAPTURE) as $i => $v) {
if (($i % 2) === 1) {
$parts[] = strlen($v) === 1
? 'chr(0)'
: 'rpad(chr(0), ' . strlen($v) . ', chr(0))';
} elseif ($v !== '') {
// workaround https://github.com/php/php-src/issues/13958
foreach (preg_split('~(\\\+)(?=\'|$)~', $v, -1, \PREG_SPLIT_DELIM_CAPTURE) as $i2 => $v2) {
if (($i2 % 2) === 1) {
for ($j = 0; $j < strlen($v2); ++$j) {
$parts[] = 'chr(' . ord('\\') . ')';
}
$parts[] = strlen($v2) === 1
? 'chr(' . ord('\\') . ')'
: 'rpad(chr(' . ord('\\') . '), ' . strlen($v2) . ', chr(' . ord('\\') . '))';
} elseif ($v2 !== '') {
$parts[] = '\'' . str_replace('\'', '\'\'', $v2) . '\'';
}
Expand Down

0 comments on commit 4a7e193

Please sign in to comment.