From 4bde8d372469ce75e7f1ee6aaf47eaa3c8b937e9 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Mon, 27 May 2013 09:40:14 +0530 Subject: [PATCH 1/2] Use 'self' inside the class to refer to the class --- libraries/DatabaseInterface.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/DatabaseInterface.class.php b/libraries/DatabaseInterface.class.php index 8275ec8f27..8c21784703 100644 --- a/libraries/DatabaseInterface.class.php +++ b/libraries/DatabaseInterface.class.php @@ -311,7 +311,7 @@ class PMA_DatabaseInterface null, 0, $link, - PMA_DatabaseInterface::QUERY_STORE + self::QUERY_STORE ); } @@ -1411,7 +1411,7 @@ class PMA_DatabaseInterface * @return mixed value for mysql server variable */ public function getVariable( - $var, $type = PMA_DatabaseInterface::GETVAR_SESSION, $link = null + $var, $type = self::GETVAR_SESSION, $link = null ) { if ($link === null) { if (isset($GLOBALS['userlink'])) { @@ -1525,7 +1525,7 @@ class PMA_DatabaseInterface $this->query( "SET CHARACTER SET 'utf8';", $link, - PMA_DatabaseInterface::QUERY_STORE + self::QUERY_STORE ); $set_collation_con_query = "SET collation_connection = '" . PMA_Util::sqlAddSlashes($GLOBALS['collation_connection']) @@ -1533,13 +1533,13 @@ class PMA_DatabaseInterface $this->query( $set_collation_con_query, $link, - PMA_DatabaseInterface::QUERY_STORE + self::QUERY_STORE ); } else { $this->query( "SET NAMES 'utf8' COLLATE 'utf8_general_ci';", $link, - PMA_DatabaseInterface::QUERY_STORE + self::QUERY_STORE ); } } @@ -1587,7 +1587,7 @@ class PMA_DatabaseInterface $result = $this->tryQuery( $result, $link, - PMA_DatabaseInterface::QUERY_STORE, + self::QUERY_STORE, false ); } @@ -1645,7 +1645,7 @@ class PMA_DatabaseInterface $result = $this->tryQuery( $result, $link, - PMA_DatabaseInterface::QUERY_STORE, + self::QUERY_STORE, false ); } @@ -2073,7 +2073,7 @@ class PMA_DatabaseInterface $result = (bool) $GLOBALS['dbi']->tryQuery( 'SELECT COUNT(*) FROM mysql.user', $GLOBALS['userlink'], - PMA_DatabaseInterface::QUERY_STORE + self::QUERY_STORE ); } PMA_Util::cacheSet('is_superuser', $result, true); From 17b3df1422b88ebb8f04d06c7bf6c458ce52e8ed Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Mon, 27 May 2013 12:02:50 +0530 Subject: [PATCH 2/2] Move drizzle related code to PMA_DBI_Drizzle class. Make sure the method signature of the implementation matches that of the interface. --- libraries/DatabaseInterface.class.php | 53 +----------- libraries/dbi/DBIAbstractExtension.class.php | 41 +++++++++ libraries/dbi/DBIDrizzle.class.php | 89 ++++++++++++++++++-- libraries/dbi/DBIDummy.class.php | 4 +- libraries/dbi/DBIExtension.int.php | 15 ++++ libraries/dbi/DBIMysql.class.php | 12 ++- libraries/dbi/DBIMysqli.class.php | 4 +- 7 files changed, 153 insertions(+), 65 deletions(-) create mode 100644 libraries/dbi/DBIAbstractExtension.class.php diff --git a/libraries/DatabaseInterface.class.php b/libraries/DatabaseInterface.class.php index 8c21784703..b00dc77769 100644 --- a/libraries/DatabaseInterface.class.php +++ b/libraries/DatabaseInterface.class.php @@ -1204,58 +1204,7 @@ class PMA_DatabaseInterface */ public function getColumnsSql($database, $table, $column = null, $full = false) { - if (PMA_DRIZZLE) { - // `Key` column: - // * used in primary key => PRI - // * unique one-column => UNI - // * indexed, one-column or first in multi-column => MUL - // Promotion of UNI to PRI in case no promary index exists - // is done after query is executed - $sql = "SELECT - column_name AS `Field`, - (CASE - WHEN character_maximum_length > 0 - THEN concat(lower(data_type), '(', character_maximum_length, ')') - WHEN numeric_precision > 0 OR numeric_scale > 0 - THEN concat(lower(data_type), '(', numeric_precision, - ',', numeric_scale, ')') - WHEN enum_values IS NOT NULL - THEN concat(lower(data_type), '(', enum_values, ')') - ELSE lower(data_type) END) - AS `Type`, - " . ($full ? " - collation_name AS `Collation`," : '') . " - (CASE is_nullable - WHEN 1 THEN 'YES' - ELSE 'NO' END) AS `Null`, - (CASE - WHEN is_used_in_primary THEN 'PRI' - WHEN is_unique AND NOT is_multi THEN 'UNI' - WHEN is_indexed - AND (NOT is_multi OR is_first_in_multi) THEN 'MUL' - ELSE '' END) AS `Key`, - column_default AS `Default`, - (CASE - WHEN is_auto_increment THEN 'auto_increment' - WHEN column_default_update <> '' - THEN 'on update ' || column_default_update - ELSE '' END) AS `Extra` - " . ($full ? " , - NULL AS `Privileges`, - column_comment AS `Comment`" : '') . " - FROM data_dictionary.columns - WHERE table_schema = '" . PMA_Util::sqlAddSlashes($database) . "' - AND table_name = '" . PMA_Util::sqlAddSlashes($table) . "' - " . (($column != null) ? " - AND column_name = '" . PMA_Util::sqlAddSlashes($column) . "'" : ''); - // ORDER BY ordinal_position - } else { - $sql = 'SHOW ' . ($full ? 'FULL' : '') . ' COLUMNS FROM ' - . PMA_Util::backquote($database) . '.' . PMA_Util::backquote($table) - . (($column != null) ? "LIKE '" - . PMA_Util::sqlAddSlashes($column, true) . "'" : ''); - } - return $sql; + return $this->_extension->getColumnsSql($database, $table, $column, $full); } /** diff --git a/libraries/dbi/DBIAbstractExtension.class.php b/libraries/dbi/DBIAbstractExtension.class.php new file mode 100644 index 0000000000..e03971a10c --- /dev/null +++ b/libraries/dbi/DBIAbstractExtension.class.php @@ -0,0 +1,41 @@ +getColumns() + * to get correct values. + * + * @param string $database name of database + * @param string $table name of table to retrieve columns from + * @param string $column name of column, null to show all columns + * @param boolean $full whether to return full info or only column names + * + * @return string + */ + public function getColumnsSql($database, $table, $column = null, $full = false) + { + return 'SHOW ' . ($full ? 'FULL' : '') . ' COLUMNS FROM ' + . PMA_Util::backquote($database) . '.' . PMA_Util::backquote($table) + . (($column != null) ? "LIKE '" + . PMA_Util::sqlAddSlashes($column, true) . "'" : ''); + } +} +?> \ No newline at end of file diff --git a/libraries/dbi/DBIDrizzle.class.php b/libraries/dbi/DBIDrizzle.class.php index 5e3a5f4e3b..b786cc1139 100644 --- a/libraries/dbi/DBIDrizzle.class.php +++ b/libraries/dbi/DBIDrizzle.class.php @@ -20,12 +20,12 @@ if (! defined('PHPMYADMIN')) { require_once './libraries/logging.lib.php'; require_once './libraries/dbi/drizzle-wrappers.lib.php'; -require_once './libraries/dbi/DBIExtension.int.php'; +require_once './libraries/dbi/DBIAbstractExtension.class.php'; /** * MySQL client API */ -if (!defined('PMA_MYSQL_CLIENT_API')) { +if (! defined('PMA_MYSQL_CLIENT_API')) { define('PMA_MYSQL_CLIENT_API', (int)drizzle_version()); } @@ -35,7 +35,7 @@ if (!defined('PMA_MYSQL_CLIENT_API')) { * @package PhpMyAdmin-DBI * @subpackage Drizzle */ -class PMA_DBI_Drizzle implements PMA_DBI_Extension +class PMA_DBI_Drizzle extends PMA_DBI_AbstractExtension { /** * Helper function for connecting to the database server @@ -205,6 +205,19 @@ class PMA_DBI_Drizzle implements PMA_DBI_Extension return $res; } + /** + * Run the multi query and output the results + * + * @param object $link connection object + * @param string $query multi query statement to execute + * + * @return result collection | boolean(false) + */ + public function realMultiQuery($link, $query) + { + return false; + } + /** * returns array of rows with associative and numeric keys from $result * @@ -271,9 +284,11 @@ class PMA_DBI_Drizzle implements PMA_DBI_Extension /** * Check if there are any more query results from a multi query * + * @param object $link the connection object + * * @return bool false */ - public function moreResults() + public function moreResults($link = null) { // N.B.: PHP's 'mysql' extension does not support // multi_queries so this function will always @@ -285,9 +300,11 @@ class PMA_DBI_Drizzle implements PMA_DBI_Extension /** * Prepare next result from multi_query * + * @param object $link the connection object + * * @return bool false */ - public function nextResult() + public function nextResult($link = null) { // N.B.: PHP's 'mysql' extension does not support // multi_queries so this function will always @@ -675,5 +692,67 @@ class PMA_DBI_Drizzle implements PMA_DBI_Extension { return false; } + + /** + * Returns SQL query for fetching columns for a table + * + * The 'Key' column is not calculated properly, use $GLOBALS['dbi']->getColumns() + * to get correct values. + * + * @param string $database name of database + * @param string $table name of table to retrieve columns from + * @param string $column name of column, null to show all columns + * @param boolean $full whether to return full info or only column names + * + * @return string + */ + public function getColumnsSql($database, $table, $column = null, $full = false) + { + // `Key` column: + // * used in primary key => PRI + // * unique one-column => UNI + // * indexed, one-column or first in multi-column => MUL + // Promotion of UNI to PRI in case no promary index exists + // is done after query is executed + $sql = "SELECT + column_name AS `Field`, + (CASE + WHEN character_maximum_length > 0 + THEN concat(lower(data_type), '(', character_maximum_length, ')') + WHEN numeric_precision > 0 OR numeric_scale > 0 + THEN concat(lower(data_type), '(', numeric_precision, + ',', numeric_scale, ')') + WHEN enum_values IS NOT NULL + THEN concat(lower(data_type), '(', enum_values, ')') + ELSE lower(data_type) END) + AS `Type`, + " . ($full ? " + collation_name AS `Collation`," : '') . " + (CASE is_nullable + WHEN 1 THEN 'YES' + ELSE 'NO' END) AS `Null`, + (CASE + WHEN is_used_in_primary THEN 'PRI' + WHEN is_unique AND NOT is_multi THEN 'UNI' + WHEN is_indexed + AND (NOT is_multi OR is_first_in_multi) THEN 'MUL' + ELSE '' END) AS `Key`, + column_default AS `Default`, + (CASE + WHEN is_auto_increment THEN 'auto_increment' + WHEN column_default_update <> '' + THEN 'on update ' || column_default_update + ELSE '' END) AS `Extra` + " . ($full ? " , + NULL AS `Privileges`, + column_comment AS `Comment`" : '') . " + FROM data_dictionary.columns + WHERE table_schema = '" . PMA_Util::sqlAddSlashes($database) . "' + AND table_name = '" . PMA_Util::sqlAddSlashes($table) . "' + " . (($column != null) ? " + AND column_name = '" . PMA_Util::sqlAddSlashes($column) . "'" : ''); + // ORDER BY ordinal_position + return $sql; + } } ?> \ No newline at end of file diff --git a/libraries/dbi/DBIDummy.class.php b/libraries/dbi/DBIDummy.class.php index 0a7d4a5a45..dc484169e3 100644 --- a/libraries/dbi/DBIDummy.class.php +++ b/libraries/dbi/DBIDummy.class.php @@ -14,7 +14,7 @@ if (! defined('PHPMYADMIN')) { exit; } -require_once './libraries/dbi/DBIExtension.int.php'; +require_once './libraries/dbi/DBIAbstractExtension.class.php'; /** * Array of queries this "driver" supports @@ -280,7 +280,7 @@ if (! defined('PMA_DRIZZLE')) { * @package PhpMyAdmin-DBI * @subpackage Dummy */ -class PMA_DBI_Dummy implements PMA_DBI_Extension +class PMA_DBI_Dummy extends PMA_DBI_AbstractExtension { /** * connects to the database server diff --git a/libraries/dbi/DBIExtension.int.php b/libraries/dbi/DBIExtension.int.php index 9cc743300b..bb4b2e4067 100644 --- a/libraries/dbi/DBIExtension.int.php +++ b/libraries/dbi/DBIExtension.int.php @@ -244,5 +244,20 @@ interface PMA_DBI_Extension * @return string field flags */ public function fieldFlags($result, $i); + + /** + * Returns SQL query for fetching columns for a table + * + * The 'Key' column is not calculated properly, use $GLOBALS['dbi']->getColumns() + * to get correct values. + * + * @param string $database name of database + * @param string $table name of table to retrieve columns from + * @param string $column name of column, null to show all columns + * @param boolean $full whether to return full info or only column names + * + * @return string + */ + public function getColumnsSql($database, $table, $column = null, $full = false); } ?> \ No newline at end of file diff --git a/libraries/dbi/DBIMysql.class.php b/libraries/dbi/DBIMysql.class.php index e1b3b3865a..19e06d7ca0 100644 --- a/libraries/dbi/DBIMysql.class.php +++ b/libraries/dbi/DBIMysql.class.php @@ -11,7 +11,7 @@ if (! defined('PHPMYADMIN')) { } require_once './libraries/logging.lib.php'; -require_once './libraries/dbi/DBIExtension.int.php'; +require_once './libraries/dbi/DBIAbstractExtension.class.php'; /** * MySQL client API @@ -34,7 +34,7 @@ if (! defined('PMA_MYSQL_CLIENT_API')) { * @package PhpMyAdmin-DBI * @subpackage MySQL */ -class PMA_DBI_Mysql implements PMA_DBI_Extension +class PMA_DBI_Mysql extends PMA_DBI_AbstractExtension { /** * Helper function for connecting to the database server @@ -297,9 +297,11 @@ class PMA_DBI_Mysql implements PMA_DBI_Extension /** * Check if there are any more query results from a multi query * + * @param object $link the connection object + * * @return bool false */ - public function moreResults() + public function moreResults($link = null) { // N.B.: PHP's 'mysql' extension does not support // multi_queries so this function will always @@ -311,9 +313,11 @@ class PMA_DBI_Mysql implements PMA_DBI_Extension /** * Prepare next result from multi_query * + * @param object $link the connection object + * * @return boo false */ - public function nextResult() + public function nextResult($link = null) { // N.B.: PHP's 'mysql' extension does not support // multi_queries so this function will always diff --git a/libraries/dbi/DBIMysqli.class.php b/libraries/dbi/DBIMysqli.class.php index 0f1c126cf7..ebbeebde1a 100644 --- a/libraries/dbi/DBIMysqli.class.php +++ b/libraries/dbi/DBIMysqli.class.php @@ -11,7 +11,7 @@ if (! defined('PHPMYADMIN')) { } require_once './libraries/logging.lib.php'; -require_once './libraries/dbi/DBIExtension.int.php'; +require_once './libraries/dbi/DBIAbstractExtension.class.php'; /** * MySQL client API @@ -63,7 +63,7 @@ if (! defined('MYSQLI_TYPE_VARCHAR')) { * @package PhpMyAdmin-DBI * @subpackage MySQLi */ -class PMA_DBI_Mysqli implements PMA_DBI_Extension +class PMA_DBI_Mysqli extends PMA_DBI_AbstractExtension { /** * Helper function for connecting to the database server