From df37fd140f7d0efbcbf19af19380b3a453873d91 Mon Sep 17 00:00:00 2001 From: Chanaka Indrajith Date: Sun, 26 May 2013 16:07:00 +0530 Subject: Fixed bug 3912 --- tbl_export.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'tbl_export.php') 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)) { -- cgit v1.2.3