Merge branch 'master' of github.com:phpmyadmin/phpmyadmin

This commit is contained in:
Marc Delisle 2012-04-11 17:15:25 -04:00
commit 21153122d1
6 changed files with 581 additions and 97 deletions

View File

@ -23,6 +23,9 @@ phpMyAdmin - ChangeLog
- bug #3507917 [export] JSON has unescaped values for allegedly numeric columns
+ rfe #3516187 show tables creation, last update, last check timestamps in db_structure
- bug #3059806 Supporting running from CIFS/Samba shares
- bug #3516341 [export] Open Document Text, Word and Texy! Text show table structure twice
- bug [export] Texy! Text: Columns containing Pipe Character don't export properly
+ [export] Show triggers in Open Document Text, Word and Texy! Text
3.5.1.0 (not yet released)
- bug #3510784 [edit] Limit clause ignored when sort order is remembered

View File

@ -52,11 +52,11 @@ function PMA_select_language($use_fieldset = false, $show_doc = true)
if ($use_fieldset) {
echo '<fieldset><legend lang="en" dir="ltr">' . $language_title . '</legend>';
} else {
echo '<bdo lang="en" dir="ltr">' . $language_title . ':</bdo>';
echo '<bdo lang="en" dir="ltr"><label for="sel-lang">' . $language_title . ':</label></bdo>';
}
?>
<select name="lang" class="autosubmit" lang="en" dir="ltr">
<select name="lang" class="autosubmit" lang="en" dir="ltr" id="sel-lang">
<?php
uasort($GLOBALS['available_languages'], 'PMA_language_cmp');

View File

