From 8920c2662b85efe7c3d61932ac3b6e2d50d4f949 Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Sat, 1 Oct 2005 14:58:25 +0000 Subject: [PATCH] Appliced callproc patch. --- ChangeLog | 6 ++++++ psycopg/cursor_type.c | 50 +++++++++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7e439220..710d4dd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-10-02 Federico Di Gregorio + + * psycopg/cursor_type.c (psyco_curs_callproc): applied callproc + patch from Matt Goodall (added a check on _psyco_curs_execute + return value and substituted malloc/free with PyMem versions.) + 2005-10-01 Federico Di Gregorio * psycopg/connection_int.c: fixed segfault by moving PyErr_Format diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 9b0b97df..dcabf92d 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -803,27 +803,55 @@ psyco_curs_fetchall(cursorObject *self, PyObject *args) -/* callproc method - execute a stored procedure (not YET supported) */ +/* callproc method - execute a stored procedure */ #define psyco_curs_callproc_doc \ -"callproc(procname, [parameters]) -> execute stored procedure\n\n" \ -"This method is not (yet) impelemented and calling it raise an exception." +"callproc(procname, [parameters]) -> execute stored procedure" static PyObject * -psyco_curs_callproc(cursorObject *self, PyObject *args) +psyco_curs_callproc(cursorObject *self, PyObject *args, PyObject *kwargs) { - PyObject *procname, *procargs; - - if (!PyArg_ParseTuple(args, "O|O", &procname, &procargs)) + char *procname = NULL, *sql = NULL; + long int async = 0; + int i, nparameters = 0, sl = 0; + PyObject *parameters = NULL; + PyObject *operation = NULL; + PyObject *res = NULL; + + if (!PyArg_ParseTuple(args, "s|Oi", &procname, ¶meters, &async)) { return NULL; - + } + EXC_IF_CURS_CLOSED(self); - PyErr_SetString(NotSupportedError, "not yet implemented"); - return NULL; + if(parameters && parameters != Py_None) { + nparameters = PyObject_Length(parameters); + } + + /* allocate some memory, build the SQL and create a PyString from it */ + sl = strlen(procname) + 10 + nparameters*3; + sql = (char*)PyMem_Malloc(sl); + if (sql == NULL) return NULL; + + sprintf(sql, "SELECT %s(", procname); + for(i=0; i