lithium\data\source\database\adapter\Sqlite3::describe PHP Method

describe() public method

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).
public describe ( mixed $entity, array $fields = [], array $meta = [] ) : array
$entity mixed 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.
$fields array Any schema data pre-defined by the model.
$meta array
return 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 name
    public function describe($entity, $fields = array(), array $meta = array())
    {
        $params = compact('entity', 'meta', 'fields');
        $regex = $this->_regex;
        return $this->_filter(__METHOD__, $params, function ($self, $params) use($regex) {
            extract($params);
            if ($fields) {
                return $self->invokeMethod('_instance', array('schema', compact('fields')));
            }
            $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) {
                $schema = $self->invokeMethod('_column', array($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 + array('null' => $column['notnull'] === '1', 'default' => $default);
            }
            return $self->invokeMethod('_instance', array('schema', compact('fields')));
        });
    }