@ -133,7 +133,7 @@ if (isset($plugin_list)) {
if (isset($GLOBALS['htmlword_columns'])) {
$schema_insert = '<tr class="print-category">';
for ($i = 0; $i < $fields_cnt; $i++) {
$schema_insert .= '<td class="print"><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>';
$schema_insert .= '<td class="print"><strong>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</strong></td>';
} // end for
$schema_insert .= '</tr>';
if (! PMA_exportOutputHandler($schema_insert)) {
@ -168,33 +168,93 @@ if (isset($plugin_list)) {
}
/**
* Outputs table's structure
* Returns a stand-in CREATE definition to resolve view dependencies
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* @param string $db the database name
* @param string $view the view name
* @param string $crlf the end of line sequence
*
* @return string resulting definition
*
* @access public
*/
function PMA_getTableDefStandIn($db, $view, $crlf)
{
$schema_insert = '<table class="width100" cellspacing="1">';
$columns_cnt = 4;
$schema_insert .= '<tr class="print-category">';
$schema_insert .= '<th class="print">' . __('Column') . '</th>';
$schema_insert .= '<td class="print"><strong>' . __('Type') . '</strong></td>';
$schema_insert .= '<td class="print"><strong>' . __('Null') . '</strong></td>';
$schema_insert .= '<td class="print"><strong>' . __('Default') . '</strong></td>';
$schema_insert .= '</tr>';
$columns = PMA_DBI_get_columns($db, $view);
foreach ($columns as $column) {
$schema_insert .= '<tr class="print-category">';
$extracted_fieldspec = PMA_extractFieldSpec($column['Type']);
$type = htmlspecialchars($extracted_fieldspec['print_type']);
if (empty($type)) {
$type = '&nbsp;';
}
if (! isset($column['Default'])) {
if ($column['Null'] != 'NO') {
$column['Default'] = 'NULL';
}
}
$fmt_pre = '';
$fmt_post = '';
if (in_array($column['Field'], $unique_keys)) {
$fmt_pre = '<strong>' . $fmt_pre;
$fmt_post = $fmt_post . '</strong>';
}
if ($column['Key'] == 'PRI') {
$fmt_pre = '<em>' . $fmt_pre;
$fmt_post = $fmt_post . '</em>';
}
$schema_insert .= '<td class="print">' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post . '</td>';
$schema_insert .= '<td class="print">' . htmlspecialchars($type) . '</td>';
$schema_insert .= '<td class="print">' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')) . '</td>';
$schema_insert .= '<td class="print">' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : '') . '</td>';
$schema_insert .= '</tr>';
}
$schema_insert .= '</table>';
return $schema_insert;
}
/**
* Returns $table's CREATE definition
*
* @param string $db the database name
* @param string $table the table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
* @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @return bool Whether it succeeded
* @param bool $do_mime whether to include mime comments
* @param bool $show_dates whether to include creation/update/check dates
* @param bool $add_semicolon whether to add semicolon and end-of-line at the end
* @param bool $view whether we're handling a view
*
* @access public
* @return string resulting schema
*
* @access public
*/
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type)
function PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false)
{
global $cfgRelation;
if (! PMA_exportOutputHandler('<h2>' . __('Table structure for table') . ' ' . htmlspecialchars($table) . '</h2>')) {
return false;
}
$schema_insert = '';
/**
* Get the unique keys in the table
@ -230,9 +290,7 @@ if (isset($plugin_list)) {
/**
* Displays the table structure
*/
if (! PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) {
return false;
}
$schema_insert .= '<table class="width100" cellspacing="1">';
$columns_cnt = 4;
if ($do_relation && $have_rel) {
@ -245,32 +303,28 @@ if (isset($plugin_list)) {
$columns_cnt++;
}
$schema_insert = '<tr class="print-category">';
$schema_insert .= '<tr class="print-category">';
$schema_insert .= '<th class="print">' . __('Column') . '</th>';
$schema_insert .= '<td class="print"><b>' . __('Type') . '</b></td>';
$schema_insert .= '<td class="print"><b>' . __('Null') . '</b></td>';
$schema_insert .= '<td class="print"><b>' . __('Default') . '</b></td>';
$schema_insert .= '<td class="print"><strong>' . __('Type') . '</strong></td>';
$schema_insert .= '<td class="print"><strong>' . __('Null') . '</strong></td>';
$schema_insert .= '<td class="print"><strong>' . __('Default') . '</strong></td>';
if ($do_relation && $have_rel) {
$schema_insert .= '<td class="print"><b>' . __('Links to') . '</b></td>';
$schema_insert .= '<td class="print"><strong>' . __('Links to') . '</strong></td>';
}
if ($do_comments) {
$schema_insert .= '<td class="print"><b>' . __('Comments') . '</b></td>';
$schema_insert .= '<td class="print"><strong>' . __('Comments') . '</strong></td>';
$comments = PMA_getComments($db, $table);
}
if ($do_mime && $cfgRelation['mimework']) {
$schema_insert .= '<td class="print"><b>' . htmlspecialchars('MIME') . '</b></td>';
$schema_insert .= '<td class="print"><strong>' . htmlspecialchars('MIME') . '</strong></td>';
$mime_map = PMA_getMIME($db, $table, true);
}
$schema_insert .= '</tr>';
if (! PMA_exportOutputHandler($schema_insert)) {
return false;
}
$columns = PMA_DBI_get_columns($db, $table);
foreach ($columns as $column) {
$schema_insert = '<tr class="print-category">';
$schema_insert .= '<tr class="print-category">';
$extracted_fieldspec = PMA_extractFieldSpec($column['Type']);
$type = htmlspecialchars($extracted_fieldspec['print_type']);
@ -287,12 +341,12 @@ if (isset($plugin_list)) {
$fmt_pre = '';
$fmt_post = '';
if (in_array($column['Field'], $unique_keys)) {
$fmt_pre = '<b>' . $fmt_pre;
$fmt_post = $fmt_post . '</b>';
$fmt_pre = '<strong>' . $fmt_pre;
$fmt_post = $fmt_post . '</strong>';
}
if ($column['Key'] == 'PRI') {
$fmt_pre = '<i>' . $fmt_pre;
$fmt_post = $fmt_post . '</i>';
$fmt_pre = '<em>' . $fmt_pre;
$fmt_post = $fmt_post . '</em>';
}
$schema_insert .= '<td class="print">' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post . '</td>';
$schema_insert .= '<td class="print">' . htmlspecialchars($type) . '</td>';
@ -312,13 +366,95 @@ if (isset($plugin_list)) {
}
$schema_insert .= '</tr>';
if (! PMA_exportOutputHandler($schema_insert)) {
return false;
}
} // end while
return PMA_exportOutputHandler('</table>');
$schema_insert .= '</table>';
return $schema_insert;
} // end of the 'PMA_getTableDef()' function
/**
* Outputs triggers
*
* @param string $db database name
* @param string $table table name
* @return string Formatted triggers list
*
* @access public
*/
function PMA_getTriggers($db, $table)
{
$dump = '<table class="width100" cellspacing="1">';
$dump .= '<tr class="print-category">';
$dump .= '<th class="print">' . __('Name') . '</th>';
$dump .= '<td class="print"><strong>' . __('Time') . '</strong></td>';
$dump .= '<td class="print"><strong>' . __('Event') . '</strong></td>';
$dump .= '<td class="print"><strong>' . __('Definition') . '</strong></td>';
$dump .= '</tr>';
$triggers = PMA_DBI_get_triggers($db, $table);
foreach($triggers as $trigger) {
$dump .= '<tr class="print-category">';
$dump .= '<td class="print">' . htmlspecialchars($trigger['name']) . '</td>';
$dump .= '<td class="print">' . htmlspecialchars($trigger['action_timing']) . '</td>';
$dump .= '<td class="print">' . htmlspecialchars($trigger['event_manipulation']) . '</td>';
$dump .= '<td class="print">' . htmlspecialchars($trigger['definition']) . '</td>';
$dump .= '</tr>';
}
$dump .= '</table>';
return $dump;
}
/**
* Outputs table's structure
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
* @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @return bool Whether it succeeded
*
* @access public
*/
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type)
{
$dump = '';
switch($export_mode) {
case 'create_table':
$dump .= '<h2>' . __('Table structure for table') . ' ' . htmlspecialchars($table) . '</h2>';
$dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates);
break;
case 'triggers':
$dump = '';
$triggers = PMA_DBI_get_triggers($db, $table);
if ($triggers) {
$dump .= '<h2>' . __('Triggers') . ' ' . htmlspecialchars($table) . '</h2>';
$dump .= PMA_getTriggers($db, $table);
}
break;
case 'create_view':
$dump .= '<h2>' . __('Structure for view') . ' ' . htmlspecialchars($table) . '</h2>';
$dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates, true, true);
break;
case 'stand_in':
$dump .= '<h2>' . __('Stand-in structure for view') . ' ' . htmlspecialchars($table) . '</h2>';
// export a stand-in definition to resolve view dependencies
$dump .= PMA_getTableDefStandIn($db, $table, $crlf);
} // end switch
return PMA_exportOutputHandler($dump);
}
}

