Skip to content

Commit

Permalink
Replace all SHOW FIELDS calls with PMA_DBI_get_columns() or PMA_DBI_g…
Browse files Browse the repository at this point in the history
…et_columns_sql()

Fix PMA_DBI_get_columns() in Drizzle when $full == false
  • Loading branch information
piotrp committed Jun 16, 2011
1 parent d607fa3 commit 12f70e8
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 43 deletions.
4 changes: 2 additions & 2 deletions db_datadict.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@

if (PMA_MYSQL_INT_VERSION < 50025) {
// We need this to correctly learn if a TIMESTAMP is NOT NULL, since
// SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
// SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
// and SHOW CREATE TABLE says NOT NULL
// http://bugs.mysql.com/20910.

Expand Down Expand Up @@ -233,7 +233,7 @@
&& ! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
&& $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
&& $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
// here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
// here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
// NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
// the latter.
/**
Expand Down
7 changes: 3 additions & 4 deletions db_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ function PMA_getSearchSqls($table, $field, $search_str, $search_option)
$sqlstr_delete = 'DELETE';

// Fields to select
$tblfields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($GLOBALS['db']),
null, 'Field');
$tblfields = PMA_DBI_get_columns($GLOBALS['db'], $table);

// Table to use
$sqlstr_from = ' FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table);
Expand All @@ -179,8 +178,8 @@ function PMA_getSearchSqls($table, $field, $search_str, $search_option)

$thefieldlikevalue = array();
foreach ($tblfields as $tblfield) {
if (! isset($field) || strlen($field) == 0 || $tblfield == $field) {
$thefieldlikevalue[] = 'CONVERT(' . PMA_backquote($tblfield) . ' USING utf8)'
if (! isset($field) || strlen($field) == 0 || $tblfield['Field'] == $field) {
$thefieldlikevalue[] = 'CONVERT(' . PMA_backquote($tblfield['Field']) . ' USING utf8)'
. ' ' . $like_or_regex . ' '
. "'" . $automatic_wildcard
. $search_word
Expand Down
34 changes: 26 additions & 8 deletions libraries/database_interface.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ function PMA_DBI_get_columns_full($database = null, $table = null,
// for PMA bc:
// `[SCHEMA_FIELD_NAME]` AS `[SHOW_FULL_COLUMNS_FIELD_NAME]`
if (PMA_DRIZZLE) {
$sql = "SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME,
$sql = "SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME,
column_name AS `Field`,
(CASE
WHEN character_maximum_length > 0
Expand Down Expand Up @@ -952,15 +952,15 @@ function PMA_DBI_get_columns_full($database = null, $table = null,
}

/**
* array PMA_DBI_get_columns(string $database, string $table, bool $full = false, mysql db link $link = null)
* Returns SQL query for fetching columns for a table
*
* @param string $database name of database
* @param string $table name of table to retrieve columns from
* @param string $column name of column, null to show all columns
* @param boolean $full whether to return full info or only column names
* @param mixed $link mysql link resource
* @return array column names
*/
function PMA_DBI_get_columns($database, $table, $full = false, $link = null)
function PMA_DBI_get_columns_sql($database, $table, $column = null, $full = false)
{
if (PMA_DRIZZLE) {
// `Key` column isn't correctly calculated, the only value that works is PRI
Expand All @@ -987,18 +987,36 @@ function PMA_DBI_get_columns($database, $table, $full = false, $link = null)
(CASE
WHEN is_auto_increment THEN 'auto_increment'
WHEN column_default_update THEN 'on update ' || column_default_update
ELSE '' END) AS `Extra`,
" . ($full ? "
ELSE '' END) AS `Extra`
" . ($full ? " ,
NULL AS `Privileges`,
column_comment AS `Comment`" : '') . "
FROM data_dictionary.columns
WHERE table_schema = '" . PMA_sqlAddslashes($database) . "'
AND table_name = '" . PMA_sqlAddslashes($table) . "'
ORDER BY ordinal_position";
" . ($column ? "
AND column_name = '" . PMA_sqlAddslashes($column) . "'" : '');
// ORDER BY ordinal_position
} else {
$sql = 'SHOW ' . ($full ? 'FULL' : '') . ' COLUMNS
FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table);
FROM ' . PMA_backquote($database) . '.' . PMA_backquote($table)
. ($column ? "LIKE '" . PMA_sqlAddslashes($column) . "'" : '');
}
return $sql;
}

