Appliced callproc patch.

This commit is contained in:
Federico Di Gregorio 2005-10-01 14:58:25 +00:00
parent 67720de497
commit 8920c2662b
2 changed files with 45 additions and 11 deletions

View File

@ -1,3 +1,9 @@
2005-10-02 Federico Di Gregorio <fog@debian.org>
* 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 <fog@debian.org> 2005-10-01 Federico Di Gregorio <fog@debian.org>
* psycopg/connection_int.c: fixed segfault by moving PyErr_Format * psycopg/connection_int.c: fixed segfault by moving PyErr_Format

View File

@ -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 \ #define psyco_curs_callproc_doc \
"callproc(procname, [parameters]) -> execute stored procedure\n\n" \ "callproc(procname, [parameters]) -> execute stored procedure"
"This method is not (yet) impelemented and calling it raise an exception."
static PyObject * static PyObject *
psyco_curs_callproc(cursorObject *self, PyObject *args) psyco_curs_callproc(cursorObject *self, PyObject *args, PyObject *kwargs)
{ {
PyObject *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, "O|O", &procname, &procargs)) if (!PyArg_ParseTuple(args, "s|Oi", &procname, &parameters, &async)) {
return NULL;
EXC_IF_CURS_CLOSED(self);
PyErr_SetString(NotSupportedError, "not yet implemented");
return NULL; return NULL;
} }
EXC_IF_CURS_CLOSED(self);
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<nparameters; i++) {
strcat(sql, "%s,");
}
sql[sl-2] = ')';
sql[sl-1] = '\0';
operation = PyString_FromString(sql);
PyMem_Free((void*)sql);
if (_psyco_curs_execute(self, operation, parameters, async)) {
Py_INCREF(Py_None);
res = Py_None;
}
Py_DECREF(operation);
return res;
}
/* nextset method - return the next set of data (not supported) */ /* nextset method - return the next set of data (not supported) */