diff --git a/ChangeLog b/ChangeLog index e9067e7fa..cf3b6dbfd 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,20 @@ phpMyAdmin - Changelog $Id$ $Source$ +2003-12-30 Alexander M. Turek + * config.inc.php, db_details_common.php, db_details_structure.php, + tbl_properties_operations.php, css/phpmyadmin.css.php, + libraries/common.lib.php, libraries/config_import.lib.php, + libraries/mysql_charsets.lib.php, libraries/sqlparser.lib.php: + - SQL parser detected the character set "binary" as column attribute; + - MySQL charsets are now parsed and highlighted - Note: the SQL parser + library now has to be included AFTER having connected to the MySQL + server; + - The default charset of a database may now be changed; + - Ensured that the user's connection is used for setting and retreiving + charset information. + * libraries/defines.lib.php: typo. + 2003-12-30 Marc Delisle * tbl_select.php: bug 867320, dropdowns in search page diff --git a/config.inc.php b/config.inc.php index f48dbb2de..c97eea89d 100644 --- a/config.inc.php +++ b/config.inc.php @@ -562,6 +562,7 @@ $cfg['SQP']['fmtColor'] = array( // Syntax colouring data 'alpha_reservedWord' => '#990099', 'alpha_functionName' => '#FF0000', 'alpha_identifier' => 'black', + 'alpha_charset' => '#6495ed' 'alpha_variable' => '#800000', 'quote' => '#008000', 'quote_double' => '', diff --git a/css/phpmyadmin.css.php b/css/phpmyadmin.css.php index d2d02e063..2c7000162 100644 --- a/css/phpmyadmin.css.php +++ b/css/phpmyadmin.css.php @@ -6,6 +6,7 @@ chdir('..'); $is_minimum_common = TRUE; require_once('./libraries/grab_globals.lib.php'); require_once('./libraries/common.lib.php'); +require_once('./libraries/sqlparser.lib.php'); // Gets the default font sizes // garvin: TODO: Should be optimized to not include the whole common.lib.php bunch @@ -220,6 +221,7 @@ button.mult_submit { .print{font-family:arial;font-size:8pt;} +/* MySQL Parser */ .syntax {font-family: sans-serif; font-size: ;} .syntax_comment { padding-left: 4pt; padding-right: 4pt;} .syntax_digit {} @@ -233,6 +235,7 @@ button.mult_submit { .syntax_alpha_reservedWord {text-transform: uppercase; font-weight: bold;} .syntax_alpha_functionName {text-transform: uppercase;} .syntax_alpha_identifier {} +.syntax_alpha_charset {} .syntax_alpha_variable {} .syntax_quote {white-space: pre;} .syntax_quote_backtick {} diff --git a/db_details_common.php b/db_details_common.php index e9e41b67f..fe132485e 100644 --- a/db_details_common.php +++ b/db_details_common.php @@ -32,6 +32,16 @@ if (!isset($is_db) || !$is_db) { exit; } } // end if (ensures db exists) + +/** + * Changes database charset if requested by the user + */ +if (isset($submitcharset) && PMA_MYSQL_INT_VERSION >= 40101) { + $sql_query = 'ALTER DATABASE ' . PMA_backquote($db) . ' DEFAULT CHARACTER SET ' . $db_charset; + $result = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query, '', $err_url); + $message = $strSuccess; +} + // Displays headers if (!isset($message)) { $js_to_run = 'functions.js'; diff --git a/db_details_structure.php b/db_details_structure.php index 69b06a605..ec5486077 100644 --- a/db_details_structure.php +++ b/db_details_structure.php @@ -7,7 +7,6 @@ require_once('./libraries/grab_globals.lib.php'); require_once('./libraries/common.lib.php'); require_once('./libraries/mysql_charsets.lib.php'); - /** * Prepares the tables list if the user where not redirected to this script * because there is no table in the database ($is_info is TRUE) @@ -37,6 +36,11 @@ if (empty($is_info)) { } } +if (PMA_MYSQL_INT_VERSION >= 40100) { + $db_collation = PMA_getDbCollation($db); +} + + // Display function function pma_TableHeader($alternate = FALSE) { echo ' ' . "\n" @@ -447,7 +451,6 @@ else { . ' --' . "\n" . ' ' . "\n"; if (PMA_MYSQL_INT_VERSION >= 40100) { - $db_collation = PMA_getDbCollation($db); echo ' ' . "\n"; @@ -597,6 +600,27 @@ echo ' ' . ' ' . "\n"; = 40101) { + // MySQL supports setting default charsets / collations for databases since + // version 4.1.1. + echo ' ' . "\n" + . '
  • ' . "\n" + . '
    ' . "\n" + . PMA_generate_common_hidden_inputs($db, $table, 3) + . ' ' . $strCharset . ' : ' . "\n" + . '  ' . "\n" + . '  ' . "\n" + . ' ' . "\n" + . '
  • ' . "\n\n"; +} + if ($num_tables > 0 && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == FALSE) { echo '
  • ' . "\n"; diff --git a/libraries/common.lib.php b/libraries/common.lib.php index d17f23d3f..7ca6a2444 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -136,7 +136,7 @@ if (isset($cfg['FileRevision'])) { } else { $cfg['FileRevision'] = array(1, 1); } -if ($cfg['FileRevision'][0] < 2 || ($cfg['FileRevision'][0] == 2 && $cfg['FileRevision'][1] < 1)) { +if ($cfg['FileRevision'][0] < 2 || ($cfg['FileRevision'][0] == 2 && $cfg['FileRevision'][1] < 4)) { require_once('./libraries/config_import.lib.php'); } @@ -172,7 +172,7 @@ if ($is_minimum_common == FALSE) { /** * Maximum upload size as limited by PHP - * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas + * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas * * this section generates $max_upload_size in bytes */ @@ -211,7 +211,7 @@ if ($is_minimum_common == FALSE) { if ($postsize < $max_upload_size) { $max_upload_size = $postsize; } - } + } unset($filesize); unset($postsize); @@ -222,7 +222,7 @@ if ($is_minimum_common == FALSE) { /** * Displays the maximum size for an upload * - * @param integer the size + * @param integer the size * * @return string the message * @@ -237,14 +237,14 @@ if ($is_minimum_common == FALSE) { * Generates a hidden field which should indicate to the browser * the maximum size for upload * - * @param integer the size + * @param integer the size * * @return string the INPUT field * * @access public */ function PMA_generateHiddenMaxFileSize($max_size){ - return ''; + return ''; } /** @@ -260,26 +260,6 @@ if ($is_minimum_common == FALSE) { require_once('./libraries/string.lib.php'); } -if ($is_minimum_common == FALSE) { - /** - * SQL Parser data - */ - require_once('./libraries/sqlparser.data.php'); -} - -/** - * SQL Parser code - */ - -require_once('./libraries/sqlparser.lib.php'); - -if ($is_minimum_common == FALSE) { - /** - * SQL Validator interface code - */ - require_once('./libraries/sqlvalidator.lib.php'); -} - // If zlib output compression is set in the php configuration file, no // output buffering should be run if (@ini_get('zlib.output_compression')) { @@ -1131,6 +1111,16 @@ if ($is_minimum_common == FALSE) { // Gets the mysql release number require_once('./libraries/defines_mysql.lib.php'); + /** + * SQL Parser code + */ + require_once('./libraries/sqlparser.lib.php'); + + /** + * SQL Validator interface code + */ + require_once('./libraries/sqlvalidator.lib.php'); + // if 'only_db' is set for the current user, there is no need to check for // available databases in the "mysql" db $dblist_cnt = count($dblist); @@ -1406,6 +1396,8 @@ if ($is_minimum_common == FALSE) { { global $cfg; + require_once('./header.inc.php'); + // Reloads the navigation frame via JavaScript if required if (isset($GLOBALS['reload']) && $GLOBALS['reload']) { echo "\n"; diff --git a/libraries/config_import.lib.php b/libraries/config_import.lib.php index 129453383..993a3b94e 100644 --- a/libraries/config_import.lib.php +++ b/libraries/config_import.lib.php @@ -915,6 +915,10 @@ if (!isset($cfg['SQP']['fmtColor']['alpha_identifier'])) { $cfg['SQP']['fmtColor']['alpha_identifier'] = 'black'; } +if (!isset($cfg['SQP']['fmtColor']['alpha_charset'])) { + $cfg['SQP']['fmtColor']['alpha_charset'] = '#6495ed'; +} + if (!isset($cfg['SQP']['fmtColor']['alpha_variable'])) { $cfg['SQP']['fmtColor']['alpha_variable'] = '#800000'; } diff --git a/libraries/defines.lib.php b/libraries/defines.lib.php index 68c7e723a..33cf3484e 100644 --- a/libraries/defines.lib.php +++ b/libraries/defines.lib.php @@ -9,10 +9,10 @@ * PMA_PHP_INT_VERSION (int) - eg: 30017 instead of 3.0.17 or * 40006 instead of 4.0.6RC3 * PMA_MYSQL_CLIENT_API (int) - the version number of the MySQL client - * API which php is built against. + * API which php is built against. * PMA_IS_WINDOWS (bool) - mark if phpMyAdmin running on windows * server - * PMA_IS_GD2 (bool) - true is GD2 is present + * PMA_IS_GD2 (bool) - true if GD2 is present * PMA_USR_OS (string) - the plateform (os) of the user * PMA_USR_BROWSER_AGENT (string) - the browser of the user * PMA_USR_BROWSER_VER (double) - the version of this browser diff --git a/libraries/mysql_charsets.lib.php b/libraries/mysql_charsets.lib.php index 5a9e43346..4d044e115 100644 --- a/libraries/mysql_charsets.lib.php +++ b/libraries/mysql_charsets.lib.php @@ -225,14 +225,14 @@ if (PMA_MYSQL_INT_VERSION >= 40100){ } function PMA_getDbCollation($db) { - global $dbh; + global $userlink; if (PMA_MYSQL_INT_VERSION >= 40101) { // MySQL 4.1.0 does not support seperate charset settings // for databases. $sql_query = 'SHOW CREATE DATABASE `' . $db . '`;'; - $res = PMA_mysql_query($sql_query, $dbh) or PMA_mysqlDie(PMA_mysql_error($dbh), $sql_query); + $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); $row = PMA_mysql_fetch_row($res); mysql_free_result($res); $tokenized = explode(' ', $row[1]); diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 0b0d71879..fe89a949f 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -49,6 +49,10 @@ if ($is_minimum_common == FALSE) { * Include data for the SQL Parser */ require_once('./libraries/sqlparser.data.php'); + require_once('./libraries/mysql_charsets.lib.php'); + if (!isset($mysql_charsets)) { + $mysql_charsets = array(); + } if (!defined('DEBUG_TIMING')) { function PMA_SQP_arrayAdd(&$arr, $type, $data, &$arrsize) @@ -186,6 +190,7 @@ if ($is_minimum_common == FALSE) { * @global integer MySQL reserved words count * @global integer MySQL column types count * @global integer MySQL function names count + * @global array List of available character sets * * @access public */ @@ -193,7 +198,8 @@ if ($is_minimum_common == FALSE) { { global $cfg; global $PMA_SQPdata_column_attrib, $PMA_SQPdata_reserved_word, $PMA_SQPdata_column_type, $PMA_SQPdata_function_name, - $PMA_SQPdata_column_attrib_cnt, $PMA_SQPdata_reserved_word_cnt, $PMA_SQPdata_column_type_cnt, $PMA_SQPdata_function_name_cnt; + $PMA_SQPdata_column_attrib_cnt, $PMA_SQPdata_reserved_word_cnt, $PMA_SQPdata_column_type_cnt, $PMA_SQPdata_function_name_cnt; + global $mysql_charsets; // rabus: Convert all line feeds to Unix style $sql = str_replace("\r\n", "\n", $sql); @@ -527,24 +533,30 @@ if ($is_minimum_common == FALSE) { if ($arraysize > 0) { - $t_next = $sql_array[0]['type']; - $t_prev = ''; - $t_cur = ''; - $d_next = $sql_array[0]['data']; - $d_prev = ''; - $d_cur = ''; - $d_next_upper = $t_next == 'alpha' ? strtoupper($d_next) : $d_next; - $d_prev_upper = ''; - $d_cur_upper = ''; + $t_next = $sql_array[0]['type']; + $t_prev = ''; + $t_bef_prev = ''; + $t_cur = ''; + $d_next = $sql_array[0]['data']; + $d_prev = ''; + $d_bef_prev = ''; + $d_cur = ''; + $d_next_upper = $t_next == 'alpha' ? strtoupper($d_next) : $d_next; + $d_prev_upper = ''; + $d_bef_prev_upper = ''; + $d_cur_upper = ''; } for ($i = 0; $i < $arraysize; $i++) { - $t_prev = $t_cur; - $t_cur = $t_next; - $d_prev = $d_cur; - $d_cur = $d_next; - $d_prev_upper = $d_cur_upper; - $d_cur_upper = $d_next_upper; + $t_bef_prev = $t_prev; + $t_prev = $t_cur; + $t_cur = $t_next; + $d_bef_prev = $d_prev; + $d_prev = $d_cur; + $d_cur = $d_next; + $d_bef_prev_upper = $d_prev_upper; + $d_prev_upper = $d_cur_upper; + $d_cur_upper = $d_next_upper; if (($i + 1) < $arraysize) { $t_next = $sql_array[$i + 1]['type']; $d_next = $sql_array[$i + 1]['data']; @@ -602,6 +614,17 @@ if ($is_minimum_common == FALSE) { if ($d_cur_upper == 'DEFAULT' && $d_next_upper == 'CHARACTER') { $t_suffix = '_reservedWord'; } + // Binary as character set + if ($d_cur_upper == 'BINARY' && ( + ($d_bef_prev_upper == 'CHARACTER' && $d_prev_upper == 'SET') + || ($d_bef_prev_upper == 'SET' && $d_prev_upper == '=') + || ($d_bef_prev_upper == 'CHARSET' && $d_prev_upper == '=') + || $prev_upper == 'CHARSET' + ) && PMA_STR_binarySearchInArr($d_cur, $mysql_charsets, count($mysql_charsets))) { + $t_suffix = '_charset'; + } + } elseif (PMA_STR_binarySearchInArr($d_cur, $mysql_charsets, count($mysql_charsets))) { + $t_suffix = '_charset'; } else { // Do nothing } diff --git a/tbl_properties_operations.php b/tbl_properties_operations.php index fd0ef96d6..929965487 100644 --- a/tbl_properties_operations.php +++ b/tbl_properties_operations.php @@ -39,7 +39,7 @@ if (isset($submittype)) { } if (isset($submitcharset)) { $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHARACTER SET = ' . $tbl_charset; - $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url); + $result = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query, '', $err_url); $message = $strSuccess; } if (isset($submitoptions)) {
  • ' . "\n" . '  ' . $db_collation . ' ' . "\n" . '