summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2005-10-17 16:04:43 +0000
committerFederico Di Gregorio <fog@initd.org>2005-10-17 16:04:43 +0000
commita237209a5e20e1cb557acde1e797107597b2b85f (patch)
tree36d5de4a1516c16b610163c24fb545ce7e14af08
parent206aa79225745815ad8cb46b059859baadd2cf5a (diff)
downloadpsycopg2-a237209a5e20e1cb557acde1e797107597b2b85f.tar.gz
Default tzinfo_factory for cursors.
-rw-r--r--ChangeLog3
-rw-r--r--examples/tz.py8
-rw-r--r--psycopg/adapter_datetime.c4
-rw-r--r--psycopg/cursor_type.c9
-rw-r--r--psycopg/psycopgmodule.c9
5 files changed, 25 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index cd6719d..edd53b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2005-10-18 Federico Di Gregorio <fog@initd.org>
+ * psycopg/cursor_type.c: cursors now have a FixedOffsetTimezone
+ tzinfo_factory by default.
+
* psycopg/adapter_datetime.c: added tzinfo argument to psycopg2.Time and
psycopg2.Timestamp. Also now TimestampFromTicks sets the tzinfo object
to psycopg2.tz.LOCAL.
diff --git a/examples/tz.py b/examples/tz.py
index 0ae9fa3..8fe40af 100644
--- a/examples/tz.py
+++ b/examples/tz.py
@@ -51,7 +51,12 @@ curs.execute("INSERT INTO test_tz VALUES (%s)", (d,))
print "Inserted timestamp with timezone:", d
print "Time zone:", d.tzinfo.tzname(d), "offset:", d.tzinfo.utcoffset(d)
-curs.tzinfo_factory = FixedOffsetTimezone
+curs.execute("SELECT * FROM test_tz")
+d = curs.fetchone()[0]
+curs.execute("INSERT INTO test_tz VALUES (%s)", (d,))
+print "Inserted SELECTed timestamp:", d
+print "Time zone:", d.tzinfo.tzname(d), "offset:", d.tzinfo.utcoffset(d)
+
curs.execute("SELECT * FROM test_tz")
for d in curs:
u = d[0].utcoffset() or ZERO
@@ -59,5 +64,6 @@ for d in curs:
print "Local time:", d[0]
print "Time zone:", d[0].tzinfo.tzname(d[0]), d[0].tzinfo.utcoffset(d[0])
+
curs.execute("DROP TABLE test_tz")
conn.commit()
diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c
index 024b712..8443df9 100644
--- a/psycopg/adapter_datetime.c
+++ b/psycopg/adapter_datetime.c
@@ -44,7 +44,7 @@ extern PyObject *pyDateTimeTypeP;
extern PyObject *pyDeltaTypeP;
extern PyObject *pyPsycopgTzModule;
-extern PyObject *pyPsycopgTzLocalTimezone;
+extern PyObject *pyPsycopgTzLOCAL;
/* datetime_str, datetime_getquoted - return result of quoting */
@@ -401,7 +401,7 @@ psyco_TimestampFromTicks(PyObject *self, PyObject *args)
args = Py_BuildValue("iiiiidO",
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, (double)tm.tm_sec,
- pyPsycopgTzLocalTimezone);
+ pyPsycopgTzLOCAL);
if (args) {
res = psyco_Timestamp(self, args);
Py_DECREF(args);
diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c
index dcabf92..9de563d 100644
--- a/psycopg/cursor_type.c
+++ b/psycopg/cursor_type.c
@@ -35,6 +35,9 @@
#include "psycopg/microprotocols_proto.h"
#include "pgversion.h"
+extern PyObject *pyPsycopgTzFixedOffsetTimezone;
+
+
/** DBAPI methods **/
/* close method - close the cursor */
@@ -1266,8 +1269,10 @@ cursor_setup(cursorObject *self, connectionObject *conn)
Py_INCREF(Py_None);
self->tuple_factory = Py_None;
Py_INCREF(Py_None);
- self->tzinfo_factory = Py_None;
- Py_INCREF(Py_None);
+
+ /* default tzinfo factory */
+ self->tzinfo_factory = pyPsycopgTzFixedOffsetTimezone;
+ Py_INCREF(self->tzinfo_factory);
Dprintf("cursor_setup: good cursor object at %p, refcnt = %d",
self, ((PyObject *)self)->ob_refcnt);
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 4166cc2..31d16f9 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -57,7 +57,8 @@ PyObject *pyDeltaTypeP = NULL;
/* pointers to the psycopg.tz classes */
PyObject *pyPsycopgTzModule = NULL;
-PyObject *pyPsycopgTzLocalTimezone = NULL;
+PyObject *pyPsycopgTzLOCAL = NULL;
+PyObject *pyPsycopgTzFixedOffsetTimezone = NULL;
PyObject *psycoEncodings = NULL;
PyObject *decimalType = NULL;
@@ -485,9 +486,11 @@ init_psycopg(void)
/* import psycopg2.tz anyway (TODO: replace with C-level module?) */
pyPsycopgTzModule = PyImport_ImportModule("psycopg2.tz");
- pyPsycopgTzLocalTimezone =
+ pyPsycopgTzLOCAL =
PyObject_GetAttrString(pyPsycopgTzModule, "LOCAL");
-
+ pyPsycopgTzFixedOffsetTimezone =
+ PyObject_GetAttrString(pyPsycopgTzModule, "FixedOffsetTimezone");
+
/* initialize the module and grab module's dictionary */
module = Py_InitModule("_psycopg", psycopgMethods);
dict = PyModule_GetDict(module);