mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-14 13:06:34 +03:00
More straightforward param refcount handling in callproc
This commit is contained in:
parent
7302f348bc
commit
021f6d22ad
|
@ -1022,6 +1022,7 @@ psyco_curs_callproc(cursorObject *self, PyObject *args)
|
||||||
char *sql = NULL;
|
char *sql = NULL;
|
||||||
Py_ssize_t procname_len, i, nparameters = 0, sl = 0;
|
Py_ssize_t procname_len, i, nparameters = 0, sl = 0;
|
||||||
PyObject *parameters = Py_None;
|
PyObject *parameters = Py_None;
|
||||||
|
PyObject *pvals = NULL;
|
||||||
PyObject *operation = NULL;
|
PyObject *operation = NULL;
|
||||||
PyObject *res = NULL;
|
PyObject *res = NULL;
|
||||||
|
|
||||||
|
@ -1057,9 +1058,8 @@ psyco_curs_callproc(cursorObject *self, PyObject *args)
|
||||||
/* a Dict is complicated; the parameter names go into the query */
|
/* a Dict is complicated; the parameter names go into the query */
|
||||||
if (using_dict) {
|
if (using_dict) {
|
||||||
#if PG_VERSION_NUM >= 90000
|
#if PG_VERSION_NUM >= 90000
|
||||||
if (!(pnames = PyDict_Keys(parameters))) {
|
if (!(pnames = PyDict_Keys(parameters))) { goto exit; }
|
||||||
goto exit;
|
if (!(pvals = PyDict_Values(parameters))) { goto exit; }
|
||||||
}
|
|
||||||
|
|
||||||
sl = procname_len + 17 + nparameters * 5 - (nparameters ? 1 : 0);
|
sl = procname_len + 17 + nparameters * 5 - (nparameters ? 1 : 0);
|
||||||
|
|
||||||
|
@ -1104,9 +1104,6 @@ psyco_curs_callproc(cursorObject *self, PyObject *args)
|
||||||
sql[sl-2] = ')';
|
sql[sl-2] = ')';
|
||||||
sql[sl-1] = '\0';
|
sql[sl-1] = '\0';
|
||||||
|
|
||||||
if (!(parameters = PyDict_Values(parameters))) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
PyErr_SetString(PyExc_NotImplementedError,
|
PyErr_SetString(PyExc_NotImplementedError,
|
||||||
"named parameters require psycopg2 compiled against libpq 9.0+");
|
"named parameters require psycopg2 compiled against libpq 9.0+");
|
||||||
|
@ -1116,6 +1113,9 @@ psyco_curs_callproc(cursorObject *self, PyObject *args)
|
||||||
|
|
||||||
/* a list (or None, or empty data structure) is a little bit simpler */
|
/* a list (or None, or empty data structure) is a little bit simpler */
|
||||||
else {
|
else {
|
||||||
|
Py_INCREF(parameters);
|
||||||
|
pvals = parameters;
|
||||||
|
|
||||||
sl = procname_len + 17 + nparameters * 3 - (nparameters ? 1 : 0);
|
sl = procname_len + 17 + nparameters * 3 - (nparameters ? 1 : 0);
|
||||||
|
|
||||||
sql = (char*)PyMem_Malloc(sl);
|
sql = (char*)PyMem_Malloc(sl);
|
||||||
|
@ -1136,11 +1136,9 @@ psyco_curs_callproc(cursorObject *self, PyObject *args)
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 <= _psyco_curs_execute(self, operation, parameters,
|
if (0 <= _psyco_curs_execute(
|
||||||
self->conn->async, 0)) {
|
self, operation, pvals, self->conn->async, 0)) {
|
||||||
if (using_dict) {
|
|
||||||
Py_DECREF(parameters);
|
|
||||||
}
|
|
||||||
/* return None from this until it's DBAPI compliant... */
|
/* return None from this until it's DBAPI compliant... */
|
||||||
res = Py_None;
|
res = Py_None;
|
||||||
}
|
}
|
||||||
|
@ -1159,6 +1157,7 @@ exit:
|
||||||
Py_XDECREF(pnames);
|
Py_XDECREF(pnames);
|
||||||
#endif
|
#endif
|
||||||
Py_XDECREF(operation);
|
Py_XDECREF(operation);
|
||||||
|
Py_XDECREF(pvals);
|
||||||
PyMem_Free((void*)sql);
|
PyMem_Free((void*)sql);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user