diff options
author | Jan UrbaĆski <wulczer@wulczer.org> | 2010-03-26 04:00:47 +0100 |
---|---|---|
committer | Federico Di Gregorio <fog@initd.org> | 2010-04-05 11:31:37 +0200 |
commit | 9b259a8a5489928f9abf12cf4c7459696ef18a3e (patch) | |
tree | e39621512b1c0eb399c87980d21c667d3fcc5587 | |
parent | 34317dc4c3686d48dd58756ad4edd9b6942567c8 (diff) | |
download | psycopg2-9b259a8a5489928f9abf12cf4c7459696ef18a3e.tar.gz |
Disallow some methods depending on the connection's sync/async mode
-rw-r--r-- | psycopg/cursor_type.c | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 0609ca3..1fc88f9 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -442,16 +442,32 @@ _psyco_curs_execute(cursorObject *self, static PyObject * psyco_curs_execute(cursorObject *self, PyObject *args, PyObject *kwargs) { - long int async = 0; + long int async; PyObject *vars = NULL, *operation = NULL; static char *kwlist[] = {"query", "vars", "async", NULL}; + async = self->conn->async; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Ol", kwlist, &operation, &vars, &async)) { 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->query != Py_None) { psyco_set_error(ProgrammingError, (PyObject*)self, @@ -510,6 +526,12 @@ psyco_curs_executemany(cursorObject *self, PyObject *args, PyObject *kwargs) 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)) { vars = iter = PyObject_GetIter(vars); if (iter == NULL) return NULL; @@ -943,17 +965,34 @@ psyco_curs_callproc(cursorObject *self, PyObject *args, PyObject *kwargs) { const char *procname = NULL; char *sql = NULL; - long int async = 0; + long int async; Py_ssize_t procname_len, i, nparameters = 0, sl = 0; PyObject *parameters = Py_None; PyObject *operation = NULL; PyObject *res = NULL; + async = self->conn->async; + if (!PyArg_ParseTuple(args, "s#|Ol", &procname, &procname_len, ¶meters, &async )) { 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); if (self->name != NULL) { |