View File

@ -219,35 +219,122 @@ if (isset($plugin_list)) {
}
/**
* Outputs table's structure
* Returns a stand-in CREATE definition to resolve view dependencies
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
* @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @param string $db the database name
* @param string $view the view name
* @param string $crlf the end of line sequence
*
* @return bool Whether it succeeded
* @return bool true
*
* @access public
*/
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type)
function PMA_getTableDefStandIn($db, $view, $crlf)
{
/**
* Get the unique keys in the table
*/
$unique_keys = array();
$keys = PMA_DBI_get_table_indexes($db, $table);
foreach ($keys as $key) {
if ($key['Non_unique'] == 0) {
$unique_keys[] = $key['Column_name'];
}
}
/**
* Gets fields properties
*/
PMA_DBI_select_db($db);
/**
* Displays the table structure
*/
$GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_data">';
$columns_cnt = 4;
$GLOBALS['odt_buffer'] .= '<table:table-column table:number-columns-repeated="' . $columns_cnt . '"/>';
/* Header */
$GLOBALS['odt_buffer'] .= '<table:table-row>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . __('Column') . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . __('Type') . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . __('Null') . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . __('Default') . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '</table:table-row>';
$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($field_name) . '</text:p>'
. '</table:table-cell>';
$extracted_fieldspec = PMA_extractFieldSpec($column['Type']);
$type = htmlspecialchars($extracted_fieldspec['print_type']);
if (empty($type)) {
$type = '&nbsp;';
}
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($type) . '</text:p>'
. '</table:table-cell>';
if (!isset($column['Default'])) {
if ($column['Null'] != 'NO') {
$column['Default'] = 'NULL';
} else {
$column['Default'] = '';
}
} else {
$column['Default'] = $column['Default'];
}
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . (($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($column['Default']) . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '</table:table-row>';
} // end while
$GLOBALS['odt_buffer'] .= '</table:table>';
return true;
}
/**
* Returns $table's CREATE definition
*
* @param string $db the database name
* @param string $table the table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $show_dates whether to include creation/update/check dates
* @param bool $add_semicolon whether to add semicolon and end-of-line at the end
* @param bool $view whether we're handling a view
*
* @return bool true
*
* @access public
*/
function PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false)
{
global $cfgRelation;
/* Heading */
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
. __('Table structure for table') . ' ' . htmlspecialchars($table) . '</text:h>';
/**
* Get the unique keys in the table
*/
@ -282,7 +369,7 @@ if (isset($plugin_list)) {
/**
* Displays the table structure
*/
$GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_data">';
$GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_structure">';
$columns_cnt = 4;
if ($do_relation && $have_rel) {
$columns_cnt++;
@ -394,6 +481,110 @@ if (isset($plugin_list)) {
$GLOBALS['odt_buffer'] .= '</table:table>';
return true;
} // end of the 'PMA_getTableDef()' function
/**
* Outputs triggers
*
* @param string $db database name
* @param string $table table name
* @return bool true
*
* @access public
*/
function PMA_getTriggers($db, $table)
{
$GLOBALS['odt_buffer'] .= '<table:table table:name="' . htmlspecialchars($table) . '_triggers">';
$GLOBALS['odt_buffer'] .= '<table:table-column table:number-columns-repeated="4"/>';
$GLOBALS['odt_buffer'] .= '<table:table-row>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . __('Name') . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . __('Time') . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . __('Event') . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . __('Definition') . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '</table:table-row>';
$triggers = PMA_DBI_get_triggers($db, $table);
foreach($triggers as $trigger) {
$GLOBALS['odt_buffer'] .= '<table:table-row>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($trigger['name']) . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($trigger['action_timing']) . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($trigger['event_manipulation']) . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
. '<text:p>' . htmlspecialchars($trigger['definition']) . '</text:p>'
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '</table:table-row>';
}
$GLOBALS['odt_buffer'] .= '</table:table>';
return true;
}
/**
* Outputs table's structure
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
* @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
* @param string $export_type 'server', 'database', 'table'
*
* @return bool Whether it succeeded
*
* @access public
*/
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type)
{
switch($export_mode) {
case 'create_table':
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
. __('Table structure for table') . ' ' . htmlspecialchars($table) . '</text:h>';
PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates);
break;
case 'triggers':
$triggers = PMA_DBI_get_triggers($db, $table);
if ($triggers) {
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
. __('Triggers') . ' ' . htmlspecialchars($table) . '</text:h>';
PMA_getTriggers($db, $table);
}
break;
case 'create_view':
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
. __('Structure for view') . ' ' . htmlspecialchars($table) . '</text:h>';
PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates, true, true);
break;
case 'stand_in':
$GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2" text:is-list-header="true">'
. __('Stand-in structure for view') . ' ' . htmlspecialchars($table) . '</text:h>';
// export a stand-in definition to resolve view dependencies
PMA_getTableDefStandIn($db, $table, $crlf);
} // end switch
return PMA_exportOutputHandler($dump);
} // end of the 'PMA_exportStructure' function
} // end else

