From 281faa1c018ba53fab07fbbe3c333498da2da120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 26 Apr 2012 10:20:02 +0200 Subject: [PATCH 1/2] Prepare for different Types class for MySQL/Drizzle --- libraries/Types.class.php | 14 ++++++++++++++ libraries/common.inc.php | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libraries/Types.class.php b/libraries/Types.class.php index a5f5e2c0f7..feb74c76c1 100644 --- a/libraries/Types.class.php +++ b/libraries/Types.class.php @@ -155,3 +155,17 @@ class PMA_Types return $html; } } + +/** + * Class holding type definitions for MySQL. + */ +class PMA_Types_MySQL extends PMA_Types +{ +} + +/** + * Class holding type definitions for Drizzle. + */ +class PMA_Types_Drizzle extends PMA_Types +{ +} diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 1c1ca9ed5d..12d38bc85b 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -981,7 +981,11 @@ if (! defined('PMA_MINIMUM_COMMON')) { /** * Type handling object. */ - $GLOBALS['PMA_Types'] = new PMA_Types(); + if (PMA_DRIZZLE) { + $GLOBALS['PMA_Types'] = new PMA_Types_Drizzle(); + } else { + $GLOBALS['PMA_Types'] = new PMA_Types_MySQL(); + } if (PMA_DRIZZLE) { // DisableIS must be set to false for Drizzle, it maps SHOW commands From e3bc5ae97b9183d171629e125cafb71b0b01f7b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 26 Apr 2012 10:30:21 +0200 Subject: [PATCH 2/2] Move type descriptions to Type class --- libraries/Types.class.php | 152 +++++++++++++++++++++++++++++++++ libraries/common.lib.php | 25 +----- libraries/data_drizzle.inc.php | 31 ------- libraries/data_mysql.inc.php | 52 ----------- 4 files changed, 156 insertions(+), 104 deletions(-) diff --git a/libraries/Types.class.php b/libraries/Types.class.php index feb74c76c1..f7c54a4942 100644 --- a/libraries/Types.class.php +++ b/libraries/Types.class.php @@ -154,6 +154,18 @@ class PMA_Types return $html; } + + /** + * Returns the data type description. + * + * @param string $type The data type to get a description. + * + * @return string + * + */ + public function getTypeDescription($type) { + return ''; + } } /** @@ -161,6 +173,98 @@ class PMA_Types */ class PMA_Types_MySQL extends PMA_Types { + /** + * Returns the data type description. + * + * @param string $type The data type to get a description. + * + * @return string + * + */ + public function getTypeDescription($type) { + $type = strtoupper($type); + switch ($type) { + case 'TINYINT': + return __('A 1-byte integer, signed range is -128 to 127, unsigned range is 0 to 255'); + case 'SMALLINT': + return __('A 2-byte integer, signed range is -32,768 to 32,767, unsigned range is 0 to 65,535'); + case 'MEDIUMINT': + return __('A 3-byte integer, signed range is -8,388,608 to 8,388,607, unsigned range is 0 to 16,777,215'); + case 'INT': + return __('A 4-byte integer, signed range is -2,147,483,648 to 2,147,483,647, unsigned range is 0 to 4,294,967,295.'); + case 'BIGINT': + return __('An 8-byte integer, signed range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, unsigned range is 0 to 18,446,744,073,709,551,615'); + case 'DECIMAL': + return __('A fixed-point number (M, D) - the maximum number of digits (M) is 65 (default 10), the maximum number of decimals (D) is 30 (default 0)'); + case 'FLOAT': + return __('A small floating-point number, allowable values are -3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to 3.402823466E+38'); + case 'DOUBLE': + return __('A double-precision floating-point number, allowable values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to 1.7976931348623157E+308'); + case 'REAL': + return __('Synonym for DOUBLE (exception: in REAL_AS_FLOAT SQL mode it is a synonym for FLOAT)'); + case 'BIT': + return __('A bit-field type (M), storing M of bits per value (default is 1, maximum is 64)'); + case 'BOOLEAN': + return __('A synonym for TINYINT(1), a value of zero is considered false, nonzero values are considered true'); + case 'SERIAL': + return __('An alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE'); + case 'DATE': + return sprintf(__("A date, supported range is '%s' to '%s'"), '1000-01-01', '9999-12-31'); + case 'DATETIME': + return sprintf(__("A date and time combination, supported range is '%s' to '%s'"), '1000-01-01 00:00:00', '9999-12-31 23:59:59'); + case 'TIMESTAMP': + return __("A timestamp, range is '1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC, stored as the number of seconds since the epoch ('1970-01-01 00:00:00' UTC)"); + case 'TIME': + return sprintf(__("A time, range is '%s' to '%s'"), '-838:59:59', '838:59:59'); + case 'YEAR': + return __("A year in four-digit (4, default) or two-digit (2) format, the allowable values are 70 (1970) to 69 (2069) or 1901 to 2155 and 0000"); + case 'CHAR': + return __('A fixed-length (0-255, default 1) string that is always right-padded with spaces to the specified length when stored'); + case 'VARCHAR': + return sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-65,535'); + case 'TINYTEXT': + return __('A TEXT column with a maximum length of 255 (2^8 - 1) characters, stored with a one-byte prefix indicating the length of the value in bytes'); + case 'TEXT': + return __('A TEXT column with a maximum length of 65,535 (2^16 - 1) characters, stored with a two-byte prefix indicating the length of the value in bytes'); + case 'MEDIUMTEXT': + return __('A TEXT column with a maximum length of 16,777,215 (2^24 - 1) characters, stored with a three-byte prefix indicating the length of the value in bytes'); + case 'LONGTEXT': + return __('A TEXT column with a maximum length of 4,294,967,295 or 4GB (2^32 - 1) characters, stored with a four-byte prefix indicating the length of the value in bytes'); + case 'BINARY': + return __('Similar to the CHAR type, but stores binary byte strings rather than non-binary character strings'); + case 'VARBINARY': + return __('Similar to the VARCHAR type, but stores binary byte strings rather than non-binary character strings'); + case 'TINYBLOB': + return __('A BLOB column with a maximum length of 255 (2^8 - 1) bytes, stored with a one-byte prefix indicating the length of the value'); + case 'MEDIUMBLOB': + return __('A BLOB column with a maximum length of 16,777,215 (2^24 - 1) bytes, stored with a three-byte prefix indicating the length of the value'); + case 'BLOB': + return __('A BLOB column with a maximum length of 65,535 (2^16 - 1) bytes, stored with a four-byte prefix indicating the length of the value'); + case 'LONGBLOB': + return __('A BLOB column with a maximum length of 4,294,967,295 or 4GB (2^32 - 1) bytes, stored with a two-byte prefix indicating the length of the value'); + case 'ENUM': + return __("An enumeration, chosen from the list of up to 65,535 values or the special '' error value"); + case 'SET': + return __("A single value chosen from a set of up to 64 members"); + case 'GEOMETRY': + return __('A type that can store a geometry of any type'); + case 'POINT': + return __('A point in 2-dimensional space'); + case 'LINESTRING': + return __('A curve with linear interpolation between points'); + case 'POLYGON': + return __('A polygon'); + case 'MULTIPOINT': + return __('A collection of points'); + case 'MULTILINESTRING': + return __('A collection of curves with linear interpolation between points'); + case 'MULTIPOLYGON': + return __('A collection of polygons'); + case 'GEOMETRYCOLLECTION': + return __('A collection of geometry objects of any type'); + } + return ''; + } } /** @@ -168,4 +272,52 @@ class PMA_Types_MySQL extends PMA_Types */ class PMA_Types_Drizzle extends PMA_Types { + /** + * Returns the data type description. + * + * @param string $type The data type to get a description. + * + * @return string + * + */ + public function getTypeDescription($type) { + $type = strtoupper($type); + switch ($type) { + case 'INTEGER': + return __('A 4-byte integer, range is -2,147,483,648 to 2,147,483,647'); + case 'BIGINT': + return __('An 8-byte integer, range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807'); + case 'DECIMAL': + return __('A fixed-point number (M, D) - the maximum number of digits (M) is 65 (default 10), the maximum number of decimals (D) is 30 (default 0)'); + case 'DOUBLE': + return __("A system's default double-precision floating-point number"); + case 'BOOLEAN': + return __('True or false'); + // Drizzle doesn't have UNSIGNED types + case 'SERIAL': + return __('An alias for BIGINT NOT NULL AUTO_INCREMENT UNIQUE'); + case 'UUID': + return __('Stores a Universally Unique Identifier (UUID)'); + case 'DATE': + return sprintf(__("A date, supported range is '%s' to '%s'"), '0001-01-01', '9999-12-31'); + case 'DATETIME': + return sprintf(__("A date and time combination, supported range is '%s' to '%s'"), '0001-01-01 00:00:0', '9999-12-31 23:59:59'); + case 'TIMESTAMP': + return __("A timestamp, range is '0001-01-01 00:00:00' UTC to '9999-12-31 23:59:59' UTC; TIMESTAMP(6) can store microseconds"); + case 'TIME': + return sprintf(__("A time, range is '%s' to '%s'"), '00:00:00', '23:59:59'); + case 'VARCHAR': + return sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-16,383'); + case 'TEXT': + return __('A TEXT column with a maximum length of 65,535 (2^16 - 1) characters, stored with a two-byte prefix indicating the length of the value in bytes'); + case 'VARBINARY': + return __('A variable-length (0-65,535) string, uses binary collation for all comparisons'); + case 'BLOB': + return __('A BLOB column with a maximum length of 65,535 (2^16 - 1) bytes, stored with a four-byte prefix indicating the length of the value'); + // there is no limit on ENUM length + case 'ENUM': + return __("An enumeration, chosen from the list of defined values"); + } + return ''; + } } diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 4bac5a0d47..f2813c40d9 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -3434,7 +3434,7 @@ function PMA_getSupportedDatatypes($html = false, $selected = '') if ($subvalue == $selected) { $retval .= sprintf( "", - PMA_getDatatypeDescription($subvalue), + $GLOBALS['PMA_Types']->getTypeDescription($subvalue), $subvalue ); } else if ($subvalue === '-') { @@ -3444,7 +3444,7 @@ function PMA_getSupportedDatatypes($html = false, $selected = '') } else { $retval .= sprintf( "", - PMA_getDatatypeDescription($subvalue), + $GLOBALS['PMA_Types']->getTypeDescription($subvalue), $subvalue ); } @@ -3454,13 +3454,13 @@ function PMA_getSupportedDatatypes($html = false, $selected = '') if ($selected == $value) { $retval .= sprintf( "", - PMA_getDatatypeDescription($value), + $GLOBALS['PMA_Types']->getTypeDescription($value), $value ); } else { $retval .= sprintf( "", - PMA_getDatatypeDescription($value), + $GLOBALS['PMA_Types']->getTypeDescription($value), $value ); } @@ -3486,23 +3486,6 @@ function PMA_getSupportedDatatypes($html = false, $selected = '') return $retval; } // end PMA_getSupportedDatatypes() -/** - * This function returns the data type description. - * - * @param string $type The data type to get a description. - * - * @return string - * - */ -function PMA_getDatatypeDescription($type) -{ - $type = strtoupper($type); - $descriptions = PMA_supportedDataTypesDescriptions(); - - return isset($descriptions[$type]) - ? htmlentities($descriptions[$type], ENT_QUOTES) : ''; -} // end PMA_getDatatypeDescription() - /** * Returns a list of datatypes that are not (yet) handled by PMA. * Used by: tbl_change.php and libraries/db_routines.inc.php diff --git a/libraries/data_drizzle.inc.php b/libraries/data_drizzle.inc.php index 3ff3a99072..a1a1bffeab 100644 --- a/libraries/data_drizzle.inc.php +++ b/libraries/data_drizzle.inc.php @@ -226,35 +226,4 @@ if ($cfg['ShowFunctionFields']) { unset($restrict_functions); } // end if -/** - * This function returns datatypes descriptions. - * - * @return array Drizzle datatypes descriptions. - * - */ -function PMA_supportedDataTypesDescriptions() -{ - // if possible, for easy translation these strings should be the same as for MySQL - return array( - 'INTEGER' => __('A 4-byte integer, range is -2,147,483,648 to 2,147,483,647'), - 'BIGINT' => __('An 8-byte integer, range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807'), - 'DECIMAL' => __('A fixed-point number (M, D) - the maximum number of digits (M) is 65 (default 10), the maximum number of decimals (D) is 30 (default 0)'), - 'DOUBLE' => __("A system's default double-precision floating-point number"), - 'BOOLEAN' => __('True or false'), - // Drizzle doesn't have UNSIGNED types - 'SERIAL' => __('An alias for BIGINT NOT NULL AUTO_INCREMENT UNIQUE'), - 'UUID' => __('Stores a Universally Unique Identifier (UUID)'), - 'DATE' => sprintf(__("A date, supported range is '%s' to '%s'"), '0001-01-01', '9999-12-31'), - 'DATETIME' => sprintf(__("A date and time combination, supported range is '%s' to '%s'"), '0001-01-01 00:00:0', '9999-12-31 23:59:59'), - 'TIMESTAMP' => __("A timestamp, range is '0001-01-01 00:00:00' UTC to '9999-12-31 23:59:59' UTC; TIMESTAMP(6) can store microseconds"), - 'TIME' => sprintf(__("A time, range is '%s' to '%s'"), '00:00:00', '23:59:59'), - 'VARCHAR' => sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-16,383'), - 'TEXT' => __('A TEXT column with a maximum length of 65,535 (2^16 - 1) characters, stored with a two-byte prefix indicating the length of the value in bytes'), - 'VARBINARY' => __('A variable-length (0-65,535) string, uses binary collation for all comparisons'), - 'BLOB' => __('A BLOB column with a maximum length of 65,535 (2^16 - 1) bytes, stored with a four-byte prefix indicating the length of the value'), - // there is no limit on ENUM length - 'ENUM' => __("An enumeration, chosen from the list of defined values"), - ); -} // end PMA_supportedDataTypesDescriptions() - ?> diff --git a/libraries/data_mysql.inc.php b/libraries/data_mysql.inc.php index 97e614f25b..b3b44f8fa2 100644 --- a/libraries/data_mysql.inc.php +++ b/libraries/data_mysql.inc.php @@ -287,56 +287,4 @@ if ($cfg['ShowFunctionFields']) { unset($restrict_functions); } // end if -/** - * This function returns datatypes descriptions. - * - * @return array MySQL datatypes descriptions. - * - */ -function PMA_supportedDataTypesDescriptions() -{ - // if possible, for easy translation these strings should be the same as for Drizzle - return array( - 'TINYINT' => __('A 1-byte integer, signed range is -128 to 127, unsigned range is 0 to 255'), - 'SMALLINT' => __('A 2-byte integer, signed range is -32,768 to 32,767, unsigned range is 0 to 65,535'), - 'MEDIUMINT' => __('A 3-byte integer, signed range is -8,388,608 to 8,388,607, unsigned range is 0 to 16,777,215'), - 'INT' => __('A 4-byte integer, signed range is -2,147,483,648 to 2,147,483,647, unsigned range is 0 to 4,294,967,295.'), - 'BIGINT' => __('An 8-byte integer, signed range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, unsigned range is 0 to 18,446,744,073,709,551,615'), - 'DECIMAL' => __('A fixed-point number (M, D) - the maximum number of digits (M) is 65 (default 10), the maximum number of decimals (D) is 30 (default 0)'), - 'FLOAT' => __('A small floating-point number, allowable values are -3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to 3.402823466E+38'), - 'DOUBLE' => __('A double-precision floating-point number, allowable values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 to 1.7976931348623157E+308'), - 'REAL' => __('Synonym for DOUBLE (exception: in REAL_AS_FLOAT SQL mode it is a synonym for FLOAT)'), - 'BIT' => __('A bit-field type (M), storing M of bits per value (default is 1, maximum is 64)'), - 'BOOLEAN' => __('A synonym for TINYINT(1), a value of zero is considered false, nonzero values are considered true'), - 'SERIAL' => __('An alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE'), - 'DATE' => sprintf(__("A date, supported range is '%s' to '%s'"), '1000-01-01', '9999-12-31'), - 'DATETIME' => sprintf(__("A date and time combination, supported range is '%s' to '%s'"), '1000-01-01 00:00:00', '9999-12-31 23:59:59'), - 'TIMESTAMP' => __("A timestamp, range is '1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC, stored as the number of seconds since the epoch ('1970-01-01 00:00:00' UTC)"), - 'TIME' => sprintf(__("A time, range is '%s' to '%s'"), '-838:59:59', '838:59:59'), - 'YEAR' => __("A year in four-digit (4, default) or two-digit (2) format, the allowable values are 70 (1970) to 69 (2069) or 1901 to 2155 and 0000"), - 'CHAR' => __('A fixed-length (0-255, default 1) string that is always right-padded with spaces to the specified length when stored'), - 'VARCHAR' => sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-65,535'), - 'TINYTEXT' => __('A TEXT column with a maximum length of 255 (2^8 - 1) characters, stored with a one-byte prefix indicating the length of the value in bytes'), - 'TEXT' => __('A TEXT column with a maximum length of 65,535 (2^16 - 1) characters, stored with a two-byte prefix indicating the length of the value in bytes'), - 'MEDIUMTEXT' => __('A TEXT column with a maximum length of 16,777,215 (2^24 - 1) characters, stored with a three-byte prefix indicating the length of the value in bytes'), - 'LONGTEXT' => __('A TEXT column with a maximum length of 4,294,967,295 or 4GB (2^32 - 1) characters, stored with a four-byte prefix indicating the length of the value in bytes'), - 'BINARY' => __('Similar to the CHAR type, but stores binary byte strings rather than non-binary character strings'), - 'VARBINARY' => __('Similar to the VARCHAR type, but stores binary byte strings rather than non-binary character strings'), - 'TINYBLOB' => __('A BLOB column with a maximum length of 255 (2^8 - 1) bytes, stored with a one-byte prefix indicating the length of the value'), - 'MEDIUMBLOB' => __('A BLOB column with a maximum length of 16,777,215 (2^24 - 1) bytes, stored with a three-byte prefix indicating the length of the value'), - 'BLOB' => __('A BLOB column with a maximum length of 65,535 (2^16 - 1) bytes, stored with a four-byte prefix indicating the length of the value'), - 'LONGBLOB' => __('A BLOB column with a maximum length of 4,294,967,295 or 4GB (2^32 - 1) bytes, stored with a two-byte prefix indicating the length of the value'), - 'ENUM' => __("An enumeration, chosen from the list of up to 65,535 values or the special '' error value"), - 'SET' => __("A single value chosen from a set of up to 64 members"), - 'GEOMETRY' => __('A type that can store a geometry of any type'), - 'POINT' => __('A point in 2-dimensional space'), - 'LINESTRING' => __('A curve with linear interpolation between points'), - 'POLYGON' => __('A polygon'), - 'MULTIPOINT' => __('A collection of points'), - 'MULTILINESTRING' => __('A collection of curves with linear interpolation between points'), - 'MULTIPOLYGON' => __('A collection of polygons'), - 'GEOMETRYCOLLECTION' => __('A collection of geometry objects of any type'), - ); -} // end PMA_supportedDataTypesDescriptions() - ?>