summaryrefslogtreecommitdiff
path: root/psycopg/adapter_datetime.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-12 21:48:54 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-21 04:24:36 +0000
commitcb6b52945b4c114d39613e6a7b35c73762e5045f (patch)
tree30fd118d454aa4008174f0aac71fc15023612867 /psycopg/adapter_datetime.c
parente182201e6ee8075a88b63c9d8338f833bd2471b0 (diff)
downloadpsycopg2-cb6b52945b4c114d39613e6a7b35c73762e5045f.tar.gz
The library can be compiled with Python 3.
Just compiled! No test run yet and many points to review, marked in the code. The patch is largely Martin von Löwis work, simplified after refactoring in the previous commits and adapted to the new code (as the patch was originally for Psycopg 2.0.9)
Diffstat (limited to 'psycopg/adapter_datetime.c')
-rw-r--r--psycopg/adapter_datetime.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c
index f640684..19fd97e 100644
--- a/psycopg/adapter_datetime.c
+++ b/psycopg/adapter_datetime.c
@@ -62,26 +62,30 @@ pydatetime_str(pydatetimeObject *self)
if (self->type <= PSYCO_DATETIME_TIMESTAMP) {
PyObject *tz;
- /* Select the right PG type to cast into. */
+ /* Select the right PG type to cast into.
+ * fmt contains %s in Py2 and %U in Py3,
+ * So it can be used with the Text_FromFormatS macro */
char *fmt = NULL;
switch (self->type) {
case PSYCO_DATETIME_TIME:
- fmt = "'%s'::time";
+ fmt = "'" Text_S "'::time";
break;
case PSYCO_DATETIME_DATE:
- fmt = "'%s'::date";
+ fmt = "'" Text_S "'::date";
break;
case PSYCO_DATETIME_TIMESTAMP:
tz = PyObject_GetAttrString(self->wrapped, "tzinfo");
if (!tz) { return NULL; }
- fmt = (tz == Py_None) ? "'%s'::timestamp" : "'%s'::timestamptz";
+ fmt = (tz == Py_None)
+ ? "'" Text_S "'::timestamp"
+ : "'" Text_S "'::timestamptz";
Py_DECREF(tz);
break;
}
iso = PyObject_CallMethod(self->wrapped, "isoformat", NULL);
if (iso) {
- res = PyString_FromFormat(fmt, PyString_AsString(iso));
+ res = Text_FromFormatS(fmt, iso);
Py_DECREF(iso);
}
return res;
@@ -89,7 +93,7 @@ pydatetime_str(pydatetimeObject *self)
else {
PyDateTime_Delta *obj = (PyDateTime_Delta*)self->wrapped;
- char buffer[8];
+ char buffer[8];
int i;
int a = obj->microseconds;