From 2dcb1c9b0a9c6603a3bb39fb49f568a2c8d9b5cd Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Sun, 21 Dec 2014 22:57:25 +0100 Subject: [PATCH 1/2] Fix #4645 Import of export created with mysqldump Signed-off-by: Hugues Peccatte --- ChangeLog | 1 + libraries/plugins/import/ImportSql.class.php | 71 +++++++++++++------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index f777e1edfc..0a5b9b393e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ phpMyAdmin - ChangeLog ====================== 4.3.4.0 (not yet released) +- #4645 Import of export created with mysqldump 4.3.3.0 (2014-12-21) - bug The "Recently used tables" setting should be with Nav panel diff --git a/libraries/plugins/import/ImportSql.class.php b/libraries/plugins/import/ImportSql.class.php index 306d75abba..8fa36a9d59 100644 --- a/libraries/plugins/import/ImportSql.class.php +++ b/libraries/plugins/import/ImportSql.class.php @@ -40,6 +40,11 @@ class ImportSql extends ImportPlugin */ private $_delimiterPosition = false; + /** + * @var string Query to execute + */ + private $_query = null; + /** * @var int Query start position */ @@ -212,7 +217,10 @@ class ImportSql extends ImportPlugin { //Search for closing quote $posClosingString = $this->_stringFctToUse['strpos']( - $this->_data, $this->_quote, $this->_delimiterPosition + $this->_data, $this->_quote, + $this->_delimiterPosition + $this->_stringFctToUse['strlen']( + $this->_quote + ) ); if (false === $posClosingString) { @@ -268,49 +276,53 @@ class ImportSql extends ImportPlugin $posClosingComment = $this->_stringFctToUse['strpos']( $this->_data, "\n", - $this->_delimiterPosition + $this->_delimiterPosition + $this->_stringFctToUse['strlen']( + $this->_openingComment + ) ); if (false === $posClosingComment) { return false; } //Move after the end of the line. $this->_delimiterPosition = $posClosingComment + 1; - $this->_isInComment = false; - $this->_openingComment = null; } elseif ('/*' === $this->_openingComment) { //Search for closing comment $posClosingComment = $this->_stringFctToUse['strpos']( $this->_data, '*/', - $this->_delimiterPosition + $this->_delimiterPosition + $this->_stringFctToUse['strlen']( + $this->_openingComment + ) ); if (false === $posClosingComment) { return false; } //Move after closing comment. $this->_delimiterPosition = $posClosingComment + 2; - $this->_isInComment = false; - $this->_openingComment = null; } else { //We shouldn't be able to come here. //throw new Exception('Unknown case.'); break; } - if (0 === $this->_firstSearchChar) { - $this->_queryBeginPosition = $this->_delimiterPosition; - } + $this->_queryBeginPosition = $this->_delimiterPosition; + $this->_isInComment = false; + $this->_openingComment = null; continue; } if ($this->_isInDelimiter) { + $posAfterKeyword = $this->_delimiterPosition + + $this->_stringFctToUse['strlen']( + $this->_delimiterKeyword + ); //Search for new line. if (!preg_match( "/^(.*)\n/", $this->_stringFctToUse['substr']( $this->_data, - $this->_delimiterPosition + $posAfterKeyword ), $matches, PREG_OFFSET_CAPTURE @@ -320,8 +332,8 @@ class ImportSql extends ImportPlugin $this->_setDelimiter($matches[1][0]); //Start after delimiter and new line. - $this->_queryBeginPosition = $this->_delimiterPosition - + $matches[1][1] + $this->_delimiterLength + 1; + $this->_queryBeginPosition = $posAfterKeyword + $matches[1][1] + + $this->_delimiterLength + 1; $this->_delimiterPosition = $this->_queryBeginPosition; $this->_isInDelimiter = false; $firstSqlDelimiter = null; @@ -343,6 +355,7 @@ class ImportSql extends ImportPlugin && $firstSqlDelimiter < $this->_firstSearchChar) ) { $this->_delimiterPosition = $firstSqlDelimiter; + $this->_fillQuery(); return true; } @@ -355,7 +368,7 @@ class ImportSql extends ImportPlugin $this->_isInString = true; $this->_quote = $specialChars; //Move after quote. - $this->_delimiterPosition = $this->_firstSearchChar + 1; + $this->_delimiterPosition = $this->_firstSearchChar; continue; } @@ -364,16 +377,15 @@ class ImportSql extends ImportPlugin $this->_isInComment = true; $this->_openingComment = $specialChars; //Move after comment opening. - $this->_delimiterPosition = $this->_firstSearchChar - + $this->_stringFctToUse['strlen']($specialChars); + $this->_delimiterPosition = $this->_firstSearchChar; + $this->_fillQuery(); continue; } //If DELIMITER is found. if ($specialChars === $this->_delimiterKeyword) { $this->_isInDelimiter = true; - $this->_delimiterPosition = $this->_firstSearchChar - + $this->_stringFctToUse['strlen']($specialChars); + $this->_delimiterPosition = $this->_firstSearchChar; continue; } } @@ -447,11 +459,7 @@ class ImportSql extends ImportPlugin } PMA_importRunQuery( - $this->_stringFctToUse['substr']( - $this->_data, - $this->_queryBeginPosition, - $this->_delimiterPosition - $this->_queryBeginPosition - ), //Query to execute + $this->_query, //Query to execute $this->_stringFctToUse['substr']( $this->_data, 0, @@ -460,6 +468,7 @@ class ImportSql extends ImportPlugin false, $sql_data ); + $this->_query = null; $this->_setData( $this->_stringFctToUse['substr']( @@ -616,4 +625,20 @@ class ImportSql extends ImportPlugin return $this->_dataLength; } + + /** + * Fill current query from indexes + * + * @return string Current query + */ + private function _fillQuery() + { + $this->_query .= $this->_stringFctToUse['substr']( + $this->_data, + $this->_queryBeginPosition, + $this->_delimiterPosition - $this->_queryBeginPosition + ); + + return $this->_query; + } } From 647078cab3bcf357de6a4cece675d219b78cab12 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Tue, 23 Dec 2014 22:38:35 +0100 Subject: [PATCH 2/2] Update ChangeLog. Signed-off-by: Hugues Peccatte --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0a5b9b393e..9f4e985662 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,7 @@ phpMyAdmin - ChangeLog ====================== 4.3.4.0 (not yet released) -- #4645 Import of export created with mysqldump +- bug #4645 Import of export created with mysqldump 4.3.3.0 (2014-12-21) - bug The "Recently used tables" setting should be with Nav panel