2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * SQL data types definition
8 if (! defined('PHPMYADMIN')) {
13 * Generic class holding type definitions.
20 * Returns list of unary operators.
24 public function getUnaryOperators()
35 * Check whether operator is unary.
37 * @param string $op operator name
41 public function isUnaryOperator($op)
43 return in_array($op, $this->getUnaryOperators());
47 * Returns list of operators checking for NULL.
51 public function getNullOperators()
60 * ENUM search operators
64 public function getEnumOperators()
73 * TEXT search operators
77 public function getTextOperators()
98 * Number search operators
102 public function getNumberOperators()
122 * Returns operators for given type
124 * @param string $type Type of field
125 * @param boolean $null Whether field can be NULL
129 public function getTypeOperators($type, $null)
132 $class = $this->getTypeClass($type);
134 if (strncasecmp($type, 'enum', 4) == 0) {
135 $ret = array_merge($ret, $this->getEnumOperators());
136 } elseif ($class == 'CHAR') {
137 $ret = array_merge($ret, $this->getTextOperators());
139 $ret = array_merge($ret, $this->getNumberOperators());
143 $ret = array_merge($ret, $this->getNullOperators());
150 * Returns operators for given type as html options
152 * @param string $type Type of field
153 * @param boolean $null Whether field can be NULL
154 * @param string $selectedOperator Option to be selected
156 * @return string Generated Html
158 public function getTypeOperatorsHtml($type, $null, $selectedOperator = null)
162 foreach ($this->getTypeOperators($type, $null) as $fc) {
163 if (isset($selectedOperator) && $selectedOperator == $fc) {
164 $selected = ' selected="selected"';
168 $html .= '<option value="' . htmlspecialchars($fc) . '"'
170 . htmlspecialchars($fc) . '</option>';
177 * Returns the data type description.
179 * @param string $type The data type to get a description.
184 public function getTypeDescription($type)
190 * Returns class of a type, used for functions available for type
193 * @param string $type The data type to get a class.
198 public function getTypeClass($type)
204 * Returns array of functions available for a class.
206 * @param string $class The class to get function list.
211 public function getFunctionsClass($class)
217 * Returns array of functions available for a type.
219 * @param string $type The data type to get function list.
224 public function getFunctions($type)
226 $class = $this->getTypeClass($type);
227 return $this->getFunctionsClass($class);
231 * Returns array of all functions available.
236 public function getAllFunctions()
239 $this->getFunctionsClass('CHAR'),
240 $this->getFunctionsClass('NUMBER'),
241 $this->getFunctionsClass('DATE'),
242 $this->getFunctionsClass('UUID')
249 * Returns array of all attributes available.
254 public function getAttributes()
260 * Returns array of all column types available.
265 public function getColumns()
278 * Class holding type definitions for MySQL.
280 * @package PhpMyAdmin
282 class PMA_Types_MySQL
extends PMA_Types
285 * Returns the data type description.
287 * @param string $type The data type to get a description.
292 public function getTypeDescription($type)
294 $type = strtoupper($type);
297 return __('A 1-byte integer, signed range is -128 to 127, unsigned range is 0 to 255');
299 return __('A 2-byte integer, signed range is -32,768 to 32,767, unsigned range is 0 to 65,535');
301 return __('A 3-byte integer, signed range is -8,388,608 to 8,388,607, unsigned range is 0 to 16,777,215');
303 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');
305 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');
307 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)');
309 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');
311 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');
313 return __('Synonym for DOUBLE (exception: in REAL_AS_FLOAT SQL mode it is a synonym for FLOAT)');
315 return __('A bit-field type (M), storing M of bits per value (default is 1, maximum is 64)');
317 return __('A synonym for TINYINT(1), a value of zero is considered false, nonzero values are considered true');
319 return __('An alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE');
321 return sprintf(__('A date, supported range is %1$s to %2$s'), '1000-01-01', '9999-12-31');
323 return sprintf(__('A date and time combination, supported range is %1$s to %2$s'), '1000-01-01 00:00:00', '9999-12-31 23:59:59');
325 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)');
327 return sprintf(__('A time, range is %1$s to %2$s'), '-838:59:59', '838:59:59');
329 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");
331 return __('A fixed-length (0-255, default 1) string that is always right-padded with spaces to the specified length when stored');
333 return sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-65,535');
335 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');
337 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');
339 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');
341 return __('A TEXT column with a maximum length of 4,294,967,295 or 4GiB (2^32 - 1) characters, stored with a four-byte prefix indicating the length of the value in bytes');
343 return __('Similar to the CHAR type, but stores binary byte strings rather than non-binary character strings');
345 return __('Similar to the VARCHAR type, but stores binary byte strings rather than non-binary character strings');
347 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');
349 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');
351 return __('A BLOB column with a maximum length of 65,535 (2^16 - 1) bytes, stored with a two-byte prefix indicating the length of the value');
353 return __('A BLOB column with a maximum length of 4,294,967,295 or 4GiB (2^32 - 1) bytes, stored with a four-byte prefix indicating the length of the value');
355 return __("An enumeration, chosen from the list of up to 65,535 values or the special '' error value");
357 return __("A single value chosen from a set of up to 64 members");
359 return __('A type that can store a geometry of any type');
361 return __('A point in 2-dimensional space');
363 return __('A curve with linear interpolation between points');
365 return __('A polygon');
367 return __('A collection of points');
368 case 'MULTILINESTRING':
369 return __('A collection of curves with linear interpolation between points');
371 return __('A collection of polygons');
372 case 'GEOMETRYCOLLECTION':
373 return __('A collection of geometry objects of any type');
379 * Returns class of a type, used for functions available for type
382 * @param string $type The data type to get a class.
387 public function getTypeClass($type)
389 $type = strtoupper($type);
433 case 'MULTILINESTRING':
435 case 'GEOMETRYCOLLECTION':
443 * Returns array of functions available for a class.
445 * @param string $class The class to get function list.
450 public function getFunctionsClass($class)
554 'UNCOMPRESSED_LENGTH',
562 // remove functions that are unavailable on current server
563 if (PMA_MYSQL_INT_VERSION
< 50500) {
564 $ret = array_diff($ret, array('TO_SECONDS'));
566 if (PMA_MYSQL_INT_VERSION
< 50120) {
567 $ret = array_diff($ret, array('UUID_SHORT'));
597 * Returns array of all attributes available.
602 public function getAttributes()
609 'on update CURRENT_TIMESTAMP',
614 * Returns array of all column types available.
616 * VARCHAR, TINYINT, TEXT and DATE are listed first, based on
617 * estimated popularity.
622 public function getColumns()
624 $ret = parent
::getColumns();
626 $ret[_pgettext('numeric types', 'Numeric')] = array(
645 $ret[_pgettext('date and time types', 'Date and time')] = array(
654 $ret[_pgettext('string types', 'String')] = array(
675 $ret[_pgettext('spatial types', 'Spatial')] = array(
683 'GEOMETRYCOLLECTION',
691 * Class holding type definitions for Drizzle.
693 * @package PhpMyAdmin
695 class PMA_Types_Drizzle
extends PMA_Types
698 * Returns the data type description.
700 * @param string $type The data type to get a description.
705 public function getTypeDescription($type)
707 $type = strtoupper($type);
710 return __('A 4-byte integer, range is -2,147,483,648 to 2,147,483,647');
712 return __('An 8-byte integer, range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807');
714 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)');
716 return __("A system's default double-precision floating-point number");
718 return __('True or false');
720 return __('An alias for BIGINT NOT NULL AUTO_INCREMENT UNIQUE');
722 return __('Stores a Universally Unique Identifier (UUID)');
724 return sprintf(__('A date, supported range is %1$s to %2$s'), '0001-01-01', '9999-12-31');
726 return sprintf(__('A date and time combination, supported range is %1$s to %2$s'), '0001-01-01 00:00:0', '9999-12-31 23:59:59');
728 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");
730 return sprintf(__('A time, range is %1$s to %2$s'), '00:00:00', '23:59:59');
732 return sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-16,383');
734 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');
736 return __('A variable-length (0-65,535) string, uses binary collation for all comparisons');
738 return __('A BLOB column with a maximum length of 65,535 (2^16 - 1) bytes, stored with a two-byte prefix indicating the length of the value');
740 return __("An enumeration, chosen from the list of defined values");
746 * Returns class of a type, used for functions available for type
749 * @param string $type The data type to get a class.
754 public function getTypeClass($type)
756 $type = strtoupper($type);
786 * Returns array of functions available for a class.
788 * @param string $class The class to get function list.
793 public function getFunctionsClass($class)
824 // check for some functions known to be in modules
831 $sql = "SELECT upper(plugin_name) f
832 FROM data_dictionary.plugins
833 WHERE plugin_name IN ('" . implode("','", $functions) . "')
834 AND plugin_type = 'Function'
836 $drizzle_functions = $GLOBALS['dbi']->fetchResult($sql, 'f', 'f');
837 if (count($drizzle_functions) > 0) {
838 $ret = array_merge($ret, $drizzle_functions);
859 //'TIME', // https://bugs.launchpad.net/drizzle/+bug/804571
910 'UNCOMPRESSED_LENGTH',
912 //'WEEK', // same as TIME
922 * Returns array of all attributes available.
927 public function getAttributes()
931 'on update CURRENT_TIMESTAMP',
936 * Returns array of all column types available.
941 public function getColumns()
960 $types_string = array(
969 if (PMA_MYSQL_INT_VERSION
>= 20120130) {
970 $types_string[] = '-';
971 $types_string[] = 'IPV6';
974 $ret = parent
::getColumns();
976 $ret[_pgettext('numeric types', 'Numeric')] = $types_num;
979 $ret[_pgettext('date and time types', 'Date and time')] = $types_date;
982 $ret[_pgettext('string types', 'String')] = $types_string;