--3MwIy2ne0vdjdPXF
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Oct 17, 2002 at 04:54:17PM +0900, Gavin Sinclair wrote:
> Rubyists,
>=20
> Given a table in a database defined by the following:
>=20
>   create table test ( test DATE );
>=20
> how can I insert the current time using Ruby/DBI?  Given a DBI::DatabaseH=
andler
> "dbh" I'd expect that you can do the following:
>=20
>   dbh.do "insert into test values (#{Time.now})"
>=20
> That is, I expect the DBI library to convert a Time object into the datab=
ase's
> DATE data type.  It appears that this is not the case.  The above code ca=
uses
> an error.
>=20
> It doesn't convert the String '2002-10-04 18:30:00' into a DATE either.
>=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 d=
ata
> handling?

I use DBI with Mysql and prepared statements:

stm =3D dbh.prepare("intert into test values (?)")
stm.execute(Time.now)

-billy.

--=20
Meisterbohne       S=F6flinger Stra=DFe 100          Tel: +49-731-399 499-0
   eL=F6sungen       89077 Ulm                     Fax: +49-731-399 499-9

--3MwIy2ne0vdjdPXF
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQE9rq7yfBriNoqItSYRAgbiAJ9T+ZuGK8bwTi39YF3DP24hSXcfVwCfYPcw
ljccc+UKRSfEep/5r9mZsRE=
=t0BD
-----END PGP SIGNATURE-----

--3MwIy2ne0vdjdPXF--

On Thu, Oct 17, 2002 at 04:54:17PM +0900, Gavin Sinclair wrote:
> Rubyists,
>=20
> Given a table in a database defined by the following:
>=20
>   create table test ( test DATE );
>=20
> how can I insert the current time using Ruby/DBI?  Given a DBI::DatabaseH=
andler
> "dbh" I'd expect that you can do the following:
>=20
>   dbh.do "insert into test values (#{Time.now})"
>=20
> That is, I expect the DBI library to convert a Time object into the datab=
ase's
> DATE data type.  It appears that this is not the case.  The above code ca=
uses
> an error.
>=20
> It doesn't convert the String '2002-10-04 18:30:00' into a DATE either.
>=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 d=
ata
> handling?

I use DBI with Mysql and prepared statements:

stm =3D dbh.prepare("intert into test values (?)")
stm.execute(Time.now)

-billy.

--=20
Meisterbohne       S=F6flinger Stra=DFe 100          Tel: +49-731-399 499-0
   eL=F6sungen       89077 Ulm                     Fax: +49-731-399 499-9
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQE9rq7yfBriNoqItSYRAgbiAJ9T+ZuGK8bwTi39YF3DP24hSXcfVwCfYPcw
ljccc+UKRSfEep/5r9mZsRE=
=t0BD
-----END PGP SIGNATURE-----