/** * Function to handle the creation or edit of an index * * @param string $db current db * @param string $table current table * @param PMA_Index $index current index * * @return void */ function PMA_handleCreateOrEditIndex($db, $table, $index) { $error = false; $sql_query = PMA_getSqlQueryForIndexCreateOrEdit($db, $table, $index, $error); // If there is a request for SQL previewing. if (isset($_REQUEST['preview_sql'])) { PMA_previewSQL($sql_query); } if (!$error) { $GLOBALS['dbi']->query($sql_query); $message = PMA_Message::success(__('Table %1$s has been altered successfully.')); $message->addParam($table); if ($GLOBALS['is_ajax_request'] == true) { $response = PMA_Response::getInstance(); $response->addJSON('message', $message); $response->addJSON('index_table', PMA_Index::getView($table, $db)); $response->addJSON('sql_query', PMA_Util::getMessage(null, $sql_query)); } else { include 'tbl_structure.php'; } exit; } else { $response = PMA_Response::getInstance(); $response->isSuccess(false); $response->addJSON('message', $error); exit; } }
/** * Get HTML for display indexes * * @return string $html_output */ function PMA_getHtmlForDisplayIndexes() { $html_output = PMA_Util::getDivForSliderEffect('indexes', __('Indexes')); $html_output .= PMA_Index::getView($GLOBALS['table'], $GLOBALS['db']); $html_output .= '<fieldset class="tblFooters" style="text-align: left;">' . '<form action="tbl_indexes.php" method="post">'; $html_output .= PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']) . sprintf(__('Create an index on %s columns'), '<input type="text" size="2" name="added_fields" value="1" />'); $html_output .= '<input type="hidden" name="create_index" value="1" />' . '<input class="add_index ajax"' . ' type="submit" value="' . __('Go') . '" />'; $html_output .= '</form>' . '</fieldset>' . '</div>' . '</div>'; return $html_output; }
/** * return html for Table Structure * * @param bool $have_rel whether have relation * @param bool $tbl_is_view Is a table view? * @param array $columns columns list * @param array $analyzed_sql analyzed sql * @param array $res_rel relations array * @param string $db database * @param string $table table * @param array $cfgRelation config from PMA_getRelationsParam * @param array $cfg global config * @param array $showtable showing table information * @param int $cell_align_left cell align left * * @return string */ function PMA_getHtmlForTableStructure($have_rel, $tbl_is_view, $columns, $analyzed_sql, $res_rel, $db, $table, $cfgRelation, $cfg, $showtable, $cell_align_left) { /** * Displays the table structure */ $html = '<table style="width: 100%;">'; $html .= '<thead>'; $html .= '<tr>'; $html .= '<th>' . __('Column') . '</th>'; $html .= '<th>' . __('Type') . '</th>'; $html .= '<th>' . __('Null') . '</th>'; $html .= '<th>' . __('Default') . '</th>'; if ($have_rel) { $html .= '<th>' . __('Links to') . '</th>' . "\n"; } $html .= ' <th>' . __('Comments') . '</th>' . "\n"; if ($cfgRelation['mimework']) { $html .= ' <th>MIME</th>' . "\n"; } $html .= '</tr>'; $html .= '</thead>'; $html .= '<tbody>'; $html .= PMA_getHtmlForPrintViewColumns($tbl_is_view, $columns, $analyzed_sql, $have_rel, $res_rel, $db, $table, $cfgRelation); $html .= '</tbody>'; $html .= '</table>'; if (!$tbl_is_view && !$GLOBALS['dbi']->isSystemSchema($db)) { /** * Displays indexes */ $html .= PMA_Index::getView($table, $db, true); /** * Displays Space usage and row statistics * */ if ($cfg['ShowStats']) { $html .= PMA_getHtmlForSpaceUsageAndRowStatistics($showtable, $db, $table, $cell_align_left); } // end if ($cfg['ShowStats']) } return $html; }
/** * Function to handle all aspects relating to executing the query * * @param array $analyzed_sql_results analyzed sql results * @param String $full_sql_query full sql query * @param boolean $is_gotofile whether to go to a file * @param String $db current database * @param String $table current table * @param boolean $find_real_end whether to find the real end * @param String $sql_query_for_bookmark sql query to be stored as bookmark * @param array $extra_data extra data * * @return mixed */ function PMA_executeTheQuery($analyzed_sql_results, $full_sql_query, $is_gotofile, $db, $table, $find_real_end, $sql_query_for_bookmark, $extra_data) { $response = PMA_Response::getInstance(); $response->getHeader()->getMenu()->setTable($table); // Only if we ask to see the php code if (isset($GLOBALS['show_as_php'])) { $result = null; $num_rows = 0; $unlim_num_rows = 0; } else { // If we don't ask to see the php code if (isset($_SESSION['profiling']) && PMA_Util::profilingSupported()) { $GLOBALS['dbi']->query('SET PROFILING=1;'); } $result = PMA_executeQueryAndStoreResults($full_sql_query); // Displays an error message if required and stop parsing the script $error = $GLOBALS['dbi']->getError(); if ($error) { PMA_handleQueryExecuteError($is_gotofile, $error, $full_sql_query); } // If there are no errors and bookmarklabel was given, // store the query as a bookmark if (!empty($_POST['bkm_label']) && !empty($sql_query_for_bookmark)) { $cfgBookmark = PMA_Bookmark_getParams(); PMA_storeTheQueryAsBookmark($db, $cfgBookmark['user'], $sql_query_for_bookmark, $_POST['bkm_label'], isset($_POST['bkm_replace']) ? $_POST['bkm_replace'] : null); } // end store bookmarks // Gets the number of rows affected/returned // (This must be done immediately after the query because // mysql_affected_rows() reports about the last query done) $num_rows = PMA_getNumberOfRowsAffectedOrChanged($analyzed_sql_results['is_affected'], $result, isset($num_rows) ? $num_rows : null); // Grabs the profiling results if (isset($_SESSION['profiling']) && PMA_Util::profilingSupported()) { $profiling_results = $GLOBALS['dbi']->fetchResult('SHOW PROFILE;'); } $justBrowsing = PMA_isJustBrowsing($analyzed_sql_results, isset($find_real_end) ? $find_real_end : null); $unlim_num_rows = PMA_countQueryResults($num_rows, $analyzed_sql_results['is_select'], $justBrowsing, $db, $table, $analyzed_sql_results['parsed_sql'], $analyzed_sql_results); $extra_data = PMA_cleanupRelations(isset($db) ? $db : '', isset($table) ? $table : '', isset($_REQUEST['dropped_column']) ? $_REQUEST['dropped_column'] : null, isset($_REQUEST['purge']) ? $_REQUEST['purge'] : null, isset($extra_data) ? $extra_data : null); // Update Indexes list. if (isset($_REQUEST['index_change'])) { $extra_data['indexes_list'] = PMA_Index::getView($table, $db); } } return array($result, $num_rows, $unlim_num_rows, isset($profiling_results) ? $profiling_results : null, $extra_data); }
/** * If there are more than 20 rows, displays browse/select/insert/empty/drop * links again */ if ($fields_cnt > 20) { require './libraries/tbl_links.inc.php'; } // end if ($fields_cnt > 20) /** * Displays indexes */ if (!$tbl_is_view && !$db_is_information_schema && 'ARCHIVE' != $tbl_type) { /** * Display indexes */ echo PMA_Index::getView($table, $db); ?> <br /> <form action="./tbl_indexes.php" method="post" onsubmit="return checkFormElementInRange(this, 'idx_num_fields', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidColumnCount']); ?> ', 1)"> <fieldset> <?php echo PMA_generate_common_hidden_inputs($db, $table); echo sprintf($strCreateIndex, '<input type="text" size="2" name="added_fields" value="1" />'); ?> <input type="submit" name="create_index" value="<?php
$response->addHTML('<div id="structure-action-links">'); if ($tbl_is_view) { $response->addHTML(PMA_getHtmlForEditView($url_params)); } $response->addHTML(PMA_getHtmlForOptionalActionLinks($url_query, $tbl_is_view, $db_is_system_schema, $tbl_storage_engine, $cfgRelation)); $response->addHTML('</div>'); if (!$tbl_is_view && !$db_is_system_schema) { $response->addHTML('<br />'); $response->addHTML(PMA_getHtmlForAddColumn($columns_list)); } /** * Displays indexes */ if (!$tbl_is_view && !$db_is_system_schema && 'ARCHIVE' != $tbl_storage_engine) { //return the list of index $response->addJSON('indexes_list', PMA_Index::getView($GLOBALS['table'], $GLOBALS['db'])); $response->addHTML(PMA_getHtmlForDisplayIndexes()); } /** * Displays Space usage and row statistics */ // BEGIN - Calc Table Space // Get valid statistics whatever is the table type if ($cfg['ShowStats']) { //get table stats in HTML format $tablestats = PMA_getHtmlForDisplayTableStats($showtable, $table_info_num_rows, $tbl_is_view, $db_is_system_schema, $tbl_storage_engine, $url_query, $tbl_collation); //returning the response in JSON format to be used by Ajax $response->addJSON('tableStat', $tablestats); $response->addHTML($tablestats); } // END - Calc Table Space
if (strlen($table) && strlen($db)) { PMA_relationsCleanupTable($db, $table); } elseif (strlen($db)) { PMA_relationsCleanupDatabase($db); } else { // VOID. No DB/Table gets deleted. } // end if relation-stuff } // end if ($purge) // If a column gets dropped, do relation magic. if (isset($dropped_column) && strlen($db) && strlen($table) && ! empty($dropped_column)) { include_once 'libraries/relation_cleanup.lib.php'; PMA_relationsCleanupColumn($db, $table, $dropped_column); // to refresh the list of indexes (Ajax mode) $extra_data['indexes_list'] = PMA_Index::getView($table, $db); } // end if column was dropped } // end else "didn't ask to see php code" // No rows returned -> move back to the calling page if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { if ($is_delete) { $message = PMA_Message::deleted_rows($num_rows); } elseif ($is_insert) { if ($is_replace) { /* For replace we get DELETED + INSERTED row count, so we have to call it affected */ $message = PMA_Message::affected_rows($num_rows); } else { $message = PMA_Message::inserted_rows($num_rows); } $insert_id = PMA_DBI_insert_id();
echo ' </td>' . "\n"; } ?> </tr> <?php } // end foreach ?> </tbody> </table> <?php if (!$tbl_is_view && !PMA_is_system_schema($db)) { /** * 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 a table, database or column gets dropped, clean comments. * * @param String $db current database * @param String $table current table * @param String $dropped_column dropped column if any * @param bool $purge whether purge set or not * @param array $extra_data extra data * * @return array $extra_data */ function PMA_cleanupRelations($db, $table, $dropped_column, $purge, $extra_data) { include_once 'libraries/relation_cleanup.lib.php'; if (isset($purge) && $purge == 1) { if (strlen($table) && strlen($db)) { PMA_relationsCleanupTable($db, $table); } elseif (strlen($db)) { PMA_relationsCleanupDatabase($db); } } if (isset($dropped_column) && !empty($dropped_column) && strlen($db) && strlen($table)) { PMA_relationsCleanupColumn($db, $table, $dropped_column); if (isset($extra_data)) { // to refresh the list of indexes (Ajax mode) $extra_data['indexes_list'] = PMA_Index::getView($table, $db); } } return $extra_data; }
} } // end while if (empty($index_fields)) { $error = PMA_Message::error(__('No index parts defined!')); } else { $sql_query .= ' (' . implode(', ', $index_fields) . ')'; } if (! $error) { PMA_DBI_query($sql_query); $message = PMA_Message::success(__('Table %1$s has been altered successfully')); $message->addParam($table); if ( $GLOBALS['is_ajax_request'] == true) { $extra_data['index_table'] = PMA_Index::getView($table, $db); $extra_data['sql_query'] = PMA_showMessage(null, $sql_query); PMA_ajaxResponse($message, $message->isSuccess(), $extra_data); } $active_page = 'tbl_structure.php'; include 'tbl_structure.php'; exit; } else { if ( $GLOBALS['is_ajax_request'] == true) { $extra_data['error'] = $error; PMA_ajaxResponse($error, false); } $error->display(); } } // end builds the new index
$error = PMA_Message::error(__('No index parts defined!')); } else { $sql_query .= ' (' . implode(', ', $index_fields) . ')'; } if (PMA_MYSQL_INT_VERSION > 50500) { $sql_query .= "COMMENT '" . PMA_Util::sqlAddSlashes($index->getComment()) . "'"; } $sql_query .= ';'; if (!$error) { PMA_DBI_query($sql_query); $message = PMA_Message::success(__('Table %1$s has been altered successfully')); $message->addParam($table); if ($GLOBALS['is_ajax_request'] == true) { $response = PMA_Response::getInstance(); $response->addJSON('message', $message); $response->addJSON('index_table', PMA_Index::getView($table, $db)); $response->addJSON('sql_query', PMA_Util::getMessage(null, $sql_query)); } else { $active_page = 'tbl_structure.php'; include 'tbl_structure.php'; } exit; } else { if ($GLOBALS['is_ajax_request'] == true) { $response = PMA_Response::getInstance(); $response->isSuccess(false); $response->addJSON('message', $error); exit; } else { $error->display(); }