[Informixdb-cvs] informixdb/ext _informixdb.ec,1.81,1.82
Brought to you by:
chaese,
f-apolloner
From: Carsten H. <ch...@us...> - 2006-11-13 15:46:03
|
Update of /cvsroot/informixdb/informixdb/ext In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv15691/ext Modified Files: _informixdb.ec Log Message: To allow duck-typing, named parameters should be allowed to come from any mapping, not just dictionaries. Also, only inspect the length of the parameter object when we actually need it, since it could be a mapping that doesn't specify a length, but for named parameters we don't care about how many there are as long as the right keys are there. Index: _informixdb.ec =================================================================== RCS file: /cvsroot/informixdb/informixdb/ext/_informixdb.ec,v retrieving revision 1.81 retrieving revision 1.82 diff -C2 -d -r1.81 -r1.82 *** _informixdb.ec 11 Nov 2006 22:36:39 -0000 1.81 --- _informixdb.ec 13 Nov 2006 15:45:59 -0000 1.82 *************** *** 491,495 **** 'command' attribute as the operation.\n\ \n\ ! 'parameters' is a sequence or dictionary of values to be bound to\n\ the placeholders in the SQL statement. For sequences, the number\n\ of values must exactly match the number of parameters required by\n\ --- 491,495 ---- 'command' attribute as the operation.\n\ \n\ ! 'parameters' is a sequence or mapping of values to be bound to\n\ the placeholders in the SQL statement. For sequences, the number\n\ of values must exactly match the number of parameters required by\n\ *************** *** 507,513 **** The 'operation' parameter is the same as for execute.\n\ 'seq_of_parameters' is an sequence of parameter sequences or\n\ ! dictionaries suitable for passing to execute(). The operation will\n\ be prepared once and then executes for all parameter sequences or\n\ ! dictionaries in 'seq_of_parameters'.\n\ \n\ For insert statements, executemany() will use an insert cursor\n\ --- 507,513 ---- The 'operation' parameter is the same as for execute.\n\ 'seq_of_parameters' is an sequence of parameter sequences or\n\ ! mappings suitable for passing to execute(). The operation will\n\ be prepared once and then executes for all parameter sequences or\n\ ! mappings in 'seq_of_parameters'.\n\ \n\ For insert statements, executemany() will use an insert cursor\n\ *************** *** 1575,1592 **** { struct sqlvar_struct *var = cur->daIn.sqlvar; - int n_vars = vars ? (int)PyObject_Length(vars) : 0; int i; - int maxp=0; if (PyList_Size(cur->named_params)) { /* If cur->named_params is not empty, the statement is using named ! parameters, so the vars must be supplied in a dictionary. ! Note that we allow the vars dictionary to contain more keys than the statement needs. This is analogous to string%dict interpolation, and it allows passing locals() as the parameter ! dictionary. */ ! if (vars && !PyDict_Check(vars)) { ! PyErr_SetString(PyExc_TypeError, "SQL parameters are not a dictionary"); return 0; } --- 1575,1590 ---- { struct sqlvar_struct *var = cur->daIn.sqlvar; int i; if (PyList_Size(cur->named_params)) { /* If cur->named_params is not empty, the statement is using named ! parameters, so the vars must be supplied in a mapping. ! Note that we allow the vars mapping to contain more keys than the statement needs. This is analogous to string%dict interpolation, and it allows passing locals() as the parameter ! mapping. */ ! if (vars && !PyMapping_Check(vars)) { ! PyErr_SetString(PyExc_TypeError, "SQL parameters are not a mapping"); return 0; } *************** *** 1596,1608 **** PyObject *parmname = PyList_GetItem(cur->named_params, cur->parmIdx[i]); /* Get the corresponding value from the dictionary. */ ! PyObject *item = PyDict_GetItem(vars, parmname); if (!item) { ! /* PyDict_GetItem doesn't set an exception, so we'll raise KeyError. */ ! PyErr_SetObject(PyExc_KeyError, parmname); ! /* PyList_GetItem and PyDict_GetItem borrow the references ! to their result, so no decref necessary here. */ return 0; } success = (*ibindFcn(item))(var++, item); if (!success) return 0; --- 1594,1605 ---- PyObject *parmname = PyList_GetItem(cur->named_params, cur->parmIdx[i]); /* Get the corresponding value from the dictionary. */ ! PyObject *item = PyObject_GetItem(vars, parmname); if (!item) { ! /* PyList_GetItem borrows the reference to its result, no decref ! on parmname necessary. */ return 0; } success = (*ibindFcn(item))(var++, item); + Py_DECREF(item); if (!success) return 0; *************** *** 1610,1613 **** --- 1607,1612 ---- } else { + int n_vars = vars ? (int)PyObject_Length(vars) : 0; + int maxp=0; /* The statement is using positional parameters */ if (vars && !PySequence_Check(vars)) { |