_before_type_cast


#1

Hi,

When ActiveRecord gets any field from the database does it receive the
field
as a string regardless of the field’s type in the db?

And this is why ActiveRecord must subsequently cast the data into a Ruby
type?

If the answers are yes, then is it correct to say that the only way
databases export data for any request is through strings? (If so, wow,
primative but understandable)

Thanks,
Peter


#2

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 13, 2005, at 10:48 PM, Peter M. wrote:

When ActiveRecord gets any field from the database does it receive
the field as a string regardless of the field’s type in the db?

And this is why ActiveRecord must subsequently cast the data into a
Ruby type?

If the answers are yes, then is it correct to say that the only way
databases export data for any request is through strings? (If so,
wow, primative but understandable)

The other way around: all data from the web (query and form
parameters, cookies, headers, etc) are strings. So
foo_before_type_cast gives you the “source” string whereas foo is
type-cast according to the database column type.

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDeEOIAQHALep9HFYRAqbvAKC3ERFDbWljsnMbEys0BcFIXjfauwCfYUzj
jAZ8PessmkTbMNEtE680oiU=
=00+R
-----END PGP SIGNATURE-----


#3

Now I’m feeling dense. How does the database send the info to rails when
rails makes a request? INT is sent differently then TEXT or DATE?

Peter


#4

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 14, 2005, at 4:12 AM, Peter M. wrote:

Now I’m feeling dense. How does the database send the info to rails
when rails makes a request? INT is sent differently then TEXT or DATE?

All the database drivers do it differently. Most have a binary
protocol that efficiently encodes each data type. The driver speaks
that protocol and spits out numbers, strings, etc. This isn’t
enough, though, since we want the all the drivers to operate
uniformly, so the connection adapters translate the driver’s results
into a standard set of Ruby classes according to the database column
types.

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDeNgAAQHALep9HFYRAsl/AKCYAwr1coU4jIbeNG/6AoudIQYeywCgojDV
V74JufdvmK3agYjSqaE02Bw=
=YgDV
-----END PGP SIGNATURE-----