yet more charset stuff

This commit is contained in:
Alexander M. Turek
2003-12-30 18:24:11 +00:00
parent 5e9411e18d
commit e2b955cc90
11 changed files with 120 additions and 49 deletions

View File

@@ -5,6 +5,20 @@ phpMyAdmin - Changelog
$Id$
$Source$
2003-12-30 Alexander M. Turek <facevalue@derrabus.de>
* 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 <lem9@users.sourceforge.net>
* tbl_select.php: bug 867320, dropdowns in search page

View File

@@ -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' => '',

View File

@@ -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: <?php echo $font_smaller; ?>;}
.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 {}

View File

@@ -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';

View File

@@ -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 ' <table border="' . $GLOBALS['cfg']['Border'] . '">' . "\n"
@@ -447,7 +451,6 @@ else {
. ' <b>--</b>' . "\n"
. ' </th>' . "\n";
if (PMA_MYSQL_INT_VERSION >= 40100) {
$db_collation = PMA_getDbCollation($db);
echo ' <th align="center">' . "\n"
. ' &nbsp;<b><dfn title="' . PMA_getCollationDescr($db_collation) . '">' . $db_collation . '</dfn></b>&nbsp;' . "\n"
. ' </th>' . "\n";
@@ -597,6 +600,27 @@ echo ' ' . '&nbsp;<input type="submit" value="' . $strGo . '" />' . "\n";
</li>
<?php
if (PMA_MYSQL_INT_VERSION >= 40101) {
// MySQL supports setting default charsets / collations for databases since
// version 4.1.1.
echo ' <!-- Change database charset -->' . "\n"
. ' <li>' . "\n"
. ' <form method="post" action="./db_details_structure.php">' . "\n"
. PMA_generate_common_hidden_inputs($db, $table, 3)
. ' ' . $strCharset . '&nbsp;:&nbsp;' . "\n"
. ' <select name="db_charset" style="vertical-align: middle">' . "\n";
$real_charset = strpos($db_collation, '_') ? substr($db_collation, 0, strpos($db_collation, '_')) : $db_collation;
for ($i = 1; isset($mysql_charsets[$i]); $i++) {
echo ' <option value="' . $mysql_charsets[$i] . '"' . ($mysql_charsets[$i] == $real_charset ? ' selected="selected"' : '') . '>' . $mysql_charsets[$i] . '</option>' . "\n";
}
unset($i, $real_charset);
echo ' </select>&nbsp;' . "\n"
. ' <input type="submit" name="submitcharset" value="' . $strGo . '" style="vertical-align: middle" />&nbsp;' . "\n"
. ' </form>' . "\n"
. ' </li>' . "\n\n";
}
if ($num_tables > 0
&& !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == FALSE) {
echo ' <li>' . "\n";

View File

@@ -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 '<input type="hidden" name="MAX_FILE_SIZE" value="' .$max_size . '" />';
return '<input type="hidden" name="MAX_FILE_SIZE" value="' .$max_size . '" />';
}
/**
@@ -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";

View File

@@ -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';
}

View File

@@ -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

View File

@@ -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]);

View File

@@ -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
}

View File

@@ -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)) {