View File

@ -1178,7 +1178,7 @@ if (isset($plugin_list)) {
$insert_delayed .= ' IGNORE';
}
//truncate table before insert
if ($GLOBALS['sql_truncate'] && $sql_command == 'INSERT') {
if (isset($GLOBALS['sql_truncate']) && $GLOBALS['sql_truncate'] && $sql_command == 'INSERT') {
$truncate = 'TRUNCATE TABLE ' . PMA_backquote($table, $sql_backquotes) . ";";
$truncatehead = PMA_possibleCRLF()
. PMA_exportComment()

View File

@ -137,7 +137,7 @@ if (isset($plugin_list)) {
} else {
$value = ' ';
}
$text_output .= '|' . htmlspecialchars($value);
$text_output .= '|' . str_replace('|', '&#124;', htmlspecialchars($value));
} // end for
$text_output .= "\n";
if (! PMA_exportOutputHandler($text_output)) {
@ -150,33 +150,113 @@ if (isset($plugin_list)) {
}
/**
* Outputs table's structure
* Returns a stand-in CREATE definition to resolve view dependencies
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* @param string $db the database name
* @param string $view the view name
* @param string $crlf the end of line sequence
*
* @return string resulting definition
*
* @access public
*/
function PMA_getTableDefStandIn($db, $view, $crlf)
{
$text_output = '';
/**
* Get the unique keys in the table
*/
$unique_keys = array();
$keys = PMA_DBI_get_table_indexes($db, $table);
foreach ($keys as $key) {
if ($key['Non_unique'] == 0) {
$unique_keys[] = $key['Column_name'];
}
}
/**
* Gets fields properties
*/
PMA_DBI_select_db($db);
/**
* Displays the table structure
*/
$columns_cnt = 4;
$text_output .= "|------\n";
$text_output .= '|' . __('Column');
$text_output .= '|' . __('Type');
$text_output .= '|' . __('Null');
$text_output .= '|' . __('Default');
$text_output .= "\n|------\n";
$columns = PMA_DBI_get_columns($db, $table);
foreach ($columns as $column) {
$extracted_fieldspec = PMA_extractFieldSpec($column['Type']);
$type = $extracted_fieldspec['print_type'];
if (empty($type)) {
$type = '&nbsp;';
}
if (! isset($column['Default'])) {
if ($column['Null'] != 'NO') {
$column['Default'] = 'NULL';
}
}
$fmt_pre = '';
$fmt_post = '';
if (in_array($column['Field'], $unique_keys)) {
$fmt_pre = '**' . $fmt_pre;
$fmt_post = $fmt_post . '**';
}
if ($column['Key']=='PRI') {
$fmt_pre = '//' . $fmt_pre;
$fmt_post = $fmt_post . '//';
}
$text_output .= '|' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post;
$text_output .= '|' . htmlspecialchars($type);
$text_output .= '|' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes'));
$text_output .= '|' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : '');
$field_name = $column['Field'];
$text_output .= "\n";
} // end while
return $text_output;
}
/**
* Returns $table's CREATE definition
*
* @param string $db the database name
* @param string $table the table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
* @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @return bool Whether it succeeded
* @param bool $do_mime whether to include mime comments
* @param bool $show_dates whether to include creation/update/check dates
* @param bool $add_semicolon whether to add semicolon and end-of-line at the end
* @param bool $view whether we're handling a view
*
* @access public
* @return string resulting schema
*
* @access public
*/
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type)
function PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $show_dates = false, $add_semicolon = true, $view = false)
{
global $cfgRelation;
if (! PMA_exportOutputHandler('== ' . __('Table structure for table') . ' ' .$table . "\n\n")) {
return false;
}
$text_output = '';
/**
* Get the unique keys in the table
@ -224,7 +304,7 @@ if (isset($plugin_list)) {
$columns_cnt++;
}
$text_output = "|------\n";
$text_output .= "|------\n";
$text_output .= '|' . __('Column');
$text_output .= '|' . __('Type');
$text_output .= '|' . __('Null');
@ -242,15 +322,9 @@ if (isset($plugin_list)) {
}
$text_output .= "\n|------\n";
if (! PMA_exportOutputHandler($text_output)) {
return false;
}
$columns = PMA_DBI_get_columns($db, $table);
foreach ($columns as $column) {
$text_output = '';
$extracted_fieldspec = PMA_extractFieldSpec($column['Type']);
$type = $extracted_fieldspec['print_type'];
if (empty($type)) {
@ -291,13 +365,93 @@ if (isset($plugin_list)) {
}
$text_output .= "\n";
if (! PMA_exportOutputHandler($text_output)) {
return false;
}
} // end while
return true;
return $text_output;
} // end of the 'PMA_getTableDef()' function
/**
* Outputs triggers
*
* @param string $db database name
* @param string $table table name
* @return string Formatted triggers list
*
* @access public
*/
function PMA_getTriggers($db, $table)
{
$text_output .= "|------\n";
$text_output .= '|' . __('Column');
$dump = "|------\n";
$dump .= '|' . __('Name');
$dump .= '|' . __('Time');
$dump .= '|' . __('Event');
$dump .= '|' . __('Definition');
$dump .= "\n|------\n";
$triggers = PMA_DBI_get_triggers($db, $table);
foreach($triggers as $trigger) {
$dump .= '|' . $trigger['name'];
$dump .= '|' . $trigger['action_timing'];
$dump .= '|' . $trigger['event_manipulation'];
$dump .= '|' . str_replace('|', '&#124;', htmlspecialchars($trigger['definition']));
$dump .= "\n";
}
return $dump;
}
/**
* Outputs table's structure
*
* @param string $db database name
* @param string $table table name
* @param string $crlf the end of line sequence
* @param string $error_url the url to go back in case of error
* @param bool $do_relation whether to include relation comments
* @param bool $do_comments whether to include the pmadb-style column comments
* as comments in the structure; this is deprecated
* but the parameter is left here because export.php
* calls PMA_exportStructure() also for other export
* types which use this parameter
* @param bool $do_mime whether to include mime comments
* @param bool $dates whether to include creation/update/check dates
* @param string $export_mode 'create_table', 'triggers', 'create_view', 'stand_in'
* @param string $export_type 'server', 'database', 'table'
* @return bool Whether it succeeded
*
* @access public
*/
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $export_mode, $export_type)
{
$dump = '';
switch($export_mode) {
case 'create_table':
$dump .= '== ' . __('Table structure for table') . ' ' .$table . "\n\n";
$dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates);
break;
case 'triggers':
$dump = '';
$triggers = PMA_DBI_get_triggers($db, $table);
if ($triggers) {
$dump .= '== ' . __('Triggers') . ' ' .$table . "\n\n";
$dump .= PMA_getTriggers($db, $table);
}
break;
case 'create_view':
$dump .= '== ' . __('Structure for view') . ' ' .$table . "\n\n";
$dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates, true, true);
break;
case 'stand_in':
$dump .= '== ' . __('Stand-in structure for view') . ' ' .$table . "\n\n";
// export a stand-in definition to resolve view dependencies
$dump .= PMA_getTableDefStandIn($db, $table, $crlf);
} // end switch
return PMA_exportOutputHandler($dump);
}
}