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()
277 * Returns an array of integer types
279 * @return string[] integer types
281 public function getIntegerTypes()
287 * Returns the min and max values of a given integer type
289 * @param string $type integer type
290 * @param boolean $signed whether signed
292 * @return string[] min and max values
294 public function getIntegerRange($type, $signed = true)
296 return array('', '');
301 * Class holding type definitions for MySQL.
303 * @package PhpMyAdmin
305 class PMA_Types_MySQL
extends PMA_Types
308 * Returns the data type description.
310 * @param string $type The data type to get a description.
315 public function getTypeDescription($type)
317 $type = /*overload*/mb_strtoupper($type);
320 return __('A 1-byte integer, signed range is -128 to 127, unsigned range is 0 to 255');
322 return __('A 2-byte integer, signed range is -32,768 to 32,767, unsigned range is 0 to 65,535');
324 return __('A 3-byte integer, signed range is -8,388,608 to 8,388,607, unsigned range is 0 to 16,777,215');
326 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');
328 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');
330 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)');
332 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');
334 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');
336 return __('Synonym for DOUBLE (exception: in REAL_AS_FLOAT SQL mode it is a synonym for FLOAT)');
338 return __('A bit-field type (M), storing M of bits per value (default is 1, maximum is 64)');
340 return __('A synonym for TINYINT(1), a value of zero is considered false, nonzero values are considered true');
342 return __('An alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE');
344 return sprintf(__('A date, supported range is %1$s to %2$s'), '1000-01-01', '9999-12-31');
346 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');
348 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)');
350 return sprintf(__('A time, range is %1$s to %2$s'), '-838:59:59', '838:59:59');
352 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");
354 return __('A fixed-length (0-255, default 1) string that is always right-padded with spaces to the specified length when stored');
356 return sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-65,535');
358 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');
360 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');
362 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');
364 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');
366 return __('Similar to the CHAR type, but stores binary byte strings rather than non-binary character strings');
368 return __('Similar to the VARCHAR type, but stores binary byte strings rather than non-binary character strings');
370 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');
372 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');
374 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');
376 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');
378 return __("An enumeration, chosen from the list of up to 65,535 values or the special '' error value");
380 return __("A single value chosen from a set of up to 64 members");
382 return __('A type that can store a geometry of any type');
384 return __('A point in 2-dimensional space');
386 return __('A curve with linear interpolation between points');
388 return __('A polygon');
390 return __('A collection of points');
391 case 'MULTILINESTRING':
392 return __('A collection of curves with linear interpolation between points');
394 return __('A collection of polygons');
395 case 'GEOMETRYCOLLECTION':
396 return __('A collection of geometry objects of any type');
402 * Returns class of a type, used for functions available for type
405 * @param string $type The data type to get a class.
410 public function getTypeClass($type)
412 $type = /*overload*/mb_strtoupper($type);
456 case 'MULTILINESTRING':
458 case 'GEOMETRYCOLLECTION':
466 * Returns array of functions available for a class.
468 * @param string $class The class to get function list.
473 public function getFunctionsClass($class)
514 if ((PMA_MARIADB
&& PMA_MYSQL_INT_VERSION
< 100012)
515 || PMA_MYSQL_INT_VERSION
< 50603
517 $ret = array_diff($ret, array('INET6_NTOA'));
587 'UNCOMPRESSED_LENGTH',
595 if ((PMA_MARIADB
&& PMA_MYSQL_INT_VERSION
< 100012)
596 || PMA_MYSQL_INT_VERSION
< 50603
598 $ret = array_diff($ret, array('INET6_ATON'));
628 * Returns array of all attributes available.
633 public function getAttributes()
640 'on update CURRENT_TIMESTAMP',
645 * Returns array of all column types available.
647 * VARCHAR, TINYINT, TEXT and DATE are listed first, based on
648 * estimated popularity.
653 public function getColumns()
655 $ret = parent
::getColumns();
657 $ret[_pgettext('numeric types', 'Numeric')] = array(
675 $ret[_pgettext('date and time types', 'Date and time')] = array(
684 $ret[_pgettext('string types', 'String')] = array(
705 $ret[_pgettext('spatial types', 'Spatial')] = array(
713 'GEOMETRYCOLLECTION',
720 * Returns an array of integer types
722 * @return string[] integer types
724 public function getIntegerTypes()
726 return array('tinyint', 'smallint', 'mediumint', 'int', 'bigint');
730 * Returns the min and max values of a given integer type
732 * @param string $type integer type
733 * @param boolean $signed whether signed
735 * @return string[] min and max values
737 public function getIntegerRange($type, $signed = true)
739 static $min_max_data = array(
741 'tinyint' => array('0', '255'),
742 'smallint' => array('0', '65535'),
743 'mediumint' => array('0', '16777215'),
744 'int' => array('0', '4294967295'),
745 'bigint' => array('0', '18446744073709551615')
748 'tinyint' => array('-128', '127'),
749 'smallint' => array('-32768', '32767'),
750 'mediumint' => array('-8388608', '8388607'),
751 'int' => array('-2147483648', '2147483647'),
752 'bigint' => array('-9223372036854775808', '9223372036854775807')
755 $relevantArray = $signed
756 ?
$min_max_data['signed']
757 : $min_max_data['unsigned'];
758 return isset($relevantArray[$type]) ?
$relevantArray[$type] : array('', '');
763 * Class holding type definitions for Drizzle.
765 * @package PhpMyAdmin
767 class PMA_Types_Drizzle
extends PMA_Types
770 * Returns the data type description.
772 * @param string $type The data type to get a description.
777 public function getTypeDescription($type)
779 $type = /*overload*/mb_strtoupper($type);
782 return __('A 4-byte integer, range is -2,147,483,648 to 2,147,483,647');
784 return __('An 8-byte integer, range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807');
786 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)');
788 return __("A system's default double-precision floating-point number");
790 return __('True or false');
792 return __('An alias for BIGINT NOT NULL AUTO_INCREMENT UNIQUE');
794 return __('Stores a Universally Unique Identifier (UUID)');
796 return sprintf(__('A date, supported range is %1$s to %2$s'), '0001-01-01', '9999-12-31');
798 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');
800 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");
802 return sprintf(__('A time, range is %1$s to %2$s'), '00:00:00', '23:59:59');
804 return sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-16,383');
806 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');
808 return __('A variable-length (0-65,535) string, uses binary collation for all comparisons');
810 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');
812 return __("An enumeration, chosen from the list of defined values");
818 * Returns class of a type, used for functions available for type
821 * @param string $type The data type to get a class.
826 public function getTypeClass($type)
828 $type = /*overload*/mb_strtoupper($type);
858 * Returns array of functions available for a class.
860 * @param string $class The class to get function list.
865 public function getFunctionsClass($class)
896 // check for some functions known to be in modules
903 $sql = "SELECT upper(plugin_name) f
904 FROM data_dictionary.plugins
905 WHERE plugin_name IN ('" . implode("','", $functions) . "')
906 AND plugin_type = 'Function'
908 $drizzle_functions = $GLOBALS['dbi']->fetchResult($sql, 'f', 'f');
909 if (count($drizzle_functions) > 0) {
910 $ret = array_merge($ret, $drizzle_functions);
931 //'TIME', // https://bugs.launchpad.net/drizzle/+bug/804571
982 'UNCOMPRESSED_LENGTH',
984 //'WEEK', // same as TIME
994 * Returns array of all attributes available.
999 public function getAttributes()
1003 'on update CURRENT_TIMESTAMP',
1008 * Returns array of all column types available.
1013 public function getColumns()
1026 $types_date = array(
1032 $types_string = array(
1041 if (PMA_MYSQL_INT_VERSION
>= 70132) {
1042 $types_string[] = '-';
1043 $types_string[] = 'IPV6';
1046 $ret = parent
::getColumns();
1048 $ret[_pgettext('numeric types', 'Numeric')] = $types_num;
1051 $ret[_pgettext('date and time types', 'Date and time')] = $types_date;
1054 $ret[_pgettext('string types', 'String')] = $types_string;
1060 * Returns an array of integer types
1062 * @return string[] integer types
1064 public function getIntegerTypes()
1066 return array('integer', 'bigint');
1070 * Returns the min and max values of a given integer type
1072 * @param string $type integer type
1073 * @param boolean $signed whether signed (ignored for Drizzle)
1075 * @return string[] min and max values
1077 public function getIntegerRange($type, $signed = true)
1079 static $min_max_data = array(
1080 'integer' => array('-2147483648', '2147483647'),
1081 'bigint' => array('-9223372036854775808', '9223372036854775807')
1083 return isset($min_max_data[$type]) ?
$min_max_data[$type] : array('', '');