callproc: checking for libpq 9.0+ on compile. yes: use PQescapeIdentifier. no: error

This commit is contained in:
mrmilosz 2014-05-29 05:09:09 -04:00
parent 3948e909e4
commit 37a80e9de8

View File

@ -1026,11 +1026,13 @@ psyco_curs_callproc(cursorObject *self, PyObject *args)
PyObject *res = NULL; PyObject *res = NULL;
int using_dict; int using_dict;
#if PG_VERSION_HEX >= 0x090000
PyObject *pname = NULL; PyObject *pname = NULL;
PyObject *bpname = NULL; PyObject *bpname = NULL;
PyObject *pnames = NULL; PyObject *pnames = NULL;
char *cpname = NULL; char *cpname = NULL;
char **scpnames = NULL; char **scpnames = NULL;
#endif
if (!PyArg_ParseTuple(args, "s#|O", &procname, &procname_len, if (!PyArg_ParseTuple(args, "s#|O", &procname, &procname_len,
&parameters)) { &parameters)) {
@ -1055,6 +1057,7 @@ 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_HEX >= 0x090000
if (!(pnames = PyDict_Keys(parameters))) { if (!(pnames = PyDict_Keys(parameters))) {
PyErr_SetString(PyExc_RuntimeError, PyErr_SetString(PyExc_RuntimeError,
"built-in 'keys' failed on a Dict!"); "built-in 'keys' failed on a Dict!");
@ -1119,6 +1122,11 @@ psyco_curs_callproc(cursorObject *self, PyObject *args)
"built-in 'values' failed on a Dict!"); "built-in 'values' failed on a Dict!");
goto exit; goto exit;
} }
#else
PyErr_SetString(PyExc_NotImplementedError,
"named parameters require psycopg2 compiled against libpq 9.0+");
goto exit;
#endif
} }
/* 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 */
@ -1153,6 +1161,7 @@ psyco_curs_callproc(cursorObject *self, PyObject *args)
} }
exit: exit:
#if PG_VERSION_HEX >= 0x090000
if (scpnames != NULL) { if (scpnames != NULL) {
for (i = 0; i < nparameters; i++) { for (i = 0; i < nparameters; i++) {
if (scpnames[i] != NULL) { if (scpnames[i] != NULL) {
@ -1162,6 +1171,7 @@ exit:
} }
PyMem_Del(scpnames); PyMem_Del(scpnames);
Py_XDECREF(pnames); Py_XDECREF(pnames);
#endif
Py_XDECREF(operation); Py_XDECREF(operation);
PyMem_Free((void*)sql); PyMem_Free((void*)sql);
return res; return res;