From bdbb88871356bb2954c74e418fc2c468b34aab3e Mon Sep 17 00:00:00 2001 From: Piotr Przybylski Date: Thu, 14 Jul 2011 22:27:56 +0200 Subject: [PATCH] Use PMA_DBI_get_columns in odt export --- libraries/export/odt.php | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/libraries/export/odt.php b/libraries/export/odt.php index b640ca34ae..f2b13a04ee 100644 --- a/libraries/export/odt.php +++ b/libraries/export/odt.php @@ -251,9 +251,6 @@ 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); - $result = PMA_DBI_query($local_query); - $fields_cnt = PMA_DBI_num_rows($result); // Check if we can use Relations if ($do_relation && !empty($cfgRelation['relation'])) { @@ -318,16 +315,17 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals } $GLOBALS['odt_buffer'] .= ''; - while ($row = PMA_DBI_fetch_assoc($result)) { + $columns = PMA_DBI_get_columns($db, $table); + foreach ($columns as $column) { + $field_name = $column['Field']; $GLOBALS['odt_buffer'] .= ''; $GLOBALS['odt_buffer'] .= '' - . '' . htmlspecialchars($row['Field']) . '' + . '' . htmlspecialchars($field_name) . '' . ''; // reformat mysql query output // set or enum types: slashes single quotes inside options - $field_name = $row['Field']; - $type = $row['Type']; + $type = $column['Type']; if (preg_match('/^(set|enum)\((.+)\)$/i', $type, $tmp)) { $tmp[2] = substr(preg_replace('/([^,])\'\'/', '\\1\\\'', ',' . $tmp[2]), 1); $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')'; @@ -345,27 +343,27 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals $type = ' '; } - $binary = preg_match('/BINARY/i', $row['Type']); - $unsigned = preg_match('/UNSIGNED/i', $row['Type']); - $zerofill = preg_match('/ZEROFILL/i', $row['Type']); + $binary = preg_match('/BINARY/i', $column['Type']); + $unsigned = preg_match('/UNSIGNED/i', $column['Type']); + $zerofill = preg_match('/ZEROFILL/i', $column['Type']); } $GLOBALS['odt_buffer'] .= '' . '' . htmlspecialchars($type) . '' . ''; - if (!isset($row['Default'])) { - if ($row['Null'] != 'NO') { - $row['Default'] = 'NULL'; + if (!isset($column['Default'])) { + if ($column['Null'] != 'NO') { + $column['Default'] = 'NULL'; } else { - $row['Default'] = ''; + $column['Default'] = ''; } } else { - $row['Default'] = $row['Default']; + $column['Default'] = $column['Default']; } $GLOBALS['odt_buffer'] .= '' - . '' . htmlspecialchars(($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes')) . '' + . '' . htmlspecialchars(($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')) . '' . ''; $GLOBALS['odt_buffer'] .= '' - . '' . htmlspecialchars($row['Default']) . '' + . '' . htmlspecialchars($column['Default']) . '' . ''; if ($do_relation && $have_rel) { @@ -399,7 +397,6 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals } $GLOBALS['odt_buffer'] .= ''; } // end while - PMA_DBI_free_result($result); $GLOBALS['odt_buffer'] .= ''; return true;