diff --git a/ChangeLog b/ChangeLog index b1d8e560..37d8aa90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ 2005-10-19 Federico Di Gregorio * Releasing 2.0 beta 5. + + * psycopg/adapter_mxdatetime.c: reverted to old strftime method to format + mx.DateTime objects; the new method didn't worked in some corner-cases. + This makes impossible to have more than 2 decimal places for seconds but + at least we get the time right every time. 2005-10-18 Federico Di Gregorio diff --git a/NEWS b/NEWS index e22c989e..21cd8e8b 100644 --- a/NEWS +++ b/NEWS @@ -1,8 +1,6 @@ What's new in psycopg 2.0 beta 5 -------------------------------- -* First (and probably last) release candidate. - * Fixed all known bugs. * The initial isolation level is now read from the server and diff --git a/ZPsycopgDA/DA.py b/ZPsycopgDA/DA.py index 43375d58..a25a21ca 100644 --- a/ZPsycopgDA/DA.py +++ b/ZPsycopgDA/DA.py @@ -18,7 +18,7 @@ # See the LICENSE file for details. -ALLOWED_PSYCOPG_VERSIONS = ('2.0b2', '2.0b3') +ALLOWED_PSYCOPG_VERSIONS = ('2.0b4', '2.0b5') import sys import time diff --git a/examples/dt.py b/examples/dt.py index 78d53556..9933164f 100644 --- a/examples/dt.py +++ b/examples/dt.py @@ -18,7 +18,8 @@ DSN = 'dbname=test' ## don't modify anything below tis line (except for experimenting) -import sys, psycopg2 +import sys +import psycopg2 import mx.DateTime import datetime @@ -30,14 +31,13 @@ conn = psycopg2.connect(DSN) curs = conn.cursor() try: - curs.execute("""CREATE TABLE test_dt (k int4, d date, t time, dt timestamp, - z interval)""") + curs.execute("""CREATE TABLE test_dt ( + k int4, d date, t time, dt timestamp, z interval)""") except: conn.rollback() curs.execute("DROP TABLE test_dt") - curs.execute("""CREATE TABLE test_dt (k int4, - d date, t time, dt timestamp, - z interval)""") + curs.execute("""CREATE TABLE test_dt ( + k int4, d date, t time, dt timestamp, z interval)""") conn.commit() # build and insert some data using mx.DateTime @@ -48,6 +48,10 @@ mx1 = ( mx.DateTime.Timestamp(2004, 10, 19, 0, 11, 17.5), mx.DateTime.DateTimeDelta(13, 15, 17, 59.9)) +from psycopg2.extensions import adapt +import psycopg2.extras +print adapt(mx1) + print "Inserting mx.DateTime values..." curs.execute("INSERT INTO test_dt VALUES (%s, %s, %s, %s, %s)", mx1) diff --git a/psycopg/adapter_mxdatetime.c b/psycopg/adapter_mxdatetime.c index f6547f46..dcc24d46 100644 --- a/psycopg/adapter_mxdatetime.c +++ b/psycopg/adapter_mxdatetime.c @@ -45,30 +45,26 @@ mxdatetime_str(mxdatetimeObject *self) PyObject *res = NULL; char *buffer = NULL; - mxDateTimeObject *obj = (mxDateTimeObject*)self->wrapped; + /* mxDateTimeObject *obj = (mxDateTimeObject*)self->wrapped; */ switch (self->type) { - case 0: - asprintf(&buffer, "'%02d:%02d:%.6f'", - (int)obj->hour, (int)obj->minute, (float)obj->second); - if (buffer) res = PyString_FromString(buffer); + case PSYCO_MXDATETIME_TIME: + res = PyObject_CallMethod(self->wrapped, "strftime", "s", + "'%H:%M:%S'"); break; - case 1: - asprintf(&buffer, "'%ld-%02d-%02d'", - obj->year, (int)obj->month, (int)obj->day); - if (buffer) res = PyString_FromString(buffer); + case PSYCO_MXDATETIME_DATE: + res = PyObject_CallMethod(self->wrapped, "strftime", "s", + "'%Y-%m-%d'"); break; - case 2: - asprintf(&buffer, "'%ld-%02d-%02d %02d:%02d:%.6f'", - obj->year, (int)obj->month, (int)obj->day, - (int)obj->hour, (int)obj->minute, (float)obj->second); - if (buffer) res = PyString_FromString(buffer); + case PSYCO_MXDATETIME_TIMESTAMP: + res = PyObject_CallMethod(self->wrapped, "strftime", "s", + "'%Y-%m-%dT%H:%M:%S'"); break; - case 3: + case PSYCO_MXDATETIME_INTERVAL: res = PyObject_CallMethod(self->wrapped, "strftime", "s", "'%d:%H:%M:%S'"); break;