Commit Graph

2327 Commits

Author SHA1 Message Date
Daniele Varrazzo
bcfcea4b49 Fixed reference leak in notify reception. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
2af29b467d Added missing points to the changelog. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
d8f4ed1a04 Fixed documentation and example for asynchronous notifications. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
6fecc36b7f Connection method 'executing()' renamed to 'isexecuting()'. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
7ee09353ec Connection method 'issync()' changed into the attribute 'async'. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
7cf52da969 Ensure to close the connections in the doctests to avoid deadlocks. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
ac6938a26a Fixed async documentation after cursor.poll() dropped. 2010-04-21 15:09:13 +01:00
Jan Urbański
a57a9976b4 Fix the NOTIFY example to use the correct APIs 2010-04-21 15:09:13 +01:00
Jan Urbański
067161d5f3 Remove fileno() and poll() from cursors
Instead, the code should be using the fileno() and poll() methods of
the cursor's connection. Handle the case when poll() is called on an
already built connection as a request to poll the asynchronous query
(if there is one) and get NOTIFY events.
Update the tests to reflect that change, add a test for NOTIFY.
2010-04-21 15:09:13 +01:00
Daniele Varrazzo
b7327a349d FAQs grouped in themes. 2010-04-21 15:09:13 +01:00
Jan Urbański
f06f557111 Add one more test for errors involving two cursors 2010-04-20 23:01:10 +01:00
Jan Urbański
c4ebc0f702 Handle errors in asynchronous queries.
Do it by keeping the reference to the last PGresult in the cursor and
calling pq_fetch() before ending the asynchronous execution. This
takes care of handling the possible error state of the PGresult and
also allows the removal of the needsfetch flag, since now after
execution ends the results are already fetched and parsed.
2010-04-20 23:01:01 +01:00
Federico Di Gregorio
249b3ef88f Merged tests from piro and jan async fixes branches 2010-04-14 10:01:37 +02:00
Jan Urbański
5f4ef5da13 Make connection.executing() be True during an async connection attempt. 2010-04-14 10:00:37 +02:00
Jan Urbański
463724690c Set the execution status to ASYNC_READ after flushing all output.
Without this a query that did not get flushed completely to the server
would cause cursor.poll() to always go into the curs_poll_send()
branch even if it was retuning ASYNC_READ.

Bug report by Daniele Varrazzo.
2010-04-14 09:56:44 +02:00
Jan Urbański
4574bde3a2 Check for possible errors from PQflush.
Noticed by Daniele Varrazzo.
2010-04-14 09:56:44 +02:00
Jan Urbański
61f890c317 Set the initial connection status to CONN_STATUS_SETUP.
Without it the changes in e79528f9aa1f7457573720fce5548302fefffd37 are
never used.
2010-04-14 09:56:44 +02:00
Jan Urbański
6108e4dc92 Make the first poll() of an asynchronous connection return POLL_WRITE.
This hides from the user the libpq's implementation detail of
requiring the first select() to wait for the connection socket to
become writable and makes it possible to have a uniform select loop
for both cursors and connections, in which you always start by polling
the object and then acting according to the result from poll().

