Handle correctly all MySQL comments (-- can be followed with any control char) (patch #965106).

This commit is contained in:
Michal Čihař
2004-06-04 10:20:33 +00:00
parent 68ca109fe0
commit f63a765279
3 changed files with 7 additions and 33 deletions

View File

@@ -5,6 +5,11 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2004-06-04 Michal Čihař <michal@cihar.com>
* libraries/read_dump.lib.php: Do not strip comments here.
* libraries/sqlparser.lib.php: Handle correctly all MySQL comments (-- can
be followed with any control char) (patch #965106).
2004-06-04 Garvin Hicking <me@supergarv.de> 2004-06-04 Garvin Hicking <me@supergarv.de>
* Bug #959320: Broken row highlighting in vertical * Bug #959320: Broken row highlighting in vertical
browsing mode fixed. The pointer will now highlight browsing mode fixed. The pointer will now highlight

View File

@@ -90,31 +90,6 @@ function PMA_splitSqlFile(&$ret, $sql, $release)
$string_start = $char; $string_start = $char;
} // end else if (is start of string) } // end else if (is start of string)
// ... for start of a comment (and remove this comment if found)...
else if ($char == '#'
|| ($char == ' ' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '--')) {
// starting position of the comment depends on the comment type
$start_of_comment = (($sql[$i] == '#') ? $i : $i-2);
// if no "\n" exits in the remaining string, checks for "\r"
// (Mac eol style)
$end_of_comment = (strpos(' ' . $sql, "\012", $i+2))
? strpos(' ' . $sql, "\012", $i+2)
: strpos(' ' . $sql, "\015", $i+2);
if (!$end_of_comment) {
// no eol found after '#', add the parsed part to the returned
// array if required and exit
if ($start_of_comment > 0) {
$ret[] = trim(substr($sql, 0, $start_of_comment));
}
return TRUE;
} else {
$sql = substr($sql, 0, $start_of_comment)
. ltrim(substr($sql, $end_of_comment));
$sql_len = strlen($sql);
$i--;
} // end if...else
} // end else if (is comment)
// ... and finally disactivate the "/*!...*/" syntax if MySQL < 3.22.07 // ... and finally disactivate the "/*!...*/" syntax if MySQL < 3.22.07
else if ($release < 32270 else if ($release < 32270
&& ($char == '!' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '/*')) { && ($char == '!' && $i > 1 && $sql[$i-2] . $sql[$i-1] == '/*')) {

View File

@@ -268,7 +268,7 @@ if ($is_minimum_common == FALSE) {
if (($c == '#') if (($c == '#')
|| (($count2 + 1 < $len) && ($c == '/') && (PMA_substr($sql, $count2 + 1, 1) == '*')) || (($count2 + 1 < $len) && ($c == '/') && (PMA_substr($sql, $count2 + 1, 1) == '*'))
|| (($count2 + 2 == $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-')) || (($count2 + 2 == $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-'))
|| (($count2 + 2 < $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-') && ((PMA_substr($sql, $count2 + 2, 1) == ' ') || (PMA_substr($sql, $count2 + 2, 1) == "\n")))) { || (($count2 + 2 < $len) && ($c == '-') && (PMA_substr($sql, $count2 + 1, 1) == '-') && ((PMA_substr($sql, $count2 + 2, 1) <= ' ')))) {
$count2++; $count2++;
$pos = 0; $pos = 0;
$type = 'bad'; $type = 'bad';
@@ -422,13 +422,7 @@ if ($is_minimum_common == FALSE) {
if (($first == ',') || ($first == ';') || ($first == '.') || ($first == '*')) { if (($first == ',') || ($first == ';') || ($first == '.') || ($first == '*')) {
$count2 = $count1 + 1; $count2 = $count1 + 1;
$punct_data = $first; $punct_data = $first;
} else if (($last2 == '--') && $l == 2) { } else if (($last2 == '/*') || (($last2 == '--') && ($count2 == $len || PMA_substr($sql, $count2, 1) <= ' ') )) {
// Nijel: probably broken ANSI comment here (bug #905066)
$debugstr = $GLOBALS['strSQPBugSyntaxError'] . ' @ ' . ($count1+1) . "\n"
. 'STR: ' . $punct_data;
PMA_SQP_throwError($debugstr, $sql);
return $sql;
} else if (($last2 == '/*') || ($last2 == '--')) {
$count2 -= 2; $count2 -= 2;
$punct_data = PMA_substr($sql, $count1, $count2 - $count1); $punct_data = PMA_substr($sql, $count1, $count2 - $count1);
} else if (($last == '-') || ($last == '+') || ($last == '!')) { } else if (($last == '-') || ($last == '+') || ($last == '!')) {