diff --git a/htdocs/sql/tbl_select.php b/htdocs/sql/tbl_select.php new file mode 100755 --- /dev/null +++ b/htdocs/sql/tbl_select.php @@ -0,0 +1,440 @@ +'; + + if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') { + $titles['Browse'] .= $strBrowseForeignValues; + } +} else { + $titles['Browse'] = $strBrowseForeignValues; +} + +/** + * Not selection yet required -> displays the selection form + */ +if (!isset($param) || $param[0] == '') { + // Gets some core libraries + require_once './libraries/tbl_common.php'; + //$err_url = 'tbl_select.php' . $err_url; + $url_query .= '&goto=tbl_select.php&back=tbl_select.php'; + + /** + * Gets tables informations + */ + require_once './libraries/tbl_info.inc.php'; + + /** + * Displays top menu links + */ + require_once './libraries/tbl_links.inc.php'; + + if (!isset($goto)) { + $goto = $GLOBALS['cfg']['DefaultTabTable']; + } + // Defines the url to return to in case of error in the next sql statement + $err_url = $goto . '?' . PMA_generate_common_url($db, $table); + + // Gets the list and number of fields + $result = PMA_DBI_query('SHOW' . (PMA_MYSQL_INT_VERSION >= 40100 ? ' FULL' : '') . ' FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE); + $fields_cnt = PMA_DBI_num_rows($result); + // rabue: we'd better ensure, that all arrays are empty. + $fields_list = $fields_null = $fields_type = $fields_collation = array(); + while ($row = PMA_DBI_fetch_assoc($result)) { + $fields_list[] = $row['Field']; + $type = $row['Type']; + // reformat mysql query output - staybyte - 9. June 2001 + if (strncasecmp($type, 'set', 3) == 0 + || strncasecmp($type, 'enum', 4) == 0) { + $type = str_replace(',', ', ', $type); + } else { + + // strip the "BINARY" attribute, except if we find "BINARY(" because + // this would be a BINARY or VARBINARY field type + if (!preg_match('@BINARY[\(]@i', $type)) { + $type = preg_replace('@BINARY@i', '', $type); + } + $type = preg_replace('@ZEROFILL@i', '', $type); + $type = preg_replace('@UNSIGNED@i', '', $type); + + $type = strtolower($type); + } + if (empty($type)) { + $type = ' '; + } + $fields_null[] = $row['Null']; + $fields_type[] = $type; + $fields_collation[] = PMA_MYSQL_INT_VERSION >= 40100 && !empty($row['Collation']) && $row['Collation'] != 'NULL' + ? $row['Collation'] + : ''; + } // end while + PMA_DBI_free_result($result); + unset($result, $type); + + // + // retrieve keys into foreign fields, if any + $cfgRelation = PMA_getRelationsParam(); + // check also foreigners even if relwork is FALSE (to get + // foreign keys from innodb) + //$foreigners = ($cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE); + $foreigners = PMA_getForeigners($db, $table); + ?> + +
+ + + + + +
+ +
+ +
+ ' . $strOr . ' ' . $strDoAQuery; ?> + + + + + = 40100 ? '' . "\n" : ''; ?> + + + + + + + + + + + + = 40100 ? '' . "\n" : ''; ?> + + + + + +
' . $strCollation . '
' + . $fields_collation[$i] . ' + + + $field = $fields_list[$i]; + + // do not use require_once here + require './libraries/get_foreign.lib.php'; + + // we got a bug report: in some cases, even if $disp is true, + // there are no rows, so we add a fetch_array + + if ($foreigners && isset($foreigners[$field]) && isset($disp_row) && is_array($disp_row)) { + // f o r e i g n k e y s + echo ' ' . "\n"; + } elseif (isset($foreign_link) && $foreign_link == true) { + ?> + + + ' . "\n"; + for ($j = 0; $j < $cnt_enum_value; $j++) { + echo ' '; + } // end for + echo ' ' . "\n"; + } else { + // o t h e r c a s e s + echo ' ' . "\n"; + }; + $type = $fields_type[$i]; + if ($type == 'date' || $type == 'datetime' || substr($type, 0, 9) == 'timestamp') { + ?> + + + + + +
+
+
+ + +
+
+ do the work + */ +else { + // Builds the query + + $sql_query = 'SELECT ' . (isset($distinct) ? 'DISTINCT ' : ''); + + // if all fields were selected to display, we do a SELECT * + // (more efficient and this helps prevent a problem in IE + // if one of the rows is edited and we come back to the Select results) + + if (count($param) == $max_number_of_fields) { + $sql_query .= '* '; + } else { + $param = PMA_backquote($param); + $sql_query .= implode(', ', $param); + unset($param); + } // end if + + $sql_query .= ' FROM ' . PMA_backquote($table); + + // The where clause + if (trim($where) != '') { + $sql_query .= ' WHERE ' . $where; + } else { + $w = $charsets = array(); + $cnt_func = count($func); + reset($func); + while (list($i, $func_type) = each($func)) { + if (PMA_MYSQL_INT_VERSION >= 40100) { + list($charsets[$i]) = explode('_', $collations[$i]); + } + if (@$GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) { + $fields[$i] = ''; + $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type; + + } elseif (strncasecmp($types[$i], 'enum', 4) == 0) { + if (!empty($fields[$i])) { + if (!is_array($fields[$i])) { + $fields[$i] = explode(',', $fields[$i]); + } + $enum_selected_count = count($fields[$i]); + if ($func_type == '=' && $enum_selected_count > 1) { + $func_type = $func[$i] = 'IN'; + $parens_open = '('; + $parens_close = ')'; + + } elseif ($func_type == '!=' && $enum_selected_count > 1) { + $func_type = $func[$i] = 'NOT IN'; + $parens_open = '('; + $parens_close = ')'; + + } else { + $parens_open = ''; + $parens_close = ''; + } + $enum_where = '\'' . PMA_sqlAddslashes($fields[$i][0]) . '\''; + if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) { + $enum_where = 'CONVERT(_utf8 ' . $enum_where . ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i]; + } + for ($e = 1; $e < $enum_selected_count; $e++) { + $enum_where .= ', '; + $tmp_literal = '\'' . PMA_sqlAddslashes($fields[$i][$e]) . '\''; + if (PMA_MYSQL_INT_VERSION >= 40100 && $charsets[$i] != $charset_connection) { + $tmp_literal = 'CONVERT(_utf8 ' . $tmp_literal . ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i]; + } + $enum_where .= $tmp_literal; + unset($tmp_literal); + } + + $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type . ' ' . $parens_open . $enum_where . $parens_close; + } + + } elseif ($fields[$i] != '') { + // For these types we quote the value. Even if it's another type (like INT), + // for a LIKE we always quote the value. MySQL converts strings to numbers + // and numbers to strings as necessary during the comparison + if (preg_match('@char|binary|blob|text|set|date|time|year@i', $types[$i]) || strpos(' ' . $func_type, 'LIKE')) { + $quot = '\''; + } else { + $quot = ''; + } + + // Make query independant from the selected connection charset. + // But if the field's type is VARBINARY, it has no charset + // and $charsets[$i] is empty, so we cannot generate a CONVERT + + if (PMA_MYSQL_INT_VERSION >= 40101 && !empty($charsets[$i]) && $charsets[$i] != $charset_connection && preg_match('@char|binary|blob|text|set@i', $types[$i])) { + $prefix = 'CONVERT(_utf8 '; + $suffix = ' USING ' . $charsets[$i] . ') COLLATE ' . $collations[$i]; + } else { + $prefix = $suffix = ''; + } + + // LIKE %...% + if ($func_type == 'LIKE %...%') { + $func_type = 'LIKE'; + $fields[$i] = '%' . $fields[$i] . '%'; + } + $w[] = PMA_backquote(urldecode($names[$i])) . ' ' . $func_type . ' ' . $prefix . $quot . PMA_sqlAddslashes($fields[$i]) . $quot . $suffix; + + } // end if + } // end for + + if ($w) { + $sql_query .= ' WHERE ' . implode(' AND ', $w); + } + } // end if + + if ($orderField != '--nil--') { + $sql_query .= ' ORDER BY ' . PMA_backquote(urldecode($orderField)) . ' ' . $order; + } // end if + include './sql.php'; +} + +?>