Types.class.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * SQL data types definition
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * Generic class holding type definitions.
  13. *
  14. * @package PhpMyAdmin
  15. */
  16. class PMA_Types
  17. {
  18. /**
  19. * Returns list of unary operators.
  20. *
  21. * @return array
  22. */
  23. public function getUnaryOperators()
  24. {
  25. return array(
  26. 'IS NULL',
  27. 'IS NOT NULL',
  28. "= ''",
  29. "!= ''",
  30. );
  31. }
  32. /**
  33. * Check whether operator is unary.
  34. *
  35. * @param string $op operator name
  36. *
  37. * @return boolean
  38. */
  39. public function isUnaryOperator($op)
  40. {
  41. return in_array($op, $this->getUnaryOperators());
  42. }
  43. /**
  44. * Returns list of operators checking for NULL.
  45. *
  46. * @return array
  47. */
  48. public function getNullOperators()
  49. {
  50. return array(
  51. 'IS NULL',
  52. 'IS NOT NULL',
  53. );
  54. }
  55. /**
  56. * ENUM search operators
  57. *
  58. * @return array
  59. */
  60. public function getEnumOperators()
  61. {
  62. return array(
  63. '=',
  64. '!=',
  65. );
  66. }
  67. /**
  68. * TEXT search operators
  69. *
  70. * @return array
  71. */
  72. public function getTextOperators()
  73. {
  74. return array(
  75. 'LIKE',
  76. 'LIKE %...%',
  77. 'NOT LIKE',
  78. '=',
  79. '!=',
  80. 'REGEXP',
  81. 'REGEXP ^...$',
  82. 'NOT REGEXP',
  83. "= ''",
  84. "!= ''",
  85. 'IN (...)',
  86. 'NOT IN (...)',
  87. 'BETWEEN',
  88. 'NOT BETWEEN',
  89. );
  90. }
  91. /**
  92. * Number search operators
  93. *
  94. * @return array
  95. */
  96. public function getNumberOperators()
  97. {
  98. return array(
  99. '=',
  100. '>',
  101. '>=',
  102. '<',
  103. '<=',
  104. '!=',
  105. 'LIKE',
  106. 'LIKE %...%',
  107. 'NOT LIKE',
  108. 'IN (...)',
  109. 'NOT IN (...)',
  110. 'BETWEEN',
  111. 'NOT BETWEEN',
  112. );
  113. }
  114. /**
  115. * Returns operators for given type
  116. *
  117. * @param string $type Type of field
  118. * @param boolean $null Whether field can be NULL
  119. *
  120. * @return array
  121. */
  122. public function getTypeOperators($type, $null)
  123. {
  124. $ret = array();
  125. $class = $this->getTypeClass($type);
  126. if (strncasecmp($type, 'enum', 4) == 0) {
  127. $ret = array_merge($ret, $this->getEnumOperators());
  128. } elseif ($class == 'CHAR') {
  129. $ret = array_merge($ret, $this->getTextOperators());
  130. } else {
  131. $ret = array_merge($ret, $this->getNumberOperators());
  132. }
  133. if ($null) {
  134. $ret = array_merge($ret, $this->getNullOperators());
  135. }
  136. return $ret;
  137. }
  138. /**
  139. * Returns operators for given type as html options
  140. *
  141. * @param string $type Type of field
  142. * @param boolean $null Whether field can be NULL
  143. * @param string $selectedOperator Option to be selected
  144. *
  145. * @return string Generated Html
  146. */
  147. public function getTypeOperatorsHtml($type, $null, $selectedOperator = null)
  148. {
  149. $html = '';
  150. foreach ($this->getTypeOperators($type, $null) as $fc) {
  151. if (isset($selectedOperator) && $selectedOperator == $fc) {
  152. $html .= '<option value="' . htmlspecialchars($fc) . '" selected="selected">'
  153. . htmlspecialchars($fc) . '</option>';
  154. } else {
  155. $html .= '<option value="' . htmlspecialchars($fc) . '">'
  156. . htmlspecialchars($fc) . '</option>';
  157. }
  158. }
  159. return $html;
  160. }
  161. /**
  162. * Returns the data type description.
  163. *
  164. * @param string $type The data type to get a description.
  165. *
  166. * @return string
  167. *
  168. */
  169. public function getTypeDescription($type)
  170. {
  171. return '';
  172. }
  173. /**
  174. * Returns class of a type, used for functions available for type
  175. * or default values.
  176. *
  177. * @param string $type The data type to get a class.
  178. *
  179. * @return string
  180. *
  181. */
  182. public function getTypeClass($type)
  183. {
  184. return '';
  185. }
  186. /**
  187. * Returns array of functions available for a class.
  188. *
  189. * @param string $class The class to get function list.
  190. *
  191. * @return array
  192. *
  193. */
  194. public function getFunctionsClass($class)
  195. {
  196. return array();
  197. }
  198. /**
  199. * Returns array of functions available for a type.
  200. *
  201. * @param string $type The data type to get function list.
  202. *
  203. * @return array
  204. *
  205. */
  206. public function getFunctions($type)
  207. {
  208. $class = $this->getTypeClass($type);
  209. return $this->getFunctionsClass($class);
  210. }
  211. /**
  212. * Returns array of all functions available.
  213. *
  214. * @return array
  215. *
  216. */
  217. public function getAllFunctions()
  218. {
  219. $ret = array_merge(
  220. $this->getFunctionsClass('CHAR'),
  221. $this->getFunctionsClass('NUMBER'),
  222. $this->getFunctionsClass('DATE'),
  223. $this->getFunctionsClass('UUID')
  224. );
  225. sort($ret);
  226. return $ret;
  227. }
  228. /**
  229. * Returns array of all attributes available.
  230. *
  231. * @return array
  232. *
  233. */
  234. public function getAttributes()
  235. {
  236. return array();
  237. }
  238. /**
  239. * Returns array of all column types available.
  240. *
  241. * @return array
  242. *
  243. */
  244. public function getColumns()
  245. {
  246. // most used types
  247. return array(
  248. 'INT',
  249. 'VARCHAR',
  250. 'TEXT',
  251. 'DATE',
  252. );
  253. }
  254. }
  255. /**
  256. * Class holding type definitions for MySQL.
  257. *
  258. * @package PhpMyAdmin
  259. */
  260. class PMA_Types_MySQL extends PMA_Types
  261. {
  262. /**
  263. * Returns the data type description.
  264. *
  265. * @param string $type The data type to get a description.
  266. *
  267. * @return string
  268. *
  269. */
  270. public function getTypeDescription($type)
  271. {
  272. $type = strtoupper($type);
  273. switch ($type) {
  274. case 'TINYINT':
  275. return __('A 1-byte integer, signed range is -128 to 127, unsigned range is 0 to 255');
  276. case 'SMALLINT':
  277. return __('A 2-byte integer, signed range is -32,768 to 32,767, unsigned range is 0 to 65,535');
  278. case 'MEDIUMINT':
  279. return __('A 3-byte integer, signed range is -8,388,608 to 8,388,607, unsigned range is 0 to 16,777,215');
  280. case 'INT':
  281. 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.');
  282. case 'BIGINT':
  283. 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');
  284. case 'DECIMAL':
  285. 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)');
  286. case 'FLOAT':
  287. 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');
  288. case 'DOUBLE':
  289. 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');
  290. case 'REAL':
  291. return __('Synonym for DOUBLE (exception: in REAL_AS_FLOAT SQL mode it is a synonym for FLOAT)');
  292. case 'BIT':
  293. return __('A bit-field type (M), storing M of bits per value (default is 1, maximum is 64)');
  294. case 'BOOLEAN':
  295. return __('A synonym for TINYINT(1), a value of zero is considered false, nonzero values are considered true');
  296. case 'SERIAL':
  297. return __('An alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE');
  298. case 'DATE':
  299. return sprintf(__('A date, supported range is %1$s to %2$s'), '1000-01-01', '9999-12-31');
  300. case 'DATETIME':
  301. 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');
  302. case 'TIMESTAMP':
  303. 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)');
  304. case 'TIME':
  305. return sprintf(__('A time, range is %1$s to %2$s'), '-838:59:59', '838:59:59');
  306. case 'YEAR':
  307. 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");
  308. case 'CHAR':
  309. return __('A fixed-length (0-255, default 1) string that is always right-padded with spaces to the specified length when stored');
  310. case 'VARCHAR':
  311. return sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-65,535');
  312. case 'TINYTEXT':
  313. 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');
  314. case 'TEXT':
  315. 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');
  316. case 'MEDIUMTEXT':
  317. 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');
  318. case 'LONGTEXT':
  319. 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');
  320. case 'BINARY':
  321. return __('Similar to the CHAR type, but stores binary byte strings rather than non-binary character strings');
  322. case 'VARBINARY':
  323. return __('Similar to the VARCHAR type, but stores binary byte strings rather than non-binary character strings');
  324. case 'TINYBLOB':
  325. 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');
  326. case 'MEDIUMBLOB':
  327. 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');
  328. case 'BLOB':
  329. 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');
  330. case 'LONGBLOB':
  331. 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');
  332. case 'ENUM':
  333. return __("An enumeration, chosen from the list of up to 65,535 values or the special '' error value");
  334. case 'SET':
  335. return __("A single value chosen from a set of up to 64 members");
  336. case 'GEOMETRY':
  337. return __('A type that can store a geometry of any type');
  338. case 'POINT':
  339. return __('A point in 2-dimensional space');
  340. case 'LINESTRING':
  341. return __('A curve with linear interpolation between points');
  342. case 'POLYGON':
  343. return __('A polygon');
  344. case 'MULTIPOINT':
  345. return __('A collection of points');
  346. case 'MULTILINESTRING':
  347. return __('A collection of curves with linear interpolation between points');
  348. case 'MULTIPOLYGON':
  349. return __('A collection of polygons');
  350. case 'GEOMETRYCOLLECTION':
  351. return __('A collection of geometry objects of any type');
  352. }
  353. return '';
  354. }
  355. /**
  356. * Returns class of a type, used for functions available for type
  357. * or default values.
  358. *
  359. * @param string $type The data type to get a class.
  360. *
  361. * @return string
  362. *
  363. */
  364. public function getTypeClass($type)
  365. {
  366. $type = strtoupper($type);
  367. switch ($type) {
  368. case 'TINYINT':
  369. case 'SMALLINT':
  370. case 'MEDIUMINT':
  371. case 'INT':
  372. case 'BIGINT':
  373. case 'DECIMAL':
  374. case 'FLOAT':
  375. case 'DOUBLE':
  376. case 'REAL':
  377. case 'BIT':
  378. case 'BOOLEAN':
  379. case 'SERIAL':
  380. return 'NUMBER';
  381. case 'DATE':
  382. case 'DATETIME':
  383. case 'TIMESTAMP':
  384. case 'TIME':
  385. case 'YEAR':
  386. return 'DATE';
  387. case 'CHAR':
  388. case 'VARCHAR':
  389. case 'TINYTEXT':
  390. case 'TEXT':
  391. case 'MEDIUMTEXT':
  392. case 'LONGTEXT':
  393. case 'BINARY':
  394. case 'VARBINARY':
  395. case 'TINYBLOB':
  396. case 'MEDIUMBLOB':
  397. case 'BLOB':
  398. case 'LONGBLOB':
  399. case 'ENUM':
  400. case 'SET':
  401. return 'CHAR';
  402. case 'GEOMETRY':
  403. case 'POINT':
  404. case 'LINESTRING':
  405. case 'POLYGON':
  406. case 'MULTIPOINT':
  407. case 'MULTILINESTRING':
  408. case 'MULTIPOLYGON':
  409. case 'GEOMETRYCOLLECTION':
  410. return 'SPATIAL';
  411. }
  412. return '';
  413. }
  414. /**
  415. * Returns array of functions available for a class.
  416. *
  417. * @param string $class The class to get function list.
  418. *
  419. * @return array
  420. *
  421. */
  422. public function getFunctionsClass($class)
  423. {
  424. switch ($class) {
  425. case 'CHAR':
  426. return array(
  427. 'BIN',
  428. 'CHAR',
  429. 'COMPRESS',
  430. 'CURRENT_USER',
  431. 'DATABASE',
  432. 'DAYNAME',
  433. 'DES_DECRYPT',
  434. 'DES_ENCRYPT',
  435. 'ENCRYPT',
  436. 'HEX',
  437. 'INET_NTOA',
  438. 'LOAD_FILE',
  439. 'LOWER',
  440. 'LTRIM',
  441. 'MD5',
  442. 'MONTHNAME',
  443. 'OLD_PASSWORD',
  444. 'PASSWORD',
  445. 'QUOTE',
  446. 'REVERSE',
  447. 'RTRIM',
  448. 'SHA1',
  449. 'SOUNDEX',
  450. 'SPACE',
  451. 'TRIM',
  452. 'UNCOMPRESS',
  453. 'UNHEX',
  454. 'UPPER',
  455. 'USER',
  456. 'UUID',
  457. 'VERSION',
  458. );
  459. case 'DATE':
  460. return array(
  461. 'CURRENT_DATE',
  462. 'CURRENT_TIME',
  463. 'DATE',
  464. 'FROM_DAYS',
  465. 'FROM_UNIXTIME',
  466. 'LAST_DAY',
  467. 'NOW',
  468. 'SEC_TO_TIME',
  469. 'SYSDATE',
  470. 'TIME',
  471. 'TIMESTAMP',
  472. 'UTC_DATE',
  473. 'UTC_TIME',
  474. 'UTC_TIMESTAMP',
  475. 'YEAR',
  476. );
  477. case 'NUMBER':
  478. $ret = array(
  479. 'ABS',
  480. 'ACOS',
  481. 'ASCII',
  482. 'ASIN',
  483. 'ATAN',
  484. 'BIT_LENGTH',
  485. 'BIT_COUNT',
  486. 'CEILING',
  487. 'CHAR_LENGTH',
  488. 'CONNECTION_ID',
  489. 'COS',
  490. 'COT',
  491. 'CRC32',
  492. 'DAYOFMONTH',
  493. 'DAYOFWEEK',
  494. 'DAYOFYEAR',
  495. 'DEGREES',
  496. 'EXP',
  497. 'FLOOR',
  498. 'HOUR',
  499. 'INET_ATON',
  500. 'LENGTH',
  501. 'LN',
  502. 'LOG',
  503. 'LOG2',
  504. 'LOG10',
  505. 'MICROSECOND',
  506. 'MINUTE',
  507. 'MONTH',
  508. 'OCT',
  509. 'ORD',
  510. 'PI',
  511. 'QUARTER',
  512. 'RADIANS',
  513. 'RAND',
  514. 'ROUND',
  515. 'SECOND',
  516. 'SIGN',
  517. 'SIN',
  518. 'SQRT',
  519. 'TAN',
  520. 'TO_DAYS',
  521. 'TO_SECONDS',
  522. 'TIME_TO_SEC',
  523. 'UNCOMPRESSED_LENGTH',
  524. 'UNIX_TIMESTAMP',
  525. 'UUID_SHORT',
  526. 'WEEK',
  527. 'WEEKDAY',
  528. 'WEEKOFYEAR',
  529. 'YEARWEEK',
  530. );
  531. // remove functions that are unavailable on current server
  532. if (PMA_MYSQL_INT_VERSION < 50500) {
  533. $ret = array_diff($ret, array('TO_SECONDS'));
  534. }
  535. if (PMA_MYSQL_INT_VERSION < 50120) {
  536. $ret = array_diff($ret, array('UUID_SHORT'));
  537. }
  538. return $ret;
  539. case 'SPATIAL':
  540. return array(
  541. 'GeomFromText',
  542. 'GeomFromWKB',
  543. 'GeomCollFromText',
  544. 'LineFromText',
  545. 'MLineFromText',
  546. 'PointFromText',
  547. 'MPointFromText',
  548. 'PolyFromText',
  549. 'MPolyFromText',
  550. 'GeomCollFromWKB',
  551. 'LineFromWKB',
  552. 'MLineFromWKB',
  553. 'PointFromWKB',
  554. 'MPointFromWKB',
  555. 'PolyFromWKB',
  556. 'MPolyFromWKB',
  557. );
  558. }
  559. return array();
  560. }
  561. /**
  562. * Returns array of all attributes available.
  563. *
  564. * @return array
  565. *
  566. */
  567. public function getAttributes()
  568. {
  569. return array(
  570. '',
  571. 'BINARY',
  572. 'UNSIGNED',
  573. 'UNSIGNED ZEROFILL',
  574. 'on update CURRENT_TIMESTAMP',
  575. );
  576. }
  577. /**
  578. * Returns array of all column types available.
  579. *
  580. * VARCHAR, TINYINT, TEXT and DATE are listed first, based on
  581. * estimated popularity.
  582. *
  583. * @return array
  584. *
  585. */
  586. public function getColumns()
  587. {
  588. $ret = parent::getColumns();
  589. // numeric
  590. $ret[_pgettext('numeric types', 'Numeric')] = array(
  591. 'TINYINT',
  592. 'SMALLINT',
  593. 'MEDIUMINT',
  594. 'INT',
  595. 'BIGINT',
  596. '-',
  597. 'DECIMAL',
  598. 'FLOAT',
  599. 'DOUBLE',
  600. 'REAL',
  601. '-',
  602. 'BIT',
  603. 'BOOLEAN',
  604. 'SERIAL',
  605. );
  606. // Date/Time
  607. $ret[_pgettext('date and time types', 'Date and time')] = array(
  608. 'DATE',
  609. 'DATETIME',
  610. 'TIMESTAMP',
  611. 'TIME',
  612. 'YEAR',
  613. );
  614. // Text
  615. $ret[_pgettext('string types', 'String')] = array(
  616. 'CHAR',
  617. 'VARCHAR',
  618. '-',
  619. 'TINYTEXT',
  620. 'TEXT',
  621. 'MEDIUMTEXT',
  622. 'LONGTEXT',
  623. '-',
  624. 'BINARY',
  625. 'VARBINARY',
  626. '-',
  627. 'TINYBLOB',
  628. 'MEDIUMBLOB',
  629. 'BLOB',
  630. 'LONGBLOB',
  631. '-',
  632. 'ENUM',
  633. 'SET',
  634. );
  635. $ret[_pgettext('spatial types', 'Spatial')] = array(
  636. 'GEOMETRY',
  637. 'POINT',
  638. 'LINESTRING',
  639. 'POLYGON',
  640. 'MULTIPOINT',
  641. 'MULTILINESTRING',
  642. 'MULTIPOLYGON',
  643. 'GEOMETRYCOLLECTION',
  644. );
  645. return $ret;
  646. }
  647. }
  648. /**
  649. * Class holding type definitions for Drizzle.
  650. *
  651. * @package PhpMyAdmin
  652. */
  653. class PMA_Types_Drizzle extends PMA_Types
  654. {
  655. /**
  656. * Returns the data type description.
  657. *
  658. * @param string $type The data type to get a description.
  659. *
  660. * @return string
  661. *
  662. */
  663. public function getTypeDescription($type)
  664. {
  665. $type = strtoupper($type);
  666. switch ($type) {
  667. case 'INTEGER':
  668. return __('A 4-byte integer, range is -2,147,483,648 to 2,147,483,647');
  669. case 'BIGINT':
  670. return __('An 8-byte integer, range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807');
  671. case 'DECIMAL':
  672. 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)');
  673. case 'DOUBLE':
  674. return __("A system's default double-precision floating-point number");
  675. case 'BOOLEAN':
  676. return __('True or false');
  677. case 'SERIAL':
  678. return __('An alias for BIGINT NOT NULL AUTO_INCREMENT UNIQUE');
  679. case 'UUID':
  680. return __('Stores a Universally Unique Identifier (UUID)');
  681. case 'DATE':
  682. return sprintf(__('A date, supported range is %1$s to %2$s'), '0001-01-01', '9999-12-31');
  683. case 'DATETIME':
  684. 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');
  685. case 'TIMESTAMP':
  686. 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");
  687. case 'TIME':
  688. return sprintf(__('A time, range is %1$s to %2$s'), '00:00:00', '23:59:59');
  689. case 'VARCHAR':
  690. return sprintf(__('A variable-length (%s) string, the effective maximum length is subject to the maximum row size'), '0-16,383');
  691. case 'TEXT':
  692. 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');
  693. case 'VARBINARY':
  694. return __('A variable-length (0-65,535) string, uses binary collation for all comparisons');
  695. case 'BLOB':
  696. 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');
  697. case 'ENUM':
  698. return __("An enumeration, chosen from the list of defined values");
  699. }
  700. return '';
  701. }
  702. /**
  703. * Returns class of a type, used for functions available for type
  704. * or default values.
  705. *
  706. * @param string $type The data type to get a class.
  707. *
  708. * @return string
  709. *
  710. */
  711. public function getTypeClass($type)
  712. {
  713. $type = strtoupper($type);
  714. switch ($type) {
  715. case 'INTEGER':
  716. case 'BIGINT':
  717. case 'DECIMAL':
  718. case 'DOUBLE':
  719. case 'BOOLEAN':
  720. case 'SERIAL':
  721. return 'NUMBER';
  722. case 'DATE':
  723. case 'DATETIME':
  724. case 'TIMESTAMP':
  725. case 'TIME':
  726. return 'DATE';
  727. case 'VARCHAR':
  728. case 'TEXT':
  729. case 'VARBINARY':
  730. case 'BLOB':
  731. case 'ENUM':
  732. return 'CHAR';
  733. case 'UUID':
  734. return 'UUID';
  735. }
  736. return '';
  737. }
  738. /**
  739. * Returns array of functions available for a class.
  740. *
  741. * @param string $class The class to get function list.
  742. *
  743. * @return array
  744. *
  745. */
  746. public function getFunctionsClass($class)
  747. {
  748. switch ($class) {
  749. case 'CHAR':
  750. $ret = array(
  751. 'BIN',
  752. 'CHAR',
  753. 'COMPRESS',
  754. 'CURRENT_USER',
  755. 'DATABASE',
  756. 'DAYNAME',
  757. 'HEX',
  758. 'LOAD_FILE',
  759. 'LOWER',
  760. 'LTRIM',
  761. 'MD5',
  762. 'MONTHNAME',
  763. 'QUOTE',
  764. 'REVERSE',
  765. 'RTRIM',
  766. 'SCHEMA',
  767. 'SPACE',
  768. 'TRIM',
  769. 'UNCOMPRESS',
  770. 'UNHEX',
  771. 'UPPER',
  772. 'USER',
  773. 'UUID',
  774. 'VERSION',
  775. );
  776. // check for some functions known to be in modules
  777. $functions = array(
  778. 'MYSQL_PASSWORD',
  779. 'ROT13',
  780. );
  781. // add new functions
  782. $sql = "SELECT upper(plugin_name) f
  783. FROM data_dictionary.plugins
  784. WHERE plugin_name IN ('" . implode("','", $functions) . "')
  785. AND plugin_type = 'Function'
  786. AND is_active";
  787. $drizzle_functions = PMA_DBI_fetch_result($sql, 'f', 'f');
  788. if (count($drizzle_functions) > 0) {
  789. $ret = array_merge($ret, $drizzle_functions);
  790. sort($ret);
  791. }
  792. return $ret;
  793. case 'UUID':
  794. return array(
  795. 'UUID',
  796. );
  797. case 'DATE':
  798. return array(
  799. 'CURRENT_DATE',
  800. 'CURRENT_TIME',
  801. 'DATE',
  802. 'FROM_DAYS',
  803. 'FROM_UNIXTIME',
  804. 'LAST_DAY',
  805. 'NOW',
  806. 'SYSDATE',
  807. //'TIME', // https://bugs.launchpad.net/drizzle/+bug/804571
  808. 'TIMESTAMP',
  809. 'UTC_DATE',
  810. 'UTC_TIME',
  811. 'UTC_TIMESTAMP',
  812. 'YEAR',
  813. );
  814. case 'NUMBER':
  815. return array(
  816. 'ABS',
  817. 'ACOS',
  818. 'ASCII',
  819. 'ASIN',
  820. 'ATAN',
  821. 'BIT_COUNT',
  822. 'CEILING',
  823. 'CHAR_LENGTH',
  824. 'CONNECTION_ID',
  825. 'COS',
  826. 'COT',
  827. 'CRC32',
  828. 'DAYOFMONTH',
  829. 'DAYOFWEEK',
  830. 'DAYOFYEAR',
  831. 'DEGREES',
  832. 'EXP',
  833. 'FLOOR',
  834. 'HOUR',
  835. 'LENGTH',
  836. 'LN',
  837. 'LOG',
  838. 'LOG2',
  839. 'LOG10',
  840. 'MICROSECOND',
  841. 'MINUTE',
  842. 'MONTH',
  843. 'OCT',
  844. 'ORD',
  845. 'PI',
  846. 'QUARTER',
  847. 'RADIANS',
  848. 'RAND',
  849. 'ROUND',
  850. 'SECOND',
  851. 'SIGN',
  852. 'SIN',
  853. 'SQRT',
  854. 'TAN',
  855. 'TO_DAYS',
  856. 'TIME_TO_SEC',
  857. 'UNCOMPRESSED_LENGTH',
  858. 'UNIX_TIMESTAMP',
  859. //'WEEK', // same as TIME
  860. 'WEEKDAY',
  861. 'WEEKOFYEAR',
  862. 'YEARWEEK',
  863. );
  864. }
  865. return array();
  866. }
  867. /**
  868. * Returns array of all attributes available.
  869. *
  870. * @return array
  871. *
  872. */
  873. public function getAttributes()
  874. {
  875. return array(
  876. '',
  877. 'on update CURRENT_TIMESTAMP',
  878. );
  879. }
  880. /**
  881. * Returns array of all column types available.
  882. *
  883. * @return array
  884. *
  885. */
  886. public function getColumns()
  887. {
  888. $types_num = array(
  889. 'INTEGER',
  890. 'BIGINT',
  891. '-',
  892. 'DECIMAL',
  893. 'DOUBLE',
  894. '-',
  895. 'BOOLEAN',
  896. 'SERIAL',
  897. 'UUID',
  898. );
  899. $types_date = array(
  900. 'DATE',
  901. 'DATETIME',
  902. 'TIMESTAMP',
  903. 'TIME',
  904. );
  905. $types_string = array(
  906. 'VARCHAR',
  907. 'TEXT',
  908. '-',
  909. 'VARBINARY',
  910. 'BLOB',
  911. '-',
  912. 'ENUM',
  913. );
  914. if (PMA_MYSQL_INT_VERSION >= 20120130) {
  915. $types_string[] = '-';
  916. $types_string[] = 'IPV6';
  917. }
  918. $ret = parent::getColumns();
  919. // numeric
  920. $ret[_pgettext('numeric types', 'Numeric')] = $types_num;
  921. // Date/Time
  922. $ret[_pgettext('date and time types', 'Date and time')] = $types_date;
  923. // Text
  924. $ret[_pgettext('string types', 'String')] = $types_string;
  925. return $ret;
  926. }
  927. }