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);
321 'A 1-byte integer, signed range is -128 to 127, unsigned range is ' .
326 'A 2-byte integer, signed range is -32,768 to 32,767, unsigned ' .
327 'range is 0 to 65,535'
331 'A 3-byte integer, signed range is -8,388,608 to 8,388,607, ' .
332 'unsigned range is 0 to 16,777,215'
336 'A 4-byte integer, signed range is ' .
337 '-2,147,483,648 to 2,147,483,647, unsigned range is 0 to ' .
342 'An 8-byte integer, signed range is -9,223,372,036,854,775,808 ' .
343 'to 9,223,372,036,854,775,807, unsigned range is 0 to ' .
344 '18,446,744,073,709,551,615'
348 'A fixed-point number (M, D) - the maximum number of digits (M) ' .
349 'is 65 (default 10), the maximum number of decimals (D) is 30 ' .
354 'A small floating-point number, allowable values are ' .
355 '-3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to ' .
360 'A double-precision floating-point number, allowable values are ' .
361 '-1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and ' .
362 '2.2250738585072014E-308 to 1.7976931348623157E+308'
366 'Synonym for DOUBLE (exception: in REAL_AS_FLOAT SQL mode it is ' .
367 'a synonym for FLOAT)'
371 'A bit-field type (M), storing M of bits per value (default is 1, ' .
376 'A synonym for TINYINT(1), a value of zero is considered false, ' .
377 'nonzero values are considered true'
380 return __('An alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE');
383 __('A date, supported range is %1$s to %2$s'), '1000-01-01',
388 __('A date and time combination, supported range is %1$s to %2$s'),
389 '1000-01-01 00:00:00', '9999-12-31 23:59:59'
393 'A timestamp, range is 1970-01-01 00:00:01 UTC to 2038-01-09 ' .
394 '03:14:07 UTC, stored as the number of seconds since the epoch ' .
395 '(1970-01-01 00:00:00 UTC)'
399 __('A time, range is %1$s to %2$s'), '-838:59:59', '838:59:59'
403 "A year in four-digit (4, default) or two-digit (2) format, the " .
404 "allowable values are 70 (1970) to 69 (2069) or 1901 to 2155 and " .
409 'A fixed-length (0-255, default 1) string that is always ' .
410 'right-padded with spaces to the specified length when stored'
415 'A variable-length (%s) string, the effective maximum length ' .
416 'is subject to the maximum row size'
421 'A TEXT column with a maximum length of 255 (2^8 - 1) characters, ' .
422 'stored with a one-byte prefix indicating the length of the value ' .
427 'A TEXT column with a maximum length of 65,535 (2^16 - 1) ' .
428 'characters, stored with a two-byte prefix indicating the length ' .
429 'of the value in bytes'
433 'A TEXT column with a maximum length of 16,777,215 (2^24 - 1) ' .
434 'characters, stored with a three-byte prefix indicating the ' .
435 'length of the value in bytes'
439 'A TEXT column with a maximum length of 4,294,967,295 or 4GiB ' .
440 '(2^32 - 1) characters, stored with a four-byte prefix indicating ' .
441 'the length of the value in bytes'
445 'Similar to the CHAR type, but stores binary byte strings rather ' .
446 'than non-binary character strings'
450 'Similar to the VARCHAR type, but stores binary byte strings ' .
451 'rather than non-binary character strings'
455 'A BLOB column with a maximum length of 255 (2^8 - 1) bytes, ' .
456 'stored with a one-byte prefix indicating the length of the value'
460 'A BLOB column with a maximum length of 16,777,215 (2^24 - 1) ' .
461 'bytes, stored with a three-byte prefix indicating the length of ' .
466 'A BLOB column with a maximum length of 65,535 (2^16 - 1) bytes, ' .
467 'stored with a two-byte prefix indicating the length of the value'
471 'A BLOB column with a maximum length of 4,294,967,295 or 4GiB ' .
472 '(2^32 - 1) bytes, stored with a four-byte prefix indicating the ' .
473 'length of the value'
477 "An enumeration, chosen from the list of up to 65,535 values or " .
478 "the special '' error value"
481 return __("A single value chosen from a set of up to 64 members");
483 return __('A type that can store a geometry of any type');
485 return __('A point in 2-dimensional space');
487 return __('A curve with linear interpolation between points');
489 return __('A polygon');
491 return __('A collection of points');
492 case 'MULTILINESTRING':
494 'A collection of curves with linear interpolation between points'
497 return __('A collection of polygons');
498 case 'GEOMETRYCOLLECTION':
499 return __('A collection of geometry objects of any type');
505 * Returns class of a type, used for functions available for type
508 * @param string $type The data type to get a class.
513 public function getTypeClass($type)
515 $type = /*overload*/mb_strtoupper($type);
559 case 'MULTILINESTRING':
561 case 'GEOMETRYCOLLECTION':
569 * Returns array of functions available for a class.
571 * @param string $class The class to get function list.
576 public function getFunctionsClass($class)
617 if ((PMA_MARIADB
&& PMA_MYSQL_INT_VERSION
< 100012)
618 || PMA_MYSQL_INT_VERSION
< 50603
620 $ret = array_diff($ret, array('INET6_NTOA'));
690 'UNCOMPRESSED_LENGTH',
698 if ((PMA_MARIADB
&& PMA_MYSQL_INT_VERSION
< 100012)
699 || PMA_MYSQL_INT_VERSION
< 50603
701 $ret = array_diff($ret, array('INET6_ATON'));
731 * Returns array of all attributes available.
736 public function getAttributes()
743 'on update CURRENT_TIMESTAMP',
748 * Returns array of all column types available.
750 * VARCHAR, TINYINT, TEXT and DATE are listed first, based on
751 * estimated popularity.
756 public function getColumns()
758 $ret = parent
::getColumns();
760 $ret[_pgettext('numeric types', 'Numeric')] = array(
778 $ret[_pgettext('date and time types', 'Date and time')] = array(
787 $ret[_pgettext('string types', 'String')] = array(
808 $ret[_pgettext('spatial types', 'Spatial')] = array(
816 'GEOMETRYCOLLECTION',
823 * Returns an array of integer types
825 * @return string[] integer types
827 public function getIntegerTypes()
829 return array('tinyint', 'smallint', 'mediumint', 'int', 'bigint');
833 * Returns the min and max values of a given integer type
835 * @param string $type integer type
836 * @param boolean $signed whether signed
838 * @return string[] min and max values
840 public function getIntegerRange($type, $signed = true)
842 static $min_max_data = array(
844 'tinyint' => array('0', '255'),
845 'smallint' => array('0', '65535'),
846 'mediumint' => array('0', '16777215'),
847 'int' => array('0', '4294967295'),
848 'bigint' => array('0', '18446744073709551615')
851 'tinyint' => array('-128', '127'),
852 'smallint' => array('-32768', '32767'),
853 'mediumint' => array('-8388608', '8388607'),
854 'int' => array('-2147483648', '2147483647'),
855 'bigint' => array('-9223372036854775808', '9223372036854775807')
858 $relevantArray = $signed
859 ?
$min_max_data['signed']
860 : $min_max_data['unsigned'];
861 return isset($relevantArray[$type]) ?
$relevantArray[$type] : array('', '');
866 * Class holding type definitions for Drizzle.
868 * @package PhpMyAdmin
870 class PMA_Types_Drizzle
extends PMA_Types
873 * Returns the data type description.
875 * @param string $type The data type to get a description.
880 public function getTypeDescription($type)
882 $type = /*overload*/mb_strtoupper($type);
885 return __('A 4-byte integer, range is -2,147,483,648 to 2,147,483,647');
888 'An 8-byte integer, range is -9,223,372,036,854,775,808 to ' .
889 '9,223,372,036,854,775,807'
893 'A fixed-point number (M, D) - the maximum number of digits ' .
894 '(M) is 65 (default 10), the maximum number of decimals (D) ' .
898 return __("A system's default double-precision floating-point number");
900 return __('True or false');
902 return __('An alias for BIGINT NOT NULL AUTO_INCREMENT UNIQUE');
904 return __('Stores a Universally Unique Identifier (UUID)');
907 __('A date, supported range is %1$s to %2$s'), '0001-01-01',
913 'A date and time combination, supported range is %1$s to ' .
915 ), '0001-01-01 00:00:0', '9999-12-31 23:59:59'
919 "A timestamp, range is '0001-01-01 00:00:00' UTC to " .
920 "'9999-12-31 23:59:59' UTC; TIMESTAMP(6) can store microseconds"
924 __('A time, range is %1$s to %2$s'), '00:00:00', '23:59:59'
929 'A variable-length (%s) string, the effective ' .
930 'maximum length is subject to the maximum row size'
935 'A TEXT column with a maximum length of 65,535 (2^16 - 1) ' .
936 'characters, stored with a two-byte prefix indicating the ' .
937 'length of the value in bytes'
941 'A variable-length (0-65,535) string, uses binary collation ' .
942 'for all comparisons'
946 'A BLOB column with a maximum length of 65,535 (2^16 - 1) ' .
947 'bytes, stored with a two-byte prefix indicating the length of ' .
951 return __("An enumeration, chosen from the list of defined values");
958 * Returns class of a type, used for functions available for type
961 * @param string $type The data type to get a class.
966 public function getTypeClass($type)
968 $type = /*overload*/mb_strtoupper($type);
998 * Returns array of functions available for a class.
1000 * @param string $class The class to get function list.
1005 public function getFunctionsClass($class)
1036 // check for some functions known to be in modules
1042 // add new functions
1043 $sql = "SELECT upper(plugin_name) f
1044 FROM data_dictionary.plugins
1045 WHERE plugin_name IN ('" . implode("','", $functions) . "')
1046 AND plugin_type = 'Function'
1048 $drizzle_functions = $GLOBALS['dbi']->fetchResult($sql, 'f', 'f');
1049 if (count($drizzle_functions) > 0) {
1050 $ret = array_merge($ret, $drizzle_functions);
1071 //'TIME', // https://bugs.launchpad.net/drizzle/+bug/804571
1122 'UNCOMPRESSED_LENGTH',
1124 //'WEEK', // same as TIME
1134 * Returns array of all attributes available.
1139 public function getAttributes()
1143 'on update CURRENT_TIMESTAMP',
1148 * Returns array of all column types available.
1153 public function getColumns()
1166 $types_date = array(
1172 $types_string = array(
1181 if (PMA_MYSQL_INT_VERSION
>= 70132) {
1182 $types_string[] = '-';
1183 $types_string[] = 'IPV6';
1186 $ret = parent
::getColumns();
1188 $ret[_pgettext('numeric types', 'Numeric')] = $types_num;
1191 $ret[_pgettext('date and time types', 'Date and time')] = $types_date;
1194 $ret[_pgettext('string types', 'String')] = $types_string;
1200 * Returns an array of integer types
1202 * @return string[] integer types
1204 public function getIntegerTypes()
1206 return array('integer', 'bigint');
1210 * Returns the min and max values of a given integer type
1212 * @param string $type integer type
1213 * @param boolean $signed whether signed (ignored for Drizzle)
1215 * @return string[] min and max values
1217 public function getIntegerRange($type, $signed = true)
1219 static $min_max_data = array(
1220 'integer' => array('-2147483648', '2147483647'),
1221 'bigint' => array('-9223372036854775808', '9223372036854775807')
1223 return isset($min_max_data[$type]) ?
$min_max_data[$type] : array('', '');