Code redundancy

This commit is contained in:
Alexander M. Turek
2005-01-11 21:11:23 +00:00
parent 8db2f785ae
commit fa8541025e
2 changed files with 112 additions and 96 deletions

View File

@@ -5,6 +5,11 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2005-01-11 Alexander M. Turek <me@derrabus.de>
* libraries/relation.lib.php:
- Removed redundant code;
- Fixed some comments.
2005-01-11 Marc Delisle <lem9@users.sourceforge.net> 2005-01-11 Marc Delisle <lem9@users.sourceforge.net>
* libraries/dbi/mysqli.dbi.lib.php: bug #1076213, headers sent * libraries/dbi/mysqli.dbi.lib.php: bug #1076213, headers sent
on invalid login on invalid login

View File

@@ -268,25 +268,25 @@ 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; global $cfgRelation, $err_url_0, $charset_connection;
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) { if (PMA_MYSQL_INT_VERSION >= 40100) {
list($conn_charset) = explode('_', $GLOBALS['collation_connection']); $rel_query .= ' WHERE CONVERT(master_db USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($db) . '\' '
$rel_query .= ' WHERE CONVERT(master_db USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($db) . '\' ' . ' AND CONVERT(master_table USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($table) . '\' ';
. ' AND CONVERT(master_table USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($table) . '\' ';
if (!empty($column)) { if (!empty($column)) {
$rel_query .= ' AND CONVERT(master_field USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($column) . '\''; $rel_query .= ' AND CONVERT(master_field USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($column) . '\'';
} }
unset($conn_charset);
} else { } else {
$rel_query .= ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' ' $rel_query .= ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\' '; . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\' ';
@@ -371,22 +371,23 @@ 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; global $cfgRelation, $charset_connection;
if (trim(@$cfgRelation['table_info']) == '') { if (trim(@$cfgRelation['table_info']) == '') {
return FALSE; return FALSE;
} }
$disp_query = 'SELECT display_field FROM ' . PMA_backquote($cfgRelation['table_info']); $disp_query = 'SELECT display_field FROM ' . PMA_backquote($cfgRelation['table_info']);
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100) {
list($conn_charset) = explode('_', $GLOBALS['collation_connection']); $disp_query .= ' WHERE CONVERT(db_name USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($db) . '\''
$disp_query .= ' WHERE CONVERT(db_name USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND CONVERT(table_name USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($table) . '\'';
. ' AND CONVERT(table_name USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($table) . '\'';
} else { } else {
$disp_query .= ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' $disp_query .= ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
@@ -412,23 +413,21 @@ 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
* *
* @author Mike Beck <mikebeck@users.sourceforge.net> * @author Mike Beck <mikebeck@users.sourceforge.net>
*/ */
function PMA_getComments($db, $table = '') { function PMA_getComments($db, $table = '') {
global $cfgRelation; global $cfgRelation, $charset_connection;
if (PMA_MYSQL_INT_VERSION >= 40100) {
list($conn_charset) = explode('_', $GLOBALS['collation_connection']);
}
if ($table != '') { if ($table != '') {
$com_qry = 'SELECT column_name, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_info']); $com_qry = 'SELECT column_name, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_info']);
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100) {
$com_qry .= ' WHERE CONVERT(db_name USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($db) . '\'' $com_qry .= ' WHERE CONVERT(db_name USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND CONVERT(table_name USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($table) . '\''; . ' AND CONVERT(table_name USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($table) . '\'';
} else { } else {
$com_qry .= ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' $com_qry .= ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'';
@@ -437,9 +436,9 @@ function PMA_getComments($db, $table = '') {
} else { } else {
$com_qry = 'SELECT ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_info']); $com_qry = 'SELECT ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_info']);
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100) {
$com_qry .= ' WHERE CONVERT(db_name USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($db) . '\'' $com_qry .= ' WHERE CONVERT(db_name USING ' . $charset_connection . ') = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND CONVERT(table_name USING ' . $conn_charset . ') = \'\'' . ' AND CONVERT(table_name USING ' . $charset_connection . ') = \'\''
. ' AND CONVERT(column_name USING ' . $conn_charset . ') = \'(db_comment)\''; . ' AND CONVERT(column_name USING ' . $charset_connection . ') = \'(db_comment)\'';
} else { } else {
$com_qry .= ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' $com_qry .= ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
. ' AND table_name = \'\'' . ' AND table_name = \'\''
@@ -493,18 +492,19 @@ 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, $key, $value, $removekey = '') { function PMA_setComment($db, $table, $key, $value, $removekey = '') {
global $cfgRelation; global $cfgRelation, $charset_connection;
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100) {
list($conn_charset) = explode('_', $GLOBALS['collation_connection']);
$cols = array( $cols = array(
'db_name' => 'CONVERT(db_name USING ' . $conn_charset . ')', 'db_name' => 'CONVERT(db_name USING ' . $charset_connection . ')',
'table_name' => 'CONVERT(table_name USING ' . $conn_charset . ')', 'table_name' => 'CONVERT(table_name USING ' . $charset_connection . ')',
'column_name' => 'CONVERT(column_name USING ' . $conn_charset . ')' 'column_name' => 'CONVERT(column_name USING ' . $charset_connection . ')'
); );
} else { } else {
$cols = array( $cols = array(
@@ -572,6 +572,10 @@ function PMA_setComment($db, $table, $key, $value, $removekey = '') {
* @param string the username * @param string the username
* @param string the sql query * @param string the sql query
* *
* @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
* *
* @access public * @access public
@@ -599,12 +603,16 @@ function PMA_setHistory($db, $table, $username, $sqlquery) {
* *
* @param string the username * @param string the username
* *
* @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; global $cfgRelation, $charset_connection;
$hist_query = 'SELECT ' $hist_query = 'SELECT '
. PMA_backquote('db') . ',' . PMA_backquote('db') . ','
@@ -613,9 +621,7 @@ function PMA_getHistory($username) {
. ' FROM ' . PMA_backquote($cfgRelation['history']) . ' FROM ' . PMA_backquote($cfgRelation['history'])
. ' WHERE '; . ' WHERE ';
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100) {
list($conn_charset) = explode('_', $GLOBALS['collation_connection']); $hist_query .= 'CONVERT(username USING ' . $charset_connection . ')';
$hist_query .= 'CONVERT(username USING ' . $conn_charset . ')';
unset($conn_charset);
} else { } else {
$hist_query .= 'username'; $hist_query .= 'username';
} }
@@ -643,18 +649,21 @@ function PMA_getHistory($username) {
* @param string the username * @param string the username
* @param string the sql query * @param string the sql query
* *
* @global array the list of relations settings
* @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; global $cfgRelation, $cfg, $charset_connection;
$purge_query = 'SELECT timevalue FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE '; $purge_query = 'SELECT timevalue FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE ';
if (PMA_MYSQL_INT_VERSION >= 40100) { if (PMA_MYSQL_INT_VERSION >= 40100) {
list($conn_charset) = explode('_', $GLOBALS['collation_connection']); $purge_query .= 'CONVERT(username USING ' . $charset_connection . ')';
$purge_query .= 'CONVERT(username USING ' . $conn_charset . ')';
unset($conn_charset);
} else { } else {
$purge_query .= 'username'; $purge_query .= 'username';
} }
@@ -682,6 +691,8 @@ function PMA_purgeHistory($username) {
* @param string the foreign field to display * @param string the foreign field to display
* @param string the current data of the dropdown * @param string the current data of the dropdown
* *
* @global array global phpMyAdmin configuration
*
* @return string the <option value=""><option>s * @return string the <option value=""><option>s
* *
* @access public * @access public