Disallow some methods depending on the connection's sync/async mode

This commit is contained in:
Jan Urbański 2010-03-26 04:00:47 +01:00 committed by Federico Di Gregorio
parent 34317dc4c3
commit 9b259a8a54

View File

@ -442,16 +442,32 @@ _psyco_curs_execute(cursorObject *self,
static PyObject * static PyObject *
psyco_curs_execute(cursorObject *self, PyObject *args, PyObject *kwargs) psyco_curs_execute(cursorObject *self, PyObject *args, PyObject *kwargs)
{ {
long int async = 0; long int async;
PyObject *vars = NULL, *operation = NULL; PyObject *vars = NULL, *operation = NULL;
static char *kwlist[] = {"query", "vars", "async", NULL}; static char *kwlist[] = {"query", "vars", "async", NULL};
async = self->conn->async;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Ol", kwlist, if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Ol", kwlist,
&operation, &vars, &async)) { &operation, &vars, &async)) {
return NULL; return NULL;
} }
if (async != self->conn->async) {
if (async == 0)
psyco_set_error(ProgrammingError, (PyObject*)self,
"can't execute a synchronous query "
"from an asynchronous cursor",
NULL, NULL);
else
psyco_set_error(ProgrammingError, (PyObject*)self,
"can't execute an asynchronous query "
"from a synchronous cursor",
NULL, NULL);
return NULL;
}
if (self->name != NULL) { if (self->name != NULL) {
if (self->query != Py_None) { if (self->query != Py_None) {
psyco_set_error(ProgrammingError, (PyObject*)self, psyco_set_error(ProgrammingError, (PyObject*)self,
@ -510,6 +526,12 @@ psyco_curs_executemany(cursorObject *self, PyObject *args, PyObject *kwargs)
return NULL; return NULL;
} }
if (self->conn->async == 1) {
psyco_set_error(ProgrammingError, (PyObject*)self,
"can't call .executemany() on async cursors", NULL, NULL);
return NULL;
}
if (!PyIter_Check(vars)) { if (!PyIter_Check(vars)) {
vars = iter = PyObject_GetIter(vars); vars = iter = PyObject_GetIter(vars);
if (iter == NULL) return NULL; if (iter == NULL) return NULL;
@ -943,17 +965,34 @@ psyco_curs_callproc(cursorObject *self, PyObject *args, PyObject *kwargs)
{ {
const char *procname = NULL; const char *procname = NULL;
char *sql = NULL; char *sql = NULL;
long int async = 0; long int async;
Py_ssize_t procname_len, i, nparameters = 0, sl = 0; Py_ssize_t procname_len, i, nparameters = 0, sl = 0;
PyObject *parameters = Py_None; PyObject *parameters = Py_None;
PyObject *operation = NULL; PyObject *operation = NULL;
PyObject *res = NULL; PyObject *res = NULL;
async = self->conn->async;
if (!PyArg_ParseTuple(args, "s#|Ol", if (!PyArg_ParseTuple(args, "s#|Ol",
&procname, &procname_len, &parameters, &async &procname, &procname_len, &parameters, &async
)) ))
{ return NULL; } { return NULL; }
if (async != self->conn->async) {
if (async == 0)
psyco_set_error(ProgrammingError, (PyObject*)self,
"can't do a synchronous function call "
"from an asynchronous cursor",
NULL, NULL);
else
psyco_set_error(ProgrammingError, (PyObject*)self,
"can't do an asynchronous function call "
"from a synchronous cursor",
NULL, NULL);
return NULL;
}
EXC_IF_CURS_CLOSED(self); EXC_IF_CURS_CLOSED(self);
if (self->name != NULL) { if (self->name != NULL) {