Skip to content
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
26 changes: 26 additions & 0 deletions src/PHPCR/Util/QOM/Sql2Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class Sql2Scanner
*/
protected $tokens;

/**
* Delimiters between tokens
*
* @var array
*/
protected $delimiters;

/**
* Parsing position in the SQL string
*
Expand Down Expand Up @@ -75,6 +82,16 @@ public function lookupNextToken($offset = 0)
return '';
}

/**
* Get the delimiter that separated the two previous tokens
*
* @return string
*/
public function getPreviousDelimiter()
{
return $this->delimiters[$this->curpos - 1];
}

/**
* Get the next token and remove it from the queue.
* Return an empty string when there are no more tokens.
Expand Down Expand Up @@ -156,6 +173,15 @@ protected function scan($sql2)
$token = strtok(" \n\t");
}

$regexp = '';
foreach ($tokens as $token) {
$regexp[] = preg_quote($token, '/');
}

$regexp = '/^'.implode('([ \t\n]+)', $regexp).'$/';
preg_match($regexp, $sql2, $this->delimiters);
$this->delimiters[0] = '';

return $tokens;
}

Expand Down
8 changes: 2 additions & 6 deletions src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,12 +731,8 @@ protected function parseLiteral()
if ('' === $nextToken) {
break;
}
// TODO: the scanner kills spaces, tabs and newlines
// So adding a space here is just a hack for the most common token separator we can expect.
// The proper way would require that the scanner tracks the token separators so that we
// could fetch the separator between the last fetched token and the token before that token
// so that we can append it instead of this hardcoded single space, ie. ' '
$token .= ' '.$nextToken;
$token .= $this->scanner->getPreviousDelimiter();
$token .= $nextToken;
}

if (substr($token, -1) !== $quoteString) {
Expand Down