Extends
lithium\data\source\Database
Gets the column schema for a given Sqlite3 table.
A column type may not always be available, i.e. when during creation of
the column no type was declared. Those columns are internally treated
by SQLite3 as having a `NONE` affinity. The final schema will contain no
information about type and length of such columns (both values will be
`null`).
Parameters
- mixed $entity Specifies the table name for which the schema should be returned, or the class name of the model object requesting the schema, in which case the model class will be queried for the correct table name.
- array $meta
Returns
array Returns an associative array describing the given table's schema, where the array keys are the available fields, and the values are arrays describing each field, containing the following keys: - `'type'`: The field type nameSource
public function describe($entity, array $meta = array()) {
$params = compact('entity', 'meta');
$regex = $this->_regex;
return $this->_filter(__METHOD__, $params, function($self, $params) use ($regex) {
extract($params);
$name = $self->invokeMethod('_entityName', array($entity, array('quoted' => true)));
$columns = $self->read("PRAGMA table_info({$name})", array('return' => 'array'));
$fields = array();
foreach ($columns as $column) {
preg_match("/{$regex['column']}/", $column['type'], $matches);
$fields[$column['name']] = array(
'type' => isset($matches['type']) ? $matches['type'] : null,
'length' => isset($matches['length']) ? $matches['length'] : null,
'null' => $column['notnull'] == 1,
'default' => $column['dflt_value']
);
}
return $fields;
});
}