diff --git a/ChangeLog b/ChangeLog
index 52e03b965e..dd3db745d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/libraries/export/htmlword.php b/libraries/export/htmlword.php
index 104165ede1..abd492792f 100644
--- a/libraries/export/htmlword.php
+++ b/libraries/export/htmlword.php
@@ -133,7 +133,7 @@ if (isset($plugin_list)) {
if (isset($GLOBALS['htmlword_columns'])) {
$schema_insert = '
';
for ($i = 0; $i < $fields_cnt; $i++) {
- $schema_insert .= '| ' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . ' | ';
+ $schema_insert .= '' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . ' | ';
} // end for
$schema_insert .= '
';
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 = '';
+
+ $columns_cnt = 4;
+ $schema_insert .= '';
+ $schema_insert .= '| ' . __('Column') . ' | ';
+ $schema_insert .= '' . __('Type') . ' | ';
+ $schema_insert .= '' . __('Null') . ' | ';
+ $schema_insert .= '' . __('Default') . ' | ';
+ $schema_insert .= '
';
+
+
+ $columns = PMA_DBI_get_columns($db, $view);
+ foreach ($columns as $column) {
+ $schema_insert .= '';
+
+ $extracted_fieldspec = PMA_extractFieldSpec($column['Type']);
+ $type = htmlspecialchars($extracted_fieldspec['print_type']);
+ if (empty($type)) {
+ $type = ' ';
+ }
+
+ 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 . '';
+ }
+ $schema_insert .= '| ' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post . ' | ';
+ $schema_insert .= '' . htmlspecialchars($type) . ' | ';
+ $schema_insert .= '' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')) . ' | ';
+ $schema_insert .= '' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : '') . ' | ';
+ $schema_insert .= '
';
+ }
+
+ $schema_insert .= '
';
+ 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('' . __('Table structure for table') . ' ' . htmlspecialchars($table) . '
')) {
- 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('')) {
- return false;
- }
+ $schema_insert .= '';
$columns_cnt = 4;
if ($do_relation && $have_rel) {
@@ -245,32 +303,28 @@ if (isset($plugin_list)) {
$columns_cnt++;
}
- $schema_insert = '';
+ $schema_insert .= '
';
$schema_insert .= '| ' . __('Column') . ' | ';
- $schema_insert .= '' . __('Type') . ' | ';
- $schema_insert .= '' . __('Null') . ' | ';
- $schema_insert .= '' . __('Default') . ' | ';
+ $schema_insert .= '' . __('Type') . ' | ';
+ $schema_insert .= '' . __('Null') . ' | ';
+ $schema_insert .= '' . __('Default') . ' | ';
if ($do_relation && $have_rel) {
- $schema_insert .= '' . __('Links to') . ' | ';
+ $schema_insert .= '' . __('Links to') . ' | ';
}
if ($do_comments) {
- $schema_insert .= '' . __('Comments') . ' | ';
+ $schema_insert .= '' . __('Comments') . ' | ';
$comments = PMA_getComments($db, $table);
}
if ($do_mime && $cfgRelation['mimework']) {
- $schema_insert .= '' . htmlspecialchars('MIME') . ' | ';
+ $schema_insert .= '' . htmlspecialchars('MIME') . ' | ';
$mime_map = PMA_getMIME($db, $table, true);
}
$schema_insert .= '
';
- if (! PMA_exportOutputHandler($schema_insert)) {
- return false;
- }
-
$columns = PMA_DBI_get_columns($db, $table);
foreach ($columns as $column) {
- $schema_insert = '';
+ $schema_insert .= '
';
$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 = '' . $fmt_pre;
- $fmt_post = $fmt_post . '';
+ $fmt_pre = '' . $fmt_pre;
+ $fmt_post = $fmt_post . '';
}
if ($column['Key'] == 'PRI') {
- $fmt_pre = '' . $fmt_pre;
- $fmt_post = $fmt_post . '';
+ $fmt_pre = '' . $fmt_pre;
+ $fmt_post = $fmt_post . '';
}
$schema_insert .= '| ' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post . ' | ';
$schema_insert .= '' . htmlspecialchars($type) . ' | ';
@@ -312,13 +366,95 @@ if (isset($plugin_list)) {
}
$schema_insert .= '
';
-
- if (! PMA_exportOutputHandler($schema_insert)) {
- return false;
- }
} // end while
- return PMA_exportOutputHandler('
');
+ $schema_insert .= '
';
+ 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 = '';
+ $dump .= '';
+ $dump .= '| ' . __('Name') . ' | ';
+ $dump .= '' . __('Time') . ' | ';
+ $dump .= '' . __('Event') . ' | ';
+ $dump .= '' . __('Definition') . ' | ';
+ $dump .= '
';
+
+ $triggers = PMA_DBI_get_triggers($db, $table);
+
+ foreach($triggers as $trigger) {
+ $dump .= '';
+ $dump .= '| ' . htmlspecialchars($trigger['name']) . ' | ';
+ $dump .= '' . htmlspecialchars($trigger['action_timing']) . ' | ';
+ $dump .= '' . htmlspecialchars($trigger['event_manipulation']) . ' | ';
+ $dump .= '' . htmlspecialchars($trigger['definition']) . ' | ';
+ $dump .= '
';
+ }
+
+ $dump .= '
';
+ 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') . ' ' . htmlspecialchars($table) . '
';
+ $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') . ' ' . htmlspecialchars($table) . '
';
+ $dump .= PMA_getTriggers($db, $table);
+ }
+ break;
+ case 'create_view':
+ $dump .= '' . __('Structure for view') . ' ' . htmlspecialchars($table) . '
';
+ $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') . ' ' . htmlspecialchars($table) . '
';
+ // export a stand-in definition to resolve view dependencies
+ $dump .= PMA_getTableDefStandIn($db, $table, $crlf);
+ } // end switch
+
+ return PMA_exportOutputHandler($dump);
}
}
diff --git a/libraries/export/odt.php b/libraries/export/odt.php
index d6f6936b76..b1c92a451e 100644
--- a/libraries/export/odt.php
+++ b/libraries/export/odt.php
@@ -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'] .= '';
+ $columns_cnt = 4;
+ $GLOBALS['odt_buffer'] .= '';
+ /* Header */
+ $GLOBALS['odt_buffer'] .= '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . __('Column') . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . __('Type') . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . __('Null') . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . __('Default') . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= '';
+
+ $columns = PMA_DBI_get_columns($db, $table);
+ foreach ($columns as $column) {
+ $field_name = $column['Field'];
+ $GLOBALS['odt_buffer'] .= '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . htmlspecialchars($field_name) . ''
+ . '';
+
+ $extracted_fieldspec = PMA_extractFieldSpec($column['Type']);
+ $type = htmlspecialchars($extracted_fieldspec['print_type']);
+ if (empty($type)) {
+ $type = ' ';
+ }
+
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . htmlspecialchars($type) . ''
+ . '';
+ if (!isset($column['Default'])) {
+ if ($column['Null'] != 'NO') {
+ $column['Default'] = 'NULL';
+ } else {
+ $column['Default'] = '';
+ }
+ } else {
+ $column['Default'] = $column['Default'];
+ }
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')) . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . htmlspecialchars($column['Default']) . ''
+ . '';
+
+ $GLOBALS['odt_buffer'] .= '';
+ } // end while
+
+ $GLOBALS['odt_buffer'] .= '';
+ 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'] .= ''
- . __('Table structure for table') . ' ' . htmlspecialchars($table) . '';
-
/**
* Get the unique keys in the table
*/
@@ -282,7 +369,7 @@ if (isset($plugin_list)) {
/**
* Displays the table structure
*/
- $GLOBALS['odt_buffer'] .= '';
+ $GLOBALS['odt_buffer'] .= '';
$columns_cnt = 4;
if ($do_relation && $have_rel) {
$columns_cnt++;
@@ -394,6 +481,110 @@ if (isset($plugin_list)) {
$GLOBALS['odt_buffer'] .= '';
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'] .= '';
+ $GLOBALS['odt_buffer'] .= '';
+ $GLOBALS['odt_buffer'] .= '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . __('Name') . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . __('Time') . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . __('Event') . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . __('Definition') . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= '';
+
+ $triggers = PMA_DBI_get_triggers($db, $table);
+
+ foreach($triggers as $trigger) {
+ $GLOBALS['odt_buffer'] .= '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . htmlspecialchars($trigger['name']) . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . htmlspecialchars($trigger['action_timing']) . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . htmlspecialchars($trigger['event_manipulation']) . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= ''
+ . '' . htmlspecialchars($trigger['definition']) . ''
+ . '';
+ $GLOBALS['odt_buffer'] .= '';
+ }
+
+ $GLOBALS['odt_buffer'] .= '';
+ 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'] .= ''
+ . __('Table structure for table') . ' ' . htmlspecialchars($table) . '';
+ 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'] .= ''
+ . __('Triggers') . ' ' . htmlspecialchars($table) . '';
+ PMA_getTriggers($db, $table);
+ }
+ break;
+ case 'create_view':
+ $GLOBALS['odt_buffer'] .= ''
+ . __('Structure for view') . ' ' . htmlspecialchars($table) . '';
+ PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime, $dates, true, true);
+ break;
+ case 'stand_in':
+ $GLOBALS['odt_buffer'] .= ''
+ . __('Stand-in structure for view') . ' ' . htmlspecialchars($table) . '';
+ // 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
diff --git a/libraries/export/texytext.php b/libraries/export/texytext.php
index ba8e05f7be..f06ae5817a 100644
--- a/libraries/export/texytext.php
+++ b/libraries/export/texytext.php
@@ -137,7 +137,7 @@ if (isset($plugin_list)) {
} else {
$value = ' ';
}
- $text_output .= '|' . htmlspecialchars($value);
+ $text_output .= '|' . str_replace('|', '|', 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 = ' ';
+ }
+
+ 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('|', '|', 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);
}
}