From bdbe747f8fb242485f8b24f3ad214e9ea419bc23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Sat, 8 Oct 2005 19:51:41 +0000 Subject: [PATCH] Fix query parsing when there is comment or string at the end. --- ChangeLog | 2 ++ libraries/import/sql.php | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index abbec19b0..54b6b611e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -64,6 +64,8 @@ $Source$ times. * libraries/relation.lib.php: Do not try to restore database as control user, it has to fail. + * libraries/import/sql.php: Fix query parsing when there is comment or + string at the end. 2005-10-07 Marc Delisle * libraries/check_user_privileges.lib.php: bug #1313821, dbname containing a diff --git a/libraries/import/sql.php b/libraries/import/sql.php index 5b4f408ad..3c1270685 100644 --- a/libraries/import/sql.php +++ b/libraries/import/sql.php @@ -88,7 +88,12 @@ if (isset($import_list)) { } if (!$endq) break; $i++; - continue; + // Aren't we at the end? + if ($i == $len) { + $i--; + } else { + continue; + } } // Not enough data to decide @@ -110,18 +115,32 @@ if (isset($import_list)) { // Skip the rest $i = strpos($buffer, $ch == '/' ? '*/' : "\n", $i); // didn't we hit end of string? - if ($i === FALSE) break; + if ($i === FALSE) { + if ($finished) { + $i = $len - 1; + } else { + break; + } + } // Skip * if ($ch == '/') $i++; // Skip last char $i++; // Next query part will start here $start_pos = $i; + // Aren't we at the end? + if ($i == $len) { + $i--; + } else { + continue; + } } // End of SQL if ($ch == ';' || ($finished && ($i == $len - 1))) { - $sql .= substr($buffer, $start_pos, $i - $start_pos + 1); + if ($start_pos < $len) { + $sql .= substr($buffer, $start_pos, $i - $start_pos + 1); + } PMA_importRunQuery($sql, substr($buffer, 0, $i + 1)); $buffer = substr($buffer, $i + 1); // Reset parser: