Skip to content

Commit 78fee59

Browse files
committed
Merge pull request #83 from phpcr/add_delimiter_support_to_scanner
fix issues in Sql2ToQomConverterTest::testPropertyComparisonWithWhitespace
2 parents 93f76d4 + 126a336 commit 78fee59

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/PHPCR/Util/QOM/Sql2Scanner.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ class Sql2Scanner
4040
*/
4141
protected $tokens;
4242

43+
/**
44+
* Delimiters between tokens
45+
*
46+
* @var array
47+
*/
48+
protected $delimiters;
49+
4350
/**
4451
* Parsing position in the SQL string
4552
*
@@ -75,6 +82,16 @@ public function lookupNextToken($offset = 0)
7582
return '';
7683
}
7784

85+
/**
86+
* Get the delimiter that separated the two previous tokens
87+
*
88+
* @return string
89+
*/
90+
public function getPreviousDelimiter()
91+
{
92+
return $this->delimiters[$this->curpos - 1];
93+
}
94+
7895
/**
7996
* Get the next token and remove it from the queue.
8097
* Return an empty string when there are no more tokens.
@@ -156,6 +173,15 @@ protected function scan($sql2)
156173
$token = strtok(" \n\t");
157174
}
158175

176+
$regexp = '';
177+
foreach ($tokens as $token) {
178+
$regexp[] = preg_quote($token, '/');
179+
}
180+
181+
$regexp = '/^'.implode('([ \t\n]+)', $regexp).'$/';
182+
preg_match($regexp, $sql2, $this->delimiters);
183+
$this->delimiters[0] = '';
184+
159185
return $tokens;
160186
}
161187

src/PHPCR/Util/QOM/Sql2ToQomQueryConverter.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,8 @@ protected function parseLiteral()
731731
if ('' === $nextToken) {
732732
break;
733733
}
734-
// TODO: the scanner kills spaces, tabs and newlines
735-
// So adding a space here is just a hack for the most common token separator we can expect.
736-
// The proper way would require that the scanner tracks the token separators so that we
737-
// could fetch the separator between the last fetched token and the token before that token
738-
// so that we can append it instead of this hardcoded single space, ie. ' '
739-
$token .= ' '.$nextToken;
734+
$token .= $this->scanner->getPreviousDelimiter();
735+
$token .= $nextToken;
740736
}
741737

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

0 commit comments

Comments
 (0)