diff options
author | Chanaka Indrajith <pe.chanaka.ck@gmail.com> | 2012-11-01 21:42:48 +0400 |
---|---|---|
committer | Chanaka Indrajith <pe.chanaka.ck@gmail.com> | 2012-11-01 21:42:48 +0400 |
commit | 8831f48c4fc77703108d04cd645bbf7ac2e41b8b (patch) | |
tree | 7a620723fd459d6b2677b82fcb90288c54dc596e /tbl_export.php | |
parent | 6fd29116aed02753881b8de8bdd397397fb1c279 (diff) | |
parent | d93f410fe46b158953a173e2d19e53972cac2b90 (diff) |
Merge branch 'MAINT_3_5_3' into QA_3_5
Diffstat (limited to 'tbl_export.php')
-rw-r--r-- | tbl_export.php | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/tbl_export.php b/tbl_export.php index 2158b7e869..6dfd6960ea 100644 --- a/tbl_export.php +++ b/tbl_export.php @@ -35,21 +35,33 @@ if (! empty($sql_query)) { // Need to generate WHERE clause? if (isset($where_clause)) { + // Yes => rebuild query from scratch; this doesn't work with nested + // selects :-( + $sql_query = 'SELECT '; - $temp_sql_array = explode("where", strtolower($sql_query)); + if (isset($analyzed_sql[0]['queryflags']['distinct'])) { + $sql_query .= ' DISTINCT '; + } + + $sql_query .= $analyzed_sql[0]['select_expr_clause']; + + if (!empty($analyzed_sql[0]['from_clause'])) { + $sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause']; + } - // The fields which is going to select will remain - // as it is regardless of the where clause(s). - // EX :- The part "SELECT `id`, `name` FROM `customers`" - // will remain same when representing the resulted rows - // from the following query, - // "SELECT `id`, `name` FROM `customers` WHERE id NOT IN - // ( SELECT id FROM companies WHERE name LIKE '%u%')" - $sql_query = $temp_sql_array[0]; + $wheres = array(); + + if (isset($where_clause) && is_array($where_clause) + && count($where_clause) > 0) { + $wheres[] = '(' . implode(') OR (', $where_clause) . ')'; + } + + if (!empty($analyzed_sql[0]['where_clause'])) { + $wheres[] = $analyzed_sql[0]['where_clause']; + } - // Append the where clause using the primary key of each row - if (is_array($where_clause) && (count($where_clause) > 0)) { - $sql_query .= ' WHERE (' . implode(') OR (', $where_clause) . ')'; + if (count($wheres) > 0) { + $sql_query .= ' WHERE (' . implode(') AND (', $wheres) . ')'; } if (!empty($analyzed_sql[0]['group_by_clause'])) { |