diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-04-21 12:42:25 +0100 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-04-21 15:21:33 +0100 |
| commit | 8fed0aa57d588c3655423a3d25ece01662719836 (patch) | |
| tree | d5c6ec1c41a7eb04dff6a483faf09d7c4a128f27 | |
| parent | c1f0d4d46cb1f177e5966ed2d8bba413410ec424 (diff) | |
| download | psycopg2-8fed0aa57d588c3655423a3d25ece01662719836.tar.gz | |
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.
| -rw-r--r-- | doc/src/advanced.rst | 3 | ||||
| -rw-r--r-- | psycopg/cursor.h | 6 | ||||
| -rw-r--r-- | psycopg/cursor_type.c | 5 | ||||
| -rwxr-xr-x | tests/__init__.py | 8 |
4 files changed, 21 insertions, 1 deletions
diff --git a/doc/src/advanced.rst b/doc/src/advanced.rst index 13def38..a595ce5 100644 --- a/doc/src/advanced.rst +++ b/doc/src/advanced.rst @@ -429,6 +429,9 @@ callback (using `!select()` to block) is provided as .. _SQLAlchemy: http://www.sqlalchemy.org/ .. __: 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:: diff --git a/psycopg/cursor.h b/psycopg/cursor.h index 68a087a..613ed9d 100644 --- a/psycopg/cursor.h +++ b/psycopg/cursor.h @@ -116,6 +116,12 @@ if ((self)->conn->async_cursor != NULL) { \ "while an asynchronous query is underway"); \ 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 } #endif diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 2d4751e..17d1972 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -34,6 +34,7 @@ #include "psycopg/psycopg.h" #include "psycopg/cursor.h" #include "psycopg/connection.h" +#include "psycopg/green.h" #include "psycopg/pqpath.h" #include "psycopg/typecast.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_ASYNC(self, copy_from); + EXC_IF_GREEN(copy_from); quoted_delimiter = psycopg_escape_string((PyObject*)self->conn, sep, 0, NULL, 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_ASYNC(self, copy_to); + EXC_IF_GREEN(copy_to); + quoted_delimiter = psycopg_escape_string((PyObject*)self->conn, sep, 0, NULL, NULL); if (quoted_delimiter == NULL) { PyErr_NoMemory(); @@ -1395,6 +1399,7 @@ psyco_curs_copy_expert(cursorObject *self, PyObject *args, PyObject *kwargs) EXC_IF_CURS_CLOSED(self); EXC_IF_CURS_ASYNC(self, copy_expert); + EXC_IF_GREEN(copy_expert); sql = _psyco_curs_validate_sql_basic(self, sql); diff --git a/tests/__init__.py b/tests/__init__.py index df4b7a1..eeeb508 100755 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -51,7 +51,13 @@ def test_suite(): suite.addTest(types_basic.test_suite()) suite.addTest(types_extras.test_suite()) suite.addTest(test_lobject.test_suite()) - suite.addTest(test_copy.test_suite()) + + if not green: + 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_async.test_suite()) suite.addTest(test_green.test_suite()) |
