Skip to content

Commit 1a726f5

Browse files
committed
Adjusted SQL parser to skip comments
1 parent 63bc05d commit 1a726f5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/Propel/Generator/Util/SqlParser.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,30 @@ public function explodeIntoStatements(): array
232232
public function getNextStatement(): string
233233
{
234234
$isAfterBackslash = false;
235+
$isCommentLine = false;
235236
$isInString = false;
236237
$stringQuotes = '';
237238
$parsedString = '';
238239
$lowercaseString = ''; // helper variable for performance sake
239240
while ($this->pos <= $this->len) {
240241
$char = $this->sql[$this->pos] ?? '';
242+
if ($isCommentLine === true && $char !== "\n") {
243+
$this->pos++;
244+
245+
continue;
246+
}
241247
// check flags for strings or escaper
242248
switch ($char) {
249+
case '#':
250+
$isCommentLine = true;
251+
252+
continue 2;
253+
case "\n":
254+
if ($isCommentLine === true) {
255+
$isCommentLine = false;
256+
}
257+
258+
break;
243259
case '\\':
244260
$isAfterBackslash = true;
245261

@@ -295,8 +311,9 @@ public function getNextStatement(): string
295311
// check for end of statement
296312
if ($char . $nextChars == $this->delimiter) {
297313
$this->pos += $i; // increase position
314+
$parsedTrimmedString = trim($parsedString);
298315

299-
return trim($parsedString);
316+
return $parsedTrimmedString ? $parsedTrimmedString : $parsedString; // empty line
300317
}
301318
// avoid using strtolower on the whole parsed string every time new character is added
302319
// there is also no point in adding characters which are in the string

0 commit comments

Comments
 (0)