This project is archived and is in readonly mode.
rails3 : ActiveRecord sqlite3 : lost column type when using views
-
Duncan Mac-Vicar
The problem seems to come from the fact that the adapter uses PRAGMA table_info(table_name) to get the type information, and that does not return the types for views:
sqlite> pragma table_info('people'); 0|id|INTEGER|1||1 1|name|varchar(255)|0||0 2|born_at|datetime|0||0 sqlite> pragma table_info('clowns'); 0|name|varchar(255)|0||0 1|born_at|datetime|0||0 2|twenty_after_born_at||0||0However, as I said, it works in MySQL.
-
Duncan Mac-Vicar
Also, quoting this mail in sqlite-users:
RoR should be using the sqlite3_column_type() API to determine the type of the values returned from a query. Other APIs like sqlite3_column_decltype() and pragma table_info are returning other information, not the type of the result value.
-
Duncan Mac-Vicar
Also, quoting this mail in sqlite-users:
RoR should be using the sqlite3_column_type() API to determine the type of the values returned from a query. Other APIs like sqlite3_column_decltype() and pragma table_info are returning other information, not the type of the result value.
-
Dan Pickett
- Tag changed from sqlite3 activerecord to activerecord, bugmash, sqlite3
-
Diego Algorta
This is not a rails bug. It's a bug in sqlite3-ruby gem itself. I glanced at their code in current master and they're still using PRAGMA so I reported the bug in http://rubyforge.org/tracker/index.php?func=detail&aid=28203&am...
-
Aaron Patterson
- Assigned user changed from Jeremy Kemper to Aaron Patterson
-
Aaron Patterson
- State changed from new to wontfix
This can't be fixed. The sqlite3_column_type() function can't tell the difference between a column declared as a datetime vs a string as datetimes are actually stored as strings in sqlite. The pragma call is the only way to get the declared column types and it unfortunately doesn't work with views.
See the sqlite3 C api for sqlite3_column_type():
http://www.sqlite.org/capi3ref.html#sqlite3_column_blob
Also see my comments on the rubyforge ticket.