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 -> (maybe) execute it
23 $message_to_display = false;
24 if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
25 if (! preg_match('@^SELECT@i', $sql_query)) {
26 $message_to_display = true;
35 require './libraries/db_common.inc.php';
36 $url_query .= '&goto=db_qbe.php';
37 $url_params['goto'] = 'db_qbe.php';
38 require './libraries/db_info.inc.php';
40 if ($message_to_display) {
41 PMA_Message
::error(__('You have to choose at least one column to display'))->display();
43 unset($message_to_display);
46 * Initialize some variables
48 $col_cnt = PMA_ifSetOr($_REQUEST['col_cnt'], 3, 'numeric');
49 $add_col = PMA_ifSetOr($_REQUEST['add_col'], 0, 'numeric');
50 $add_row = PMA_ifSetOr($_REQUEST['add_row'], 0, 'numeric');
52 $rows = PMA_ifSetOr($_REQUEST['rows'], 0, 'numeric');
53 $ins_col = PMA_ifSetOr($_REQUEST['ins_col'], null, 'array');
54 $del_col = PMA_ifSetOr($_REQUEST['del_col'], null, 'array');
56 $prev_criteria = isset($_REQUEST['prev_criteria'])
57 ?
$_REQUEST['prev_criteria']
59 $criteria = isset($_REQUEST['criteria'])
60 ?
$_REQUEST['criteria']
61 : array_fill(0, $col_cnt, '');
63 $ins_row = isset($_REQUEST['ins_row'])
64 ?
$_REQUEST['ins_row']
65 : array_fill(0, $col_cnt, '');
66 $del_row = isset($_REQUEST['del_row'])
67 ?
$_REQUEST['del_row']
68 : array_fill(0, $col_cnt, '');
69 $and_or_row = isset($_REQUEST['and_or_row'])
70 ?
$_REQUEST['and_or_row']
71 : array_fill(0, $col_cnt, '');
72 $and_or_col = isset($_REQUEST['and_or_col'])
73 ?
$_REQUEST['and_or_col']
74 : array_fill(0, $col_cnt, '');
77 $form_column_width = 12;
78 $col = max($col_cnt +
$add_col, 0);
79 $row = max($rows +
$add_row, 0);
82 // The tables list sent by a previously submitted form
83 if (PMA_isValid($_REQUEST['TableList'], 'array')) {
84 foreach ($_REQUEST['TableList'] as $each_table) {
85 $tbl_names[$each_table] = ' selected="selected"';
90 // this was a work in progress, deactivated for now
91 //$columns = PMA_DBI_get_columns_full($GLOBALS['db']);
92 //$tables = PMA_DBI_get_columns_full($GLOBALS['db']);
98 $tbl_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
99 $tbl_result_cnt = PMA_DBI_num_rows($tbl_result);
100 if (0 == $tbl_result_cnt) {
101 PMA_Message
::error(__('No tables found in database.'))->display();
102 require './libraries/footer.inc.php';
106 // The tables list gets from MySQL
107 while (list($tbl) = PMA_DBI_fetch_row($tbl_result)) {
108 $fld_results = PMA_DBI_get_fields($db, $tbl);
110 if (empty($tbl_names[$tbl]) && !empty($_REQUEST['TableList'])) {
111 $tbl_names[$tbl] = '';
113 $tbl_names[$tbl] = ' selected="selected"';
116 // The fields list per selected tables
117 if ($tbl_names[$tbl] == ' selected="selected"') {
118 $each_table = PMA_backquote($tbl);
119 $fld[] = $each_table . '.*';
120 foreach ($fld_results as $each_field) {
121 $each_field = $each_table . '.' . PMA_backquote($each_field['Field']);
122 $fld[] = $each_field;
124 // increase the width if necessary
125 $form_column_width = max(strlen($each_field), $form_column_width);
129 PMA_DBI_free_result($tbl_result);
131 // largest width found
132 $realwidth = $form_column_width . 'ex';
136 * Displays the Query by example form
140 * Enter description here...
142 * @param array $columns
143 * @param integer $column_number
144 * @param string $selected
146 function showColumnSelectCell($columns, $column_number, $selected = '')
150 <select name
="Field[<?php echo $column_number; ?>]" size
="1">
151 <option value
=""> 
;</option
>
153 foreach ($columns as $column) {
154 if ($column === $selected) {
155 $sel = ' selected="selected"';
159 echo '<option value="' . htmlspecialchars($column) . '"' . $sel . '>'
160 . str_replace(' ', ' ', htmlspecialchars($column)) . '</option>' . "\n";
169 <?php
if (!empty($tab_designer['link'])) {
170 $tab_designer['link'] = htmlentities($tab_designer['link']);
171 $tab_designer['link'] = $tab_designer['link'] . PMA_generate_common_url($url_params);
172 if (! empty($tab_designer['args'])) {
173 foreach ($tab_designer['args'] as $param => $value) {
174 $tab_designer['link'] .= PMA_get_arg_separator('html') . urlencode($param) . '='
179 if (! empty($tab['fragment'])) {
180 $tab['link'] .= $tab['fragment'];
182 if (isset($tab_designer['link'])) {
184 <div id
="visual_builder_anchor" class="notice hide">
185 <span id
="footnote_1">
186 <?php
echo __('Switch to') . ' <a href="' . $tab_designer['link'] . PMA_get_arg_separator('html') . 'query=1">' . __('visual builder') . '</a>'; ?
>
192 <form action
="db_qbe.php" method
="post">
194 <table
class="data" style
="width: 100%;">
195 <tr
class="odd noclick">
196 <th
><?php
echo __('Column'); ?
>:</th
>
199 for ($x = 0; $x < $col; $x++
) {
200 if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {
201 showColumnSelectCell($fld, $z);
205 if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
210 if (isset($Field[$x])) {
211 $selected = $Field[$x];
212 $curField[$z] = $Field[$x];
214 showColumnSelectCell($fld, $z, $selected);
221 <tr
class="even noclick">
222 <th
><?php
echo __('Sort'); ?
>:</th
>
225 for ($x = 0; $x < $col; $x++
) {
226 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
229 <select style
="width: <?php echo $realwidth; ?>" name
="Sort[<?php echo $z; ?>]" size
="1">
230 <option value
=""> 
;</option
>
231 <option value
="ASC"><?php
echo __('Ascending'); ?
></option
>
232 <option value
="DESC"><?php
echo __('Descending'); ?
></option
>
240 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
245 <select style
="width: <?php echo $realwidth; ?>" name
="Sort[<?php echo $z; ?>]" size
="1">
246 <option value
=""> 
;</option
>
250 // If they have chosen all fields using the * selector,
251 // then sorting is not available
252 // Fix for Bug #570698
253 if (isset($Sort[$x]) && isset($Field[$x])
254 && substr($Field[$x], -2) == '.*') {
258 if (isset($Sort[$x]) && $Sort[$x] == 'ASC') {
259 $curSort[$z] = $Sort[$x];
260 $sel = ' selected="selected"';
265 echo '<option value="ASC"' . $sel . '>' . __('Ascending') . '</option>' . "\n";
266 if (isset($Sort[$x]) && $Sort[$x] == 'DESC') {
267 $curSort[$z] = $Sort[$x];
268 $sel = ' selected="selected"';
273 echo '<option value="DESC"' . $sel . '>' . __('Descending') . '</option>' . "\n";
285 <tr
class="odd noclick">
286 <th
><?php
echo __('Show'); ?
>:</th
>
289 for ($x = 0; $x < $col; $x++
) {
290 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
293 <input type
="checkbox" name
="Show[<?php echo $z; ?>]" />
300 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
303 if (isset($Show[$x])) {
304 $checked = ' checked="checked"';
305 $curShow[$z] = $Show[$x];
311 <input type
="checkbox" name
="Show[<?php echo $z; ?>]"<?php
echo $checked; ?
> />
320 <!-- Criteria row
-->
321 <tr
class="even noclick">
322 <th
><?php
echo __('Criteria'); ?
>:</th
>
325 for ($x = 0; $x < $col; $x++
) {
326 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
329 <input type
="text" name
="criteria[<?php echo $z; ?>]" value
="" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
336 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
339 if (isset($criteria[$x])) {
340 $tmp_criteria = $criteria[$x];
342 if ((empty($prev_criteria) ||
!isset($prev_criteria[$x]))
343 ||
$prev_criteria[$x] != htmlspecialchars($tmp_criteria)) {
344 $curCriteria[$z] = $tmp_criteria;
346 $curCriteria[$z] = $prev_criteria[$x];
350 <input type
="hidden" name
="prev_criteria[<?php echo $z; ?>]" value
="<?php echo htmlspecialchars($curCriteria[$z]); ?>" />
351 <input type
="text" name
="criteria[<?php echo $z; ?>]" value
="<?php echo htmlspecialchars($tmp_criteria); ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
360 <!-- And/Or columns
and rows
-->
364 for ($y = 0; $y <= $row; $y++
) {
365 if (isset($ins_row[$y]) && $ins_row[$y] == 'on') {
366 $chk['or'] = ' checked="checked"';
369 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
370 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
371 <!-- Row controls
-->
372 <table cellpadding
="0" cellspacing
="0" border
="0">
374 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
375 <small
><?php
echo __('Ins'); ?
>:</small
>
376 <input type
="checkbox" name
="ins_row[<?php echo $w; ?>]" />
378 <td align
="<?php echo $cell_align_right; ?>">
379 <strong
><?php
echo __('And'); ?
>:</strong
>
382 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
387 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
388 <small
><?php
echo __('Del'); ?
>:</small
>
389 <input type
="checkbox" name
="del_row[<?php echo $w; ?>]" />
391 <td align
="<?php echo $cell_align_right; ?>">
392 <strong
><?php
echo __('Or'); ?
>:</strong
>
395 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
403 for ($x = 0; $x < $col; $x++
) {
404 if (isset($ins_col[$x]) && $ins_col[$x] == 'on') {
406 $or = 'Or' . $w . '[' . $z . ']';
409 <input type
="text" name
="Or<?php echo $or; ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
414 if (isset($del_col[$x]) && $del_col[$x] == 'on') {
419 $or = 'Or' . $w . '[' . $z . ']';
422 <input type
="text" name
="Or<?php echo $or; ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
432 $odd_row =! $odd_row;
435 if (isset($del_row[$y]) && $del_row[$y] == 'on') {
439 if (isset($and_or_row[$y])) {
440 $curAndOrRow[$w] = $and_or_row[$y];
442 if (isset($and_or_row[$y]) && $and_or_row[$y] == 'and') {
443 $chk['and'] = ' checked="checked"';
446 $chk['or'] = ' checked="checked"';
451 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; ?> noclick">
452 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
453 <!-- Row controls
-->
454 <table border
="0" cellpadding
="0" cellspacing
="0">
456 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
457 <small
><?php
echo __('Ins'); ?
>:</small
>
458 <input type
="checkbox" name
="ins_row[<?php echo $w; ?>]" />
460 <td align
="<?php echo $cell_align_right; ?>">
461 <strong
><?php
echo __('And'); ?
>:</strong
>
464 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
468 <td align
="<?php echo $cell_align_right; ?>" nowrap
="nowrap">
469 <small
><?php
echo __('Del'); ?
>:</small
>
470 <input type
="checkbox" name
="del_row[<?php echo $w; ?>]" />
472 <td align
="<?php echo $cell_align_right; ?>">
473 <strong
><?php
echo __('Or'); ?
>:</strong
>
476 <input type
="radio" name
="and_or_row[<?php echo $w; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
483 for ($x = 0; $x < $col; $x++
) {
484 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
486 $or = 'Or' . $w . '[' . $z . ']';
489 <input type
="text" name
="Or<?php echo $or; ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
494 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
500 if (!isset($
{$or})) {
503 if (!empty($
{$or}) && isset($
{$or}[$x])) {
504 $tmp_or = $
{$or}[$x];
510 <input type
="text" name
="Or<?php echo $w . '[' . $z . ']'; ?>" value
="<?php echo htmlspecialchars($tmp_or); ?>" class="textfield" style
="width: <?php echo $realwidth; ?>" size
="20" />
513 if (!empty($
{$or}) && isset($
{$or}[$x])) {
514 $
{'cur' . $or}[$z] = $
{$or}[$x];
524 $odd_row =! $odd_row;
527 <!-- Modify columns
-->
528 <tr
class="even noclick">
529 <th
><?php
echo __('Modify'); ?
>:</th
>
532 for ($x = 0; $x < $col; $x++
) {
533 if (!empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') {
534 $curAndOrCol[$z] = $and_or_col[$y];
535 if ($and_or_col[$z] == 'or') {
536 $chk['or'] = ' checked="checked"';
539 $chk['and'] = ' checked="checked"';
544 <strong
><?php
echo __('Or'); ?
>:</strong
>
545 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
546  
; 
;<strong
><?php
echo __('And'); ?
>:</strong
>
547 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
549 <?php
echo __('Ins') . "\n"; ?
>
550 <input type
="checkbox" name
="ins_col[<?php echo $z; ?>]" />
551  
; 
;<?php
echo __('Del') . "\n"; ?
>
552 <input type
="checkbox" name
="del_col[<?php echo $z; ?>]" />
559 if (!empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') {
563 if (isset($and_or_col[$y])) {
564 $curAndOrCol[$z] = $and_or_col[$y];
566 if (isset($and_or_col[$z]) && $and_or_col[$z] == 'or') {
567 $chk['or'] = ' checked="checked"';
570 $chk['and'] = ' checked="checked"';
575 <strong
><?php
echo __('Or'); ?
>:</strong
>
576 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="or"<?php
echo $chk['or']; ?
> />
577  
; 
;<strong
><?php
echo __('And'); ?
>:</strong
>
578 <input type
="radio" name
="and_or_col[<?php echo $z; ?>]" value
="and"<?php
echo $chk['and']; ?
> />
580 <?php
echo __('Ins') . "\n"; ?
>
581 <input type
="checkbox" name
="ins_col[<?php echo $z; ?>]" />
582  
; 
;<?php
echo __('Del') . "\n"; ?
>
583 <input type
="checkbox" name
="del_col[<?php echo $z; ?>]" />
593 <!-- Other controls
-->
596 $url_params['db'] = $db;
597 $url_params['col_cnt'] = $z;
598 $url_params['rows'] = $w;
599 echo PMA_generate_common_hidden_inputs($url_params);
602 <fieldset
class="tblFooters">
603 <table border
="0" cellpadding
="2" cellspacing
="1">
606 <?php
echo __('Add/Delete criteria rows'); ?
>:
607 <select size
="1" name
="add_row">
608 <option value
="-3">-3</option
>
609 <option value
="-2">-2</option
>
610 <option value
="-1">-1</option
>
611 <option value
="0" selected
="selected">0</option
>
612 <option value
="1">1</option
>
613 <option value
="2">2</option
>
614 <option value
="3">3</option
>
617 <td width
="10"> 
;</td
>
618 <td nowrap
="nowrap"><?php
echo __('Add/Delete columns'); ?
>:
619 <select size
="1" name
="add_col">
620 <option value
="-3">-3</option
>
621 <option value
="-2">-2</option
>
622 <option value
="-1">-1</option
>
623 <option value
="0" selected
="selected">0</option
>
624 <option value
="1">1</option
>
625 <option value
="2">2</option
>
626 <option value
="3">3</option
>
629 <td width
="10"> 
;</td
>
630 <!-- Generates a query
-->
631 <td
><input type
="submit" name
="modify" value
="<?php echo __('Update Query'); ?>" /></td
>
639 <legend
><?php
echo __('Use Tables'); ?
></legend
>
642 $numTableListOptions = 0;
643 foreach ($tbl_names as $key => $val) {
645 $options .= '<option value="' . htmlspecialchars($key) . '"' . $val . '>'
646 . str_replace(' ', ' ', htmlspecialchars($key)) . '</option>' . "\n";
647 $numTableListOptions++
;
650 <select name
="TableList[]" multiple
="multiple" id
="listTable"
651 size
="<?php echo ($numTableListOptions > 30) ? '15' : '7'; ?>">
652 <?php
echo $options; ?
>
655 <fieldset
class="tblFooters">
656 <input type
="submit" name
="modify" value
="<?php echo __('Update Query'); ?>" />
659 <td width
="20"> 
;</td
>
662 <legend
><?php
echo sprintf(__('SQL query on database <b>%s</b>:'), PMA_getDbLink($db)); ?
>
664 <textarea cols
="80" name
="sql_query" id
="textSqlquery"
665 rows
="<?php echo ($numTableListOptions > 30) ? '15' : '7'; ?>"
666 dir
="<?php echo $text_dir; ?>">
670 if (!isset($qry_select)) {
673 for ($x = 0; $x < $col; $x++
) {
674 if (!empty($curField[$x]) && isset($curShow[$x]) && $curShow[$x] == 'on') {
678 $qry_select .= $curField[$x];
682 if (!empty($qry_select)) {
683 echo 'SELECT ' . htmlspecialchars($qry_select) . "\n";
688 // Create LEFT JOINS out of Relations
689 // Code originally by Mike Beck <mike.beck@ibmiller.de>
690 // If we can use Relations we could make some left joins.
691 // First find out if relations are available in this database.
693 // First we need the really needed Tables - those in TableList might still be
695 if (isset($Field) && count($Field) > 0) {
696 // Initialize some variables
702 $col_where = array();
705 // We only start this if we have fields, otherwise it would be dumb
706 foreach ($Field as $value) {
707 $parts = explode('.', $value);
708 if (!empty($parts[0]) && !empty($parts[1])) {
709 $tab_raw = $parts[0];
710 $tab = str_replace('`', '', $tab_raw);
711 $tab_all[$tab] = $tab;
713 $col_raw = $parts[1];
714 $col_all[] = $tab . '.' . str_replace('`', '', $col_raw);
718 // Check 'where' clauses
719 if ($cfgRelation['relwork'] && count($tab_all) > 0) {
720 // Now we need all tables that we have in the where clause
721 $crit_cnt = count($criteria);
722 for ($x = 0; $x < $crit_cnt; $x++
) {
723 $curr_tab = explode('.', $Field[$x]);
724 if (!empty($curr_tab[0]) && !empty($curr_tab[1])) {
725 $tab_raw = $curr_tab[0];
726 $tab = str_replace('`', '', $tab_raw);
728 $col_raw = $curr_tab[1];
729 $col1 = str_replace('`', '', $col_raw);
730 $col1 = $tab . '.' . $col1;
731 // Now we know that our array has the same numbers as $criteria
732 // we can check which of our columns has a where clause
733 if (!empty($criteria[$x])) {
734 if (substr($criteria[$x], 0, 1) == '=' ||
stristr($criteria[$x], 'is')) {
735 $col_where[$col] = $col1;
736 $tab_wher[$tab] = $tab;
742 // Cleans temp vars w/o further use
747 if (count($tab_wher) == 1) {
748 // If there is exactly one column that has a decent where-clause
749 // we will just use this
750 $master = key($tab_wher);
752 // Now let's find out which of the tables has an index
753 // (When the control user is the same as the normal user
754 // because he is using one of his databases as pmadb,
755 // the last db selected is not always the one where we need to work)
756 PMA_DBI_select_db($db);
758 foreach ($tab_all as $tab) {
759 $ind_rs = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($tab) . ';');
760 while ($ind = PMA_DBI_fetch_assoc($ind_rs)) {
761 $col1 = $tab . '.' . $ind['Column_name'];
762 if (isset($col_all[$col1])) {
763 if ($ind['non_unique'] == 0) {
764 if (isset($col_where[$col1])) {
765 $col_unique[$col1] = 'Y';
767 $col_unique[$col1] = 'N';
770 if (isset($col_where[$col1])) {
771 $col_index[$col1] = 'Y';
773 $col_index[$col1] = 'N';
777 } // end while (each col of tab)
778 } // end while (each tab)
779 // now we want to find the best.
780 if (isset($col_unique) && count($col_unique) > 0) {
781 $col_cand = $col_unique;
783 } elseif (isset($col_index) && count($col_index) > 0) {
784 $col_cand = $col_index;
786 } elseif (isset($col_where) && count($col_where) > 0) {
787 $col_cand = $tab_wher;
790 $col_cand = $tab_all;
794 // If we came up with $col_unique (very good) or $col_index (still
795 // good) as $col_cand we want to check if we have any 'Y' there
796 // (that would mean that they were also found in the whereclauses
797 // which would be great). if yes, we take only those
798 if ($needsort == 1) {
799 foreach ($col_cand as $col => $is_where) {
800 $tab = explode('.', $col);
802 if ($is_where == 'Y') {
810 // Candidates restricted in index+where
813 // None of the candidates where in a where-clause
817 // If our array of candidates has more than one member we'll just
818 // find the smallest table.
819 // Of course the actual query would be faster if we check for
820 // the Criteria which gives the smallest result set in its table,
821 // but it would take too much time to check this
822 if (count($col_cand) > 1) {
823 // Of course we only want to check each table once
824 $checked_tables = $col_cand;
825 foreach ($col_cand as $tab) {
826 if ($checked_tables[$tab] != 1) {
827 $tsize[$tab] = PMA_Table
::countRecords($db, $tab, false);
828 $checked_tables[$tab] = 1;
830 $csize[$tab] = $tsize[$tab];
834 $master = key($csize); // Smallest
837 $master = current($col_cand); // Only one single candidate
839 } // end if (exactly one where clause)
841 $tab_left = $tab_all;
842 unset($tab_left[$master]);
843 $tab_know[$master] = $master;
847 while (count($tab_left) > 0) {
849 PMA_getRelatives('master');
851 PMA_getRelatives('foreign');
856 foreach ($tab_left as $tab) {
857 $emerg .= ', ' . PMA_backquote($tab);
858 unset($tab_left[$tab]);
862 $qry_from = PMA_backquote($master) . $emerg . $fromclause;
863 } // end if ($cfgRelation['relwork'] && count($tab_all) > 0)
865 } // end count($Field) > 0
867 // In case relations are not defined, just generate the FROM clause
868 // from the list of tables, however we don't generate any JOIN
870 if (empty($qry_from) && isset($tab_all)) {
871 $qry_from = implode(', ', $tab_all);
873 // Now let's see what we got
874 if (!empty($qry_from)) {
875 echo 'FROM ' . htmlspecialchars($qry_from) . "\n";
881 for ($x = 0; $x < $col; $x++
) {
882 if (!empty($curField[$x]) && !empty($curCriteria[$x]) && $x && isset($last_where) && isset($curAndOrCol)) {
883 $qry_where .= ' ' . strtoupper($curAndOrCol[$last_where]) . ' ';
885 if (!empty($curField[$x]) && !empty($curCriteria[$x])) {
886 $qry_where .= '(' . $curField[$x] . ' ' . $curCriteria[$x] . ')';
891 if ($criteria_cnt > 1) {
892 $qry_where = '(' . $qry_where . ')';
894 // OR rows ${'cur' . $or}[$x]
895 if (!isset($curAndOrRow)) {
896 $curAndOrRow = array();
898 for ($y = 0; $y <= $row; $y++
) {
902 for ($x = 0; $x < $col; $x++
) {
903 if (!empty($curField[$x]) && !empty($
{'curOr' . $y}[$x]) && $x) {
904 $qry_orwhere .= ' ' . strtoupper($curAndOrCol[$last_orwhere]) . ' ';
906 if (!empty($curField[$x]) && !empty($
{'curOr' . $y}[$x])) {
907 $qry_orwhere .= '(' . $curField[$x]
909 . $
{'curOr' . $y}[$x]
915 if ($criteria_cnt > 1) {
916 $qry_orwhere = '(' . $qry_orwhere . ')';
918 if (!empty($qry_orwhere)) {
920 . strtoupper(isset($curAndOrRow[$y]) ?
$curAndOrRow[$y] . ' ' : '')
925 if (!empty($qry_where) && $qry_where != '()') {
926 echo 'WHERE ' . htmlspecialchars($qry_where) . "\n";
932 if (!isset($qry_orderby)) {
935 for ($x = 0; $x < $col; $x++
) {
936 if ($last_orderby && $x && !empty($curField[$x]) && !empty($curSort[$x])) {
937 $qry_orderby .= ', ';
939 if (!empty($curField[$x]) && !empty($curSort[$x])) {
940 // if they have chosen all fields using the * selector,
941 // then sorting is not available
942 // Fix for Bug #570698
943 if (substr($curField[$x], -2) != '.*') {
944 $qry_orderby .= $curField[$x] . ' ' . $curSort[$x];
949 if (!empty($qry_orderby)) {
950 echo 'ORDER BY ' . htmlspecialchars($qry_orderby) . "\n";
955 <fieldset
class="tblFooters">
956 <input type
="submit" name
="submit_sql" value
="<?php echo __('Submit Query'); ?>" />
964 * Displays the footer
966 require './libraries/footer.inc.php';