Skip to content

Commit

Permalink
Move col_extra handling code to a single method. Add such missing col…
Browse files Browse the repository at this point in the history
…_extra handling.

Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
  • Loading branch information
madhuracj committed Mar 9, 2015
1 parent 9bf5792 commit 3821b72
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 42 deletions.
20 changes: 0 additions & 20 deletions db_central_columns.php
Expand Up @@ -117,26 +117,6 @@
$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
);
Expand Down
63 changes: 41 additions & 22 deletions libraries/central_columns.lib.php
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 3821b72

Please sign in to comment.