The branch, master has been updated via 291e3b6a9f1024b05306d1c06782a7ef76e5827a (commit) via bdbb88871356bb2954c74e418fc2c468b34aab3e (commit) from 8ff9a1bb7860ff30da83f1eca0860f81a767a637 (commit)
- Log ----------------------------------------------------------------- commit 291e3b6a9f1024b05306d1c06782a7ef76e5827a Author: Piotr Przybylski piotrprz@gmail.com Date: Thu Jul 14 22:32:04 2011 +0200
Use PMA_DBI_get_columns in texytext export
commit bdbb88871356bb2954c74e418fc2c468b34aab3e Author: Piotr Przybylski piotrprz@gmail.com Date: Thu Jul 14 22:27:56 2011 +0200
Use PMA_DBI_get_columns in odt export
-----------------------------------------------------------------------
Summary of changes: libraries/export/odt.php | 33 +++++++++++++++------------------ libraries/export/texytext.php | 35 +++++++++++++++-------------------- 2 files changed, 30 insertions(+), 38 deletions(-)
diff --git a/libraries/export/odt.php b/libraries/export/odt.php index b640ca3..f2b13a0 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'] .= '</table:table-row>';
- 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'] .= 'table:table-row'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' - . 'text:p' . htmlspecialchars($row['Field']) . '</text:p>' + . 'text:p' . htmlspecialchars($field_name) . '</text:p>' . '</table:table-cell>'; // 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'] .= '<table:table-cell office:value-type="string">' . 'text:p' . htmlspecialchars($type) . '</text:p>' . '</table:table-cell>'; - 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'] .= '<table:table-cell office:value-type="string">' - . 'text:p' . htmlspecialchars(($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes')) . '</text:p>' + . 'text:p' . htmlspecialchars(($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')) . '</text:p>' . '</table:table-cell>'; $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">' - . 'text:p' . htmlspecialchars($row['Default']) . '</text:p>' + . 'text:p' . htmlspecialchars($column['Default']) . '</text:p>' . '</table:table-cell>';
if ($do_relation && $have_rel) { @@ -399,7 +397,6 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals } $GLOBALS['odt_buffer'] .= '</table:table-row>'; } // end while - PMA_DBI_free_result($result);
$GLOBALS['odt_buffer'] .= '</table:table>'; return true; diff --git a/libraries/export/texytext.php b/libraries/export/texytext.php index ceffe4d..6294311 100644 --- a/libraries/export/texytext.php +++ b/libraries/export/texytext.php @@ -195,9 +195,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'])) { @@ -251,10 +248,11 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals return false; }
- while ($row = PMA_DBI_fetch_assoc($result)) { + $columns = PMA_DBI_get_columns($db, $table); + foreach ($columns as $column) {
$text_output = ''; - $type = $row['Type']; + $type = $column['Type']; // reformat mysql query output // set or enum types: slashes single quotes inside options if (preg_match('/^(set|enum)((.+))$/i', $type, $tmp)) { @@ -274,9 +272,9 @@ 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']); } $attribute = ' '; if ($binary) { @@ -288,30 +286,28 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals if ($zerofill) { $attribute = 'UNSIGNED ZEROFILL'; } - 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'] = $row['Default']; }
$fmt_pre = ''; $fmt_post = ''; - if (in_array($row['Field'], $unique_keys)) { + if (in_array($column['Field'], $unique_keys)) { $fmt_pre = '**' . $fmt_pre; $fmt_post = $fmt_post . '**'; } - if ($row['Key']=='PRI') { + if ($column['Key']=='PRI') { $fmt_pre = '//' . $fmt_pre; $fmt_post = $fmt_post . '//'; } - $text_output .= '|' . $fmt_pre . htmlspecialchars($row['Field']) . $fmt_post; + $text_output .= '|' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post; $text_output .= '|' . htmlspecialchars($type); - $text_output .= '|' . htmlspecialchars(($row['Null'] == '' || $row['Null'] == 'NO') ? __('No') : __('Yes')); - $text_output .= '|' . htmlspecialchars(isset($row['Default']) ? $row['Default'] : ''); + $text_output .= '|' . htmlspecialchars(($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')); + $text_output .= '|' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : '');
- $field_name = $row['Field']; + $field_name = $column['Field'];
if ($do_relation && $have_rel) { $text_output .= '|' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : ''); @@ -329,7 +325,6 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals return false; } } // end while - PMA_DBI_free_result($result);
return true; }
hooks/post-receive