1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* SQL data types definition
*
* @package PhpMyAdmin
*/
namespace PMA\libraries;
/**
* Generic class holding type definitions.
*
* @package PhpMyAdmin
*/
class Types
{
/**
* Returns list of unary operators.
*
* @return string[]
*/
public function getUnaryOperators()
{
return array(
'IS NULL',
'IS NOT NULL',
"= ''",
"!= ''",
);
}
/**
* Check whether operator is unary.
*
* @param string $op operator name
*
* @return boolean
*/
public function isUnaryOperator($op)
{
return in_array($op, $this->getUnaryOperators());
}
/**
* Returns list of operators checking for NULL.
*
* @return string[]
*/
public function getNullOperators()
{
return array(
'IS NULL',
'IS NOT NULL',
);
}
/**
* ENUM search operators
*
* @return string[]
*/
public function getEnumOperators()
{
return array(
'=',
'!=',
);
}
/**
* TEXT search operators
*
* @return string[]
*/
public function getTextOperators()
{
return array(
'LIKE',
'LIKE %...%',
'NOT LIKE',
'=',
'!=',
'REGEXP',
'REGEXP ^...$',
'NOT REGEXP',
"= ''",
"!= ''",
'IN (...)',
'NOT IN (...)',
'BETWEEN',
'NOT BETWEEN',
);
}
/**
* Number search operators
*
* @return string[]
*/
public function getNumberOperators()
{
return array(
'=',
'>',
'>=',
'<',
'<=',
'!=',
'LIKE',
'LIKE %...%',
'NOT LIKE',
'IN (...)',
'NOT IN (...)',
'BETWEEN',
'NOT BETWEEN',
);
}
/**
* Returns operators for given type
*
* @param string $type Type of field
* @param boolean $null Whether field can be NULL
*
* @return string[]
*/
public function getTypeOperators($type, $null)
{
$ret = array();
$class = $this->getTypeClass($type);
if (strncasecmp($type, 'enum', 4) == 0) {
$ret = array_merge($ret, $this->getEnumOperators());
} elseif ($class == 'CHAR') {
$ret = array_merge($ret, $this->getTextOperators());
} else {
$ret = array_merge($ret, $this->getNumberOperators());
}
if ($null) {
$ret = array_merge($ret, $this->getNullOperators());
}
return $ret;
}
/**
* Returns operators for given type as html options
*
* @param string $type Type of field
* @param boolean $null Whether field can be NULL
* @param string $selectedOperator Option to be selected
*
* @return string Generated Html
*/
public function getTypeOperatorsHtml($type, $null, $selectedOperator = null)
{
$html = '';
foreach ($this->getTypeOperators($type, $null) as $fc) {
if (isset($selectedOperator) && $selectedOperator == $fc) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
$html .= '<option value="' . htmlspecialchars($fc) . '"'
. $selected . '>'
. htmlspecialchars($fc) . '</option>';
}
return $html;
}
/**
* Returns the data type description.
*
* @param string $type The data type to get a description.
*
* @return string
*
*/
public function getTypeDescription($type)
{
return '';
}
/**
* Returns class of a type, used for functions available for type
* or default values.
*
* @param string $type The data type to get a class.
*
* @return string
*
*/
public function getTypeClass($type)
{
return '';
}
/**
* Returns array of functions available for a class.
*
* @param string $class The class to get function list.
*
* @return string[]
*
*/
public function getFunctionsClass($class)
{
return array();
}
/**
* Returns array of functions available for a type.
*
* @param string $type The data type to get function list.
*
* @return string[]
*
*/
public function getFunctions($type)
{
$class = $this->getTypeClass($type);
return $this->getFunctionsClass($class);
}
/**
* Returns array of all functions available.
*
* @return string[]
*
*/
public function getAllFunctions()
{
$ret = array_merge(
$this->getFunctionsClass('CHAR'),
$this->getFunctionsClass('NUMBER'),
$this->getFunctionsClass('DATE'),
$this->getFunctionsClass('UUID')
);
sort($ret);
return $ret;
}
/**
* Returns array of all attributes available.
*
* @return string[]
*
*/
public function getAttributes()
{
return array();
}
/**
* Returns array of all column types available.
*
* @return string[]
*
*/
public function getColumns()
{
// most used types
return array(
'INT',
'VARCHAR',
'TEXT',
'DATE',
);
}
/**
* Returns an array of integer types
*
* @return string[] integer types
*/
public function getIntegerTypes()
{
return array();
}
/**
* Returns the min and max values of a given integer type
*
* @param string $type integer type
* @param boolean $signed whether signed
*
* @return string[] min and max values
*/
public function getIntegerRange($type, $signed = true)
{
return array('', '');
}
}
|