From b60fcde9ad30a253029194f84fd6d2b7fcda4209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 27 Apr 2006 10:05:04 +0000 Subject: [PATCH] Do not strip MySQL conditional statements in comments (patch #1459782, thanks to unconed - unconed). --- ChangeLog | 2 ++ libraries/import/sql.php | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index cf098113f..3c7ceb07e 100755 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,8 @@ $Source$ #1477500). * libraries/display_tbl.lib.php: Do not check for VIEW if no table name (eg. SELECT 1) (bug #1473484). + * libraries/import/sql.php: Do not strip MySQL conditional statements in + comments (patch #1459782, thanks to unconed - unconed). 2006-04-26 Michal Čihař * libraries/plugin_interface.lib.php: diff --git a/libraries/import/sql.php b/libraries/import/sql.php index 1596842d4..c13dbfc93 100644 --- a/libraries/import/sql.php +++ b/libraries/import/sql.php @@ -144,7 +144,7 @@ if (isset($plugin_list)) { ) && !$finished) { break; } - + // Comments if ($ch == '#' || ($i < ($len - 1) && $ch == '-' && $buffer[$i + 1] == '-' && (($i < ($len - 2) && $buffer[$i + 2] <= ' ') || ($i == ($len - 1) && $finished))) @@ -155,6 +155,7 @@ if (isset($plugin_list)) { $sql .= substr($buffer, $start_pos, $i - $start_pos); } // Skip the rest + $j = $i; $i = strpos($buffer, $ch == '/' ? '*/' : "\n", $i); // didn't we hit end of string? if ($i === FALSE) { @@ -166,11 +167,22 @@ if (isset($plugin_list)) { } // Skip * if ($ch == '/') { + // Check for MySQL conditional comments and include them as-is + if ($buffer[$j + 2] == '!') { + $comment = substr($buffer, $j + 3, $i - $j - 3); + if (preg_match('/^[0-9]{5}/', $comment, $version)) { + if ($version[0] <= PMA_MYSQL_INT_VERSION) { + $sql .= substr($comment, 5); + } + } else { + $sql .= $comment; + } + } $i++; } // Skip last char $i++; - // Next query part will start here + // Next query part will start here $start_pos = $i; // Aren't we at the end? if ($i == $len) {