From 3821b724cc5d105b06bbdb5f34705d2407dd2d8a Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Mon, 9 Mar 2015 15:47:09 +0530 Subject: [PATCH] Move col_extra handling code to a single method. Add such missing col_extra handling. Signed-off-by: Madhura Jayaratne --- db_central_columns.php | 20 ---------- libraries/central_columns.lib.php | 63 ++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/db_central_columns.php b/db_central_columns.php index 696319df2f..453326dd39 100644 --- a/db_central_columns.php +++ b/db_central_columns.php @@ -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 ); diff --git a/libraries/central_columns.lib.php b/libraries/central_columns.lib.php index eed0813816..a54159bec8 100644 --- a/libraries/central_columns.lib.php +++ b/libraries/central_columns.lib.php @@ -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 *