Removed recoding function calls from controluser queries as they do not depend on the connection charset anymore.

This commit is contained in:
Alexander M. Turek
2005-03-25 14:05:24 +00:00
parent 308b82e809
commit 96fff6fe00
2 changed files with 104 additions and 101 deletions

View File

@@ -11,6 +11,11 @@ $Source$
2005-03-25 Alexander M. Turek <me@derrabus.de> 2005-03-25 Alexander M. Turek <me@derrabus.de>
* db_details_structure.php: Let's prefer separate icons over CSS 3 hacks * db_details_structure.php: Let's prefer separate icons over CSS 3 hacks
for marking a functionality as unavailable. for marking a functionality as unavailable.
* libraries/relation.lib.php:
- Removed recoding function calls from controluser queries as they do
not depend on the connection charset anymore;
- Added emulated relations for some information_schema tables. To be
continued.
2005-03-24 Alexander M. Turek <me@derrabus.de> 2005-03-24 Alexander M. Turek <me@derrabus.de>
* libraries/dbi/*.dbi.lib.php, libraries/common.lib.php, * libraries/dbi/*.dbi.lib.php, libraries/common.lib.php,

View File

@@ -268,32 +268,22 @@ function PMA_getRelationsParam($verbose = FALSE)
* *
* @global array the list of relations settings * @global array the list of relations settings
* @global string the URL of the page to show in case of error * @global string the URL of the page to show in case of error
* @global string the connection charset, as defined in
* libraries/database_interface.lib.php
* *
* @access public * @access public
* *
* @author Mike Beck <mikebeck@users.sourceforge.net> and Marc Delisle * @author Mike Beck <mikebeck@users.sourceforge.net> and Marc Delisle
*/ */
function PMA_getForeigners($db, $table, $column = '', $source = 'both') { function PMA_getForeigners($db, $table, $column = '', $source = 'both') {
global $cfgRelation, $err_url_0, $charset_connection; global $cfgRelation, $err_url_0;
if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) { if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) {
$rel_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field' $rel_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field'
. ' FROM ' . PMA_backquote($cfgRelation['relation']); . ' FROM ' . PMA_backquote($cfgRelation['relation'])
if (PMA_MYSQL_INT_VERSION >= 40100) { . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
$rel_query .= ' WHERE CONVERT(master_db USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($db) . '\' '
. ' AND CONVERT(master_table USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($table) . '\' ';
if (!empty($column)) {
$rel_query .= ' AND CONVERT(master_field USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($column) . '\'';
}
} else {
$rel_query .= ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\' '; . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\' ';
if (!empty($column)) { if (!empty($column)) {
$rel_query .= ' AND master_field = \'' . PMA_sqlAddslashes($column) . '\''; $rel_query .= ' AND master_field = \'' . PMA_sqlAddslashes($column) . '\'';
} }
}
$relations = PMA_query_as_cu($rel_query); $relations = PMA_query_as_cu($rel_query);
$i = 0; $i = 0;
while ($relrow = PMA_DBI_fetch_assoc($relations)) { while ($relrow = PMA_DBI_fetch_assoc($relations)) {
@@ -354,11 +344,47 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') {
} }
} }
/**
* Emulating relations for some information_schema tables
*/
if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema'
&& ($source == 'internal' || $source == 'both')) {
$foreign = array();
switch ($table) {
case 'COLLATION_CHARACTER_SET_APPLICABILITY':
if ((empty($column) || $column == 'CHARACTER_SET_NAME') && !isset($foreign['CHARACTER_SET_NAME'])) {
$foreign['CHARACTER_SET_NAME'] = array(
'foreign_db' => 'information_schema',
'foreign_table' => 'CHARACTER_SETS',
'foreign_field' => 'CHARACTER_SET_NAME'
);
}
if ((empty($column) || $column == 'COLLATION_NAME') && !isset($foreign['COLLATION_NAME'])) {
$foreign['COLLATION_NAME'] = array(
'foreign_db' => 'information_schema',
'foreign_table' => 'COLLATIONS',
'foreign_field' => 'COLLATION_NAME'
);
}
break;
case 'SCHEMATA':
if ((empty($column) || $column == 'DEFAULT_CHARACTER_SET_NAME') && !isset($foreign['DEFAULT_CHARACTER_SET_NAME'])) {
$foreign['DEFAULT_CHARACTER_SET_NAME'] = array(
'foreign_db' => 'information_schema',
'foreign_table' => 'CHARACTER_SETS',
'foreign_field' => 'CHARACTER_SET_NAME'
);
}
break;
}
}
if (isset($foreign) && is_array($foreign)) { if (isset($foreign) && is_array($foreign)) {
return $foreign; return $foreign;
} else { } else {
return FALSE; return FALSE;
} }
} // end of the 'PMA_getForeigners()' function } // end of the 'PMA_getForeigners()' function
@@ -371,36 +397,47 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') {
* @return string field name * @return string field name
* *
* @global array the list of relations settings * @global array the list of relations settings
* @global string the connection charset, as defined in
* libraries/database_interface.lib.php
* *
* @access public * @access public
* *
* @author Mike Beck <mikebeck@users.sourceforge.net> * @author Mike Beck <mikebeck@users.sourceforge.net>
*/ */
function PMA_getDisplayField($db, $table) { function PMA_getDisplayField($db, $table) {
global $cfgRelation, $charset_connection; global $cfgRelation;
if (trim(@$cfgRelation['table_info']) == '') {
return FALSE;
}
$disp_query = 'SELECT display_field FROM ' . PMA_backquote($cfgRelation['table_info']); /**
if (PMA_MYSQL_INT_VERSION >= 40100) { * Try to fetch the display field from DB.
$disp_query .= ' WHERE CONVERT(db_name USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($db) . '\'' */
. ' AND CONVERT(table_name USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($table) . '\''; if (trim(@$cfgRelation['table_info']) != '') {
} else {
$disp_query .= ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' $disp_query = 'SELECT display_field FROM ' . PMA_backquote($cfgRelation['table_info'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
}
$disp_res = PMA_query_as_cu($disp_query); $disp_res = PMA_query_as_cu($disp_query);
$row = ($disp_res ? PMA_DBI_fetch_assoc($disp_res) : ''); $row = ($disp_res ? PMA_DBI_fetch_assoc($disp_res) : '');
PMA_DBI_free_result($disp_res); PMA_DBI_free_result($disp_res);
if (isset($row['display_field'])) { if (isset($row['display_field'])) {
return $row['display_field']; return $row['display_field'];
} else {
return FALSE;
} }
}
/**
* Emulating the display field for some information_schema tables.
*/
if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') {
switch ($table) {
case 'CHARACTER_SETS': return 'DESCRIPTION';
case 'TABLES': return 'TABLE_COMMENT';
}
}
/**
* No Luck...
*/
return FALSE;
} // end of the 'PMA_getDisplayField()' function } // end of the 'PMA_getDisplayField()' function
@@ -413,8 +450,6 @@ function PMA_getDisplayField($db, $table) {
* @return array [field_name] = comment * @return array [field_name] = comment
* *
* @global array the list of relations settings * @global array the list of relations settings
* @global string the connection charset, as defined in
* libraries/database_interface.lib.php
* *
* @access public * @access public
* *
@@ -422,7 +457,7 @@ function PMA_getDisplayField($db, $table) {
* and lem9 * and lem9
*/ */
function PMA_getComments($db, $table = '') { function PMA_getComments($db, $table = '') {
global $cfgRelation, $charset_connection; global $cfgRelation;
if ($table != '') { if ($table != '') {
@@ -443,28 +478,17 @@ function PMA_getComments($db, $table = '') {
// (this function can be called even if $cfgRelation['commwork'] is // (this function can be called even if $cfgRelation['commwork'] is
// FALSE, to get native column comments, so recheck here) // FALSE, to get native column comments, so recheck here)
if ($cfgRelation['commwork']) { if ($cfgRelation['commwork']) {
$com_qry = 'SELECT column_name, comment FROM ' . PMA_backquote($cfgRelation['db']) . '.' .PMA_backquote($cfgRelation['column_info']); $com_qry = 'SELECT column_name, comment FROM ' . PMA_backquote($cfgRelation['db']) . '.' .PMA_backquote($cfgRelation['column_info'])
if (PMA_MYSQL_INT_VERSION >= 40100) { . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
$com_qry .= ' WHERE CONVERT(db_name USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND CONVERT(table_name USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($table) . '\'';
} else {
$com_qry .= ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
}
$com_rs = PMA_query_as_cu($com_qry, TRUE, PMA_DBI_QUERY_STORE); $com_rs = PMA_query_as_cu($com_qry, TRUE, PMA_DBI_QUERY_STORE);
} }
} else { } else {
// pmadb internal db comments // pmadb internal db comments
$com_qry = 'SELECT ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']); $com_qry = 'SELECT ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
if (PMA_MYSQL_INT_VERSION >= 40100) { . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
$com_qry .= ' WHERE CONVERT(db_name USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND CONVERT(table_name USING ' . $charset_connection . ') = \'\''
. ' AND CONVERT(column_name USING ' . $charset_connection . ') = \'(db_comment)\'';
} else {
$com_qry .= ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'\'' . ' AND table_name = \'\''
. ' AND column_name = \'(db_comment)\''; . ' AND column_name = \'(db_comment)\'';
}
$com_rs = PMA_query_as_cu($com_qry, TRUE, PMA_DBI_QUERY_STORE); $com_rs = PMA_query_as_cu($com_qry, TRUE, PMA_DBI_QUERY_STORE);
} }
@@ -534,13 +558,11 @@ function PMA_handleSlashes($val) {
* @return boolean true, if comment-query was made. * @return boolean true, if comment-query was made.
* *
* @global array the list of relations settings * @global array the list of relations settings
* @global string the connection charset, as defined in
* libraries/database_interface.lib.php
* *
* @access public * @access public
*/ */
function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='auto') { function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='auto') {
global $cfgRelation, $charset_connection; global $cfgRelation;
if ($mode=='auto') { if ($mode=='auto') {
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100) {
@@ -573,20 +595,11 @@ function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='aut
// $mode == 'pmadb' section: // $mode == 'pmadb' section:
if (PMA_MYSQL_INT_VERSION >= 40100) {
$cols = array(
'db_name' => 'CONVERT(db_name USING ' . $charset_connection . ')',
'table_name' => 'CONVERT(table_name USING ' . $charset_connection . ')',
'column_name' => 'CONVERT(column_name USING ' . $charset_connection . ')'
);
} else {
$cols = array( $cols = array(
'db_name' => 'db_name ', 'db_name' => 'db_name ',
'table_name' => 'table_name ', 'table_name' => 'table_name ',
'column_name' => 'column_name' 'column_name' => 'column_name'
); );
}
if ($removekey != '' AND $removekey != $col) { if ($removekey != '' AND $removekey != $col) {
$remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info']) $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
@@ -647,8 +660,6 @@ function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='aut
* @param string the sql query * @param string the sql query
* *
* @global array the list of relations settings * @global array the list of relations settings
* @global string the connection charset, as defined in
* libraries/database_interface.lib.php
* *
* @return boolean true * @return boolean true
* *
@@ -678,28 +689,21 @@ function PMA_setHistory($db, $table, $username, $sqlquery) {
* @param string the username * @param string the username
* *
* @global array the list of relations settings * @global array the list of relations settings
* @global string the connection charset, as defined in
* libraries/database_interface.lib.php
* *
* @return array list of history items * @return array list of history items
* *
* @access public * @access public
*/ */
function PMA_getHistory($username) { function PMA_getHistory($username) {
global $cfgRelation, $charset_connection; global $cfgRelation;
$hist_query = 'SELECT ' $hist_query = 'SELECT '
. PMA_backquote('db') . ',' . PMA_backquote('db') . ','
. PMA_backquote('table') . ',' . PMA_backquote('table') . ','
. PMA_backquote('sqlquery') . PMA_backquote('sqlquery')
. ' FROM ' . PMA_backquote($cfgRelation['history']) . ' FROM ' . PMA_backquote($cfgRelation['history'])
. ' WHERE '; . ' WHERE username = \'' . PMA_sqlAddslashes($username) . '\''
if (PMA_MYSQL_INT_VERSION >= 40100) { . ' ORDER BY id DESC';
$hist_query .= 'CONVERT(username USING ' . $charset_connection . ')';
} else {
$hist_query .= 'username';
}
$hist_query .= ' = \'' . PMA_sqlAddslashes($username) . '\' ORDER BY id DESC';
$hist_rs = PMA_query_as_cu($hist_query); $hist_rs = PMA_query_as_cu($hist_query);
unset($hist_query); unset($hist_query);
@@ -725,23 +729,17 @@ function PMA_getHistory($username) {
* *
* @global array the list of relations settings * @global array the list of relations settings
* @global array global phpMyAdmin configuration * @global array global phpMyAdmin configuration
* @global string the connection charset, as defined in
* libraries/database_interface.lib.php
* *
* @return boolean true * @return boolean true
* *
* @access public * @access public
*/ */
function PMA_purgeHistory($username) { function PMA_purgeHistory($username) {
global $cfgRelation, $cfg, $charset_connection; global $cfgRelation, $cfg;
$purge_query = 'SELECT timevalue FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE '; $purge_query = 'SELECT timevalue FROM ' . PMA_backquote($cfgRelation['history'])
if (PMA_MYSQL_INT_VERSION >= 40100) { . ' WHERE username = \'' . PMA_sqlAddSlashes($username) . '\''
$purge_query .= 'CONVERT(username USING ' . $charset_connection . ')'; . ' ORDER BY timevalue DESC LIMIT ' . $cfg['QueryHistoryMax'] . ', 1';
} else {
$purge_query .= 'username';
}
$purge_query .= ' = \'' . PMA_sqlAddSlashes($username) . '\' ORDER BY timevalue DESC LIMIT ' . $cfg['QueryHistoryMax'] . ', 1';
$purge_rs = PMA_query_as_cu($purge_query); $purge_rs = PMA_query_as_cu($purge_query);
$i = 0; $i = 0;
$row = PMA_DBI_fetch_row($purge_rs); $row = PMA_DBI_fetch_row($purge_rs);