bug #1351743 undefined function: pma_getservercollation()

This commit is contained in:
Sebastian Mendel
2005-11-09 08:56:35 +00:00
parent 743416fe24
commit c2413163c0
3 changed files with 369 additions and 353 deletions

View File

@@ -5,6 +5,10 @@ phpMyAdmin - Changelog
$Id$
$Source$
2005-11-09 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* server_databases.php, mysql_charsets-lib.php:
bug #1351743 undefined function: pma_getservercollation()
2005-11-08 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* Documentation.html, browse_foreigners.php, error.php,
header_printview.inc.php, index.php, left.php, translators.html,

View File

@@ -12,16 +12,15 @@ if (PMA_MYSQL_INT_VERSION >= 40100){
$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
$mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
}
@PMA_DBI_free_result($res);
unset($res, $row);
$res = PMA_DBI_query('SHOW COLLATION;');
@PMA_DBI_free_result( $res );
$mysql_charsets_count = count($mysql_charsets);
sort($mysql_charsets, SORT_STRING);
$mysql_collations = array_flip($mysql_charsets);
$mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
$res = PMA_DBI_query('SHOW COLLATION;');
while ($row = PMA_DBI_fetch_assoc($res)) {
if (!is_array($mysql_collations[$row['Charset']])) {
$mysql_collations[$row['Charset']] = array($row['Collation']);
@@ -36,6 +35,8 @@ if (PMA_MYSQL_INT_VERSION >= 40100){
$mysql_collations_available[$row['Collation']] = TRUE;
$mysql_charsets_available[$row['Charset']] = !empty($mysql_charsets_available[$row['Charset']]) || !empty($mysql_collations_available[$row['Collation']]);
}
@PMA_DBI_free_result( $res );
unset( $res, $row );
$mysql_collations_count = count($mysql_collations_flat);
sort($mysql_collations_flat, SORT_STRING);
@@ -44,10 +45,116 @@ if (PMA_MYSQL_INT_VERSION >= 40100){
reset($mysql_collations[$key]);
}
@PMA_DBI_free_result($res);
unset($res, $row);
define('PMA_CSDROPDOWN_COLLATION', 0);
define('PMA_CSDROPDOWN_CHARSET', 1);
function PMA_getCollationDescr($collation) {
function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION, $name = NULL, $id = NULL, $default = NULL, $label = TRUE, $indent = 0, $submitOnChange = FALSE, $displayUnavailable = FALSE) {
global $mysql_charsets, $mysql_charsets_descriptions, $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
if (empty($name)) {
if ($type == PMA_CSDROPDOWN_COLLATION) {
$name = 'collation';
} else {
$name = 'character_set';
}
}
$spacer = '';
for ($i = 1; $i <= $indent; $i++) $spacer .= ' ';
$return_str = $spacer . '<select xml:lang="en" dir="ltr" name="' . htmlspecialchars($name) . '"' . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"') . ($submitOnChange ? ' onchange="this.form.submit();"' : '') . '>' . "\n";
if ($label) {
$return_str .= $spacer . ' <option value="">' . ($type == PMA_CSDROPDOWN_COLLATION ? $GLOBALS['strCollation'] : $GLOBALS['strCharset']) . '</option>' . "\n";
}
$return_str .= $spacer . ' <option value=""></option>' . "\n";
foreach ($mysql_charsets as $current_charset) {
if (!$mysql_charsets_available[$current_charset]) {
continue;
}
$current_cs_descr = empty($mysql_charsets_descriptions[$current_charset]) ? $current_charset : $mysql_charsets_descriptions[$current_charset];
if ($type == PMA_CSDROPDOWN_COLLATION) {
$return_str .= $spacer . ' <optgroup label="' . $current_charset . '" title="' . $current_cs_descr . '">' . "\n";
foreach ($mysql_collations[$current_charset] as $current_collation) {
if (!$mysql_collations_available[$current_collation]) {
continue;
}
$return_str .= $spacer . ' <option value="' . $current_collation . '" title="' . PMA_getCollationDescr($current_collation) . '"' . ($default == $current_collation ? ' selected="selected"' : '') . '>' . $current_collation . '</option>' . "\n";
}
$return_str .= $spacer . ' </optgroup>' . "\n";
} else {
$return_str .= $spacer . ' <option value="' . $current_charset . '" title="' . $current_cs_descr . '"' . ($default == $current_charset ? ' selected="selected"' : '') . '>' . $current_charset . '</option>' . "\n";
}
}
$return_str .= $spacer . '</select>' . "\n";
return $return_str;
}
function PMA_generateCharsetQueryPart($collation) {
list($charset) = explode('_', $collation);
return ' CHARACTER SET ' . $charset . ($charset == $collation ? '' : ' COLLATE ' . $collation);
}
/**
* returns collation of given db
*
* @uses PMA_MYSQL_INT_VERSION
* @uses PMA_DBI_fetch_value()
* @uses PMA_DBI_select_db()
* @uses PMA_sqlAddSlashes()
* @uses $GLOBALS['db']
* @param string $db name of db
* @return string collation of $db
*/
function PMA_getDbCollation( $db ) {
if ( PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema' ) {
// We don't have to check the collation of the virtual
// information_schema database: We know it!
return 'utf8_general_ci';
}
if ( PMA_MYSQL_INT_VERSION >= 50006 ) {
// Since MySQL 5.0.6, we don't have to parse SHOW CREATE DATABASE anymore.
return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;');
} elseif ( PMA_MYSQL_INT_VERSION >= 40101 ) {
// MySQL 4.1.0 does not support seperate charset settings
// for databases.
PMA_DBI_select_db( $db );
$return = PMA_DBI_fetch_value( 'SHOW VARIABLES LIKE "collation_database"', 0, 1 );
if ( ! empty( $GLOBALS['db'] ) && $db !== $GLOBALS['db'] ) {
PMA_DBI_select_db( $GLOBALS['db'] );
}
return $return;
}
return '';
}
} else {
function PMA_getDbCollation( $db ) { return PMA_getServerCollation(); }
}
/**
* returns default server collation from show variables
*
* @uses PMA_DBI_fetch_value()
* @return string $server_collation
*/
function PMA_getServerCollation() {
return PMA_DBI_fetch_value(
'SHOW VARIABLES LIKE \'collation_server\'', 0, 1 );
}
/**
* returns description for given collation
*
* @uses is_array()
* @uses explode()
* @uses count()
* @uses $GLOBALS['str[Languages|Sorting]']
*
* @param string $collation MySQL collation string
* @return string collation description
*/
function PMA_getCollationDescr( $collation ) {
static $collation_cache;
if (!is_array($collation_cache)) {
@@ -273,101 +380,5 @@ if (PMA_MYSQL_INT_VERSION >= 40100){
$collation_cache[$collation] = $descr;
return $descr;
}
/**
* returns collation of given db
*
* @uses PMA_MYSQL_INT_VERSION
* @uses PMA_DBI_fetch_value()
* @uses PMA_DBI_select_db()
* @uses PMA_sqlAddSlashes()
* @uses $GLOBALS['db']
* @param string $db name of db
* @return string collation of $db
*/
function PMA_getDbCollation( $db ) {
if (PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema') {
// We don't have to check the collation of the virtual
// information_schema database: We know it!
return 'utf8_general_ci';
}
if (PMA_MYSQL_INT_VERSION >= 50006) {
// Since MySQL 5.0.6, we don't have to parse SHOW CREATE DATABASE anymore.
return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;');
} else if (PMA_MYSQL_INT_VERSION >= 40101) {
// MySQL 4.1.0 does not support seperate charset settings
// for databases.
PMA_DBI_select_db( $db );
$return = PMA_DBI_fetch_value( 'SHOW VARIABLES LIKE "collation_database"', 0, 1 );
if ( ! empty( $GLOBALS['db'] ) && $db !== $GLOBALS['db'] ) {
PMA_DBI_select_db( $GLOBALS['db'] );
}
return $return;
}
return '';
}
define('PMA_CSDROPDOWN_COLLATION', 0);
define('PMA_CSDROPDOWN_CHARSET', 1);
function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION, $name = NULL, $id = NULL, $default = NULL, $label = TRUE, $indent = 0, $submitOnChange = FALSE, $displayUnavailable = FALSE) {
global $mysql_charsets, $mysql_charsets_descriptions, $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
if (empty($name)) {
if ($type == PMA_CSDROPDOWN_COLLATION) {
$name = 'collation';
} else {
$name = 'character_set';
}
}
$spacer = '';
for ($i = 1; $i <= $indent; $i++) $spacer .= ' ';
$return_str = $spacer . '<select xml:lang="en" dir="ltr" name="' . htmlspecialchars($name) . '"' . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"') . ($submitOnChange ? ' onchange="this.form.submit();"' : '') . '>' . "\n";
if ($label) {
$return_str .= $spacer . ' <option value="">' . ($type == PMA_CSDROPDOWN_COLLATION ? $GLOBALS['strCollation'] : $GLOBALS['strCharset']) . '</option>' . "\n";
}
$return_str .= $spacer . ' <option value=""></option>' . "\n";
foreach ($mysql_charsets as $current_charset) {
if (!$mysql_charsets_available[$current_charset]) {
continue;
}
$current_cs_descr = empty($mysql_charsets_descriptions[$current_charset]) ? $current_charset : $mysql_charsets_descriptions[$current_charset];
if ($type == PMA_CSDROPDOWN_COLLATION) {
$return_str .= $spacer . ' <optgroup label="' . $current_charset . '" title="' . $current_cs_descr . '">' . "\n";
foreach ($mysql_collations[$current_charset] as $current_collation) {
if (!$mysql_collations_available[$current_collation]) {
continue;
}
$return_str .= $spacer . ' <option value="' . $current_collation . '" title="' . PMA_getCollationDescr($current_collation) . '"' . ($default == $current_collation ? ' selected="selected"' : '') . '>' . $current_collation . '</option>' . "\n";
}
$return_str .= $spacer . ' </optgroup>' . "\n";
} else {
$return_str .= $spacer . ' <option value="' . $current_charset . '" title="' . $current_cs_descr . '"' . ($default == $current_charset ? ' selected="selected"' : '') . '>' . $current_charset . '</option>' . "\n";
}
}
$return_str .= $spacer . '</select>' . "\n";
return $return_str;
}
function PMA_generateCharsetQueryPart($collation) {
list($charset) = explode('_', $collation);
return ' CHARACTER SET ' . $charset . ($charset == $collation ? '' : ' COLLATE ' . $collation);
}
/**
* returns default server collation from show variables
*
* @uses PMA_DBI_fetch_value()
* @return string $server_collation
*/
function PMA_getServerCollation() {
return PMA_DBI_fetch_value(
'SHOW VARIABLES LIKE \'collation_server\'', 0, 1 );
}
}
?>

View File

@@ -124,43 +124,44 @@ if ( count($databases) > 0 ) {
usort( $databases, 'PMA_dbCmp' );
// table col order
$column_order = array(
'DEFAULT_COLLATION_NAME' => array(
// there is no db specific collation or charset prior 4.1.0
if ( PMA_MYSQL_INT_VERSION >= 40100 ) {
$column_order['DEFAULT_COLLATION_NAME'] = array(
'disp_name' => $strCollation,
'description_function' => 'PMA_getCollationDescr',
'format' => 'string',
'footer' => PMA_getServerCollation(),
),
'SCHEMA_TABLES' => array(
);
}
$column_order['SCHEMA_TABLES'] = array(
'disp_name' => $strNumTables,
'format' => 'number',
'footer' => 0,
),
'SCHEMA_TABLE_ROWS' => array(
);
$column_order['SCHEMA_TABLE_ROWS'] = array(
'disp_name' => $strRows,
'format' => 'number',
'footer' => 0,
),
'SCHEMA_DATA_LENGTH' => array(
);
$column_order['SCHEMA_DATA_LENGTH'] = array(
'disp_name' => $strData,
'format' => 'byte',
'footer' => 0,
),
'SCHEMA_INDEX_LENGTH' => array(
);
$column_order['SCHEMA_INDEX_LENGTH'] = array(
'disp_name' => $strIndexes,
'format' => 'byte',
'footer' => 0,
),
'SCHEMA_LENGTH' => array(
);
$column_order['SCHEMA_LENGTH'] = array(
'disp_name' => $strTotalUC,
'format' => 'byte',
'footer' => 0,
),
'SCHEMA_DATA_FREE' => array(
);
$column_order['SCHEMA_DATA_FREE'] = array(
'disp_name' => $strOverhead,
'format' => 'byte',
'footer' => 0,
),
);
echo '<form action="./server_databases.php" method="post" name="dbStatsForm">' . "\n"