lithium\data\source\database\adapter\PostgreSql::_column()
Converts database-layer column types to basic types.
Parameters
-
string
$real
Real database-layer column type (i.e.
"varchar(255)"
)
Returns
arrayColumn type (i.e. "string") plus 'length' when appropriate.
Source
protected function _column($real) {
if (is_array($real)) {
return $real['type'] . (isset($real['length']) ? "({$real['length']})" : '');
}
if (!preg_match('/(?P<type>\w+)(?:\((?P<length>[\d,]+)\))?/', $real, $column)) {
return $real;
}
$column = array_intersect_key($column, ['type' => null, 'length' => null]);
if (isset($column['length']) && $column['length']) {
$length = explode(',', $column['length']) + [null, null];
$column['length'] = $length[0] ? (integer) $length[0] : null;
$length[1] ? $column['precision'] = (integer) $length[1] : null;
}
switch (true) {
case in_array($column['type'], ['date', 'time', 'datetime']):
return $column;
case ($column['type'] === 'timestamp'):
$column['type'] = 'datetime';
break;
case ($column['type'] === 'tinyint' && $column['length'] == '1'):
case ($column['type'] === 'boolean'):
return ['type' => 'boolean'];
break;
case (strpos($column['type'], 'int') !== false):
$column['type'] = 'integer';
break;
case (strpos($column['type'], 'char') !== false || $column['type'] === 'tinytext'):
$column['type'] = 'string';
break;
case (strpos($column['type'], 'text') !== false):
$column['type'] = 'text';
break;
case (strpos($column['type'], 'blob') !== false || $column['type'] === 'binary'):
$column['type'] = 'binary';
break;
case preg_match('/float|double|decimal/', $column['type']):
$column['type'] = 'float';
break;
default:
$column['type'] = 'text';
break;
}
return $column;
}