Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / Types.php
blob49416add653985f2ac76f2375800fb9f1756f4c0
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * SQL data types definition
6 * @package PhpMyAdmin
7 */
8 namespace PMA\libraries;
10 /**
11 * Generic class holding type definitions.
13 * @package PhpMyAdmin
15 class Types
17 /**
18 * Returns list of unary operators.
20 * @return string[]
22 public function getUnaryOperators()
24 return array(
25 'IS NULL',
26 'IS NOT NULL',
27 "= ''",
28 "!= ''",
32 /**
33 * Check whether operator is unary.
35 * @param string $op operator name
37 * @return boolean
39 public function isUnaryOperator($op)
41 return in_array($op, $this->getUnaryOperators());
44 /**
45 * Returns list of operators checking for NULL.
47 * @return string[]
49 public function getNullOperators()
51 return array(
52 'IS NULL',
53 'IS NOT NULL',
57 /**
58 * ENUM search operators
60 * @return string[]
62 public function getEnumOperators()
64 return array(
65 '=',
66 '!=',
70 /**
71 * TEXT search operators
73 * @return string[]
75 public function getTextOperators()
77 return array(
78 'LIKE',
79 'LIKE %...%',
80 'NOT LIKE',
81 '=',
82 '!=',
83 'REGEXP',
84 'REGEXP ^...$',
85 'NOT REGEXP',
86 "= ''",
87 "!= ''",
88 'IN (...)',
89 'NOT IN (...)',
90 'BETWEEN',
91 'NOT BETWEEN',
95 /**
96 * Number search operators
98 * @return string[]
100 public function getNumberOperators()
102 return array(
103 '=',
104 '>',
105 '>=',
106 '<',
107 '<=',
108 '!=',
109 'LIKE',
110 'LIKE %...%',
111 'NOT LIKE',
112 'IN (...)',
113 'NOT IN (...)',
114 'BETWEEN',
115 'NOT BETWEEN',
120 * Returns operators for given type
122 * @param string $type Type of field
123 * @param boolean $null Whether field can be NULL
125 * @return string[]
127 public function getTypeOperators($type, $null)
129 $ret = array();
130 $class = $this->getTypeClass($type);
132 if (strncasecmp($type, 'enum', 4) == 0) {
133 $ret = array_merge($ret, $this->getEnumOperators());
134 } elseif ($class == 'CHAR') {
135 $ret = array_merge($ret, $this->getTextOperators());
136 } else {
137 $ret = array_merge($ret, $this->getNumberOperators());
140 if ($null) {
141 $ret = array_merge($ret, $this->getNullOperators());
144 return $ret;
148 * Returns operators for given type as html options
150 * @param string $type Type of field
151 * @param boolean $null Whether field can be NULL
152 * @param string $selectedOperator Option to be selected
154 * @return string Generated Html
156 public function getTypeOperatorsHtml($type, $null, $selectedOperator = null)
158 $html = '';
160 foreach ($this->getTypeOperators($type, $null) as $fc) {
161 if (isset($selectedOperator) && $selectedOperator == $fc) {
162 $selected = ' selected="selected"';
163 } else {
164 $selected = '';
166 $html .= '<option value="' . htmlspecialchars($fc) . '"'
167 . $selected . '>'
168 . htmlspecialchars($fc) . '</option>';
171 return $html;
175 * Returns the data type description.
177 * @param string $type The data type to get a description.
179 * @return string
182 public function getTypeDescription($type)
184 return '';
188 * Returns class of a type, used for functions available for type
189 * or default values.
191 * @param string $type The data type to get a class.
193 * @return string
196 public function getTypeClass($type)
198 return '';
202 * Returns array of functions available for a class.
204 * @param string $class The class to get function list.
206 * @return string[]
209 public function getFunctionsClass($class)
211 return array();
215 * Returns array of functions available for a type.
217 * @param string $type The data type to get function list.
219 * @return string[]
222 public function getFunctions($type)
224 $class = $this->getTypeClass($type);
225 return $this->getFunctionsClass($class);
229 * Returns array of all functions available.
231 * @return string[]
234 public function getAllFunctions()
236 $ret = array_merge(
237 $this->getFunctionsClass('CHAR'),
238 $this->getFunctionsClass('NUMBER'),
239 $this->getFunctionsClass('DATE'),
240 $this->getFunctionsClass('UUID')
242 sort($ret);
243 return $ret;
247 * Returns array of all attributes available.
249 * @return string[]
252 public function getAttributes()
254 return array();
258 * Returns array of all column types available.
260 * @return string[]
263 public function getColumns()
265 // most used types
266 return array(
267 'INT',
268 'VARCHAR',
269 'TEXT',
270 'DATE',
275 * Returns an array of integer types
277 * @return string[] integer types
279 public function getIntegerTypes()
281 return array();
285 * Returns the min and max values of a given integer type
287 * @param string $type integer type
288 * @param boolean $signed whether signed
290 * @return string[] min and max values
292 public function getIntegerRange($type, $signed = true)
294 return array('', '');