From 23d279945ffb3eae3bea69856b20e8271108ebd0 Mon Sep 17 00:00:00 2001 From: mrmilosz Date: Sat, 24 May 2014 23:47:09 -0400 Subject: [PATCH] cursor.callproc now also accepts dict for PostgreSQL 9+ "named notation" --- psycopg/cursor_type.c | 56 ++++++++++++++++++++++++++++++++++--------- psycopg/python.h | 2 ++ 2 files changed, 47 insertions(+), 11 deletions(-) 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