laravel/laravel — pull request #993 by causingeffect (2012-07-23 13:02:01+00:00)
Title: Column Information

Signed-off-by: Aaron Waldon

This functionality was inspired by [this pull](https://github.com/laravel/laravel/pull/848) by @AlexCogn. I needed this functionality in a project, and wrote and tested the code to ensure it works for all drivers.

Sample usage:
```php
columns();
foreach($columns as $column)
{
echo "{$column->name}: {$column->type}
";
}
?>
```

By default only the 'name' and 'type' fields are returned. These fields will **always** be returned for all drivers. If the optional `$all_info` parameter is set to `true` (ex: `DB::table('sessions')->columns(true)`), all the available information (which differs from driver to driver) for the columns will be returned in addition to the 'name' and 'type' fields.

Caveats:
* All information is always returned for the SQLite driver (5 fields total), but that should not be a problem.
* The 'type' values may be different from driver to driver. It may be worth the effort to standardize these at some point. For example, for a varchar field:
* SQLite returns `VARCHAR`
* MySQL returns something like `varchar(40)`, depending on the length
* PostgreSQL returns `character varying`
* SQL Server returns `nvarchar`