Move col_extra handling code to a single method. Add such missing col_extra handling.
Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
This commit is contained in:
parent
9bf5792dc0
commit
3821b724cc
@ -117,26 +117,6 @@ $result = PMA_getColumnsList($db, $pos, $max_rows);
|
||||
$odd_row = false;
|
||||
$row_num=0;
|
||||
foreach ($result as $row) {
|
||||
$vals = explode(',', $row['col_extra']);
|
||||
|
||||
if (in_array('BINARY', $vals)) {
|
||||
$row['col_attribute'] = 'BINARY';
|
||||
} elseif (in_array('UNSIGNED', $vals)) {
|
||||
$row['col_attribute'] = 'UNSIGNED';
|
||||
} elseif (in_array('UNSIGNED ZEROFILL', $vals)) {
|
||||
$row['col_attribute'] = 'UNSIGNED ZEROFILL';
|
||||
} elseif (in_array('on update CURRENT_TIMESTAMP', $vals)) {
|
||||
$row['col_attribute'] = 'on update CURRENT_TIMESTAMP';
|
||||
} else {
|
||||
$row['col_attribute'] = '';
|
||||
}
|
||||
|
||||
if (in_array('auto_increment', $vals)) {
|
||||
$row['col_extra'] = 'auto_increment';
|
||||
} else {
|
||||
$row['col_extra'] = '';
|
||||
}
|
||||
|
||||
$tableHtmlRow = PMA_getHTMLforCentralColumnsTableRow(
|
||||
$row, $odd_row, $row_num, $db
|
||||
);
|
||||
|
||||
@ -72,6 +72,7 @@ function PMA_getColumnsList($db, $from=0, $num=25)
|
||||
$has_list = (array) $GLOBALS['dbi']->fetchResult(
|
||||
$query, null, null, $GLOBALS['controllink']
|
||||
);
|
||||
PMA_handleColumnExtra($has_list);
|
||||
return $has_list;
|
||||
}
|
||||
|
||||
@ -123,14 +124,19 @@ function PMA_findExistingColNames($db, $cols, $allFields=false)
|
||||
if ($allFields) {
|
||||
$query = 'SELECT * FROM ' . PMA_Util::backquote($central_list_table) . ' '
|
||||
. 'WHERE db_name = \'' . $db . '\' AND col_name IN (' . $cols . ');';
|
||||
$has_list = (array) $GLOBALS['dbi']->fetchResult(
|
||||
$query, null, null, $GLOBALS['controllink']
|
||||
);
|
||||
PMA_handleColumnExtra($has_list);
|
||||
} else {
|
||||
$query = 'SELECT col_name FROM '
|
||||
. PMA_Util::backquote($central_list_table) . ' '
|
||||
. 'WHERE db_name = \'' . $db . '\' AND col_name IN (' . $cols . ');';
|
||||
$has_list = (array) $GLOBALS['dbi']->fetchResult(
|
||||
$query, null, null, $GLOBALS['controllink']
|
||||
);
|
||||
}
|
||||
$has_list = (array) $GLOBALS['dbi']->fetchResult(
|
||||
$query, null, null, $GLOBALS['controllink']
|
||||
);
|
||||
|
||||
return $has_list;
|
||||
}
|
||||
|
||||
@ -414,25 +420,6 @@ function PMA_makeConsistentWithList($db, $selected_tables)
|
||||
$query .= '(' . $column['col_length'] . ')';
|
||||
}
|
||||
|
||||
$vals = explode(',', $column['col_extra']);
|
||||
if (in_array('BINARY', $vals)) {
|
||||
$column['col_attribute'] = 'BINARY';
|
||||
} elseif (in_array('UNSIGNED', $vals)) {
|
||||
$column['col_attribute'] = 'UNSIGNED';
|
||||
} elseif (in_array('UNSIGNED ZEROFILL', $vals)) {
|
||||
$column['col_attribute'] = 'UNSIGNED ZEROFILL';
|
||||
} elseif (in_array('on update CURRENT_TIMESTAMP', $vals)) {
|
||||
$column['col_attribute'] = 'on update CURRENT_TIMESTAMP';
|
||||
} else {
|
||||
$column['col_attribute'] = '';
|
||||
}
|
||||
|
||||
if (in_array('auto_increment', $vals)) {
|
||||
$column['col_extra'] = 'auto_increment';
|
||||
} else {
|
||||
$column['col_extra'] = '';
|
||||
}
|
||||
|
||||
$query .= ' ' . $column['col_attribute'];
|
||||
if ($column['col_isNull']) {
|
||||
$query .= ' NULL';
|
||||
@ -914,9 +901,41 @@ function PMA_getCentralColumnsListRaw($db, $table)
|
||||
$columns_list = (array)$GLOBALS['dbi']->fetchResult(
|
||||
$query, null, null, $GLOBALS['controllink']
|
||||
);
|
||||
PMA_handleColumnExtra($columns_list);
|
||||
return json_encode($columns_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Column `col_extra` is used to store both extra and attributes for a column.
|
||||
* This method separates them.
|
||||
*
|
||||
* @param array columns_list columns list
|
||||
*/
|
||||
function PMA_handleColumnExtra(&$columns_list)
|
||||
{
|
||||
foreach ($columns_list as &$row) {
|
||||
$vals = explode(',', $row['col_extra']);
|
||||
|
||||
if (in_array('BINARY', $vals)) {
|
||||
$row['col_attribute'] = 'BINARY';
|
||||
} elseif (in_array('UNSIGNED', $vals)) {
|
||||
$row['col_attribute'] = 'UNSIGNED';
|
||||
} elseif (in_array('UNSIGNED ZEROFILL', $vals)) {
|
||||
$row['col_attribute'] = 'UNSIGNED ZEROFILL';
|
||||
} elseif (in_array('on update CURRENT_TIMESTAMP', $vals)) {
|
||||
$row['col_attribute'] = 'on update CURRENT_TIMESTAMP';
|
||||
} else {
|
||||
$row['col_attribute'] = '';
|
||||
}
|
||||
|
||||
if (in_array('auto_increment', $vals)) {
|
||||
$row['col_extra'] = 'auto_increment';
|
||||
} else {
|
||||
$row['col_extra'] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* build html for adding a new user defined column to central list
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user