lithium\data\source\database\adapter\Sqlite3::describe()
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
$fields
Any schema data pre-defined by the model.
-
array
$meta
Returns
arrayReturns 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 name
Filter
This method can be filtered.
Source
public function describe($entity, $fields = [], array $meta = []) {
$params = compact('entity', 'meta', 'fields');
return Filters::run($this, __FUNCTION__, $params, function($params) {
extract($params);
if ($fields) {
return $this->_instance('schema', compact('fields'));
}
$name = $this->_entityName($entity, ['quoted' => true]);
$columns = $this->read("PRAGMA table_info({$name})", ['return' => 'array']);
$fields = [];
foreach ($columns as $column) {
$schema = $this->_column($column['type']);
$default = $column['dflt_value'];
if (preg_match("/^'(.*)'/", $default, $match)) {
$default = $match[1];
} elseif ($schema['type'] === 'boolean') {
$default = !!$default;
} else {
$default = null;
}
$fields[$column['name']] = $schema + [
'null' => $column['notnull'] === '1',
'default' => $default
];
}
return $this->_instance('schema', compact('fields'));
});
}