// $allrows comes from the form when "Dump all rows" has been selected if ($allrows == '0' && $limit_to > 0 && $limit_from >= 0) { $add_query = ' LIMIT ' . ($limit_from > 0 ? $limit_from . ', ' : '') . $limit_to; } else { $add_query = ''; } $is_view = PMA_Table::isView($db, $table); if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') { if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'create_view' : 'create_table', $export_type)) { break; } } // If this is an export of a single view, we have to export data; // for example, a PDF report // if it is a merge table, no data is exported if (($GLOBALS[$what . '_structure_or_data'] == 'data' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') && !PMA_Table::isMerge($db, $table)) { if (!empty($sql_query)) { // only preg_replace if needed if (!empty($add_query)) { // remove trailing semicolon before adding a LIMIT $sql_query = preg_replace('%;\\s*$%', '', $sql_query); } $local_query = $sql_query . $add_query; PMA_DBI_select_db($db); } else { $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; } if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) { break; } }
/** * Get HTML snippet for display table statistics * * @param array $showtable full table status info * @param integer $table_info_num_rows table info number of rows * @param boolean $tbl_is_view whether table is view or not * @param boolean $db_is_system_schema whether db is information schema or not * @param string $tbl_storage_engine table storage engine * @param string $url_query url query * @param string $tbl_collation table collation * * @return string $html_output */ function PMA_getHtmlForDisplayTableStats($showtable, $table_info_num_rows, $tbl_is_view, $db_is_system_schema, $tbl_storage_engine, $url_query, $tbl_collation) { $html_output = '<div id="tablestatistics">'; if (empty($showtable)) { $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true); } $nonisam = false; $is_innodb = isset($showtable['Type']) && $showtable['Type'] == 'InnoDB'; if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) { $nonisam = true; } // Gets some sizes $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']); // this is to display for example 261.2 MiB instead of 268k KiB $max_digits = 3; $decimals = 1; list($data_size, $data_unit) = PMA_Util::formatByteDown($showtable['Data_length'], $max_digits, $decimals); if ($mergetable == false) { list($index_size, $index_unit) = PMA_Util::formatByteDown($showtable['Index_length'], $max_digits, $decimals); } // InnoDB returns a huge value in Data_free, do not use it if (!$is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) { list($free_size, $free_unit) = PMA_Util::formatByteDown($showtable['Data_free'], $max_digits, $decimals); list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals); } else { list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals); } list($tot_size, $tot_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals); if ($table_info_num_rows > 0) { list($avg_size, $avg_unit) = PMA_Util::formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1); } // Displays them $odd_row = false; $html_output .= '<fieldset>' . '<legend>' . __('Information') . '</legend>' . '<a id="showusage"></a>'; if (!$tbl_is_view && !$db_is_system_schema) { $html_output .= '<table id="tablespaceusage" class="data">' . '<caption class="tblHeaders">' . __('Space usage') . '</caption>' . '<tbody>'; $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Data'), $data_size, $data_unit); $odd_row = !$odd_row; if (isset($index_size)) { $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Index'), $index_size, $index_unit); $odd_row = !$odd_row; } if (isset($free_size)) { $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Overhead'), $free_size, $free_unit); $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Effective'), $effect_size, $effect_unit); $odd_row = !$odd_row; } if (isset($tot_size) && $mergetable == false) { $html_output .= PMA_getHtmlForSpaceUsageTableRow($odd_row, __('Total'), $tot_size, $tot_unit); $odd_row = !$odd_row; } // Optimize link if overhead if (isset($free_size) && !PMA_DRIZZLE && ($tbl_storage_engine == 'MYISAM' || $tbl_storage_engine == 'ARIA' || $tbl_storage_engine == 'MARIA' || $tbl_storage_engine == 'BDB')) { $html_output .= PMA_getHtmlForOptimizeLink($url_query); } $html_output .= '</tbody>' . '</table>'; } $html_output .= getHtmlForRowStatsTable($showtable, $tbl_collation, $is_innodb, $mergetable, isset($avg_size) ? $avg_size : '', isset($avg_unit) ? $avg_unit : ''); $html_output .= '</fieldset>' . '</div>'; return $html_output; }
if ($cfg['ShowStats']) { echo '<th>' . __('Size') . '</th>'; } ?> <th><?php echo __('Comments'); ?> </th> </tr> </thead> <tbody> <?php $sum_entries = $sum_size = 0; $odd_row = true; foreach ($tables as $sts_data) { if (PMA_Table::isMerge($db, $sts_data['TABLE_NAME']) || strtoupper($sts_data['ENGINE']) == 'FEDERATED') { $merged_size = true; } else { $merged_size = false; } $sum_entries += $sts_data['TABLE_ROWS']; ?> <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?> "> <th> <?php echo htmlspecialchars($sts_data['TABLE_NAME']); ?> </th>
/** * Displays indexes */ echo PMA_Index::getView($table, $db, true); /** * Displays Space usage and row statistics * */ if ($cfg['ShowStats']) { $nonisam = false; if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) { $nonisam = true; } if ($nonisam == false) { // Gets some sizes $mergetable = PMA_Table::isMerge($db, $table); list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']); if ($mergetable == false) { list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']); } if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) { list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']); list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']); } else { unset($free_size); unset($free_unit); list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']); } list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']); if ($num_rows > 0) { list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
// if table is broken, Engine is reported as null, so one more test if ($each_table['TABLE_TYPE'] == 'VIEW') { // countRecords() takes care of $cfg['MaxExactCountViews'] $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db, $each_table['TABLE_NAME'], $force_exact = true, $is_view = true); $table_is_view = true; } break; default: // Unknown table type. if ($is_show_stats) { $formatted_size = 'unknown'; $unit = ''; } } // end switch if (!PMA_Table::isMerge($db, $each_table['TABLE_NAME'])) { $sum_entries += $each_table['TABLE_ROWS']; } if (isset($each_table['Collation'])) { $collation = '<dfn title="' . PMA_getCollationDescr($each_table['Collation']) . '">' . $each_table['Collation'] . '</dfn>'; } else { $collation = '---'; } if ($is_show_stats) { if (isset($formatted_overhead)) { $overhead = '<a href="tbl_structure.php?' . $tbl_url_query . '#showusage">' . $formatted_overhead . ' ' . $overhead_unit . '</a>' . "\n"; unset($formatted_overhead); $overhead_check .= "document.getElementById('checkbox_tbl_" . ($i + 1) . "').checked = true;"; } else { $overhead = '-'; }
// Instance of PMA_RecentFavoriteTable class. $fav_instance = PMA_RecentFavoriteTable::getInstance('favorite'); foreach ($tables as $keyname => $current_table) { // Get valid statistics whatever is the table type $drop_query = ''; $drop_message = ''; $already_favorite = false; $overhead = ''; $table_is_view = false; $table_encoded = urlencode($current_table['TABLE_NAME']); // Sets parameters for links $tbl_url_query = $url_query . '&table=' . $table_encoded; // do not list the previous table's size info for a view list($current_table, $formatted_size, $unit, $formatted_overhead, $overhead_unit, $overhead_size, $table_is_view, $sum_size) = PMA_getStuffForEngineTypeTable($current_table, $db_is_system_schema, $is_show_stats, $table_is_view, $sum_size, $overhead_size); $_table = new PMA_Table($current_table['TABLE_NAME'], $db); if (!$_table->isMerge()) { $sum_entries += $current_table['TABLE_ROWS']; } if (isset($current_table['Collation'])) { $collation = '<dfn title="' . PMA_getCollationDescr($current_table['Collation']) . '">' . $current_table['Collation'] . '</dfn>'; } else { $collation = '---'; } if ($is_show_stats) { if ($formatted_overhead != '') { $overhead = '<a href="tbl_structure.php' . $tbl_url_query . '#showusage">' . '<span>' . $formatted_overhead . '</span> ' . '<span class="unit">' . $overhead_unit . '</span>' . '</a>' . "\n"; $overhead_check .= "markAllRows('row_tbl_" . ($i + 1) . "');"; } else { $overhead = '-'; } }
PMA_DBI_query($sql_view_standin); $GLOBALS['sql_query'] .= "\n" . $sql_view_standin; } } foreach ($tables_full as $each_table => $tmp) { // skip the views; we have creted stand-in definitions if (PMA_Table::isView($db, $each_table)) { continue; } $back = $sql_query; $sql_query = ''; // value of $what for this table only $this_what = $what; // do not copy the data from a Merge table // note: on the calling FORM, 'data' means 'structure and data' if (PMA_Table::isMerge($db, $each_table)) { if ($this_what == 'data') { $this_what = 'structure'; } if ($this_what == 'dataonly') { $this_what = 'nocopy'; } } if ($this_what != 'nocopy') { // keep the triggers from the original db+table // (third param is empty because delimiters are only intended // for importing via the mysql client or our Import feature) $triggers = PMA_DBI_get_triggers($db, $each_table, ''); if (!PMA_Table::moveCopy($db, $each_table, $newname, $each_table, isset($this_what) ? $this_what : 'data', $move, 'db_copy')) { $_error = true; // $sql_query is filled by PMA_Table::moveCopy()
/** * Prints Html For Export Options * * @param String $export_type Selected Export Type * @param String $db Selected DB * @param String $table Selected Table * @param String $multi_values Export selection * @param String $num_tables number of tables * @param ExportPlugin[] $export_list Export List * @param String $unlim_num_rows Number of Rows * * @return string */ function PMA_getHtmlForExportOptions($export_type, $db, $table, $multi_values, $num_tables, $export_list, $unlim_num_rows) { global $cfg; $html = PMA_getHtmlForExportOptionsMethod(); $html .= PMA_getHtmlForExportOptionsFormatDropdown($export_list); $html .= PMA_getHtmlForExportOptionsSelection($export_type, $multi_values); $tableLength = mb_strlen($table); if ($tableLength && empty($num_tables) && !PMA_Table::isMerge($db, $table)) { $html .= PMA_getHtmlForExportOptionsRows($db, $table, $unlim_num_rows); } if (isset($cfg['SaveDir']) && !empty($cfg['SaveDir'])) { $html .= PMA_getHtmlForExportOptionsQuickExport(); } $html .= PMA_getHtmlForAliasModalDialog($db, $table); $html .= PMA_getHtmlForExportOptionsOutput($export_type); $html .= PMA_getHtmlForExportOptionsFormat($export_list); return $html; }
/** * Get sql query for copy/rename table and boolean for whether copy/rename or not * * @param array $tables_full array of all tables in given db or dbs * @param string $sql_query sql query for all operations * @param boolean $move whether database name is empty or not * @param string $db database name * * @return array ($sql_query, $error) */ function PMA_getSqlQueryForCopyTable($tables_full, $sql_query, $move, $db) { $error = false; foreach ($tables_full as $each_table => $tmp) { // skip the views; we have created stand-in definitions if (PMA_Table::isView($db, $each_table)) { continue; } $back = $sql_query; $sql_query = ''; // value of $what for this table only $this_what = $_REQUEST['what']; // do not copy the data from a Merge table // note: on the calling FORM, 'data' means 'structure and data' if (PMA_Table::isMerge($db, $each_table)) { if ($this_what == 'data') { $this_what = 'structure'; } if ($this_what == 'dataonly') { $this_what = 'nocopy'; } } if ($this_what != 'nocopy') { // keep the triggers from the original db+table // (third param is empty because delimiters are only intended // for importing via the mysql client or our Import feature) $triggers = $GLOBALS['dbi']->getTriggers($db, $each_table, ''); if (!PMA_Table::moveCopy($db, $each_table, $_REQUEST['newname'], $each_table, isset($this_what) ? $this_what : 'data', $move, 'db_copy')) { $error = true; // $sql_query is filled by PMA_Table::moveCopy() $sql_query = $back . $sql_query; break; } // apply the triggers to the destination db+table if ($triggers) { $GLOBALS['dbi']->selectDb($_REQUEST['newname']); foreach ($triggers as $trigger) { $GLOBALS['dbi']->query($trigger['create']); $GLOBALS['sql_query'] .= "\n" . $trigger['create'] . ';'; } } // this does not apply to a rename operation if (isset($_REQUEST['add_constraints']) && !empty($GLOBALS['sql_constraints_query'])) { $GLOBALS['sql_constraints_query_full_db'][] = $GLOBALS['sql_constraints_query']; unset($GLOBALS['sql_constraints_query']); } } // $sql_query is filled by PMA_Table::moveCopy() $sql_query = $back . $sql_query; } return array($sql_query, $error); }
$overhead_size = (double) 0; $hidden_fields = array(); $odd_row = true; $sum_row_count_pre = ''; foreach ($tables as $keyname => $current_table) { // Get valid statistics whatever is the table type $drop_query = ''; $drop_message = ''; $overhead = ''; $table_is_view = false; $table_encoded = urlencode($current_table['TABLE_NAME']); // Sets parameters for links $tbl_url_query = $url_query . '&table=' . $table_encoded; // do not list the previous table's size info for a view list($current_table, $formatted_size, $unit, $formatted_overhead, $overhead_unit, $overhead_size, $table_is_view, $sum_size) = PMA_getStuffForEngineTypeTable($current_table, $db_is_information_schema, $is_show_stats, $table_is_view, $sum_size, $overhead_size); if (!PMA_Table::isMerge($db, $current_table['TABLE_NAME'])) { $sum_entries += $current_table['TABLE_ROWS']; } if (isset($current_table['Collation'])) { $collation = '<dfn title="' . PMA_getCollationDescr($current_table['Collation']) . '">' . $current_table['Collation'] . '</dfn>'; } else { $collation = '---'; } if ($is_show_stats) { if ($formatted_overhead != '') { $overhead = '<a href="tbl_structure.php?' . $tbl_url_query . '#showusage">' . '<span>' . $formatted_overhead . '</span>' . '<span class="unit">' . $overhead_unit . '</span>' . '</a>' . "\n"; $overhead_check .= "markAllRows('row_tbl_" . ($i + 1) . "');"; } else { $overhead = '-'; } }
// $allrows comes from the form when "Dump all rows" has been selected if (isset($allrows) && $allrows == '0' && $limit_to > 0 && $limit_from >= 0) { $add_query = ' LIMIT ' . ($limit_from > 0 ? $limit_from . ', ' : '') . $limit_to; } else { $add_query = ''; } $is_view = PMA_Table::isView($db, $table); if ($whatStrucOrData == 'structure' || $whatStrucOrData == 'structure_and_data') { if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, $is_view ? 'create_view' : 'create_table', $export_type, $do_relation, $do_comments, $do_mime, $do_dates)) { break; } } // If this is an export of a single view, we have to export data; // for example, a PDF report // if it is a merge table, no data is exported if (($whatStrucOrData == 'data' || $whatStrucOrData == 'structure_and_data') && !PMA_Table::isMerge($db, $table)) { if (!empty($sql_query)) { // only preg_replace if needed if (!empty($add_query)) { // remove trailing semicolon before adding a LIMIT $sql_query = preg_replace('%;\\s*$%', '', $sql_query); } $local_query = $sql_query . $add_query; $GLOBALS['dbi']->selectDb($db); } else { $local_query = 'SELECT * FROM ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table) . $add_query; } if (!$export_plugin->exportData($db, $table, $crlf, $err_url, $local_query)) { break; } }
/** * Export at the database level * * @param string $db the database to export * @param array $tables the tables to export * @param string $whatStrucOrData structure or data or both * @param array $table_structure whether to export structure for each table * @param array $table_data whether to export data for each table * @param ExportPlugin $export_plugin the selected export plugin * @param string $crlf end of line character(s) * @param string $err_url the URL in case of error * @param string $export_type the export type * @param bool $do_relation whether to export relation info * @param bool $do_comments whether to add comments * @param bool $do_mime whether to add MIME info * @param bool $do_dates whether to add dates * @param array $aliases Alias information for db/table/column * @param string $separate_files whether it is a separate-files export * * @return void */ function PMA_exportDatabase($db, $tables, $whatStrucOrData, $table_structure, $table_data, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases, $separate_files) { $db_alias = !empty($aliases[$db]['alias']) ? $aliases[$db]['alias'] : ''; if (!$export_plugin->exportDBHeader($db, $db_alias)) { return; } if (!$export_plugin->exportDBCreate($db, $export_type, $db_alias)) { return; } if ($separate_files == 'database') { PMA_saveObjectInBuffer('database', true); } if (($GLOBALS['sql_structure_or_data'] == 'structure' || $GLOBALS['sql_structure_or_data'] == 'structure_and_data') && isset($GLOBALS['sql_procedure_function'])) { $export_plugin->exportRoutines($db, $aliases); if ($separate_files == 'database') { PMA_saveObjectInBuffer('routines'); } } $views = array(); foreach ($tables as $table) { $_table = new PMA_Table($table, $db); // if this is a view, collect it for later; // views must be exported after the tables $is_view = $_table->isView(); if ($is_view) { $views[] = $table; } if (($whatStrucOrData == 'structure' || $whatStrucOrData == 'structure_and_data') && in_array($table, $table_structure)) { // for a view, export a stand-in definition of the table // to resolve view dependencies (only when it's a single-file export) if ($is_view) { if ($separate_files == '' && isset($GLOBALS['sql_create_view']) && !$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'stand_in', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) { break; } } else { if (isset($GLOBALS['sql_create_table'])) { $table_size = $GLOBALS['maxsize']; // Checking if the maximum table size constrain has been set // And if that constrain is a valid number or not if ($table_size !== '' && is_numeric($table_size)) { // This obtains the current table's size $query = 'SELECT data_length + index_length from information_schema.TABLES WHERE table_schema = "' . $db . '" AND table_name = "' . $table . '"'; $size = $GLOBALS['dbi']->fetchValue($query); //Converting the size to MB $size = $size / 1024 / 1024; if ($size > $table_size) { continue; } } if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'create_table', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) { break; } } } } // if this is a view or a merge table, don't export data if (($whatStrucOrData == 'data' || $whatStrucOrData == 'structure_and_data') && in_array($table, $table_data) && !($is_view || $_table->isMerge())) { $local_query = 'SELECT * FROM ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table); if (!$export_plugin->exportData($db, $table, $crlf, $err_url, $local_query, $aliases)) { break; } } // this buffer was filled, we save it and go to the next one if ($separate_files == 'database') { PMA_saveObjectInBuffer('table_' . $table); } // now export the triggers (needs to be done after the data because // triggers can modify already imported tables) if (isset($GLOBALS['sql_create_trigger']) && ($whatStrucOrData == 'structure' || $whatStrucOrData == 'structure_and_data') && in_array($table, $table_structure)) { if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'triggers', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) { break; } if ($separate_files == 'database') { PMA_saveObjectInBuffer('table_' . $table, true); } } } if (isset($GLOBALS['sql_create_view'])) { foreach ($views as $view) { // no data export for a view if ($whatStrucOrData == 'structure' || $whatStrucOrData == 'structure_and_data') { if (!$export_plugin->exportStructure($db, $view, $crlf, $err_url, 'create_view', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) { break; } if ($separate_files == 'database') { PMA_saveObjectInBuffer('view_' . $view); } } } } if (!$export_plugin->exportDBFooter($db)) { return; } // export metadata related to this db if (isset($GLOBALS['sql_metadata'])) { // Types of metadata to export. // In the future these can be allowed to be selected by the user $metadataTypes = PMA_getMetadataTypesToExport(); $export_plugin->exportMetadata($db, $tables, $metadataTypes); if ($separate_files == 'database') { PMA_saveObjectInBuffer('metadata'); } } if ($separate_files == 'database') { PMA_saveObjectInBuffer('extra'); } if (($GLOBALS['sql_structure_or_data'] == 'structure' || $GLOBALS['sql_structure_or_data'] == 'structure_and_data') && isset($GLOBALS['sql_procedure_function'])) { $export_plugin->exportEvents($db); if ($separate_files == 'database') { PMA_saveObjectInBuffer('events'); } } }
// $allrows comes from the form when "Dump all rows" has been selected if ($allrows == '0' && $limit_to > 0 && $limit_from >= 0) { $add_query = ' LIMIT ' . ($limit_from > 0 ? $limit_from . ', ' : '') . $limit_to; } else { $add_query = ''; } $is_view = PMA_Table::isView($db, $table); if (isset($GLOBALS[$what . '_structure'])) { if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'create_view' : 'create_table', $export_type)) { break; } } // If this is an export of a single view, we have to export data; // for example, a PDF report // if it is a merge table, no data is exported if (isset($GLOBALS[$what . '_data']) && !PMA_Table::isMerge($db, $table)) { if (!empty($sql_query)) { // only preg_replace if needed if (!empty($add_query)) { // remove trailing semicolon before adding a LIMIT $sql_query = preg_replace('%;\\s*$%', '', $sql_query); } $local_query = $sql_query . $add_query; PMA_DBI_select_db($db); } else { $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query; } if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) { break; } }
/** * Export at the table level * * @param string $db the database to export * @param string $table the table to export * @param string $whatStrucOrData structure or data or both * @param ExportPlugin $export_plugin the selected export plugin * @param string $crlf end of line character(s) * @param string $err_url the URL in case of error * @param string $export_type the export type * @param bool $do_relation whether to export relation info * @param bool $do_comments whether to add comments * @param bool $do_mime whether to add MIME info * @param bool $do_dates whether to add dates * @param string $allrows whether "dump all rows" was ticked * @param string $limit_to upper limit * @param string $limit_from starting limit * @param string $sql_query query for which exporting is requested * @param array $aliases Alias information for db/table/column * * @return void */ function PMA_exportTable($db, $table, $whatStrucOrData, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $allrows, $limit_to, $limit_from, $sql_query, $aliases) { $db_alias = !empty($aliases[$db]['alias']) ? $aliases[$db]['alias'] : ''; if (!$export_plugin->exportDBHeader($db, $db_alias)) { return; } if (isset($allrows) && $allrows == '0' && $limit_to > 0 && $limit_from >= 0) { $add_query = ' LIMIT ' . ($limit_from > 0 ? $limit_from . ', ' : '') . $limit_to; } else { $add_query = ''; } $_table = new PMA_Table($table, $db); $is_view = $_table->isView(); if ($whatStrucOrData == 'structure' || $whatStrucOrData == 'structure_and_data') { if ($is_view) { if (isset($GLOBALS['sql_create_view'])) { if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'create_view', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) { return; } } } else { if (isset($GLOBALS['sql_create_table'])) { if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'create_table', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) { return; } } } } // If this is an export of a single view, we have to export data; // for example, a PDF report // if it is a merge table, no data is exported $table = new PMA_Table($table, $db); if (($whatStrucOrData == 'data' || $whatStrucOrData == 'structure_and_data') && !$table->isMerge()) { if (!empty($sql_query)) { // only preg_replace if needed if (!empty($add_query)) { // remove trailing semicolon before adding a LIMIT $sql_query = preg_replace('%;\\s*$%', '', $sql_query); } $local_query = $sql_query . $add_query; $GLOBALS['dbi']->selectDb($db); } else { $local_query = 'SELECT * FROM ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table) . $add_query; } if (!$export_plugin->exportData($db, $table, $crlf, $err_url, $local_query, $aliases)) { return; } } // now export the triggers (needs to be done after the data because // triggers can modify already imported tables) if (isset($GLOBALS['sql_create_trigger']) && ($whatStrucOrData == 'structure' || $whatStrucOrData == 'structure_and_data')) { if (!$export_plugin->exportStructure($db, $table, $crlf, $err_url, 'triggers', $export_type, $do_relation, $do_comments, $do_mime, $do_dates, $aliases)) { return; } } if (!$export_plugin->exportDBFooter($db)) { return; } if (isset($GLOBALS['sql_metadata'])) { // Types of metadata to export. // In the future these can be allowed to be selected by the user $metadataTypes = PMA_getMetadataTypesToExport(); $export_plugin->exportMetadata($db, $table, $metadataTypes); } }
<?php if ($export_type == 'server') { echo '<h3>' . __('Database(s):') . '</h3>'; } else { if ($export_type == 'database') { echo '<h3>' . __('Table(s):') . '</h3>'; } } if (!empty($multi_values)) { echo $multi_values; } ?> </div> <?php if (strlen($table) && !isset($num_tables) && !PMA_Table::isMerge($db, $table)) { ?> <div class="exportoptions" id="rows"> <h3><?php echo __('Rows:'); ?> </h3> <ul> <li> <?php if (isset($_GET['allrows']) && $_GET['allrows'] == 1) { echo '<input type="radio" name="allrows" value="0" id="radio_allrows_0" />'; } else { echo '<input type="radio" name="allrows" value="0" id="radio_allrows_0" checked="checked" />'; } echo '<label for ="radio_allrows_0">' . __('Dump some row(s)') . '</label>';
*/ // BEGIN - Calc Table Space - staybyte - 9 June 2001 // loic1, 22 feb. 2002: updated with patch from // Joshua Nye <josh at boxcarmedia.com> to get valid // statistics whatever is the table type if ($cfg['ShowStats']) { if (empty($showtable)) { $showtable = PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], null, true); } $nonisam = false; $is_innodb = isset($showtable['Type']) && $showtable['Type'] == 'InnoDB'; if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) { $nonisam = true; } // Gets some sizes $mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']); // this is to display for example 261.2 MiB instead of 268k KiB $max_digits = 5; $decimals = 1; list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length'], $max_digits, $decimals); if ($mergetable == false) { list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length'], $max_digits, $decimals); } // InnoDB returns a huge value in Data_free, do not use it if (!$is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) { list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free'], $max_digits, $decimals); list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals); } else { list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals); } list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals);
/** * Get HTML snippet for display table statistics * * @param array $showtable full table status info * @param integer $table_info_num_rows table info number of rows * @param boolean $tbl_is_view whether table is view or not * @param boolean $db_is_system_schema whether db is information schema or not * @param string $tbl_storage_engine table storage engine * @param string $url_query url query * @param string $tbl_collation table collation * * @return string $html_output */ function PMA_getHtmlForDisplayTableStats($showtable, $table_info_num_rows, $tbl_is_view, $db_is_system_schema, $tbl_storage_engine, $url_query, $tbl_collation) { if (empty($showtable)) { $showtable = $GLOBALS['dbi']->getTable($GLOBALS['db'], $GLOBALS['table'])->sGetStatusInfo(null, true); } if (empty($showtable['Data_length'])) { $showtable['Data_length'] = 0; } if (empty($showtable['Index_length'])) { $showtable['Index_length'] = 0; } $is_innodb = isset($showtable['Type']) && $showtable['Type'] == 'InnoDB'; // Gets some sizes $table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']); $mergetable = $table->isMerge(); // this is to display for example 261.2 MiB instead of 268k KiB $max_digits = 3; $decimals = 1; list($data_size, $data_unit) = PMA_Util::formatByteDown($showtable['Data_length'], $max_digits, $decimals); if ($mergetable == false) { list($index_size, $index_unit) = PMA_Util::formatByteDown($showtable['Index_length'], $max_digits, $decimals); } // InnoDB returns a huge value in Data_free, do not use it if (!$is_innodb && isset($showtable['Data_free']) && $showtable['Data_free'] > 0) { list($free_size, $free_unit) = PMA_Util::formatByteDown($showtable['Data_free'], $max_digits, $decimals); list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free'], $max_digits, $decimals); } else { list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals); } list($tot_size, $tot_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'], $max_digits, $decimals); if ($table_info_num_rows > 0) { list($avg_size, $avg_unit) = PMA_Util::formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1); } return PMA\Template::get('structure/display_table_stats')->render(array('showtable' => $showtable, 'table_info_num_rows' => $table_info_num_rows, 'tbl_is_view' => $tbl_is_view, 'db_is_system_schema' => $db_is_system_schema, 'tbl_storage_engine' => $tbl_storage_engine, 'url_query' => $url_query, 'tbl_collation' => $tbl_collation, 'is_innodb' => $is_innodb, 'mergetable' => $mergetable, 'avg_size' => $avg_size, 'avg_unit' => $avg_unit, 'data_size' => $data_size, 'data_unit' => $data_unit, 'index_size' => $index_size, 'index_unit' => $index_unit, 'free_size' => isset($free_size) ? $free_size : null, 'free_unit' => isset($free_unit) ? $free_unit : null, 'effect_size' => $effect_size, 'effect_unit' => $effect_unit, 'tot_size' => $tot_size, 'tot_unit' => $tot_unit)); }
/** * Test for isMerge -- when ENGINE info is ISDB * * @return void */ public function testIsMergeCase4() { $map = array(array('PMA.PMA_BookMark', null, array('ENGINE' => "ISDB")), array('PMA.PMA_BookMark.ENGINE', null, "ISDB")); $GLOBALS['dbi']->expects($this->any())->method('getCachedTableContent')->will($this->returnValueMap($map)); $tableObj = new PMA_Table('PMA_BookMark', 'PMA'); $this->assertEquals(false, $tableObj->isMerge()); }
/** * Test for isMerge * * @return void */ public function testIsMerge() { $this->assertEquals(false, PMA_Table::isMerge()); //validate that it is Merge? $result = PMA_Table::isMerge('PMA', 'PMA_BookMark'); $this->assertEquals('', $result); $table = 'PMA_BookMark'; $db = 'PMA'; PMA_Table::$cache[$db][$table] = array('table_name' => "PMA_BookMark"); $result = PMA_Table::isMerge($db, $table); $this->assertEquals(false, $result); PMA_Table::$cache[$db][$table] = array('ENGINE' => "MERGE"); $result = PMA_Table::isMerge($db, $table); $this->assertEquals(true, $result); unset(PMA_Table::$cache[$db][$table]); PMA_Table::$cache[$db][$table] = array('ENGINE' => "MRG_MYISAM"); $result = PMA_Table::isMerge($db, $table); $this->assertEquals(true, $result); unset(PMA_Table::$cache[$db][$table]); PMA_Table::$cache[$db][$table] = array('ENGINE' => "ISDB"); $result = PMA_Table::isMerge($db, $table); $this->assertEquals(false, $result); }
/** * return html for Space Usage And Row Statistic * * @param array $showtable showing table information * @param string $db database * @param string $table table * @param int $cell_align_left cell align left * * @return string */ function PMA_getHtmlForSpaceUsageAndRowStatistics($showtable, $db, $table, $cell_align_left) { $html = ''; $nonisam = false; if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) { $nonisam = true; } if ($nonisam == false) { // Gets some sizes $mergetable = PMA_Table::isMerge($db, $table); list($data_size, $data_unit) = PMA_Util::formatByteDown($showtable['Data_length']); if ($mergetable == false) { list($index_size, $index_unit) = PMA_Util::formatByteDown($showtable['Index_length']); } if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) { list($free_size, $free_unit) = PMA_Util::formatByteDown($showtable['Data_free']); list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']); } else { unset($free_size); unset($free_unit); list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length']); } list($tot_size, $tot_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length']); $num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0; if ($num_rows > 0) { list($avg_size, $avg_unit) = PMA_Util::formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1); } // Displays them $html .= '<br /><br />'; $html .= PMA_getHtmlForSpaceUsage($data_size, $data_unit, isset($index_size) ? $index_size : null, isset($index_unit) ? $index_unit : null, isset($free_size) ? $free_size : null, isset($free_unit) ? $free_unit : null, isset($effect_size) ? $effect_size : null, isset($effect_unit) ? $effect_unit : null, isset($tot_size) ? $tot_size : null, isset($tot_unit) ? $tot_unit : null, $mergetable); $html .= '</td>'; $html .= PMA_getHtmlForRowStatistics($showtable, $cell_align_left, isset($avg_size) ? $avg_size : 0, isset($avg_unit) ? $avg_unit : 0, $mergetable); $html .= "\n"; $html .= '</table>'; $html .= '</td>'; $html .= '</tr>'; $html .= '</table>'; } // end if ($nonisam == false) return $html; }
echo '<thead>'; echo '<tr>'; echo '<th>' . __('Table') . '</th>'; echo '<th>' . __('Rows') . '</th>'; echo '<th>' . __('Type') . '</th>'; if ($cfg['ShowStats']) { echo '<th>' . __('Size') . '</th>'; } echo '<th>' . __('Comments') . '</th>'; echo '</tr>'; echo '</thead>'; echo '<tbody>'; $sum_entries = $sum_size = 0; $odd_row = true; foreach ($tables as $sts_data) { if (PMA_Table::isMerge($db, $sts_data['TABLE_NAME']) || $GLOBALS['PMA_String']->strtoupper($sts_data['ENGINE']) == 'FEDERATED') { $merged_size = true; } else { $merged_size = false; } $sum_entries += $sts_data['TABLE_ROWS']; echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">'; echo '<th>'; echo htmlspecialchars($sts_data['TABLE_NAME']); echo '</th>'; if (isset($sts_data['TABLE_ROWS'])) { echo '<td class="right">'; if ($merged_size) { echo '<i>'; echo PMA_Util::formatNumber($sts_data['TABLE_ROWS'], 0); echo '</i>';