diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index cd8d5ca3..7992ce4b 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -1024,6 +1024,7 @@ psyco_curs_callproc(cursorObject *self, PyObject *args) PyObject *parameters = Py_None; PyObject *operation = NULL; PyObject *res = NULL; + PyObject *parameter_names = NULL; if (!PyArg_ParseTuple(args, "s#|O", &procname, &procname_len, ¶meters @@ -1045,19 +1046,52 @@ psyco_curs_callproc(cursorObject *self, PyObject *args) } /* allocate some memory, build the SQL and create a PyString from it */ - sl = procname_len + 17 + nparameters*3 - (nparameters ? 1 : 0); - sql = (char*)PyMem_Malloc(sl); - if (sql == NULL) { - PyErr_NoMemory(); - goto exit; - } - sprintf(sql, "SELECT * FROM %s(", procname); - for(i=0; i 0 && PyDict_Check(parameters)) { + /* for a dict, we put the parameter names into the SQL */ + parameter_names = PyDict_Keys(parameters); + + /* first we need to figure out how much space we need for the SQL */ + sl = procname_len + 17 + nparameters*5 - (nparameters ? 1 : 0); + for(i=0; i 2