summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--psycopg/cursor_type.c43
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, &parameters, &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) {