diff --git a/libraries/Table.class.php b/libraries/Table.class.php index 70cf694139..963f2958fc 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -1572,5 +1572,25 @@ class PMA_Table } return true; } + + /** + * Get all column names which are MySQL reserved words + * + * @return array + * @access public + */ + public function getReservedColumnNames() + { + $columns = $this->getColumns($backquoted = false); + $return = array(); + foreach ($columns as $column) { + $temp = explode('.', $column); + $column_name = $temp[2]; + if (PMA_SQP_isKeyWord($column_name)) { + $return[] = $column_name; + } + } + return $return; + } } ?> diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index d79758980a..b9d665d804 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -2890,4 +2890,16 @@ function PMA_SQP_formatNone($arr) return $formatted_sql; } // end of the "PMA_SQP_formatNone()" function +/** + * Checks whether a given name is MySQL reserved word + * + * @param string $column The word to be checked + * + * @return boolean whether true or false + */ +function PMA_SQP_isKeyWord($column) { + global $PMA_SQPdata_forbidden_word; + return in_array(strtoupper($column), $PMA_SQPdata_forbidden_word); +} + ?> diff --git a/sql.php b/sql.php index fc85422073..2b26cd4413 100644 --- a/sql.php +++ b/sql.php @@ -1203,6 +1203,20 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { echo '' . "\n"; } + + // Check column names for MySQL reserved words + $pma_table = new PMA_Table($table, $db); + $columns = $pma_table->getReservedColumnNames(); + if (! empty($columns)) { + foreach ($columns as $column) { + $msg = PMA_message::notice( + __('The column name \'%s\' is a MySQL reserved keyword.') + ); + $msg->addParam($column); + $msg->display(); + } + } + // Displays the results in a table if (empty($disp_mode)) { // see the "PMA_setDisplayMode()" function in diff --git a/tbl_structure.php b/tbl_structure.php index ebc6f7780c..6e9598abab 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -133,6 +133,19 @@ $url_query .= '&goto=tbl_structure.php&back=tbl_structure.php'; $url_params['goto'] = 'tbl_structure.php'; $url_params['back'] = 'tbl_structure.php'; +// Check column names for MySQL reserved words +$pma_table = new PMA_Table($table, $db); +$columns = $pma_table->getReservedColumnNames(); +if (! empty($columns)) { + foreach ($columns as $column) { + $msg = PMA_message::notice( + __('The column name \'%s\' is a MySQL reserved keyword.') + ); + $msg->addParam($column); + $response->addHTML($msg); + } +} + /** * Prepares the table structure display */