Skip to content

Commit

Permalink
Merge pull request #1171 from ashutoshdhundhara/rfe_1445
Browse files Browse the repository at this point in the history
RFE: #1445 Easy access to "SHOW CREATE".
  • Loading branch information
lem9 committed May 10, 2014
2 parents 71c0eba + cc9cef8 commit d12d752
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 3 deletions.
18 changes: 18 additions & 0 deletions libraries/core.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,4 +886,22 @@ function PMA_addJSVar($key, $value, $escape = true)
PMA_addJSCode(PMA_getJsValue($key, $value, $escape));
}

/**
* Replace some html-unfriendly stuff
*
* @param string $buffer String to process
* @return string Escaped and cleaned up text suitable for html
*/
function PMA_mimeDefaultFunction($buffer)
{
$buffer = htmlspecialchars($buffer);
$buffer = str_replace(
"\011",
'    ',
str_replace(' ', '  ', $buffer)
);
$buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);

return $buffer;
}
?>
3 changes: 3 additions & 0 deletions libraries/mult_submits.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
include 'db_export.php';
exit;
break;
case 'show_create':
PMA_getHtmlShowCreate($db, $selected);
exit;
} // end switch
}
} elseif (isset($selected_fld) && !empty($selected_fld)) {
Expand Down
109 changes: 109 additions & 0 deletions libraries/structure.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ function PMA_getHtmlForCheckAllTables($pmaThemeImage, $text_dir,
$html_output .= '<option value="' . __('With selected:')
. '" selected="selected">'
. __('With selected:') . '</option>' . "\n";
$html_output .= '<option value="show_create" >'
. __('Show create') . '</option>' . "\n";
$html_output .= '<option value="export" >'
. __('Export') . '</option>' . "\n";
$html_output .= '<option value="print" >'
Expand Down Expand Up @@ -2859,4 +2861,111 @@ function PMA_synchronizeFavoriteTables($fav_instance, $user)
// Set flag when localStorage and pmadb(if present) are in sync.
$_SESSION['tmpval']['favorites_synced'][$server_id] = true;
}

/**
* Returns Html for show create.
* @param string $db Database name
* @param array $db_objects Array containing DB objects
* @return string Html
*/
function PMA_getHtmlShowCreate($db, $db_objects)
{
// Main outer container.
$html_output = '<div class="show_create_results">'
. '<h2>' . __('Showing create queries') . '</h2>';
// Table header.
$output_table = '<fieldset>'
. '<legend>%s</legend>'
. '<table class="show_create">'
. '<thead>'
. '<tr>'
. '<th>%s</th>'
. '<th>Create %s</th>'
. '</tr>'
. '</thead>'
. '<tbody>';
// Holds rows html for views.
$views = '';
// Holds rows html for tables.
$tables = '';
// Handles odd, even classes for rows.
// for 'Views'
$odd1 = true;
// for 'Tables'
$odd2 = true;
// Iterate through each object.
foreach ($db_objects as $key => $object) {
// Check if current object is a View or Table.
$isView = PMA_Table::isView($db, $object);
if ($isView) {
$row_class = ($odd1) ? 'odd' : 'even';
$create_data = PMA_getShowCreate($db, $object, 'view');
$views .= '<tr class="' . $row_class . '">'
. '<td><strong>'
. PMA_mimeDefaultFunction($create_data['View'])
. '</strong></td>'
. '<td>'
. PMA_mimeDefaultFunction($create_data['Create View'])
. '</td>'
. '</tr>';
$odd1 = ! $odd1;
} else {
$row_class = ($odd2) ? 'odd' : 'even';
$create_data = PMA_getShowCreate($db, $object, 'table');
$tables .= '<tr class="' . $row_class . '">'
. '<td><strong>'
. PMA_mimeDefaultFunction($create_data['Table'])
. '</strong></td>'
. '<td>'
. PMA_mimeDefaultFunction($create_data['Create Table'])
. '</td>'
. '</tr>';
$odd2 = ! $odd2;
}
}
// Prepare table header for each type of object.
if (! empty($tables)) {
$title = __('Tables');
$tables = sprintf($output_table, $title, 'Table', 'Table')
. $tables
. '</tbody></table></fieldset>';
}
if (! empty($views)) {
$title = __('Views');
$views = sprintf($output_table, $title, 'View', 'View')
. $views
. '</tbody></table></fieldset>';
}
// Compile the final html.
$html_output .= $tables . $views . '</div>';
// Send response to client.
$response = PMA_Response::getInstance();
$response->addJSON('message', $html_output);
}

/**
* Return 'SHOW CREATE' query for a DB object
* @param string $db Database name
* @param string $db_object Database object name
* @param string $type Type of object (table or view)
* @return mysqli_result collection | boolean(false)
*/
function PMA_getShowCreate($db, $db_object, $type = 'table')
{
// 'SHOW CREATE' SQL query for specific type of DB object.
switch ($type) {
case 'table':
$sql_query = 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.'
. PMA_Util::backquote($db_object);
break;
case 'view':
$sql_query = 'SHOW CREATE VIEW ' . PMA_Util::backquote($db) . '.'
. PMA_Util::backquote($db_object);
break;
}
// Execute the query.
$result = $GLOBALS['dbi']->fetchSingleRow($sql_query);

return $result;
}
?>
8 changes: 8 additions & 0 deletions themes/original/css/common.css.php
Original file line number Diff line number Diff line change
Expand Up @@ -2650,3 +2650,11 @@
div#page_content div#tableslistcontainer, div#page_content div.notice, div#page_content div#result_query {
margin-top: 1em;
}

table.show_create {
margin-top: 1em;
}

table.show_create td {
border-right: 1px solid #bbb;
}
14 changes: 11 additions & 3 deletions themes/pmahomme/css/common.css.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
body {
<?php if (! empty($GLOBALS['cfg']['FontFamily'])) { ?>
font-family: <?php echo $GLOBALS['cfg']['FontFamily']; ?>;
<?php
<?php
} ?>
padding: 0;
margin: 0;
Expand Down Expand Up @@ -614,7 +614,7 @@
.before-condition {
border-right: 1px solid <?php echo $GLOBALS['cfg']['BrowseMarkerBackground']; ?>;
}
<?php
<?php
} ?>

/**
Expand Down Expand Up @@ -643,7 +643,7 @@
.value {
font-family: <?php echo $GLOBALS['cfg']['FontFamilyFixed']; ?>;
}
<?php
<?php
} ?>
.attention {
color: red;
Expand Down Expand Up @@ -2941,3 +2941,11 @@
div#page_content div#tableslistcontainer, div#page_content div.notice, div#page_content div#result_query {
margin-top: 1em;
}

table.show_create {
margin-top: 1em;
}

table.show_create td {
border-right: 1px solid #bbb;
}

0 comments on commit d12d752

Please sign in to comment.