mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-23 01:16:34 +03:00
Forbid COPY-related methods in green mode.
With the current implementation, at best they would silently block. They actually hang everything. Implementation posponed after some refactoring of the polling system, because it will be probably possible to provide an implementation for 'poll()' during COPY which is good for both async and green modes.
This commit is contained in:
parent
c1f0d4d46c
commit
8fed0aa57d
|
@ -429,6 +429,9 @@ callback (using `!select()` to block) is provided as
|
||||||
.. _SQLAlchemy: http://www.sqlalchemy.org/
|
.. _SQLAlchemy: http://www.sqlalchemy.org/
|
||||||
.. __: http://www.postgresql.org/docs/8.4/static/libpq-async.html
|
.. __: http://www.postgresql.org/docs/8.4/static/libpq-async.html
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
:ref:`COPY commands <copy>` are currently not supported when a wait callback
|
||||||
|
is registered, but they will be probably implemented in a future release.
|
||||||
|
|
||||||
|
|
||||||
.. testcode::
|
.. testcode::
|
||||||
|
|
|
@ -116,6 +116,12 @@ if ((self)->conn->async_cursor != NULL) { \
|
||||||
"while an asynchronous query is underway"); \
|
"while an asynchronous query is underway"); \
|
||||||
return NULL; }
|
return NULL; }
|
||||||
|
|
||||||
|
#define EXC_IF_GREEN(cmd) \
|
||||||
|
if (psyco_green()) { \
|
||||||
|
PyErr_SetString(PyExc_NotImplementedError, #cmd " cannot be used " \
|
||||||
|
"with an asynchronous callback (yet)."); \
|
||||||
|
return NULL; }
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "psycopg/psycopg.h"
|
#include "psycopg/psycopg.h"
|
||||||
#include "psycopg/cursor.h"
|
#include "psycopg/cursor.h"
|
||||||
#include "psycopg/connection.h"
|
#include "psycopg/connection.h"
|
||||||
|
#include "psycopg/green.h"
|
||||||
#include "psycopg/pqpath.h"
|
#include "psycopg/pqpath.h"
|
||||||
#include "psycopg/typecast.h"
|
#include "psycopg/typecast.h"
|
||||||
#include "psycopg/microprotocols.h"
|
#include "psycopg/microprotocols.h"
|
||||||
|
@ -1206,6 +1207,7 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
|
||||||
EXC_IF_CURS_CLOSED(self);
|
EXC_IF_CURS_CLOSED(self);
|
||||||
EXC_IF_CURS_ASYNC(self, copy_from);
|
EXC_IF_CURS_ASYNC(self, copy_from);
|
||||||
|
EXC_IF_GREEN(copy_from);
|
||||||
|
|
||||||
quoted_delimiter = psycopg_escape_string((PyObject*)self->conn, sep, 0, NULL, NULL);
|
quoted_delimiter = psycopg_escape_string((PyObject*)self->conn, sep, 0, NULL, NULL);
|
||||||
if (quoted_delimiter == NULL) {
|
if (quoted_delimiter == NULL) {
|
||||||
|
@ -1311,6 +1313,8 @@ psyco_curs_copy_to(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
|
||||||
EXC_IF_CURS_CLOSED(self);
|
EXC_IF_CURS_CLOSED(self);
|
||||||
EXC_IF_CURS_ASYNC(self, copy_to);
|
EXC_IF_CURS_ASYNC(self, copy_to);
|
||||||
|
EXC_IF_GREEN(copy_to);
|
||||||
|
|
||||||
quoted_delimiter = psycopg_escape_string((PyObject*)self->conn, sep, 0, NULL, NULL);
|
quoted_delimiter = psycopg_escape_string((PyObject*)self->conn, sep, 0, NULL, NULL);
|
||||||
if (quoted_delimiter == NULL) {
|
if (quoted_delimiter == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
|
@ -1395,6 +1399,7 @@ psyco_curs_copy_expert(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
|
||||||
EXC_IF_CURS_CLOSED(self);
|
EXC_IF_CURS_CLOSED(self);
|
||||||
EXC_IF_CURS_ASYNC(self, copy_expert);
|
EXC_IF_CURS_ASYNC(self, copy_expert);
|
||||||
|
EXC_IF_GREEN(copy_expert);
|
||||||
|
|
||||||
sql = _psyco_curs_validate_sql_basic(self, sql);
|
sql = _psyco_curs_validate_sql_basic(self, sql);
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,13 @@ def test_suite():
|
||||||
suite.addTest(types_basic.test_suite())
|
suite.addTest(types_basic.test_suite())
|
||||||
suite.addTest(types_extras.test_suite())
|
suite.addTest(types_extras.test_suite())
|
||||||
suite.addTest(test_lobject.test_suite())
|
suite.addTest(test_lobject.test_suite())
|
||||||
|
|
||||||
|
if not green:
|
||||||
suite.addTest(test_copy.test_suite())
|
suite.addTest(test_copy.test_suite())
|
||||||
|
else:
|
||||||
|
import warnings
|
||||||
|
warnings.warn("copy not implemented in green mode: skipping tests")
|
||||||
|
|
||||||
suite.addTest(test_notify.test_suite())
|
suite.addTest(test_notify.test_suite())
|
||||||
suite.addTest(test_async.test_suite())
|
suite.addTest(test_async.test_suite())
|
||||||
suite.addTest(test_green.test_suite())
|
suite.addTest(test_green.test_suite())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user