diff --git a/src/PHPCR/Util/QOM/Sql2Scanner.php b/src/PHPCR/Util/QOM/Sql2Scanner.php index 7aea8056..2a091f59 100644 --- a/src/PHPCR/Util/QOM/Sql2Scanner.php +++ b/src/PHPCR/Util/QOM/Sql2Scanner.php @@ -40,6 +40,13 @@ class Sql2Scanner */ protected $tokens; + /** + * Delimiters between tokens + * + * @var array + */ + protected $delimiters; + /** * Parsing position in the SQL string * @@ -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. @@ -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; } diff --git a/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php b/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php index b1b306a3..360cb648 100644 --- a/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php +++ b/src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php @@ -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) {