{
$table = $this->conn->quote($table);
$query = sprintf($this->sql['listTableColumns'], $table);
$result = $this->conn->fetchAssoc($query);
$columns = array();
foreach ($result as $key => $val) {
$val = array_change_key_case($val, CASE_LOWER);
if ($val['type'] == 'character varying') {
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $val['complete_type']);
$val['length'] = $length;
} else if (strpos($val['complete_type'], 'character varying') !== false) {
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $val['complete_type']);
$val['length'] = $length;
}
$decl = $this->conn->dataDict->getPortableDeclaration($val);
$description = array(
'name' => $val['field'],
'ntype' => $val['type'],
'type' => $decl['type'][0],
'alltypes' => $decl['type'],
'length' => $decl['length'],
'fixed' => (bool) $decl['fixed'],
'unsigned' => (bool) $decl['unsigned'],
'notnull' => ($val['isnotnull'] == 'NO'),
'default' => $val['default'],
'primary' => ($val['pri'] == 't'),
);
if ($val['typtype'] == 'e'){
$description['default'] = isset($decl['default']) ? $decl['default'] : null;
$t_result = $this->conn->fetchAssoc(sprintf('select enum_range(null::%s) as range ', $decl['enum_name']));
if (isset($t_result[0])){
$range = $t_result[0]['range'];
$range = str_replace('{','',$range);
$range = str_replace('}','',$range);
$range = explode(',',$range);
$description['values'] = $range;
}
}
$matches = array();
if (preg_match("/^nextval\('(.*)'(::.*)?\)$/", $description['default'], $matches)) {
$description['sequence'] = $this->conn->formatter->fixSequenceName($matches[1]);
$description['default'] = null;
} else if (preg_match("/^'(.*)'::character varying$/", $description['default'], $matches)) {
$description['default'] = $matches[1];
} else if (preg_match("/^(.*)::character varying$/", $description['default'], $matches)) {
$description['default'] = $matches[1];
} else if ($description['type'] == 'boolean') {
if ($description['default'] === 'true') {
$description['default'] = true;
} else if ($description['default'] === 'false') {
$description['default'] = false;
}
}
$columns[$val['field']] = $description;
}
return $columns;
}