/**
* array PMA_DBI_get_columns(string $database, string $table, bool $full = false, mysql db link $link = null)
*
* @param string $database name of database
* @param string $table name of table to retrieve columns from
* @param boolean $full whether to return full info or only column names
* @param mixed $link mysql link resource
* @return array column names
*/
function PMA_DBI_get_columns($database, $table, $full = false, $link = null)
{
$sql = PMA_DBI_get_columns_sql($database, $table, $full);
$fields = PMA_DBI_fetch_result($sql, 'Field', ($full ? null : 'Field'), $link);
if (! is_array($fields) || count($fields) < 1) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion libraries/export/htmlword.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals
* Gets fields properties
*/
PMA_DBI_select_db($db);
$local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
$local_query = PMA_DBI_get_columns_sql($db, $table);
$result = PMA_DBI_query($local_query);
$fields_cnt = PMA_DBI_num_rows($result);

Expand Down
2 changes: 1 addition & 1 deletion libraries/export/latex.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals
* Gets fields properties
*/
PMA_DBI_select_db($db);
$local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
$local_query = PMA_DBI_get_columns_sql($db, $table);
$result = PMA_DBI_query($local_query);
$fields_cnt = PMA_DBI_num_rows($result);

Expand Down
2 changes: 1 addition & 1 deletion libraries/export/odt.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals
* Gets fields properties
*/
PMA_DBI_select_db($db);
$local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
$local_query = PMA_DBI_get_columns_sql($db, $table);
$result = PMA_DBI_query($local_query);
$fields_cnt = PMA_DBI_num_rows($result);

Expand Down
2 changes: 1 addition & 1 deletion libraries/export/texytext.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals
* Gets fields properties
*/
PMA_DBI_select_db($db);
$local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
$local_query = PMA_DBI_get_columns_sql($db, $table);
$result = PMA_DBI_query($local_query);
$fields_cnt = PMA_DBI_num_rows($result);

Expand Down
4 changes: 1 addition & 3 deletions libraries/relation.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ function PMA__getRelationsParam()
$cfgRelation['commwork'] = true;

if ($GLOBALS['cfg']['Server']['verbose_check']) {
$mime_query = 'SHOW FIELDS FROM '
. PMA_backquote($cfgRelation['db']) . '.'
. PMA_backquote($cfgRelation['column_info']);
$mime_query = PMA_DBI_get_columns_sql($cfgRelation['db'], $cfgRelation['column_info']);
$mime_rs = PMA_query_as_controluser($mime_query, false);

$mime_field_mimetype = false;
Expand Down
4 changes: 2 additions & 2 deletions libraries/schema/Pdf_Relation_Schema.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ public function dataDictionaryDoc($alltables)
$pdf->SetX(10);
$pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']);
// $pdf->Ln(1);
$result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';');
$result = PMA_DBI_query(PMA_DBI_get_columns_sql($db, $table));
while ($row = PMA_DBI_fetch_assoc($result)) {
$pdf->SetX(20);
$field_name = $row['Field'];
Expand Down Expand Up @@ -1187,7 +1187,7 @@ public function dataDictionaryDoc($alltables)
/**
* Gets fields properties
*/
$result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
$result = PMA_DBI_query(PMA_DBI_get_columns_sql($db, $table), null, PMA_DBI_QUERY_STORE);
$fields_cnt = PMA_DBI_num_rows($result);
// Check if we can use Relations
if (!empty($cfgRelation['relation'])) {
Expand Down
4 changes: 1 addition & 3 deletions libraries/schema/User_Schema.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,7 @@ private function _displayScratchboardTables($array_sh_page)
$reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
$reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n";

$local_query = 'SHOW FIELDS FROM '
. PMA_backquote($temp_sh_page['table_name'])
. ' FROM ' . PMA_backquote($db);
$local_query = PMA_DBI_get_columns_sql($db, $temp_sh_page['table_name']);
$fields_rs = PMA_DBI_query($local_query);
unset($local_query);
$fields_cnt = PMA_DBI_num_rows($fields_rs);
Expand Down
4 changes: 2 additions & 2 deletions libraries/tbl_properties.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
if ($row['Null'] == 'YES') {
$row['DefaultType'] = 'NULL';
$row['DefaultValue'] = '';
// SHOW FULL FIELDS does not report the case when there is a DEFAULT value
// SHOW FULL COLUMNS does not report the case when there is a DEFAULT value
// which is empty so we need to use the results of SHOW CREATE TABLE
} elseif (isset($row) && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_value'])) {
$row['DefaultType'] = 'USER_DEFINED';
Expand Down Expand Up @@ -458,7 +458,7 @@
$attribute = $submit_attribute;
}

// here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
// here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
// NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
// the latter.
if (PMA_MYSQL_INT_VERSION < 50025
Expand Down
2 changes: 1 addition & 1 deletion pmd_common.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function get_tab_info()
PMA_DBI_select_db($GLOBALS['db']);
$tab_column = array();
for ($i = 0, $cnt = count($GLOBALS['PMD']["TABLE_NAME"]); $i < $cnt; $i++) {
$fields_rs = PMA_DBI_query('SHOW FULL FIELDS FROM '.PMA_backquote($GLOBALS['PMD']["TABLE_NAME_SMALL"][$i]), NULL, PMA_DBI_QUERY_STORE);
$fields_rs = PMA_DBI_query(PMA_DBI_get_columns_sql($GLOBALS['db'], $GLOBALS['PMD']["TABLE_NAME_SMALL"][$i], true), NULL, PMA_DBI_QUERY_STORE);
$j = 0;
while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
$tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['COLUMN_ID'][$j] = $j;
Expand Down
4 changes: 2 additions & 2 deletions sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
* Logic taken from libraries/display_tbl_lib.php
*/
if(isset($_REQUEST['get_enum_values']) && $_REQUEST['get_enum_values'] == true) {
$field_info_query = 'SHOW FIELDS FROM `' . $db . '`.`' . $table . '` LIKE \'' . $_REQUEST['column'] . '\' ;';
$field_info_query = PMA_DBI_get_columns_sql($db, $table, $_REQUEST['column']);

$field_info_result = PMA_DBI_fetch_result($field_info_query, null, null, null, PMA_DBI_QUERY_STORE);

Expand All @@ -135,7 +135,7 @@
* Find possible values for set fields during inline edit.
*/
if(isset($_REQUEST['get_set_values']) && $_REQUEST['get_set_values'] == true) {
$field_info_query = 'SHOW FIELDS FROM `' . $db . '`.`' . $table . '` LIKE \'' . $_REQUEST['column'] . '\' ;';
$field_info_query = PMA_DBI_get_columns_sql($db, $table, $_REQUEST['column']);

$field_info_result = PMA_DBI_fetch_result($field_info_query, null, null, null, PMA_DBI_QUERY_STORE);

Expand Down
4 changes: 2 additions & 2 deletions tbl_alter.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@
// For now, this is done to obtain MySQL 4.1.2+ new TIMESTAMP options
// and to know when there is an empty DEFAULT value.
// Later, if the analyser returns more information, it
// could be executed to replace the info given by SHOW FULL FIELDS FROM.
// could be executed to replace the info given by SHOW FULL COLUMNS FROM.
/**
* @todo put this code into a require()
* or maybe make it part of PMA_DBI_get_fields();
*/

// We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
// SHOW FULL FIELDS says NULL and SHOW CREATE TABLE says NOT NULL (tested
// SHOW FULL COLUMNS says NULL and SHOW CREATE TABLE says NOT NULL (tested
// in MySQL 4.0.25).

$show_create_table = PMA_DBI_fetch_value('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0, 1);
Expand Down
3 changes: 1 addition & 2 deletions tbl_change.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@
* Get the list of the fields of the current table
*/
PMA_DBI_select_db($db);
$table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';',
null, null, null, PMA_DBI_QUERY_STORE);
$table_fields = PMA_DBI_get_columns($db, $table);
$rows = array();
if (isset($where_clause)) {
// when in edit mode load all selected rows from table
Expand Down
6 changes: 3 additions & 3 deletions tbl_printview.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@
* Gets fields properties
*/
$result = PMA_DBI_query(
'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
PMA_DBI_get_columns_sql($db, $table), null,
PMA_DBI_QUERY_STORE);
$fields_cnt = PMA_DBI_num_rows($result);


// We need this to correctly learn if a TIMESTAMP is NOT NULL, since
// SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
// SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
// and SHOW CREATE TABLE says NOT NULL (tested
// in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).

Expand Down Expand Up @@ -198,7 +198,7 @@
}
$field_name = htmlspecialchars($row['Field']);

// here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
// here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
// NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
// the latter.
/**
Expand Down
2 changes: 1 addition & 1 deletion tbl_select.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
$err_url = $goto . '?' . PMA_generate_common_url($db, $table);

// Gets the list and number of fields
$result = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE);
$result = PMA_DBI_query(PMA_DBI_get_columns_sql($db, $table, null, true), null, PMA_DBI_QUERY_STORE);
$fields_cnt = PMA_DBI_num_rows($result);
$fields_list = $fields_null = $fields_type = $fields_collation = array();
while ($row = PMA_DBI_fetch_assoc($result)) {
Expand Down
6 changes: 3 additions & 3 deletions tbl_structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@
// For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
// but later, if the analyser returns more information, it
// could be executed for any MySQL version and replace
// the info given by SHOW FULL FIELDS FROM.
// the info given by SHOW FULL COLUMNS FROM.
//
// We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
// SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
// SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
// and SHOW CREATE TABLE says NOT NULL (tested
// in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).

Expand Down Expand Up @@ -326,7 +326,7 @@
$attribute = 'on update CURRENT_TIMESTAMP';
}

// here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
// here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
// NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
// the latter.
if (!empty($analyzed_sql[0]['create_table_fields'][$row['Field']]['type']) && $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null']) {
Expand Down
1 change: 0 additions & 1 deletion transformation_wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* Get the list of the fields of the current table
*/
PMA_DBI_select_db($db);
$table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), null, PMA_DBI_QUERY_STORE);
if (isset($where_clause)) {
$result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';', null, PMA_DBI_QUERY_STORE);
$row = PMA_DBI_fetch_assoc($result);
Expand Down

0 comments on commit 12f70e8

Please sign in to comment.