Navigation Menu

Skip to content

Commit

Permalink
Fix bugs #2908984 and #2579270 in our "query parser"
Browse files Browse the repository at this point in the history
This "query trivial parser" is in function Postgres.php:executeScript()

  * about #2908984, we were getting each line of the uploaded file
    using fgets($fd, 32768); because of PHP 4.3 and bellow that
    were considering a line has a length of 1024 by default. So we
    had to set a large value, but it wasn't not large enough here.
    Since we officialy support PHP 5+, I just removed this max length
    so PHP keep parsing the line till the end.
  * about #2579270, that was just a bad test on $in_quote so we were
    not parsing quoted values correclty, and the -- were catching as
    comments.
  • Loading branch information
ioguix committed Aug 26, 2010
1 parent 8740dd5 commit 36c782e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions classes/database/Postgres.php
Expand Up @@ -7390,7 +7390,7 @@ function executeScript($name, $callback = null) {

// Loop over each line in the file
while (!feof($fd)) {
$line = fgets($fd, 32768);
$line = fgets($fd);
$lineno++;

// Nothing left on line? Then ignore...
Expand Down Expand Up @@ -7423,7 +7423,7 @@ function executeScript($name, $callback = null) {
*/

/* in quote? */
if ($in_quote != 0)
if ($in_quote !== 0)
{
/*
* end of quote if matching non-backslashed character.
Expand Down Expand Up @@ -7466,7 +7466,7 @@ function executeScript($name, $callback = null) {

/*
* start of $foo$ type quote?
*/
*/
else if (!$dol_quote && $this->valid_dolquote(substr($line, $i))) {
$dol_end = strpos(substr($line, $i + 1), '$');
$dol_quote = substr($line, $i, $dol_end + 1);
Expand All @@ -7485,9 +7485,9 @@ function executeScript($name, $callback = null) {
}

/* count nested parentheses */
else if (substr($line, $i, 1) == '(') {
else if (substr($line, $i, 1) == '(') {
$paren_level++;
}
}

else if (substr($line, $i, 1) == ')' && $paren_level > 0) {
$paren_level--;
Expand All @@ -7503,7 +7503,7 @@ function executeScript($name, $callback = null) {
/*
* insert a cosmetic newline, if this is not the first
* line in the buffer
*/
*/
if (strlen($query_buf) > 0)
$query_buf .= "\n";
/* append the line to the query buffer */
Expand All @@ -7529,8 +7529,8 @@ function executeScript($name, $callback = null) {
break;
}
}
}
}
}
}

$query_buf = null;
$query_start = $i + $thislen;
Expand All @@ -7541,7 +7541,7 @@ function executeScript($name, $callback = null) {
* We grab the whole string so that we don't
* mistakenly see $foo$ inside an identifier as the start
* of a dollar quote.
*/
*/
// XXX: multibyte here
else if (preg_match('/^[_[:alpha:]]$/', substr($line, $i, 1))) {
$sub = substr($line, $i, $thislen);
Expand All @@ -7553,7 +7553,7 @@ function executeScript($name, $callback = null) {
// Since we're now over the next character to be examined, it is necessary
// to move back one space.
$i-=$prevlen;
}
}
} // end for

/* Put the rest of the line in the query buffer. */
Expand All @@ -7572,7 +7572,7 @@ function executeScript($name, $callback = null) {
/*
* Process query at the end of file without a semicolon, so long as
* it's non-empty.
*/
*/
if (strlen($query_buf) > 0 && strspn($query_buf, " \t\n\r") != strlen($query_buf))
{
// Execute the query (supporting 4.1.x PHP...)
Expand All @@ -7591,10 +7591,10 @@ function executeScript($name, $callback = null) {
if ($copy == "\\.\n" || $copy == "\\.\r\n") {
pg_end_copy($conn);
break;
}
}
}
}
}
}
}

fclose($fd);

Expand Down

0 comments on commit 36c782e

Please sign in to comment.