Implement generic logic for checking table engine

Fixes #12703

Signed-off-by: arimourao <amlima@gmail.com>
Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
arimourao 2016-11-19 18:19:34 +00:00 committed by Michal Čihař
parent 6e35113914
commit 791a338946
2 changed files with 35 additions and 18 deletions

View File

@ -160,6 +160,30 @@ class Table
. $this->getName($backquoted);
}
/**
* Checks the storage engine used to create table
*
* @param array or string $engine Checks the table engine against an
* array of engine strings or a single string
*
* @return bool True, if $engine matches the storage engine for the table,
* False otherwise.
*/
public function isEngine($engine)
{
if (is_array($engine)){
foreach($engine as $e){
if($e == $this->tbl_storage_engine){
return true;
}
}
return false;
}else{
return $this->tbl_storage_engine == $engine;
}
}
/**
* returns whether the table is actually a view
*

View File

@ -51,11 +51,7 @@ $GLOBALS['dbi']->selectDb($GLOBALS['db']);
require 'libraries/tbl_info.inc.php';
// set initial value of these variables, based on the current table engine
list($is_myisam_or_aria, $is_innodb, $is_isam,
$is_berkeleydb, $is_aria, $is_pbxt
) = PMA_setGlobalVariablesForEngine($tbl_storage_engine);
if ($is_aria) {
if ($pma_table->isEngine('ARIA')) {
// the value for transactional can be implicit
// (no create option found, in this case it means 1)
// or explicit (option found with a value of 0 or 1)
@ -126,12 +122,8 @@ if (isset($_REQUEST['submitoptions'])) {
&& mb_strtoupper($_REQUEST['new_tbl_storage_engine']) !== $tbl_storage_engine
) {
$new_tbl_storage_engine = mb_strtoupper($_REQUEST['new_tbl_storage_engine']);
// reset the globals for the new engine
list($is_myisam_or_aria, $is_innodb, $is_isam,
$is_berkeleydb, $is_aria, $is_pbxt
) = PMA_setGlobalVariablesForEngine($new_tbl_storage_engine);
if ($is_aria) {
if ($pma_table->isEngine('ARIA')) {
$create_options['transactional'] = (isset($create_options['transactional']) && $create_options['transactional'] == '0')
? '0'
: '1';
@ -142,12 +134,12 @@ if (isset($_REQUEST['submitoptions'])) {
}
$table_alters = PMA_getTableAltersArray(
$is_myisam_or_aria, $is_isam, $create_options['pack_keys'],
$pma_table->isEngine('MYISAM', 'ARIA'), $pma_table->isEngine('ISAM'), $create_options['pack_keys'],
(empty($create_options['checksum']) ? '0' : '1'),
$is_aria,
((isset($create_options['page_checksum'])) ? $create_options['page_checksum'] : ''),
(empty($create_options['delay_key_write']) ? '0' : '1'),
$is_innodb, $is_pbxt, $create_options['row_format'],
$pma_table->isEngine('INNODB'), $pma_table->isEngine('PBXT'), $create_options['row_format'],
$new_tbl_storage_engine,
((isset($create_options['transactional']) && $create_options['transactional'] == '0') ? '0' : '1'),
$tbl_collation
@ -334,12 +326,13 @@ if (mb_strstr($show_comment, '; InnoDB free') === false) {
$response->addHTML(
PMA_getTableOptionDiv(
$comment, $tbl_collation, $tbl_storage_engine,
$is_myisam_or_aria, $is_isam, $create_options['pack_keys'],
$pma_table->isEngine(array("MYISAM", "ARIA")), $pma_table->isEngine('ISAM'), $create_options['pack_keys'],
$auto_increment,
(empty($create_options['delay_key_write']) ? '0' : '1'),
((isset($create_options['transactional']) && $create_options['transactional'] == '0') ? '0' : '1'),
((isset($create_options['page_checksum'])) ? $create_options['page_checksum'] : ''),
$is_innodb, $is_pbxt, $is_aria, (empty($create_options['checksum']) ? '0' : '1')
$pma_table->isEngine('INNODB'), $pma_table->isEngine('PBXT'), $pma_table->isEngine('ARIA'),
(empty($create_options['checksum']) ? '0' : '1')
)
);
@ -353,9 +346,9 @@ $response->addHTML(PMA_getHtmlForCopytable());
*/
$response->addHTML(
PMA_getHtmlForTableMaintenance(
$is_myisam_or_aria,
$is_innodb,
$is_berkeleydb,
$pma_table->isEngine(array('MYISAM', 'ARIA')),
$pma_table->isEngine('INNODB'),
$pma_table->isEngine('BERKELEYDB'),
$url_params
)
);
@ -430,7 +423,7 @@ unset($partition_names);
// so I assume that if the current table is InnoDB, I don't display
// this choice (InnoDB maintains integrity by itself)
if ($cfgRelation['relwork'] && ! $is_innodb) {
if ($cfgRelation['relwork'] && ! $pma_table->isEngine("INNODB")) {
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
$foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'internal');