From 22fa5adee3cece9229f457d724d516eb96975186 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Wed, 29 Sep 2010 08:04:32 -0400 Subject: [PATCH] bug #3056023 [import] USE query not working --- ChangeLog | 1 + libraries/import.lib.php | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 699aaba6e8..a7c8d83eb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA - [core] Update library PHPExcel to version 1.7.4 - bug #3062455 [core] copy procedures and routines before tables - bug #3062455 [export] with SQL, export procedures and routines before tables +- bug #3056023 [import] USE query not working 3.3.7.0 (2010-09-07) - patch #3050492 [PDF scratchboard] Cannot drag table box to the edge after diff --git a/libraries/import.lib.php b/libraries/import.lib.php index 24b27db81a..12dfbf6687 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -118,6 +118,8 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) $display_query = ''; } $sql_query = $import_run_buffer['sql']; + // If a 'USE ' SQL-clause was found, set our current $db to the new one + list($db, $reload) = PMA_lookForUse($import_run_buffer['sql'], $db, $reload); } elseif ($run_query) { if ($controluser) { $result = PMA_query_as_controluser($import_run_buffer['sql']); @@ -156,10 +158,8 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) } // If a 'USE ' SQL-clause was found and the query succeeded, set our current $db to the new one - if ($result != FALSE && preg_match('@^[\s]*USE[[:space:]]*([\S]+)@i', $import_run_buffer['sql'], $match)) { - $db = trim($match[1]); - $db = trim($db,';'); // for example, USE abc; - $reload = TRUE; + if ($result != FALSE) { + list($db, $reload) = PMA_lookForUse($import_run_buffer['sql'], $db, $reload); } if ($result != FALSE && preg_match('@^[\s]*(DROP|CREATE)[\s]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@im', $import_run_buffer['sql'])) { @@ -205,6 +205,25 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false) } } +/** + * Looks for the presence of USE to possibly change current db + * + * @param string buffer to examine + * @param string current db + * @param boolean reload + * @return array (current or new db, whether to reload) + * @access public + */ +function PMA_lookForUse($buffer, $db, $reload) +{ + if (preg_match('@^[\s]*USE[[:space:]]*([\S]+)@i', $buffer, $match)) { + $db = trim($match[1]); + $db = trim($db,';'); // for example, USE abc; + $reload = TRUE; + } + return(array($db, $reload)); +} + /** * Returns next part of imported file/buffer -- 2.11.4.GIT