diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | libraries/database_interface.lib.php | 32 | ||||
-rw-r--r-- | tbl_export.php | 15 |
3 files changed, 47 insertions, 3 deletions
@@ -5,7 +5,8 @@ phpMyAdmin - ChangeLog - bug #3941 Recent tables list always empty - bug #3933 Do not translate "Open Document" in export settings - bug #3927 List of tables is missing after expanding in the navigation frame -- bug #3942 Warnings about reserved word for many non reserved words +- bug #3942 Warnings about reserved word for many non reserved words +- bug #3912 Exporting row selection, resulted by ORDER BY query 4.0.2.0 (2013-05-24) - bug #3902 Cannot browse when table name contains keyword "call" diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index 0a43ce44a1..e224113ee9 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -2099,4 +2099,36 @@ function PMA_is_system_schema($schema_name, $test_for_mysql_schema = false) || (PMA_DRIZZLE && strtolower($schema_name) == 'data_dictionary') || ($test_for_mysql_schema && !PMA_DRIZZLE && $schema_name == 'mysql'); } + +/** + * Get regular expression which occur first inside the given sql query. + * + * @param Array $regex_array Comparing regular expressions. + * @param String $query SQL query to be checked. + * + * @return String Matching regular expression. + */ +function PMA_getFirstOccuringRegularExpression($regex_array, $query) +{ + + $minimum_first_occurance_index = null; + $regex = null; + + for ($i=0; $i<count($regex_array); $i++) { + if (preg_match($regex_array[$i], $query, $matches, PREG_OFFSET_CAPTURE)) { + + if (is_null($minimum_first_occurance_index) + || ($matches[0][1] < $minimum_first_occurance_index) + ) { + $regex = $regex_array[$i]; + $minimum_first_occurance_index = $matches[0][1]; + } + + } + } + + return $regex; + +} + ?> diff --git a/tbl_export.php b/tbl_export.php index 557dcb352b..aa4880b9e0 100644 --- a/tbl_export.php +++ b/tbl_export.php @@ -37,14 +37,25 @@ if (! empty($sql_query)) { // Need to generate WHERE clause? if (isset($where_clause)) { - $temp_sql_array = preg_split("/\bwhere\b/i", $sql_query); + // Regular expressions which can appear in sql query, + // before the sql segment which remains as it is. + $regex_array = array( + '/\bwhere\b/i', '/\bgroup by\b/i', '/\bhaving\b/i', '/\border by\b/i' + ); + + $first_occuring_regex = PMA_getFirstOccuringRegularExpression( + $regex_array, $sql_query + ); // The part "SELECT `id`, `name` FROM `customers`" // is not modified by the next code segment, when exporting // the result set from a query such as // "SELECT `id`, `name` FROM `customers` WHERE id NOT IN // ( SELECT id FROM companies WHERE name LIKE '%u%')" - $sql_query = $temp_sql_array[0]; + if (! is_null($first_occuring_regex)) { + $temp_sql_array = preg_split($first_occuring_regex, $sql_query); + $sql_query = $temp_sql_array[0]; + } // Append the where clause using the primary key of each row if (is_array($where_clause) && (count($where_clause) > 0)) { |