From ef61073c6cdea3ab0e22970cc64d4a887d392a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 25 Jun 2004 21:15:18 +0000 Subject: [PATCH] Lets handle better comments, current detection still doesn't work with comments inside checked SQL commands, but I thing checking these would be overhead (bug #978114). --- ChangeLog | 3 +++ read_dump.php | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 79c7ee98b..0ff8006ae 100755 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,9 @@ $Source$ * libraries/display_export.lib.php: Add back key checking disabling. * libraries/export/sql.php: Brand new CREATE query rewriter from LinuxTag, fixes bug #979635. + * read_dump.php: Lets handle better comments, current detection still + doesn't work with comments inside checked SQL commands, but I thing + checking these would be overhead (bug #978114). 2004-06-25 Alexander M. Turek * queryframe.php: Undefined index errors. diff --git a/read_dump.php b/read_dump.php index 9caa6934f..31d7d86d9 100644 --- a/read_dump.php +++ b/read_dump.php @@ -240,7 +240,8 @@ if ($sql_query != '') { // Only one query to run if ($pieces_count == 1 && !empty($pieces[0]['query'])) { $sql_query = $pieces[0]['query']; - if (preg_match('@^(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@i', $sql_query)) { + // .*? bellow is non greedy expansion, just in case somebody wants to understand it... + if (preg_match('@^((-- |#)^[\n]*|/\*.*?\*/)*(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@i', $sql_query)) { $reload = 1; } require('./sql.php'); @@ -259,7 +260,8 @@ if ($sql_query != '') { for ($i = 0; $i < $count; $i++) { $a_sql_query = $pieces[$i]['query']; - if ($i == $count - 1 && preg_match('@^(SELECT|SHOW)@i', $a_sql_query)) { + // .*? bellow is non greedy expansion, just in case somebody wants to understand it... + if ($i == $count - 1 && preg_match('@^((-- |#)^[\n]*|/\*.*?\*/)*(SELECT|SHOW)@i', $a_sql_query)) { $complete_query = $sql_query; $display_query = $sql_query; $sql_query = $a_sql_query; @@ -304,11 +306,13 @@ if ($sql_query != '') { } // If a 'USE ' SQL-clause was found and the query succeeded, set our current $db to the new one - if ($result != FALSE && preg_match('@^USE[[:space:]]*([^[:space]+)@i', $a_sql_query, $match)) { + // .*? bellow is non greedy expansion, just in case somebody wants to understand it... + if ($result != FALSE && preg_match('@^((-- |#)^[\n]*|/\*.*?\*/)*USE[[:space:]]*([^[:space]+)@i', $a_sql_query, $match)) { $db = trim($match[0]); } - if (!isset($reload) && preg_match('@^(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@i', $a_sql_query)) { + // .*? bellow is non greedy expansion, just in case somebody wants to understand it... + if (!isset($reload) && preg_match('@^((-- |#)^[\n]*|/\*.*?\*/)*(DROP|CREATE)[[:space:]]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@i', $a_sql_query)) { $reload = 1; } } // end for