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 $html .= '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
165 . htmlspecialchars($fc) . '</option>';
167 $html .= '<option value="' . htmlspecialchars($fc) . '">'
168 . htmlspecialchars($fc) . '</option>';
176 * Returns the data type description.
178 * @param string $type The data type to get a description.
183 public function getTypeDescription($type)
189 * Returns class of a type, used for functions available for type
192 * @param string $type The data type to get a class.
197 public function getTypeClass($type)
203 * Returns array of functions available for a class.
205 * @param string $class The class to get function list.
210 public function getFunctionsClass($class)
216 * Returns array of functions available for a type.
218 * @param string $type The data type to get function list.
223 public function getFunctions($type)
225 $class = $this->getTypeClass($type);
226 return $this->getFunctionsClass($class);
230 * Returns array of all functions available.
235 public function getAllFunctions()
238 $this->getFunctionsClass('CHAR'),
239 $this->getFunctionsClass('NUMBER'),
240 $this->getFunctionsClass('DATE'),
241 $this->getFunctionsClass('UUID')
248 * Returns array of all attributes available.
253 public function getAttributes()
259 * Returns array of all column types available.
264 public function getColumns()
277 * Class holding type definitions for MySQL.
279 * @package PhpMyAdmin
281 class PMA_Types_MySQL
extends PMA_Types
284 * Returns the data type description.
286 * @param string $type The data type to get a description.
291 public function getTypeDescription($type)
293 $type = strtoupper($type);
296 return __('A 1-byte integer, signed range is -128 to 127, unsigned range is 0 to 255');
298 return __('A 2-byte integer, signed range is -32,768 to 32,767, unsigned range is 0 to 65,535');
300 return __('A 3-byte integer, signed range is -8,388,608 to 8,388,607, unsigned range is 0 to 16,777,215');
302 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.');
304 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');
306 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)');
308 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');
310 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');
312 return __('Synonym for DOUBLE (exception: in REAL_AS_FLOAT SQL mode it is a synonym for FLOAT)');
314 return __('A bit-field type (M), storing M of bits per value (default is 1, maximum is 64)');
316 return __('A synonym for TINYINT(1), a value of zero is considered false, nonzero values are considered true');
318 return __('An alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE');
320 return sprintf(__('A date, supported range is %1$s to %2$s'), '1000-01-01', '9999-12-31');
322 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');
324 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)');
326 return sprintf(__('A time, range is %1$s to %2$s'), '-838:59:59', '838:59:59');
328 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");
330 return __('A fixed-length (0-255, default 1) string that is always right-padded with spaces to the specified length when stored');
332 return sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-65,535');
334 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');
336 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');
338 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');
340 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');
342 return __('Similar to the CHAR type, but stores binary byte strings rather than non-binary character strings');
344 return __('Similar to the VARCHAR type, but stores binary byte strings rather than non-binary character strings');
346 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');
348 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');
350 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');
352 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');
354 return __("An enumeration, chosen from the list of up to 65,535 values or the special '' error value");
356 return __("A single value chosen from a set of up to 64 members");
358 return __('A type that can store a geometry of any type');
360 return __('A point in 2-dimensional space');
362 return __('A curve with linear interpolation between points');
364 return __('A polygon');
366 return __('A collection of points');
367 case 'MULTILINESTRING':
368 return __('A collection of curves with linear interpolation between points');
370 return __('A collection of polygons');
371 case 'GEOMETRYCOLLECTION':
372 return __('A collection of geometry objects of any type');
378 * Returns class of a type, used for functions available for type
381 * @param string $type The data type to get a class.
386 public function getTypeClass($type)
388 $type = strtoupper($type);
432 case 'MULTILINESTRING':
434 case 'GEOMETRYCOLLECTION':
442 * Returns array of functions available for a class.
444 * @param string $class The class to get function list.
449 public function getFunctionsClass($class)
552 'UNCOMPRESSED_LENGTH',
560 // remove functions that are unavailable on current server
561 if (PMA_MYSQL_INT_VERSION
< 50500) {
562 $ret = array_diff($ret, array('TO_SECONDS'));
564 if (PMA_MYSQL_INT_VERSION
< 50120) {
565 $ret = array_diff($ret, array('UUID_SHORT'));
595 * Returns array of all attributes available.
600 public function getAttributes()
607 'on update CURRENT_TIMESTAMP',
612 * Returns array of all column types available.
614 * VARCHAR, TINYINT, TEXT and DATE are listed first, based on
615 * estimated popularity.
620 public function getColumns()
622 $ret = parent
::getColumns();
624 $ret[_pgettext('numeric types', 'Numeric')] = array(
643 $ret[_pgettext('date and time types', 'Date and time')] = array(
652 $ret[_pgettext('string types', 'String')] = array(
673 $ret[_pgettext('spatial types', 'Spatial')] = array(
681 'GEOMETRYCOLLECTION',
689 * Class holding type definitions for Drizzle.
691 * @package PhpMyAdmin
693 class PMA_Types_Drizzle
extends PMA_Types
696 * Returns the data type description.
698 * @param string $type The data type to get a description.
703 public function getTypeDescription($type)
705 $type = strtoupper($type);
708 return __('A 4-byte integer, range is -2,147,483,648 to 2,147,483,647');
710 return __('An 8-byte integer, range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807');
712 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)');
714 return __("A system's default double-precision floating-point number");
716 return __('True or false');
718 return __('An alias for BIGINT NOT NULL AUTO_INCREMENT UNIQUE');
720 return __('Stores a Universally Unique Identifier (UUID)');
722 return sprintf(__('A date, supported range is %1$s to %2$s'), '0001-01-01', '9999-12-31');
724 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');
726 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");
728 return sprintf(__('A time, range is %1$s to %2$s'), '00:00:00', '23:59:59');
730 return sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-16,383');
732 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');
734 return __('A variable-length (0-65,535) string, uses binary collation for all comparisons');
736 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');
738 return __("An enumeration, chosen from the list of defined values");
744 * Returns class of a type, used for functions available for type
747 * @param string $type The data type to get a class.
752 public function getTypeClass($type)
754 $type = strtoupper($type);
784 * Returns array of functions available for a class.
786 * @param string $class The class to get function list.
791 public function getFunctionsClass($class)
822 // check for some functions known to be in modules
829 $sql = "SELECT upper(plugin_name) f
830 FROM data_dictionary.plugins
831 WHERE plugin_name IN ('" . implode("','", $functions) . "')
832 AND plugin_type = 'Function'
834 $drizzle_functions = PMA_DBI_fetch_result($sql, 'f', 'f');
835 if (count($drizzle_functions) > 0) {
836 $ret = array_merge($ret, $drizzle_functions);
857 //'TIME', // https://bugs.launchpad.net/drizzle/+bug/804571
908 'UNCOMPRESSED_LENGTH',
910 //'WEEK', // same as TIME
920 * Returns array of all attributes available.
925 public function getAttributes()
929 'on update CURRENT_TIMESTAMP',
934 * Returns array of all column types available.
939 public function getColumns()
958 $types_string = array(
967 if (PMA_MYSQL_INT_VERSION
>= 20120130) {
968 $types_string[] = '-';
969 $types_string[] = 'IPV6';
972 $ret = parent
::getColumns();
974 $ret[_pgettext('numeric types', 'Numeric')] = $types_num;
977 $ret[_pgettext('date and time types', 'Date and time')] = $types_date;
980 $ret[_pgettext('string types', 'String')] = $types_string;