From: Philipp Meier Date: 2002-10-18T01:52:44+09:00 Subject: Re: Date handling with DBI --oyUTqETQ0mS9luUI Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Oct 17, 2002 at 11:53:19PM +0900, Gavin Sinclair wrote: > From: "Philipp Meier" >=20 >=20 > > For now, I am resorting to storing my date information as strings in the > > database. Does anyone know about the logistics of database-independent= date > > handling? >=20 > I use DBI with Mysql and prepared statements: >=20 > stm =3D dbh.prepare("intert into test values (?)") > stm.execute(Time.now) >=20 > -billy. >=20 > Hmmm.... I can't test right now, but I'll give it a try. Just so this po= st is > not a totally information-free zone, let me pass on a curious result. >=20 > SQL> create table test_date (test DATE); > SQL> insert into test_date values ('01-OCT-2002'); >=20 > % ruby < require "dbi" > DBI.connect(...) do |dbi| > date =3D dbi.select_one("select * from test_date").to_h["TEST"] > puts date > puts date.class > end > EOF >=20 > 01-OCT-02 > String >=20 > =3D=3D=3D >=20 > So, DATE information in the database in returned through either DBI or the > Oracle driver as a String. I'll try the method you posted shortly, but I= 'm not > confident. (It's probably the Oracle driver.) Yes, indeed. DBI _returns_ every column as String. You can use dbh.columns(table)[0].sql_type to determine the sql type an convert it yourself. -billy. --=20 Meisterbohne S=F6flinger Stra=DFe 100 Tel: +49-731-399 499-0 eL=F6sungen 89077 Ulm Fax: +49-731-399 499-9 --oyUTqETQ0mS9luUI Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.0 (GNU/Linux) iD8DBQE9rurYfBriNoqItSYRAiVhAJ0VZNYUbmkrHQOhOKx8o17DqBGnMgCfT0lG QKgbGhYSLH2gkDFWuiz46d4= =/3qg -----END PGP SIGNATURE----- --oyUTqETQ0mS9luUI--