[DB-SIG] pb with Datetime

Federico Di Gregorio fog@initd.org
13 Sep 2002 09:53:58 +0200

Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Il ven, 2002-09-13 alle 09:27, Denis Cartier Millon ha scritto:
> I try to get datetime from sybase with python and a connection ODBC:
> with the script "select * from Atable"
> and cursor.execute()
> (1458, <DateTime object for '2000-12-26 11:04:00.00' at 2148670>, 4,=20
> None, 1.0)
> why ?

because the sybase module is well-written and you get a usefull
mx.DateTime object. (i think :)

> when i want to insert this in a database Postgresql : i can't...
> is there a solution?

two solutions:

1/ use psycopg and bound variables (psycopg has an extension that allows
   you to directly insert a DateTime, e.g.)

       curs.execute("""INSERT INTO xxx VALUES (%d, %s)""",
                    (123, psycopg.TimestampFromMx(your_datetime_object)))

2/ convert the DateTime object yourself and insert the result into the db
   (see both DBAPI and mx documentation for that).

Federico Di Gregorio
Debian GNU/Linux Developer & Italian Press Contact        fog@debian.org
INIT.D Developer                                           fog@initd.org
   God is real. Unless declared integer. -- Anonymous FORTRAN programmer

Content-Type: application/pgp-signature; name=signature.asc

Version: GnuPG v1.0.7 (GNU/Linux)