mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-11 03:26:37 +03:00
Ported mxDateTime formatting changes from 1.1.x.
This commit is contained in:
parent
4d536c1f12
commit
c123389378
|
@ -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.
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -42,12 +42,6 @@ typedef struct {
|
|||
|
||||
} 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
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user