mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-26 02:43:43 +03:00
Add psyco_curs_datetime_init
This commit is contained in:
parent
28a1a00d1c
commit
9ab38ee8c5
|
@ -107,6 +107,8 @@ HIDDEN void curs_reset(cursorObject *self);
|
|||
HIDDEN int psyco_curs_withhold_set(cursorObject *self, PyObject *pyvalue);
|
||||
HIDDEN int psyco_curs_scrollable_set(cursorObject *self, PyObject *pyvalue);
|
||||
|
||||
RAISES_NEG int psyco_curs_datetime_init(void);
|
||||
|
||||
/* exception-raising macros */
|
||||
#define EXC_IF_CURS_CLOSED(self) \
|
||||
do { \
|
||||
|
|
|
@ -1780,6 +1780,21 @@ psyco_curs_flush_replication_feedback(cursorObject *self, PyObject *args, PyObje
|
|||
return curs_flush_replication_feedback(self, reply);
|
||||
}
|
||||
|
||||
|
||||
RAISES_NEG int
|
||||
psyco_curs_datetime_init(void)
|
||||
{
|
||||
Dprintf("psyco_curs_datetime_init: datetime init");
|
||||
|
||||
PyDateTime_IMPORT;
|
||||
|
||||
if (!PyDateTimeAPI) {
|
||||
PyErr_SetString(PyExc_ImportError, "datetime initialization failed");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define psyco_curs_replication_io_timestamp_doc \
|
||||
"replication_io_timestamp -- the timestamp of latest IO with the server"
|
||||
|
||||
|
@ -1791,9 +1806,6 @@ psyco_curs_get_replication_io_timestamp(cursorObject *self)
|
|||
|
||||
EXC_IF_CURS_CLOSED(self);
|
||||
|
||||
// TODO: move to a one-call init function
|
||||
PyDateTime_IMPORT;
|
||||
|
||||
seconds = self->repl_last_io.tv_sec + self->repl_last_io.tv_usec / 1.0e6;
|
||||
|
||||
tval = Py_BuildValue("(d)", seconds);
|
||||
|
|
|
@ -939,6 +939,7 @@ INIT_MODULE(_psycopg)(void)
|
|||
/* Initialize the PyDateTimeAPI everywhere is used */
|
||||
PyDateTime_IMPORT;
|
||||
if (psyco_adapter_datetime_init()) { goto exit; }
|
||||
if (psyco_curs_datetime_init()) { goto exit; }
|
||||
if (psyco_replmsg_datetime_init()) { goto exit; }
|
||||
|
||||
Py_TYPE(&pydatetimeType) = &PyType_Type;
|
||||
|
|
Loading…
Reference in New Issue
Block a user