summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2005-08-22 15:45:06 +0000
committerFederico Di Gregorio <fog@initd.org>2005-08-22 15:45:06 +0000
commitc123389378cb1261126831363cf41b8124a0622e (patch)
treeffeda84a9b5e40213f88aedc7058ff322489d877
parent4d536c1f1231140764b16923c547f60cfd40bf22 (diff)
downloadpsycopg2-c123389378cb1261126831363cf41b8124a0622e.tar.gz
Ported mxDateTime formatting changes from 1.1.x.
-rw-r--r--ChangeLog6
-rw-r--r--psycopg/adapter_mxdatetime.c42
-rw-r--r--psycopg/adapter_mxdatetime.h6
-rw-r--r--psycopg/cursor_type.c2
4 files changed, 41 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 8909521..e4ee7bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-08-23 Federico Di Gregorio <fog@debian.org>
+
+ * psycopg/adapter_mxdatetime.c (mxdatetime_str): ported code from 1.1.x
+ to convert mxDateTime object preserving the precision of fractional
+ seconds.
+
2005-08-22 Federico Di Gregorio <fog@debian.org>
* ZPsycopgDA/*.py: psycopg -> psycopg2.
diff --git a/psycopg/adapter_mxdatetime.c b/psycopg/adapter_mxdatetime.c
index 3c9dc76..7ae8ee7 100644
--- a/psycopg/adapter_mxdatetime.c
+++ b/psycopg/adapter_mxdatetime.c
@@ -39,17 +39,43 @@ extern mxDateTimeModule_APIObject *mxDateTimeP;
/* mxdatetime_str, mxdatetime_getquoted - return result of quoting */
-static char *mxdatetimeObject_str_conv[] = {
- PSYCO_MXDATETIME_TIME_CONV,
- PSYCO_MXDATETIME_DATE_CONV,
- PSYCO_MXDATETIME_TIMESTAMP_CONV
-};
-
static PyObject *
mxdatetime_str(mxdatetimeObject *self)
{
- return PyObject_CallMethod(self->wrapped, "strftime", "s",
- mxdatetimeObject_str_conv[self->type]);
+ PyObject *res = NULL;
+ char *buffer = NULL;
+
+ 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);
+ break;
+
+ case 1:
+ asprintf(&buffer, "'%ld-%02d-%02d'",
+ obj->year, (int)obj->month, (int)obj->day);
+ if (buffer) res = PyString_FromString(buffer);
+ 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);
+ break;
+
+ case 3:
+ res = PyObject_CallMethod(self->wrapped, "strftime", "s",
+ "'%d:%H:%M:%S'");
+ break;
+ }
+
+ if (buffer) free(buffer);
+ return res;
}
PyObject *
diff --git a/psycopg/adapter_mxdatetime.h b/psycopg/adapter_mxdatetime.h
index b7cd173..b5e4b13 100644
--- a/psycopg/adapter_mxdatetime.h
+++ b/psycopg/adapter_mxdatetime.h
@@ -41,12 +41,6 @@ typedef struct {
#define PSYCO_MXDATETIME_INTERVAL 3
} mxdatetimeObject;
-
-/* the conversion strings */
-#define PSYCO_MXDATETIME_TIME_CONV "'%H:%M:%S'"
-#define PSYCO_MXDATETIME_DATE_CONV "'%Y-%m-%d'"
-#define PSYCO_MXDATETIME_TIMESTAMP_CONV "'%Y-%m-%d %H:%M:%S'"
-#define PSYCO_MXDATETIME_INTERVAL_CONV "'%d:%H:%M:%S'"
/* functions exported to psycopgmodule.c */
#ifdef PSYCOPG_DEFAULT_MXDATETIME
diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c
index 8cb5f2c..2220170 100644
--- a/psycopg/cursor_type.c
+++ b/psycopg/cursor_type.c
@@ -588,7 +588,7 @@ _psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
len = 0;
}
else {
- str = PQgetvalue(self->pgres, row, i);
+ str = (unsigned char*)PQgetvalue(self->pgres, row, i);
len = PQgetlength(self->pgres, row, i);
}