protected function _process_fields($create_table = FALSE)
{
$fields = array();
foreach ($this->fields as $key => $attributes) {
if (is_int($key) && !is_array($attributes)) {
$fields[] = array('_literal' => $attributes);
continue;
}
$attributes = array_change_key_case($attributes, CASE_UPPER);
if ($create_table === TRUE && empty($attributes['TYPE'])) {
continue;
}
isset($attributes['TYPE']) && $this->_attr_type($attributes);
$field = array('name' => $key, 'new_name' => isset($attributes['NAME']) ? $attributes['NAME'] : NULL, 'type' => isset($attributes['TYPE']) ? $attributes['TYPE'] : NULL, 'length' => '', 'unsigned' => '', 'null' => '', 'unique' => '', 'default' => '', 'auto_increment' => '', '_literal' => FALSE);
isset($attributes['TYPE']) && $this->_attr_unsigned($attributes, $field);
if ($create_table === FALSE) {
if (isset($attributes['AFTER'])) {
$field['after'] = $attributes['AFTER'];
} elseif (isset($attributes['FIRST'])) {
$field['first'] = (bool) $attributes['FIRST'];
}
}
$this->_attr_default($attributes, $field);
if (isset($attributes['NULL'])) {
if ($attributes['NULL'] === TRUE) {
$field['null'] = empty($this->_null) ? '' : ' ' . $this->_null;
} else {
$field['null'] = ' NOT NULL';
}
} elseif ($create_table === TRUE) {
$field['null'] = ' NOT NULL';
}
$this->_attr_auto_increment($attributes, $field);
$this->_attr_unique($attributes, $field);
if (isset($attributes['COMMENT'])) {
$field['comment'] = $this->db->escape($attributes['COMMENT']);
}
if (isset($attributes['TYPE']) && !empty($attributes['CONSTRAINT'])) {
switch (strtoupper($attributes['TYPE'])) {
case 'ENUM':
case 'SET':
$attributes['CONSTRAINT'] = $this->db->escape($attributes['CONSTRAINT']);
default:
$field['length'] = is_array($attributes['CONSTRAINT']) ? '(' . implode(',', $attributes['CONSTRAINT']) . ')' : '(' . $attributes['CONSTRAINT'] . ')';
break;
}
}
$fields[] = $field;
}
return $fields;
}