/** * Get all column names which are MySQL reserved words * * @return array * @access public */ public function getReservedColumnNames() { $columns = $this->getColumns(false); $return = array(); foreach ($columns as $column) { $temp = explode('.', $column); $column_name = $temp[2]; if (SqlParser\Context::isKeyword($column_name, true)) { $return[] = $column_name; } } return $return; }
/** * Adds backquotes on both sides of a database, table or field name. * in compatibility mode * * example: * <code> * echo backquoteCompat('owner`s db'); // `owner``s db` * * </code> * * @param mixed $a_name the database, table or field name to * "backquote" or array of it * @param string $compatibility string compatibility mode (used by dump * functions) * @param boolean $do_it a flag to bypass this function (used by dump * functions) * * @return mixed the "backquoted" database, table or field name * * @access public */ public static function backquoteCompat($a_name, $compatibility = 'MSSQL', $do_it = true) { if (is_array($a_name)) { foreach ($a_name as &$data) { $data = self::backquoteCompat($data, $compatibility, $do_it); } return $a_name; } if (!$do_it) { if (!SqlParser\Context::isKeyword($a_name)) { return $a_name; } } // @todo add more compatibility cases (ORACLE for example) switch ($compatibility) { case 'MSSQL': $quote = '"'; break; default: $quote = "`"; break; } // '0' is also empty for php :-( if (mb_strlen($a_name) && $a_name !== '*') { return $quote . $a_name . $quote; } else { return $a_name; } }
exit; } /** * handle MySQL reserved words columns check */ if (isset($_REQUEST['reserved_word_check'])) { $response = PMA_Response::getInstance(); if ($GLOBALS['cfg']['ReservedWordDisableWarning'] === false) { $columns_names = $_REQUEST['field_name']; $reserved_keywords_names = array(); foreach ($columns_names as $column) { if (SqlParser\Context::isKeyword(trim($column), true)) { $reserved_keywords_names[] = trim($column); } } if (SqlParser\Context::isKeyword(trim($table), true)) { $reserved_keywords_names[] = trim($table); } if (count($reserved_keywords_names) == 0) { $response->isSuccess(false); } $response->addJSON('message', sprintf(_ngettext('The name \'%s\' is a MySQL reserved keyword.', 'The names \'%s\' are MySQL reserved keywords.', count($reserved_keywords_names)), implode(',', $reserved_keywords_names))); } else { $response->isSuccess(false); } exit; } /** * A click on Change has been made for one column */ if (isset($_REQUEST['change_column'])) {