[Informixdb-cvs] informixdb/ext _informixdb.ec,1.85,1.86
Brought to you by:
chaese,
f-apolloner
From: Carsten H. <ch...@us...> - 2006-12-23 05:40:17
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv14305/ext Modified Files: _informixdb.ec Log Message: - experimental support for SQL query interrupt and timeout - check existence of decimal module at run time - make executemany and fetchmany/fetchall interruptible - fetchall "only" fetched the next MAXINT rows. Probably didn't affect anybody, but it's not hard to really fetch all rows. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.85 retrieving revision 1.86 diff -C2 -d -r1.85 -r1.86 *** _informixdb.ec 2 Dec 2006 03:22:22 -0000 1.85 --- _informixdb.ec 23 Dec 2006 05:40:14 -0000 1.86 *************** *** 113,116 **** --- 113,117 ---- */ #define DEFERRED_ADDRESS(ADDR) 0 + #include <signal.h> /************************* Error handling *************************/ *************** *** 130,136 **** static PyObject *IntervalD2FType; static PyObject *DataRowType; - #if HAVE_DECIMAL == 1 static PyObject *DecimalType; - #endif PyDoc_STRVAR(ExcWarning_doc, --- 131,135 ---- *************** *** 442,448 **** int pending_scroll; int scroll_value; - #if HAVE_DECIMAL == 1 int use_decimal; - #endif PyObject *messages; PyObject *errorhandler; --- 441,445 ---- *************** *** 450,453 **** --- 447,452 ---- PyObject *named_params; int have_named_params; + int sqltimeout; + int allow_interrupt; } Cursor; *************** *** 643,646 **** --- 642,649 ---- { "binary_types", T_OBJECT_EX, offsetof(Cursor, binary_types), READONLY, Cursor_binary_types_doc }, + { "sqltimeout", T_INT, offsetof(Cursor, sqltimeout), 0, + "SQL query timeout in milliseconds." }, + { "allow_interrupt", T_INT, offsetof(Cursor, allow_interrupt), 0, + "Indicates if SIGINT interrupts SQL queries." }, { NULL } }; *************** *** 1861,1864 **** --- 1864,1877 ---- } + static void _sqltimeouthandler(mint status) + { + if (status==2) { sqlbreak(); } + } + + static void _sigint_sqlbreak(int sig) + { + sqlbreak(); + } + static PyObject *do_prepare(Cursor *self, PyObject *op) { *************** *** 1973,1977 **** char *cursorName = self->cursorName; EXEC SQL END DECLARE SECTION; ! clear_messages(self); require_cursor_open(self); --- 1986,1992 ---- char *cursorName = self->cursorName; EXEC SQL END DECLARE SECTION; ! void (*oldsighandler)(int); ! ! oldsighandler = NULL; clear_messages(self); require_cursor_open(self); *************** *** 1994,1999 **** --- 2009,2026 ---- if (self->has_output) { + Py_BEGIN_ALLOW_THREADS; + if (self->sqltimeout>0) { + sqlbreakcallback(self->sqltimeout, _sqltimeouthandler); + } + if (self->allow_interrupt) { + oldsighandler = signal(2, _sigint_sqlbreak); + } EXEC SQL OPEN :cursorName USING DESCRIPTOR tdaIn; + if (self->allow_interrupt) { + signal(2, oldsighandler); + } + Py_END_ALLOW_THREADS; ret_on_dberror_cursor(self, "OPEN"); + sqlbreakcallback(-1, (void*)NULL); self->state = 3; *************** *** 2004,2010 **** --- 2031,2047 ---- } else { Py_BEGIN_ALLOW_THREADS; + if (self->sqltimeout>0) { + sqlbreakcallback(self->sqltimeout, _sqltimeouthandler); + } + if (self->allow_interrupt) { + oldsighandler = signal(2, _sigint_sqlbreak); + } EXEC SQL EXECUTE :queryName USING DESCRIPTOR tdaIn; + if (self->allow_interrupt) { + signal(2, oldsighandler); + } Py_END_ALLOW_THREADS; ret_on_dberror_cursor(self, "EXECUTE"); + sqlbreakcallback(-1, (void*)NULL); for (i=0; i<6; i++) self->sqlerrd[i] = sqlca.sqlerrd[i]; *************** *** 2122,2125 **** --- 2159,2165 ---- } Py_DECREF(inputvars); + if (PyErr_CheckSignals()) { + return NULL; + } } Py_DECREF(paramiter); *************** *** 2275,2279 **** case SQLDECIMAL: case SQLMONEY: - #if HAVE_DECIMAL == 1 if (cur->use_decimal) { char dbuf[35]; --- 2315,2318 ---- *************** *** 2281,2284 **** --- 2320,2327 ---- mint right; PyObject *retval = NULL; + if (DecimalType==Py_None) { + PyErr_SetString(PyExc_ImportError, "can't find decimal.Decimal"); + return NULL; + } right = PRECDEC(sqllen); if (right==255) right = -1; *************** *** 2293,2299 **** } return retval; ! } else ! #endif ! { double dval; dectodbl((dec_t*)data, &dval); --- 2336,2341 ---- } return retval; ! } ! else { double dval; dectodbl((dec_t*)data, &dval); *************** *** 2655,2674 **** int is_scroll = 0; int is_hold = 0; - #if HAVE_DECIMAL == 1 int use_decimal = 1; static char* kwdlist[] = { "connection", "name", "rowformat", ! "scroll", "hold", "use_decimal", 0 }; ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|siiii", kwdlist, &Connection_type, &conn, &name, &rowformat, &is_scroll, &is_hold, ! &use_decimal)) return -1; self->use_decimal = (use_decimal)?1:0; ! #else ! static char* kwdlist[] = { "connection", "name", "rowformat", ! "scroll", "hold", 0 }; ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|siii", kwdlist, ! &Connection_type, &conn, &name, &rowformat, &is_scroll, &is_hold)) ! return -1; ! #endif Py_INCREF(Py_None); --- 2697,2714 ---- int is_scroll = 0; int is_hold = 0; int use_decimal = 1; + int sqltimeout = 0; + int allow_interrupt = 0; static char* kwdlist[] = { "connection", "name", "rowformat", ! "scroll", "hold", "use_decimal", ! "sqltimeout", "allow_interrupt", 0 }; ! if (DecimalType==Py_None) { use_decimal = 0; } ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|siiiiii", kwdlist, &Connection_type, &conn, &name, &rowformat, &is_scroll, &is_hold, ! &use_decimal, &sqltimeout, &allow_interrupt)) return -1; self->use_decimal = (use_decimal)?1:0; ! self->sqltimeout = sqltimeout; ! self->allow_interrupt = allow_interrupt; Py_INCREF(Py_None); *************** *** 2742,2745 **** --- 2782,2787 ---- struct sqlda *tdaOut = self->daOut; int i; + void (*oldsighandler)(int); + oldsighandler = NULL; EXEC SQL BEGIN DECLARE SECTION; *************** *** 2756,2759 **** --- 2798,2807 ---- Py_BEGIN_ALLOW_THREADS; + if (self->sqltimeout>0) { + sqlbreakcallback(self->sqltimeout, _sqltimeouthandler); + } + if (self->allow_interrupt) { + oldsighandler = signal(2, _sigint_sqlbreak); + } if (self->is_scroll) { exec sql begin declare section; *************** *** 2778,2781 **** --- 2826,2832 ---- EXEC SQL FETCH :cursorName USING DESCRIPTOR tdaOut; } + if (self->allow_interrupt) { + signal(2, oldsighandler); + } Py_END_ALLOW_THREADS; for (i=0; i<6; i++) *************** *** 2787,2790 **** --- 2838,2842 ---- ret_on_dberror_cursor(self, "FETCH"); } + sqlbreakcallback(-1,(void*)NULL); return processOutput(self); } *************** *** 2796,2800 **** require_cursor_open(self); ! while ( count-- > 0 ) { PyObject *entry = Cursor_fetchone(self); --- 2848,2852 ---- require_cursor_open(self); ! while ( count==-1 || count-- > 0 ) { PyObject *entry = Cursor_fetchone(self); *************** *** 2819,2822 **** --- 2871,2878 ---- Py_DECREF(entry); + + if (PyErr_CheckSignals()) { + return NULL; + } } *************** *** 2833,2842 **** return NULL; ! return fetchCounted(self, n_rows); } static PyObject *Cursor_fetchall(Cursor *self) { ! return fetchCounted(self, INT_MAX); } --- 2889,2903 ---- return NULL; ! if (n_rows<1) { ! return PyList_New(0); ! } ! else { ! return fetchCounted(self, n_rows); ! } } static PyObject *Cursor_fetchall(Cursor *self) { ! return fetchCounted(self, -1); } *************** *** 4172,4176 **** PyDateTime_IMPORT; - #if HAVE_DECIMAL DecimalType = NULL; module = PyImport_ImportModule("decimal"); --- 4233,4236 ---- *************** *** 4183,4190 **** if (!DecimalType) { DecimalType = Py_None; ! PyErr_SetString(PyExc_ImportError, "can't find decimal.Decimal"); } Py_INCREF(DecimalType); - #endif #ifndef _WIN32 --- 4243,4249 ---- if (!DecimalType) { DecimalType = Py_None; ! PyErr_Clear(); } Py_INCREF(DecimalType); #ifndef _WIN32 |