Types.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * SQL data types definition
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin;
  9. /**
  10. * Class holding type definitions for MySQL and MariaDB.
  11. *
  12. * @package PhpMyAdmin
  13. */
  14. class Types
  15. {
  16. /**
  17. * @var PhpMyAdmin\DatabaseInteface Database interface
  18. */
  19. private $_dbi;
  20. /**
  21. * Constructor
  22. *
  23. * @param PhpMyAdmin\DatabaseInteface $dbi Database interface instance
  24. */
  25. public function __construct($dbi)
  26. {
  27. $this->_dbi = $dbi;
  28. }
  29. /**
  30. * Returns list of unary operators.
  31. *
  32. * @return string[]
  33. */
  34. public function getUnaryOperators()
  35. {
  36. return array(
  37. 'IS NULL',
  38. 'IS NOT NULL',
  39. "= ''",
  40. "!= ''",
  41. );
  42. }
  43. /**
  44. * Check whether operator is unary.
  45. *
  46. * @param string $op operator name
  47. *
  48. * @return boolean
  49. */
  50. public function isUnaryOperator($op)
  51. {
  52. return in_array($op, $this->getUnaryOperators());
  53. }
  54. /**
  55. * Returns list of operators checking for NULL.
  56. *
  57. * @return string[]
  58. */
  59. public function getNullOperators()
  60. {
  61. return array(
  62. 'IS NULL',
  63. 'IS NOT NULL',
  64. );
  65. }
  66. /**
  67. * ENUM search operators
  68. *
  69. * @return string[]
  70. */
  71. public function getEnumOperators()
  72. {
  73. return array(
  74. '=',
  75. '!=',
  76. );
  77. }
  78. /**
  79. * TEXT search operators
  80. *
  81. * @return string[]
  82. */
  83. public function getTextOperators()
  84. {
  85. return array(
  86. 'LIKE',
  87. 'LIKE %...%',
  88. 'NOT LIKE',
  89. '=',
  90. '!=',
  91. 'REGEXP',
  92. 'REGEXP ^...$',
  93. 'NOT REGEXP',
  94. "= ''",
  95. "!= ''",
  96. 'IN (...)',
  97. 'NOT IN (...)',
  98. 'BETWEEN',
  99. 'NOT BETWEEN',
  100. );
  101. }
  102. /**
  103. * Number search operators
  104. *
  105. * @return string[]
  106. */
  107. public function getNumberOperators()
  108. {
  109. return array(
  110. '=',
  111. '>',
  112. '>=',
  113. '<',
  114. '<=',
  115. '!=',
  116. 'LIKE',
  117. 'LIKE %...%',
  118. 'NOT LIKE',
  119. 'IN (...)',
  120. 'NOT IN (...)',
  121. 'BETWEEN',
  122. 'NOT BETWEEN',
  123. );
  124. }
  125. /**
  126. * Returns operators for given type
  127. *
  128. * @param string $type Type of field
  129. * @param boolean $null Whether field can be NULL
  130. *
  131. * @return string[]
  132. */
  133. public function getTypeOperators($type, $null)
  134. {
  135. $ret = array();
  136. $class = $this->getTypeClass($type);
  137. if (strncasecmp($type, 'enum', 4) == 0) {
  138. $ret = array_merge($ret, $this->getEnumOperators());
  139. } elseif ($class == 'CHAR') {
  140. $ret = array_merge($ret, $this->getTextOperators());
  141. } else {
  142. $ret = array_merge($ret, $this->getNumberOperators());
  143. }
  144. if ($null) {
  145. $ret = array_merge($ret, $this->getNullOperators());
  146. }
  147. return $ret;
  148. }
  149. /**
  150. * Returns operators for given type as html options
  151. *
  152. * @param string $type Type of field
  153. * @param boolean $null Whether field can be NULL
  154. * @param string $selectedOperator Option to be selected
  155. *
  156. * @return string Generated Html
  157. */
  158. public function getTypeOperatorsHtml($type, $null, $selectedOperator = null)
  159. {
  160. $html = '';
  161. foreach ($this->getTypeOperators($type, $null) as $fc) {
  162. if (isset($selectedOperator) && $selectedOperator == $fc) {
  163. $selected = ' selected="selected"';
  164. } else {
  165. $selected = '';
  166. }
  167. $html .= '<option value="' . htmlspecialchars($fc) . '"'
  168. . $selected . '>'
  169. . htmlspecialchars($fc) . '</option>';
  170. }
  171. return $html;
  172. }
  173. /**
  174. * Returns the data type description.
  175. *
  176. * @param string $type The data type to get a description.
  177. *
  178. * @return string
  179. *
  180. */
  181. public function getTypeDescription($type)
  182. {
  183. $type = mb_strtoupper($type);
  184. switch ($type) {
  185. case 'TINYINT':
  186. return __(
  187. 'A 1-byte integer, signed range is -128 to 127, unsigned range is ' .
  188. '0 to 255'
  189. );
  190. case 'SMALLINT':
  191. return __(
  192. 'A 2-byte integer, signed range is -32,768 to 32,767, unsigned ' .
  193. 'range is 0 to 65,535'
  194. );
  195. case 'MEDIUMINT':
  196. return __(
  197. 'A 3-byte integer, signed range is -8,388,608 to 8,388,607, ' .
  198. 'unsigned range is 0 to 16,777,215'
  199. );
  200. case 'INT':
  201. return __(
  202. 'A 4-byte integer, signed range is ' .
  203. '-2,147,483,648 to 2,147,483,647, unsigned range is 0 to ' .
  204. '4,294,967,295'
  205. );
  206. case 'BIGINT':
  207. return __(
  208. 'An 8-byte integer, signed range is -9,223,372,036,854,775,808 ' .
  209. 'to 9,223,372,036,854,775,807, unsigned range is 0 to ' .
  210. '18,446,744,073,709,551,615'
  211. );
  212. case 'DECIMAL':
  213. return __(
  214. 'A fixed-point number (M, D) - the maximum number of digits (M) ' .
  215. 'is 65 (default 10), the maximum number of decimals (D) is 30 ' .
  216. '(default 0)'
  217. );
  218. case 'FLOAT':
  219. return __(
  220. 'A small floating-point number, allowable values are ' .
  221. '-3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to ' .
  222. '3.402823466E+38'
  223. );
  224. case 'DOUBLE':
  225. return __(
  226. 'A double-precision floating-point number, allowable values are ' .
  227. '-1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and ' .
  228. '2.2250738585072014E-308 to 1.7976931348623157E+308'
  229. );
  230. case 'REAL':
  231. return __(
  232. 'Synonym for DOUBLE (exception: in REAL_AS_FLOAT SQL mode it is ' .
  233. 'a synonym for FLOAT)'
  234. );
  235. case 'BIT':
  236. return __(
  237. 'A bit-field type (M), storing M of bits per value (default is 1, ' .
  238. 'maximum is 64)'
  239. );
  240. case 'BOOLEAN':
  241. return __(
  242. 'A synonym for TINYINT(1), a value of zero is considered false, ' .
  243. 'nonzero values are considered true'
  244. );
  245. case 'SERIAL':
  246. return __('An alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE');
  247. case 'DATE':
  248. return sprintf(
  249. __('A date, supported range is %1$s to %2$s'), '1000-01-01',
  250. '9999-12-31'
  251. );
  252. case 'DATETIME':
  253. return sprintf(
  254. __('A date and time combination, supported range is %1$s to %2$s'),
  255. '1000-01-01 00:00:00', '9999-12-31 23:59:59'
  256. );
  257. case 'TIMESTAMP':
  258. return __(
  259. 'A timestamp, range is 1970-01-01 00:00:01 UTC to 2038-01-09 ' .
  260. '03:14:07 UTC, stored as the number of seconds since the epoch ' .
  261. '(1970-01-01 00:00:00 UTC)'
  262. );
  263. case 'TIME':
  264. return sprintf(
  265. __('A time, range is %1$s to %2$s'), '-838:59:59', '838:59:59'
  266. );
  267. case 'YEAR':
  268. return __(
  269. "A year in four-digit (4, default) or two-digit (2) format, the " .
  270. "allowable values are 70 (1970) to 69 (2069) or 1901 to 2155 and " .
  271. "0000"
  272. );
  273. case 'CHAR':
  274. return __(
  275. 'A fixed-length (0-255, default 1) string that is always ' .
  276. 'right-padded with spaces to the specified length when stored'
  277. );
  278. case 'VARCHAR':
  279. return sprintf(
  280. __(
  281. 'A variable-length (%s) string, the effective maximum length ' .
  282. 'is subject to the maximum row size'
  283. ), '0-65,535'
  284. );
  285. case 'TINYTEXT':
  286. return __(
  287. 'A TEXT column with a maximum length of 255 (2^8 - 1) characters, ' .
  288. 'stored with a one-byte prefix indicating the length of the value ' .
  289. 'in bytes'
  290. );
  291. case 'TEXT':
  292. return __(
  293. 'A TEXT column with a maximum length of 65,535 (2^16 - 1) ' .
  294. 'characters, stored with a two-byte prefix indicating the length ' .
  295. 'of the value in bytes'
  296. );
  297. case 'MEDIUMTEXT':
  298. return __(
  299. 'A TEXT column with a maximum length of 16,777,215 (2^24 - 1) ' .
  300. 'characters, stored with a three-byte prefix indicating the ' .
  301. 'length of the value in bytes'
  302. );
  303. case 'LONGTEXT':
  304. return __(
  305. 'A TEXT column with a maximum length of 4,294,967,295 or 4GiB ' .
  306. '(2^32 - 1) characters, stored with a four-byte prefix indicating ' .
  307. 'the length of the value in bytes'
  308. );
  309. case 'BINARY':
  310. return __(
  311. 'Similar to the CHAR type, but stores binary byte strings rather ' .
  312. 'than non-binary character strings'
  313. );
  314. case 'VARBINARY':
  315. return __(
  316. 'Similar to the VARCHAR type, but stores binary byte strings ' .
  317. 'rather than non-binary character strings'
  318. );
  319. case 'TINYBLOB':
  320. return __(
  321. 'A BLOB column with a maximum length of 255 (2^8 - 1) bytes, ' .
  322. 'stored with a one-byte prefix indicating the length of the value'
  323. );
  324. case 'MEDIUMBLOB':
  325. return __(
  326. 'A BLOB column with a maximum length of 16,777,215 (2^24 - 1) ' .
  327. 'bytes, stored with a three-byte prefix indicating the length of ' .
  328. 'the value'
  329. );
  330. case 'BLOB':
  331. return __(
  332. 'A BLOB column with a maximum length of 65,535 (2^16 - 1) bytes, ' .
  333. 'stored with a two-byte prefix indicating the length of the value'
  334. );
  335. case 'LONGBLOB':
  336. return __(
  337. 'A BLOB column with a maximum length of 4,294,967,295 or 4GiB ' .
  338. '(2^32 - 1) bytes, stored with a four-byte prefix indicating the ' .
  339. 'length of the value'
  340. );
  341. case 'ENUM':
  342. return __(
  343. "An enumeration, chosen from the list of up to 65,535 values or " .
  344. "the special '' error value"
  345. );
  346. case 'SET':
  347. return __("A single value chosen from a set of up to 64 members");
  348. case 'GEOMETRY':
  349. return __('A type that can store a geometry of any type');
  350. case 'POINT':
  351. return __('A point in 2-dimensional space');
  352. case 'LINESTRING':
  353. return __('A curve with linear interpolation between points');
  354. case 'POLYGON':
  355. return __('A polygon');
  356. case 'MULTIPOINT':
  357. return __('A collection of points');
  358. case 'MULTILINESTRING':
  359. return __(
  360. 'A collection of curves with linear interpolation between points'
  361. );
  362. case 'MULTIPOLYGON':
  363. return __('A collection of polygons');
  364. case 'GEOMETRYCOLLECTION':
  365. return __('A collection of geometry objects of any type');
  366. case 'JSON':
  367. return __(
  368. 'Stores and enables efficient access to data in JSON'
  369. . ' (JavaScript Object Notation) documents'
  370. );
  371. }
  372. return '';
  373. }
  374. /**
  375. * Returns class of a type, used for functions available for type
  376. * or default values.
  377. *
  378. * @param string $type The data type to get a class.
  379. *
  380. * @return string
  381. *
  382. */
  383. public function getTypeClass($type)
  384. {
  385. $type = mb_strtoupper($type);
  386. switch ($type) {
  387. case 'TINYINT':
  388. case 'SMALLINT':
  389. case 'MEDIUMINT':
  390. case 'INT':
  391. case 'BIGINT':
  392. case 'DECIMAL':
  393. case 'FLOAT':
  394. case 'DOUBLE':
  395. case 'REAL':
  396. case 'BIT':
  397. case 'BOOLEAN':
  398. case 'SERIAL':
  399. return 'NUMBER';
  400. case 'DATE':
  401. case 'DATETIME':
  402. case 'TIMESTAMP':
  403. case 'TIME':
  404. case 'YEAR':
  405. return 'DATE';
  406. case 'CHAR':
  407. case 'VARCHAR':
  408. case 'TINYTEXT':
  409. case 'TEXT':
  410. case 'MEDIUMTEXT':
  411. case 'LONGTEXT':
  412. case 'BINARY':
  413. case 'VARBINARY':
  414. case 'TINYBLOB':
  415. case 'MEDIUMBLOB':
  416. case 'BLOB':
  417. case 'LONGBLOB':
  418. case 'ENUM':
  419. case 'SET':
  420. return 'CHAR';
  421. case 'GEOMETRY':
  422. case 'POINT':
  423. case 'LINESTRING':
  424. case 'POLYGON':
  425. case 'MULTIPOINT':
  426. case 'MULTILINESTRING':
  427. case 'MULTIPOLYGON':
  428. case 'GEOMETRYCOLLECTION':
  429. return 'SPATIAL';
  430. case 'JSON':
  431. return 'JSON';
  432. }
  433. return '';
  434. }
  435. /**
  436. * Returns array of functions available for a class.
  437. *
  438. * @param string $class The class to get function list.
  439. *
  440. * @return string[]
  441. *
  442. */
  443. public function getFunctionsClass($class)
  444. {
  445. $isMariaDB = $this->_dbi->isMariaDB();
  446. $serverVersion = $this->_dbi->getVersion();
  447. switch ($class) {
  448. case 'CHAR':
  449. $ret = array(
  450. 'AES_DECRYPT',
  451. 'AES_ENCRYPT',
  452. 'BIN',
  453. 'CHAR',
  454. 'COMPRESS',
  455. 'CURRENT_USER',
  456. 'DATABASE',
  457. 'DAYNAME',
  458. 'DES_DECRYPT',
  459. 'DES_ENCRYPT',
  460. 'ENCRYPT',
  461. 'HEX',
  462. 'INET6_NTOA',
  463. 'INET_NTOA',
  464. 'LOAD_FILE',
  465. 'LOWER',
  466. 'LTRIM',
  467. 'MD5',
  468. 'MONTHNAME',
  469. 'OLD_PASSWORD',
  470. 'PASSWORD',
  471. 'QUOTE',
  472. 'REVERSE',
  473. 'RTRIM',
  474. 'SHA1',
  475. 'SOUNDEX',
  476. 'SPACE',
  477. 'TRIM',
  478. 'UNCOMPRESS',
  479. 'UNHEX',
  480. 'UPPER',
  481. 'USER',
  482. 'UUID',
  483. 'VERSION',
  484. );
  485. if (($isMariaDB && $serverVersion < 100012)
  486. || $serverVersion < 50603
  487. ) {
  488. $ret = array_diff($ret, array('INET6_NTOA'));
  489. }
  490. return $ret;
  491. case 'DATE':
  492. return array(
  493. 'CURRENT_DATE',
  494. 'CURRENT_TIME',
  495. 'DATE',
  496. 'FROM_DAYS',
  497. 'FROM_UNIXTIME',
  498. 'LAST_DAY',
  499. 'NOW',
  500. 'SEC_TO_TIME',
  501. 'SYSDATE',
  502. 'TIME',
  503. 'TIMESTAMP',
  504. 'UTC_DATE',
  505. 'UTC_TIME',
  506. 'UTC_TIMESTAMP',
  507. 'YEAR',
  508. );
  509. case 'NUMBER':
  510. $ret = array(
  511. 'ABS',
  512. 'ACOS',
  513. 'ASCII',
  514. 'ASIN',
  515. 'ATAN',
  516. 'BIT_LENGTH',
  517. 'BIT_COUNT',
  518. 'CEILING',
  519. 'CHAR_LENGTH',
  520. 'CONNECTION_ID',
  521. 'COS',
  522. 'COT',
  523. 'CRC32',
  524. 'DAYOFMONTH',
  525. 'DAYOFWEEK',
  526. 'DAYOFYEAR',
  527. 'DEGREES',
  528. 'EXP',
  529. 'FLOOR',
  530. 'HOUR',
  531. 'INET6_ATON',
  532. 'INET_ATON',
  533. 'LENGTH',
  534. 'LN',
  535. 'LOG',
  536. 'LOG2',
  537. 'LOG10',
  538. 'MICROSECOND',
  539. 'MINUTE',
  540. 'MONTH',
  541. 'OCT',
  542. 'ORD',
  543. 'PI',
  544. 'QUARTER',
  545. 'RADIANS',
  546. 'RAND',
  547. 'ROUND',
  548. 'SECOND',
  549. 'SIGN',
  550. 'SIN',
  551. 'SQRT',
  552. 'TAN',
  553. 'TO_DAYS',
  554. 'TO_SECONDS',
  555. 'TIME_TO_SEC',
  556. 'UNCOMPRESSED_LENGTH',
  557. 'UNIX_TIMESTAMP',
  558. 'UUID_SHORT',
  559. 'WEEK',
  560. 'WEEKDAY',
  561. 'WEEKOFYEAR',
  562. 'YEARWEEK',
  563. );
  564. if (($isMariaDB && $serverVersion < 100012)
  565. || $serverVersion < 50603
  566. ) {
  567. $ret = array_diff($ret, array('INET6_ATON'));
  568. }
  569. return $ret;
  570. case 'SPATIAL':
  571. if ($serverVersion >= 50600) {
  572. return array(
  573. 'ST_GeomFromText',
  574. 'ST_GeomFromWKB',
  575. 'ST_GeomCollFromText',
  576. 'ST_LineFromText',
  577. 'ST_MLineFromText',
  578. 'ST_PointFromText',
  579. 'ST_MPointFromText',
  580. 'ST_PolyFromText',
  581. 'ST_MPolyFromText',
  582. 'ST_GeomCollFromWKB',
  583. 'ST_LineFromWKB',
  584. 'ST_MLineFromWKB',
  585. 'ST_PointFromWKB',
  586. 'ST_MPointFromWKB',
  587. 'ST_PolyFromWKB',
  588. 'ST_MPolyFromWKB',
  589. );
  590. } else {
  591. return array(
  592. 'GeomFromText',
  593. 'GeomFromWKB',
  594. 'GeomCollFromText',
  595. 'LineFromText',
  596. 'MLineFromText',
  597. 'PointFromText',
  598. 'MPointFromText',
  599. 'PolyFromText',
  600. 'MPolyFromText',
  601. 'GeomCollFromWKB',
  602. 'LineFromWKB',
  603. 'MLineFromWKB',
  604. 'PointFromWKB',
  605. 'MPointFromWKB',
  606. 'PolyFromWKB',
  607. 'MPolyFromWKB',
  608. );
  609. }
  610. }
  611. return array();
  612. }
  613. /**
  614. * Returns array of functions available for a type.
  615. *
  616. * @param string $type The data type to get function list.
  617. *
  618. * @return string[]
  619. *
  620. */
  621. public function getFunctions($type)
  622. {
  623. $class = $this->getTypeClass($type);
  624. return $this->getFunctionsClass($class);
  625. }
  626. /**
  627. * Returns array of all functions available.
  628. *
  629. * @return string[]
  630. *
  631. */
  632. public function getAllFunctions()
  633. {
  634. $ret = array_merge(
  635. $this->getFunctionsClass('CHAR'),
  636. $this->getFunctionsClass('NUMBER'),
  637. $this->getFunctionsClass('DATE'),
  638. $this->getFunctionsClass('UUID')
  639. );
  640. sort($ret);
  641. return $ret;
  642. }
  643. /**
  644. * Returns array of all attributes available.
  645. *
  646. * @return string[]
  647. *
  648. */
  649. public function getAttributes()
  650. {
  651. return array(
  652. '',
  653. 'BINARY',
  654. 'UNSIGNED',
  655. 'UNSIGNED ZEROFILL',
  656. 'on update CURRENT_TIMESTAMP',
  657. );
  658. }
  659. /**
  660. * Returns array of all column types available.
  661. *
  662. * VARCHAR, TINYINT, TEXT and DATE are listed first, based on
  663. * estimated popularity.
  664. *
  665. * @return string[]
  666. *
  667. */
  668. public function getColumns()
  669. {
  670. $isMariaDB = $this->_dbi->isMariaDB();
  671. $serverVersion = $this->_dbi->getVersion();
  672. // most used types
  673. $ret = array(
  674. 'INT',
  675. 'VARCHAR',
  676. 'TEXT',
  677. 'DATE',
  678. );
  679. // numeric
  680. $ret[_pgettext('numeric types', 'Numeric')] = array(
  681. 'TINYINT',
  682. 'SMALLINT',
  683. 'MEDIUMINT',
  684. 'INT',
  685. 'BIGINT',
  686. '-',
  687. 'DECIMAL',
  688. 'FLOAT',
  689. 'DOUBLE',
  690. 'REAL',
  691. '-',
  692. 'BIT',
  693. 'BOOLEAN',
  694. 'SERIAL',
  695. );
  696. // Date/Time
  697. $ret[_pgettext('date and time types', 'Date and time')] = array(
  698. 'DATE',
  699. 'DATETIME',
  700. 'TIMESTAMP',
  701. 'TIME',
  702. 'YEAR',
  703. );
  704. // Text
  705. $ret[_pgettext('string types', 'String')] = array(
  706. 'CHAR',
  707. 'VARCHAR',
  708. '-',
  709. 'TINYTEXT',
  710. 'TEXT',
  711. 'MEDIUMTEXT',
  712. 'LONGTEXT',
  713. '-',
  714. 'BINARY',
  715. 'VARBINARY',
  716. '-',
  717. 'TINYBLOB',
  718. 'MEDIUMBLOB',
  719. 'BLOB',
  720. 'LONGBLOB',
  721. '-',
  722. 'ENUM',
  723. 'SET',
  724. );
  725. $ret[_pgettext('spatial types', 'Spatial')] = array(
  726. 'GEOMETRY',
  727. 'POINT',
  728. 'LINESTRING',
  729. 'POLYGON',
  730. 'MULTIPOINT',
  731. 'MULTILINESTRING',
  732. 'MULTIPOLYGON',
  733. 'GEOMETRYCOLLECTION',
  734. );
  735. if (($isMariaDB && $serverVersion > 100207)
  736. || (!$isMariaDB && $serverVersion >= 50708)) {
  737. $ret['JSON'] = array(
  738. 'JSON',
  739. );
  740. }
  741. return $ret;
  742. }
  743. /**
  744. * Returns an array of integer types
  745. *
  746. * @return string[] integer types
  747. */
  748. public function getIntegerTypes()
  749. {
  750. return array('tinyint', 'smallint', 'mediumint', 'int', 'bigint');
  751. }
  752. /**
  753. * Returns the min and max values of a given integer type
  754. *
  755. * @param string $type integer type
  756. * @param boolean $signed whether signed
  757. *
  758. * @return string[] min and max values
  759. */
  760. public function getIntegerRange($type, $signed = true)
  761. {
  762. static $min_max_data = array(
  763. 'unsigned' => array(
  764. 'tinyint' => array('0', '255'),
  765. 'smallint' => array('0', '65535'),
  766. 'mediumint' => array('0', '16777215'),
  767. 'int' => array('0', '4294967295'),
  768. 'bigint' => array('0', '18446744073709551615')
  769. ),
  770. 'signed' => array(
  771. 'tinyint' => array('-128', '127'),
  772. 'smallint' => array('-32768', '32767'),
  773. 'mediumint' => array('-8388608', '8388607'),
  774. 'int' => array('-2147483648', '2147483647'),
  775. 'bigint' => array('-9223372036854775808', '9223372036854775807')
  776. )
  777. );
  778. $relevantArray = $signed
  779. ? $min_max_data['signed']
  780. : $min_max_data['unsigned'];
  781. return isset($relevantArray[$type]) ? $relevantArray[$type] : array('', '');
  782. }
  783. }