On Sat, Jan 14, 2012 at 08:52:58AM +1300, Michael Koziarski wrote:
> 
> 
> On Saturday, 14 January 2012 at 8:37 AM, Ken Collins wrote:
> 
> > 
> > I remember a long time ago I had a patch for average that would trust what 
> > the DB returned, in my case integers.
> > 
> > https://github.com/rails/rails/commit/95d5d9b6c48c08f1fba0c77ecbc97b62b2603824
> > 
> > It would be nice if calculations could always rely on the raw_connection to 
> > return data types converted to ruby primitives correctly. Not sure if that 
> > '0' should be a 0 or not, maybe be helpful to see what fails if changed?
> > 
> >  - Ken
> That '0' likely just predates the raw_connection returning rich data types.  
> I believe sql server and oracle have done so for ages, but it's relatively 
> new for the other adapters.  
> 
> In preparation for 4.0 perhaps we could do an audit of the  various database 
> drivers and make sure they return the correct types.  After that we could 
> remove the custom typecasting we do?

It depends on the level of API people want to use.  For example, PG
always returns strings.  That means we need to know the types for which
we're querying.  Say someone does this against pg:

  connection.execute 'select 1.2 + 20'

we can't know to cast that to a float.  Even doing regexp tests will be
wrong since someone may have tried to select a string.

We can do automatic casting, but it's going to break down at some point
depending on the level of abstraction and the database used.

-- 
Aaron Patterson
http://tenderlovemaking.com/

Attachment: pgpuQjkgxtBJd.pgp
Description: PGP signature

Reply via email to