mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-23 01:16:34 +03:00
Disallow some methods depending on the connection's sync/async mode
This commit is contained in:
parent
34317dc4c3
commit
9b259a8a54
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user