Idea and implementation by Daniele Varrazzo.
2010-04-14 09:56:44 +02:00
Jan Urbański
4afc1baf35 Make polling a cursor that's not in an async query raise an exception.
If there is an asynchronous query, polling a cursor that did not
initiate it will raise an exception. Polling while there is no
asynchronous query underway still works, because the user needs to
have a way to get asynchronous NOTIFYs.
2010-04-14 09:56:44 +02:00
Federico Di Gregorio
a90935930b Merge remote branch 'piro/fix22' into python2 2010-04-14 08:57:30 +02:00
Federico Di Gregorio
eaa97def73 Applied GC patch from Michael Tharp 2010-04-14 08:50:16 +02:00
Daniele Varrazzo
431920b367 Added recipe to get Python floats from Postgres decimals in the FAQ. 2010-04-14 01:05:36 +01:00
Daniele Varrazzo
0ac4c8ac17 Typecasters section in the extensions doc reordered. 2010-04-14 00:41:03 +01:00
Daniele Varrazzo
d162c08cfa PY* and MX* typecasters imported into the extensions module. 2010-04-14 00:27:28 +01:00
Daniele Varrazzo
54e9c89ea4 DECIMAL typecaster imported into the extensions module. 2010-04-14 00:20:16 +01:00
Daniele Varrazzo
595dc7effa Added a test to check poll() correctly calls PQflush.
When a large query is sent to the backend (and probably in high
concurrency situations), writing the query could block. In
this case PQflush() should be called until it returns 0. The test checks
this is done correctly.
2010-04-11 01:05:31 +01:00
Daniele Varrazzo
88fe5f91d2 Fixed parameters parsing in the connection constructor.
Keyword arguments were silently discarded.
2010-04-11 00:30:54 +01:00
Daniele Varrazzo
47ff5a6b01 test_async made properly executable. 2010-04-11 00:06:54 +01:00
Federico Di Gregorio
b8953cb345 Fixed Python 2.4 compatibility breakage 2010-04-09 12:53:38 +02:00
Federico Di Gregorio
0a33ed01f5 Added test for refcounting/gc bug reported by Michael Tharp 2010-04-08 18:42:20 +02:00
Daniele Varrazzo
6aaa50703e Added documentation for the new asynchronous support. 2010-04-08 13:25:17 +01:00
Daniele Varrazzo
d197346ce3 Added test to check that connections subclasses can be asynchronous. 2010-04-08 12:51:33 +01:00
Daniele Varrazzo
236b97045e Dropped README.async files referring to pre-2.2. 2010-04-08 10:51:30 +01:00
Daniele Varrazzo
e8286084e9 Free the GIL in blocking operations in V2 COPY FROM. 2010-04-07 23:52:53 +01:00
Daniele Varrazzo
aeec583ff1 Ensure running COPY in blocking mode. 2010-04-07 23:41:32 +01:00
Daniele Varrazzo
b114e25c31 Added some COPY tests. 2010-04-07 23:41:32 +01:00
Daniele Varrazzo
7e0dcfdda5 Added pq_set_non_blocking utility function. 2010-04-07 23:41:18 +01:00
Daniele Varrazzo
d339466c6a Speedup of the copy functions.
Python objects are evaluated only once outside the I/O loops.
2010-04-07 18:22:31 +01:00
Daniele Varrazzo
5a75d693a3 Dropped warnings when compiling on Python 2.5 2010-04-07 18:12:24 +01:00
Daniele Varrazzo
c75ddea895 Pass the async parameter to the connection only if nonzero.
This avoids breaking connection subclasses redefining '__init__' (at
least when used sync, which is good for most of the people).
2010-04-05 18:31:09 +01:00
Daniele Varrazzo
c486136df7 Delegate the destruction of the PGconn to the connection finalization.
This way we can have an usable connection before complete
initialization: this will be required to allow a Python callback to
interact with connect().
2010-04-05 18:19:37 +01:00
Federico Di Gregorio
012e2e3c72 Preparing 2.2.0 release candidate 1 2010-04-05 17:06:35 +02:00
Federico Di Gregorio
c1a24f4ca2 NOTIFYs fix and poll status changes
POLL_OK has been changed from 3 to 0 to let the user specify a short loop
just as "if not curs.poll()" instead of having to check for write and read
separately. For an example of this, see examples/notify.py.
2010-04-05 16:52:25 +02:00
Jan Urbański
e15bc9da05 Adapt the tests to recent changes
Some methods were forbidden in asynchronous mode, the isolation level
of an asynchronous connection is not always 0 and these changes
influenced expected test results.
2010-04-05 16:28:39 +02:00
Jan Urbański
31f60be000 Be a bit more explicit 2010-04-05 16:27:59 +02:00
Jan Urbański
58eb868db6 Avoid the possibility when curs_get_last_result would block
It was trying to get all pending results from the connection and if
the client sent many and anyone except the first one would not be
immediately available the loop in curs_get_last_result would call
PQgetResult blockingly.
Avoid that by calling PQisBusy every time and telling the client to
wait for more data if it returns 1.
2010-04-05 16:27:39 +02:00
Jan Urbański
25a609c9a7 Handle initial connection queries being sent partly
The CONN_STATUS_SENT_* statuses were not being handled at all, and
they indicate that a query has been sent, but not fully, so the client
should wait for the socket to become writable again and flush the output.
2010-04-05 16:25:17 +02:00
Jan Urbański
b99eac18f8 Make cursor.scroll() raise an exception in asynchronous mode
The exception is raised if an asynchronous query is in progress,
otherwise it will behave normally (since the data is already on the
client side).
2010-04-05 16:24:45 +02:00
Jan Urbański
727670c269 Make some methods raise an exception in asynchronous mode
The methods changed are connection.commit(), rollback(), reset(),
set_isolation_level(), set_client_encoding(), lobject(), cursor(str)
as well as cursor.execute() and cursor.callproc() if another query is
in progress and cursor.executemany(), cursor.copy_{from,to,expert)().
2010-04-05 16:23:44 +02:00
Jan Urbański
01799e9137 Make asynchronous connections produce asynchronous cursors by default
Drop the async kwarg from cursor.execute(), cursors created by
asynchronous connections will be asynchronous by default, ones created
by synchronous connections will be synchronous.

Mind that this might break third party subclasses of
psycopg2.extensions.cursor, if they try to chain to the superclass in
their execute() implementation and are passing the async kwarg. The
example cursors in psycopg2.extras have been fixed no to do that.
2010-04-05 11:41:32 +02:00