2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * query by example the whole database
12 require_once './libraries/common.inc.php';
15 * Gets the relation settings
17 $cfgRelation = PMA_getRelationsParam();
21 * A query has been submitted -> execute it, else display the headers
23 if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
25 $message_to_show = htmlspecialchars(__('Your SQL query has been executed successfully'));
30 require './libraries/db_common.inc.php';
31 $url_query .= '&goto=db_qbe.php';
32 $url_params['goto'] = 'db_qbe.php';
33 require './libraries/db_info.inc.php';
36 if (isset($_REQUEST['submit_sql'])
37 && ! preg_match('@^SELECT@i', $sql_query)) {
38 PMA_Message
::warning(__('You have to choose at least one column to display'))->display();
43 * Initialize some variables
45 $col_cnt = PMA_ifSetOr($_REQUEST['col_cnt'], 3, 'numeric');
46 $add_col = PMA_ifSetOr($_REQUEST['add_col'], 0, 'numeric');
47 $add_row = PMA_ifSetOr($_REQUEST['add_row'], 0, 'numeric');
49 $rows = PMA_ifSetOr($_REQUEST['rows'], 0, 'numeric');
50 $ins_col = PMA_ifSetOr($_REQUEST['ins_col'], null, 'array');
51 $del_col = PMA_ifSetOr($_REQUEST['del_col'], null, 'array');
53 $prev_criteria = isset($_REQUEST['prev_criteria'])
54 ?
$_REQUEST['prev_criteria']
56 $criteria = isset($_REQUEST['criteria'])
57 ?
$_REQUEST['criteria']
58 : array_fill(0, $col_cnt, '');
60 $ins_row = isset($_REQUEST['ins_row'])
61 ?
$_REQUEST['ins_row']
62 : array_fill(0, $col_cnt, '');
63 $del_row = isset($_REQUEST['del_row'])
64 ?
$_REQUEST['del_row']
65 : array_fill(0, $col_cnt, '');
66 $and_or_row = isset($_REQUEST['and_or_row'])
67 ?
$_REQUEST['and_or_row']
68 : array_fill(0, $col_cnt, '');
69 $and_or_col = isset($_REQUEST['and_or_col'])
70 ?
$_REQUEST['and_or_col']
71 : array_fill(0, $col_cnt, '');
74 $form_column_width = 12;
75 $col = max($col_cnt +
$add_col, 0);
76 $row = max($rows +
$add_row, 0);
79 // The tables list sent by a previously submitted form
80 if (PMA_isValid($_REQUEST['TableList'], 'array')) {
81 foreach ($_REQUEST['TableList'] as $each_table) {
82 $tbl_names[$each_table] = ' selected="selected"';
87 // this was a work in progress, deactivated for now
88 //$columns = PMA_DBI_get_columns_full($GLOBALS['db']);
89 //$tables = PMA_DBI_get_columns_full($GLOBALS['db']);
95 $tbl_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
96 $tbl_result_cnt = PMA_DBI_num_rows($tbl_result);
97 if (0 == $tbl_result_cnt) {
98 PMA_Message
::error(__('No tables found in database.'))->display();
99 require './libraries/footer.inc.php';
103 // The tables list gets from MySQL
104 while (list($tbl) = PMA_DBI_fetch_row($tbl_result)) {
105 $fld_results = PMA_DBI_get_fields($db, $tbl);
107 if (empty($tbl_names[$tbl]) && !empty($_REQUEST['TableList'])) {
108 $tbl_names[$tbl] = '';
110 $tbl_names[$tbl] = ' selected="selected"';
113 // The fields list per selected tables
114 if ($tbl_names[$tbl] == ' selected="selected"') {
115 $each_table = PMA_backquote($tbl);
116 $fld[] = $each_table . '.*';
117 foreach ($fld_results as $each_field) {
118 $each_field = $each_table . '.' . PMA_backquote($each_field['Field']);
119 $fld[] = $each_field;
121 // increase the width if necessary
122 $form_column_width = max(strlen($each_field), $form_column_width);
126 PMA_DBI_free_result($tbl_result);
128 // largest width found
129 $realwidth = $form_column_width . 'ex';
133 * Displays the Query by example form
137 * Enter description here...
139 * @param array $columns
140 * @param integer $column_number
141 * @param string $selected
143 function showColumnSelectCell($columns, $column_number, $selected = '')
147 <select name
="Field[<?php echo $column_number; ?>]" size
="1">
148 <option value
=""> 
;</option
>
150 foreach ($columns as $column) {
151 if ($column === $selected) {
152 $sel = ' selected="selected"';
156 echo '<option value="' . htmlspecialchars($column) . '"' . $sel . '>'
157 . str_replace(' ', ' ', htmlspecialchars($column)) . '</option>' . "\n";
166 <?php
if (!empty($tab_designer['link'])) {
167 $tab_designer['link'] = htmlentities($tab_designer['link']);
168 $tab_designer['link'] = $tab_designer['link'] . PMA_generate_common_url($url_params);
169 if (! empty($tab_designer['args'])) {
170 foreach ($tab_designer['args'] as $param => $value) {
171 $tab_designer['link'] .= PMA_get_arg_separator('html') . urlencode($param) . '='
176 if (! empty($tab['fragment'])) {
177 $tab['link'] .= $tab['fragment'];
179 if (isset($tab_designer['link'])) {
181 <div id
="visual_builder_anchor" class="notice hide">
182 <span id
="footnote_1">
183 <?php
echo __('Switch to') . ' <a href="' . $tab_designer['link'] . PMA_get_arg_separator('html') . 'query=1">' . __('visual builder') . '</a>'; ?
>
189 <form action
="db_qbe.php" method
="post">
191 <table
class="data" style
="width: 100%;">
192 <tr
class="odd noclick">
193 <th
><?php
echo __('Column'); ?
>:</th
>
196 for ($x = 0; $x < $col; $x++
) {
197 if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {
198 showColumnSelectCell($fld, $z);
202 if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
207 if (isset($Field[$x])) {
208 $selected = $Field[$x];
209 $curField[$z] = $Field[$x];
211 showColumnSelectCell($fld, $z, $selected);
218 <tr
class="even noclick">
219 <th
><?php
echo __('Sort'); ?
>:</th
>
222 for ($x = 0; $x < $col; $x++
) {
223 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
226 <select style
="width: <?php echo $realwidth; ?>" name
="Sort[<?php echo $z; ?>]" size
="1">
227 <option value
=""> 
;</option
>
228 <option value
="ASC"><?php
echo __('Ascending'); ?
></option
>
229 <option value
="DESC"><?php
echo __('Descending'); ?
></option
>
237 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
242 <select style
="width: <?php echo $realwidth; ?>" name
="Sort[<?php echo $z; ?>]" size
="1">
243 <option value
=""> 
;</option
>
247 // If they have chosen all fields using the * selector,
248 // then sorting is not available
249 // Fix for Bug #570698
250 if (isset($Sort[$x]) && isset($Field[$x])
251 && substr($Field[$x], -2) == '.*') {
255 if (isset($Sort[$x]) && $Sort[$x] == 'ASC') {
256 $curSort[$z] = $Sort[$x];
257 $sel = ' selected="selected"';
262 echo '<option value="ASC"' . $sel . '>' . __('Ascending') . '</option>' . "\n";
263 if (isset($Sort[$x]) && $Sort[$x] == 'DESC') {
264 $curSort[$z] = $Sort[$x];
265 $sel = ' selected="selected"';
270 echo '<option value="DESC"' . $sel . '>' . __('Descending') . '</option>' . "\n";
282 <tr
class="odd noclick">
283 <th
><?php
echo __('Show'); ?
>:</th
>
286 for ($x = 0; $x < $col; $x++
) {
287 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
290 <input type
="checkbox" name
="Show[<?php echo $z; ?>]" />
297 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
300 if (isset($Show[$x])) {
301 $checked = ' checked="checked"';
302 $curShow[$z] = $Show[$x];
308 <input type
="checkbox" name
="Show[<?php echo $z; ?>]"<?php
echo $checked; ?
> />
317 <!-- Criteria row
-->
318 <tr
class="even noclick">
319 <th
><?php
echo __('Criteria'); ?
>:</th
>
322 for ($x = 0; $x < $col; $x++
) {
323 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
326 <input type
="text" name
="criteria[<?php echo $z; ?>]" value
="" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
333 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
336 if (isset($criteria[$x])) {
337 $tmp_criteria = $criteria[$x];
339 if ((empty($prev_criteria) ||
!isset($prev_criteria[$x]))
340 ||
$prev_criteria[$x] != htmlspecialchars($tmp_criteria)) {
341 $curCriteria[$z] = $tmp_criteria;
343 $curCriteria[$z] = $prev_criteria[$x];
347 <input type
="hidden" name
="prev_criteria[<?php echo $z; ?>]" value
="<?php echo htmlspecialchars($curCriteria[$z]); ?>" />
348 <input type
="text" name
="criteria[<?php echo $z; ?>]" value
="<?php echo htmlspecialchars($tmp_criteria); ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
357 <!-- And/Or columns
and rows
-->
361 for ($y = 0; $y <= $row; $y++
) {
362 if (isset($ins_row[$y]) && $ins_row[$y] == 'on') {
363 $chk['or'] = ' checked="checked"';
366 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
367 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
368 <!-- Row controls
-->
369 <table cellpadding
="0" cellspacing
="0" border
="0">
371 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
372 <small
><?php
echo __('Ins'); ?
>:</small
>
373 <input type
="checkbox" name
="ins_row[<?php echo $w; ?>]" />
375 <td align
="<?php echo $cell_align_right; ?>">
376 <strong
><?php
echo __('And'); ?
>:</strong
>
379 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
384 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
385 <small
><?php
echo __('Del'); ?
>:</small
>
386 <input type
="checkbox" name
="del_row[<?php echo $w; ?>]" />
388 <td align
="<?php echo $cell_align_right; ?>">
389 <strong
><?php
echo __('Or'); ?
>:</strong
>
392 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
400 for ($x = 0; $x < $col; $x++
) {
401 if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {
403 $or = 'Or' . $w . '[' . $z . ']';
406 <input type
="text" name
="Or<?php echo $or; ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
411 if (isset($del_col[$x]) && $del_col[$x] == 'on') {
416 $or = 'Or' . $w . '[' . $z . ']';
419 <input type
="text" name
="Or<?php echo $or; ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
429 $odd_row =! $odd_row;
432 if (isset($del_row[$y]) && $del_row[$y] == 'on') {
436 if (isset($and_or_row[$y])) {
437 $curAndOrRow[$w] = $and_or_row[$y];
439 if (isset($and_or_row[$y]) && $and_or_row[$y] == 'and') {
440 $chk['and'] = ' checked="checked"';
443 $chk['or'] = ' checked="checked"';
448 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
449 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
450 <!-- Row controls
-->
451 <table border
="0" cellpadding
="0" cellspacing
="0">
453 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
454 <small
><?php
echo __('Ins'); ?
>:</small
>
455 <input type
="checkbox" name
="ins_row[<?php echo $w; ?>]" />
457 <td align
="<?php echo $cell_align_right; ?>">
458 <strong
><?php
echo __('And'); ?
>:</strong
>
461 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
465 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
466 <small
><?php
echo __('Del'); ?
>:</small
>
467 <input type
="checkbox" name
="del_row[<?php echo $w; ?>]" />
469 <td align
="<?php echo $cell_align_right; ?>">
470 <strong
><?php
echo __('Or'); ?
>:</strong
>
473 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
480 for ($x = 0; $x < $col; $x++
) {
481 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
483 $or = 'Or' . $w . '[' . $z . ']';
486 <input type
="text" name
="Or<?php echo $or; ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
491 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
497 if (!isset($
{$or})) {
500 if (!empty($
{$or}) && isset($
{$or}[$x])) {
501 $tmp_or = $
{$or}[$x];
507 <input type
="text" name
="Or<?php echo $w . '[' . $z . ']'; ?>" value
="<?php echo htmlspecialchars($tmp_or); ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
510 if (!empty($
{$or}) && isset($
{$or}[$x])) {
511 $
{'cur' . $or}[$z] = $
{$or}[$x];
521 $odd_row =! $odd_row;
524 <!-- Modify columns
-->
525 <tr
class="even noclick">
526 <th
><?php
echo __('Modify'); ?
>:</th
>
529 for ($x = 0; $x < $col; $x++
) {
530 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
531 $curAndOrCol[$z] = $and_or_col[$y];
532 if ($and_or_col[$z] == 'or') {
533 $chk['or'] = ' checked="checked"';
536 $chk['and'] = ' checked="checked"';
541 <strong
><?php
echo __('Or'); ?
>:</strong
>
542 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
543  
; 
;<strong
><?php
echo __('And'); ?
>:</strong
>
544 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
546 <?php
echo __('Ins') . "\n"; ?
>
547 <input type
="checkbox" name
="ins_col[<?php echo $z; ?>]" />
548  
; 
;<?php
echo __('Del') . "\n"; ?
>
549 <input type
="checkbox" name
="del_col[<?php echo $z; ?>]" />
556 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
560 if (isset($and_or_col[$y])) {
561 $curAndOrCol[$z] = $and_or_col[$y];
563 if (isset($and_or_col[$z]) && $and_or_col[$z] == 'or') {
564 $chk['or'] = ' checked="checked"';
567 $chk['and'] = ' checked="checked"';
572 <strong
><?php
echo __('Or'); ?
>:</strong
>
573 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
574  
; 
;<strong
><?php
echo __('And'); ?
>:</strong
>
575 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
577 <?php
echo __('Ins') . "\n"; ?
>
578 <input type
="checkbox" name
="ins_col[<?php echo $z; ?>]" />
579  
; 
;<?php
echo __('Del') . "\n"; ?
>
580 <input type
="checkbox" name
="del_col[<?php echo $z; ?>]" />
590 <!-- Other controls
-->
593 $url_params['db'] = $db;
594 $url_params['col_cnt'] = $z;
595 $url_params['rows'] = $w;
596 echo PMA_generate_common_hidden_inputs($url_params);
599 <fieldset
class="tblFooters">
600 <table border
="0" cellpadding
="2" cellspacing
="1">
603 <?php
echo __('Add/Delete criteria rows'); ?
>:
604 <select size
="1" name
="add_row">
605 <option value
="-3">-3</option
>
606 <option value
="-2">-2</option
>
607 <option value
="-1">-1</option
>
608 <option value
="0" selected
="selected">0</option
>
609 <option value
="1">1</option
>
610 <option value
="2">2</option
>
611 <option value
="3">3</option
>
614 <td width
="10"> 
;</td
>
615 <td nowrap
="nowrap"><?php
echo __('Add/Delete columns'); ?
>:
616 <select size
="1" name
="add_col">
617 <option value
="-3">-3</option
>
618 <option value
="-2">-2</option
>
619 <option value
="-1">-1</option
>
620 <option value
="0" selected
="selected">0</option
>
621 <option value
="1">1</option
>
622 <option value
="2">2</option
>
623 <option value
="3">3</option
>
626 <td width
="10"> 
;</td
>
627 <!-- Generates a query
-->
628 <td
><input type
="submit" name
="modify" value
="<?php echo __('Update Query'); ?>" /></td
>
636 <legend
><?php
echo __('Use Tables'); ?
></legend
>
639 $numTableListOptions = 0;
640 foreach ($tbl_names as $key => $val) {
642 $options .= '<option value="' . htmlspecialchars($key) . '"' . $val . '>'
643 . str_replace(' ', ' ', htmlspecialchars($key)) . '</option>' . "\n";
644 $numTableListOptions++
;
647 <select name
="TableList[]" multiple
="multiple" id
="listTable"
648 size
="<?php echo ($numTableListOptions > 30) ? '15' : '7'; ?>">
649 <?php
echo $options; ?
>
652 <fieldset
class="tblFooters">
653 <input type
="submit" name
="modify" value
="<?php echo __('Update Query'); ?>" />
656 <td width
="20"> 
;</td
>
659 <legend
><?php
echo sprintf(__('SQL query on database <b>%s</b>:'), PMA_getDbLink($db)); ?
>
661 <textarea cols
="80" name
="sql_query" id
="textSqlquery"
662 rows
="<?php echo ($numTableListOptions > 30) ? '15' : '7'; ?>"
663 dir
="<?php echo $text_dir; ?>">
667 if (!isset($qry_select)) {
670 for ($x = 0; $x < $col; $x++
) {
671 if (!empty($curField[$x]) && isset($curShow[$x]) && $curShow[$x] == 'on') {
675 $qry_select .= $curField[$x];
679 if (!empty($qry_select)) {
680 echo 'SELECT ' . htmlspecialchars($qry_select) . "\n";
685 // Create LEFT JOINS out of Relations
686 // Code originally by Mike Beck <mike.beck@ibmiller.de>
687 // If we can use Relations we could make some left joins.
688 // First find out if relations are available in this database.
690 // First we need the really needed Tables - those in TableList might still be
692 if (isset($Field) && count($Field) > 0) {
693 // Initialize some variables
699 $col_where = array();
702 // We only start this if we have fields, otherwise it would be dumb
703 foreach ($Field as $value) {
704 $parts = explode('.', $value);
705 if (!empty($parts[0]) && !empty($parts[1])) {
706 $tab_raw = $parts[0];
707 $tab = str_replace('`', '', $tab_raw);
708 $tab_all[$tab] = $tab;
710 $col_raw = $parts[1];
711 $col_all[] = $tab . '.' . str_replace('`', '', $col_raw);
715 // Check 'where' clauses
716 if ($cfgRelation['relwork'] && count($tab_all) > 0) {
717 // Now we need all tables that we have in the where clause
718 $crit_cnt = count($criteria);
719 for ($x = 0; $x < $crit_cnt; $x++
) {
720 $curr_tab = explode('.', $Field[$x]);
721 if (!empty($curr_tab[0]) && !empty($curr_tab[1])) {
722 $tab_raw = $curr_tab[0];
723 $tab = str_replace('`', '', $tab_raw);
725 $col_raw = $curr_tab[1];
726 $col1 = str_replace('`', '', $col_raw);
727 $col1 = $tab . '.' . $col1;
728 // Now we know that our array has the same numbers as $criteria
729 // we can check which of our columns has a where clause
730 if (!empty($criteria[$x])) {
731 if (substr($criteria[$x], 0, 1) == '=' ||
stristr($criteria[$x], 'is')) {
732 $col_where[$col] = $col1;
733 $tab_wher[$tab] = $tab;
739 // Cleans temp vars w/o further use
744 if (count($tab_wher) == 1) {
745 // If there is exactly one column that has a decent where-clause
746 // we will just use this
747 $master = key($tab_wher);
749 // Now let's find out which of the tables has an index
750 // (When the control user is the same as the normal user
751 // because he is using one of his databases as pmadb,
752 // the last db selected is not always the one where we need to work)
753 PMA_DBI_select_db($db);
755 foreach ($tab_all as $tab) {
756 $ind_rs = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($tab) . ';');
757 while ($ind = PMA_DBI_fetch_assoc($ind_rs)) {
758 $col1 = $tab . '.' . $ind['Column_name'];
759 if (isset($col_all[$col1])) {
760 if ($ind['non_unique'] == 0) {
761 if (isset($col_where[$col1])) {
762 $col_unique[$col1] = 'Y';
764 $col_unique[$col1] = 'N';
767 if (isset($col_where[$col1])) {
768 $col_index[$col1] = 'Y';
770 $col_index[$col1] = 'N';
774 } // end while (each col of tab)
775 } // end while (each tab)
776 // now we want to find the best.
777 if (isset($col_unique) && count($col_unique) > 0) {
778 $col_cand = $col_unique;
780 } elseif (isset($col_index) && count($col_index) > 0) {
781 $col_cand = $col_index;
783 } elseif (isset($col_where) && count($col_where) > 0) {
784 $col_cand = $tab_wher;
787 $col_cand = $tab_all;
791 // If we came up with $col_unique (very good) or $col_index (still
792 // good) as $col_cand we want to check if we have any 'Y' there
793 // (that would mean that they were also found in the whereclauses
794 // which would be great). if yes, we take only those
795 if ($needsort == 1) {
796 foreach ($col_cand as $col => $is_where) {
797 $tab = explode('.', $col);
799 if ($is_where == 'Y') {
807 // Candidates restricted in index+where
810 // None of the candidates where in a where-clause
814 // If our array of candidates has more than one member we'll just
815 // find the smallest table.
816 // Of course the actual query would be faster if we check for
817 // the Criteria which gives the smallest result set in its table,
818 // but it would take too much time to check this
819 if (count($col_cand) > 1) {
820 // Of course we only want to check each table once
821 $checked_tables = $col_cand;
822 foreach ($col_cand as $tab) {
823 if ($checked_tables[$tab] != 1) {
824 $tsize[$tab] = PMA_Table
::countRecords($db, $tab, false);
825 $checked_tables[$tab] = 1;
827 $csize[$tab] = $tsize[$tab];
831 $master = key($csize); // Smallest
834 $master = current($col_cand); // Only one single candidate
836 } // end if (exactly one where clause)
838 $tab_left = $tab_all;
839 unset($tab_left[$master]);
840 $tab_know[$master] = $master;
844 while (count($tab_left) > 0) {
846 PMA_getRelatives('master');
848 PMA_getRelatives('foreign');
853 foreach ($tab_left as $tab) {
854 $emerg .= ', ' . PMA_backquote($tab);
855 unset($tab_left[$tab]);
859 $qry_from = PMA_backquote($master) . $emerg . $fromclause;
860 } // end if ($cfgRelation['relwork'] && count($tab_all) > 0)
862 } // end count($Field) > 0
864 // In case relations are not defined, just generate the FROM clause
865 // from the list of tables, however we don't generate any JOIN
867 if (empty($qry_from) && isset($tab_all)) {
868 $qry_from = implode(', ', $tab_all);
870 // Now let's see what we got
871 if (!empty($qry_from)) {
872 echo 'FROM ' . htmlspecialchars($qry_from) . "\n";
878 for ($x = 0; $x < $col; $x++
) {
879 if (!empty($curField[$x]) && !empty($curCriteria[$x]) && $x && isset($last_where) && isset($curAndOrCol)) {
880 $qry_where .= ' ' . strtoupper($curAndOrCol[$last_where]) . ' ';
882 if (!empty($curField[$x]) && !empty($curCriteria[$x])) {
883 $qry_where .= '(' . $curField[$x] . ' ' . $curCriteria[$x] . ')';
888 if ($criteria_cnt > 1) {
889 $qry_where = '(' . $qry_where . ')';
891 // OR rows ${'cur' . $or}[$x]
892 if (!isset($curAndOrRow)) {
893 $curAndOrRow = array();
895 for ($y = 0; $y <= $row; $y++
) {
899 for ($x = 0; $x < $col; $x++
) {
900 if (!empty($curField[$x]) && !empty($
{'curOr' . $y}[$x]) && $x) {
901 $qry_orwhere .= ' ' . strtoupper($curAndOrCol[$last_orwhere]) . ' ';
903 if (!empty($curField[$x]) && !empty($
{'curOr' . $y}[$x])) {
904 $qry_orwhere .= '(' . $curField[$x]
906 . $
{'curOr' . $y}[$x]
912 if ($criteria_cnt > 1) {
913 $qry_orwhere = '(' . $qry_orwhere . ')';
915 if (!empty($qry_orwhere)) {
917 . strtoupper(isset($curAndOrRow[$y]) ?
$curAndOrRow[$y] . ' ' : '')
922 if (!empty($qry_where) && $qry_where != '()') {
923 echo 'WHERE ' . htmlspecialchars($qry_where) . "\n";
929 if (!isset($qry_orderby)) {
932 for ($x = 0; $x < $col; $x++
) {
933 if ($last_orderby && $x && !empty($curField[$x]) && !empty($curSort[$x])) {
934 $qry_orderby .= ', ';
936 if (!empty($curField[$x]) && !empty($curSort[$x])) {
937 // if they have chosen all fields using the * selector,
938 // then sorting is not available
939 // Fix for Bug #570698
940 if (substr($curField[$x], -2) != '.*') {
941 $qry_orderby .= $curField[$x] . ' ' . $curSort[$x];
946 if (!empty($qry_orderby)) {
947 echo 'ORDER BY ' . htmlspecialchars($qry_orderby) . "\n";
952 <fieldset
class="tblFooters">
953 <input type
="submit" name
="submit_sql" value
="<?php echo __('Submit Query'); ?>" />
961 * Displays the footer
963 require './libraries/footer.inc.php';