bug #3056023 [import] USE query not working

This commit is contained in:
Marc Delisle
2010-09-29 08:04:32 -04:00
parent c0d1c7a2ae
commit 22fa5adee3
2 changed files with 24 additions and 4 deletions

View File

@@ -10,6 +10,7 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA
- [core] Update library PHPExcel to version 1.7.4 - [core] Update library PHPExcel to version 1.7.4
- bug #3062455 [core] copy procedures and routines before tables - bug #3062455 [core] copy procedures and routines before tables
- bug #3062455 [export] with SQL, export 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) 3.3.7.0 (2010-09-07)
- patch #3050492 [PDF scratchboard] Cannot drag table box to the edge after - patch #3050492 [PDF scratchboard] Cannot drag table box to the edge after

View File

@@ -118,6 +118,8 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
$display_query = ''; $display_query = '';
} }
$sql_query = $import_run_buffer['sql']; $sql_query = $import_run_buffer['sql'];
// If a 'USE <db>' 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) { } elseif ($run_query) {
if ($controluser) { if ($controluser) {
$result = PMA_query_as_controluser($import_run_buffer['sql']); $result = PMA_query_as_controluser($import_run_buffer['sql']);
@@ -156,10 +158,8 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false)
} }
// If a 'USE <db>' SQL-clause was found and the query succeeded, set our current $db to the new one // If a 'USE <db>' 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)) { if ($result != FALSE) {
$db = trim($match[1]); list($db, $reload) = PMA_lookForUse($import_run_buffer['sql'], $db, $reload);
$db = trim($db,';'); // for example, USE abc;
$reload = TRUE;
} }
if ($result != FALSE && preg_match('@^[\s]*(DROP|CREATE)[\s]+(IF EXISTS[[:space:]]+)?(TABLE|DATABASE)[[:space:]]+(.+)@im', $import_run_buffer['sql'])) { 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 * Returns next part of imported file/buffer