[Informixdb-cvs] informixdb/ext _informixdb.ec,1.78,1.79
Brought to you by:
chaese,
f-apolloner
From: Carsten H. <ch...@us...> - 2006-11-11 05:53:03
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv6484/ext Modified Files: _informixdb.ec Log Message: implement optional parameter binding by name Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.78 retrieving revision 1.79 diff -C2 -d -r1.78 -r1.79 *** _informixdb.ec 3 Nov 2006 05:04:27 -0000 1.78 --- _informixdb.ec 11 Nov 2006 05:53:00 -0000 1.79 *************** *** 448,451 **** --- 448,452 ---- PyObject *errorhandler; PyObject *binary_types; + PyObject *named_params; } Cursor; *************** *** 1081,1084 **** --- 1082,1087 ---- setConnectionName(NULL); + PyDict_Clear(self->binary_types); + Py_XDECREF(self->binary_types); Py_XDECREF(self->messages); Py_XDECREF(self->errorhandler); *************** *** 1153,1156 **** --- 1156,1160 ---- char state; char prev; + const char *parmName; } parseContext; *************** *** 1163,1166 **** --- 1167,1171 ---- ct->parmIdx = 0; ct->prev = '\0'; + ct->parmName = 0; } *************** *** 1188,1204 **** const char *m = in; int n = 0; ! while (isdigit(*m)) { ! n *= 10; ! n += *m - '0'; ! m++; } ! if (n) { ! ct->parmIdx = n-1; ! ct->parmCount++; ! in = m; ! ct->isParm = 1; ! ct->prev = '0'; ! rc = 1; ! break; } } --- 1193,1226 ---- const char *m = in; int n = 0; ! if (isdigit(*m)) { ! while (isdigit(*m)) { ! n *= 10; ! n += *m - '0'; ! m++; ! } ! if (n) { ! ct->parmIdx = n-1; ! ct->parmCount++; ! in = m; ! ct->isParm = 1; ! ct->prev = '0'; ! rc = 1; ! break; ! } } ! else { ! while (isalnum(*m) || *m=='_') { ! n++; m++; ! } ! if (n) { ! ct->parmIdx = -n; ! ct->parmName = in; ! ct->parmCount++; ! in = m; ! ct->isParm = 1; ! ct->prev = '0'; ! rc = 1; ! break; ! } } } *************** *** 1506,1510 **** initParseContext(&ctx, in, out); while (doParse(&ctx)) { ! cur->parmIdx[ctx.parmCount-1] = ctx.parmIdx; if (ctx.parmCount == n_slots) { n_slots += PARM_COUNT_INCREMENT; --- 1528,1542 ---- initParseContext(&ctx, in, out); while (doParse(&ctx)) { ! if (ctx.parmIdx >= 0) { ! cur->parmIdx[ctx.parmCount-1] = ctx.parmIdx; ! } ! else { ! PyObject *parmname; ! parmname = PyString_FromStringAndSize(ctx.parmName,-ctx.parmIdx); ! if (PyList_Append(cur->named_params, parmname)==-1) { ! return 0; ! } ! cur->parmIdx[ctx.parmCount-1] = -PyList_Size(cur->named_params); ! } if (ctx.parmCount == n_slots) { n_slots += PARM_COUNT_INCREMENT; *************** *** 1535,1566 **** int maxp=0; ! if (vars && !PySequence_Check(vars)) { ! PyErr_SetString(PyExc_TypeError, "SQL parameters are not a sequence"); ! return 0; } ! ! for (i = 0; i < cur->daIn.sqld; ++i) { ! if (cur->parmIdx[i] < n_vars) { ! int success; ! PyObject *item = PySequence_GetItem(vars, cur->parmIdx[i]); ! ! success = (*ibindFcn(item))(var++, item); ! Py_DECREF(item); /* PySequence_GetItem increments it */ ! if (!success) return 0; ! maxp = maxp > cur->parmIdx[i] ? maxp : cur->parmIdx[i]; ! } else { error_handle(cur->conn, cur, ExcInterfaceError, ! PyString_FromString("too few actual parameters")); return 0; } } - if (maxp+1 < n_vars) { - error_handle(cur->conn, cur, ExcInterfaceError, - PyString_FromString("too many actual parameters")); - return 0; - } - return 1; } --- 1567,1629 ---- int maxp=0; ! if (PyList_Size(cur->named_params)) { ! if (vars && !PyDict_Check(vars)) { ! PyErr_SetString(PyExc_TypeError, "SQL parameters are not a dictionary"); ! return 0; ! } ! for (i = 0; i < cur->daIn.sqld; ++i) { ! if (cur->parmIdx[i] >= 0) { ! PyErr_SetString(PyExc_TypeError, ! "can't mix named parameters and positional parameters"); ! return 0; ! } ! else { ! int success; ! PyObject *parmname = PyList_GetItem(cur->named_params, ! -cur->parmIdx[i]-1); ! PyObject *item = PyDict_GetItem(vars, parmname); ! /* PyList_GetItem and PyDict_GetItem borrow the references ! to their result, so no decref necessary here. */ ! if (!item) { ! /* PyDict_GetItem doesn't set an exception. */ ! PyErr_SetObject(PyExc_KeyError, parmname); ! return 0; ! } ! success = (*ibindFcn(item))(var++, item); ! if (!success) ! return 0; ! } ! } } ! else { ! if (vars && !PySequence_Check(vars)) { ! PyErr_SetString(PyExc_TypeError, "SQL parameters are not a sequence"); ! return 0; ! } ! ! for (i = 0; i < cur->daIn.sqld; ++i) { ! if (cur->parmIdx[i] < n_vars) { ! int success; ! PyObject *item = PySequence_GetItem(vars, cur->parmIdx[i]); ! ! success = (*ibindFcn(item))(var++, item); ! Py_DECREF(item); /* PySequence_GetItem increments it */ ! if (!success) ! return 0; ! maxp = maxp > cur->parmIdx[i] ? maxp : cur->parmIdx[i]; ! } else { ! error_handle(cur->conn, cur, ExcInterfaceError, ! PyString_FromString("too few actual parameters")); return 0; ! } ! } ! ! if (maxp+1 < n_vars) { error_handle(cur->conn, cur, ExcInterfaceError, ! PyString_FromString("too many actual parameters")); return 0; } } return 1; } *************** *** 2428,2431 **** --- 2491,2497 ---- cur->parmIdx = 0; } + if (cur->named_params) { + PySequence_DelSlice(cur->named_params,0,PyList_Size(cur->named_params)); + } } *************** *** 2522,2525 **** --- 2588,2595 ---- deleteOutputBinding(self); + PyDict_Clear(self->binary_types); + Py_XDECREF(self->binary_types); + PySequence_DelSlice(self->named_params,0,PyList_Size(self->named_params)); + Py_XDECREF(self->named_params); Py_XDECREF(self->conn); Py_XDECREF(self->messages); *************** *** 2615,2618 **** --- 2685,2689 ---- self->messages = PyList_New(0); self->binary_types = PyDict_Copy(conn->binary_types); + self->named_params = PyList_New(0); self->errorhandler = conn->errorhandler; Py_INCREF(self->errorhandler); |