Commit Graph

796 Commits

Author SHA1 Message Date
Daniele Varrazzo
a50a91fc7b No need to put connection fields to zero: tp_alloc already did. 2010-12-21 04:02:14 +00:00
Daniele Varrazzo
7b5d80d36d Added a few missing encodings.
EUC_CN, EUC_JIS_2004, ISO885910, ISO885916, LATIN10, SHIFT_JIS_2004.
2010-12-21 04:02:14 +00:00
Daniele Varrazzo
657bcb4828 Encodings mapping reordered in a more maintainable order. 2010-12-21 04:02:14 +00:00
Daniele Varrazzo
4635c2aa4f Import structmember/stringobject headers from python.h.
stringobject is not to be imported with Python 3.
2010-12-21 04:02:13 +00:00
Daniele Varrazzo
9b30147341 Using PyVarObject_HEAD_INIT macro. 2010-12-21 04:02:13 +00:00
Daniele Varrazzo
8dfa9915eb Using Py_TYPE and Py_REFCNT macros. 2010-12-21 04:02:13 +00:00
Daniele Varrazzo
2196ff5488 Added a few compatibility macros defined in Py 2.6. 2010-12-21 04:02:13 +00:00
Marti Raudsepp
a08419406c Don't segfault when PQparameterStatus(DateStyle) returns NULL
pgbouncer for example does not pass on DateStyle.
2010-12-18 15:27:15 +00:00
Daniele Varrazzo
89f70bdb3c Changed Python const RO -> READONLY. 2010-12-12 13:39:32 +00:00
Daniele Varrazzo
6d7916cfe1 Internal imports simplified.
.c files only need to import psycopg.h: it will in turn import
dependencies from Python and libpq and configure.h. psycopg.h should be
the first to be imported, so the basic imports are not required in
the .h's

As a guideline I'm trying to import from the most specific to the most
generic to detect missing imports in the .h's.
2010-12-12 13:39:32 +00:00
Daniele Varrazzo
9fa1eac2b4 Dropped unused include file. 2010-12-12 13:39:32 +00:00
Daniele Varrazzo
557e28d744 Dropped interface for two private functions.
Note: the functions are private because typecast.c imports the .c's of
typecast_[mx]datetime, not the .h's.

Work around the warning for 'skip_until_space' not used with an #ifdef.
Furthermore, those functions are now static.
2010-12-04 13:51:21 +00:00
Daniele Varrazzo
288f9ee809 Work around CentOS 5.5 x86_64 buld problem.
Closes ticket #23
2010-12-04 13:51:21 +00:00
Daniele Varrazzo
0c7b0a943b A prepared connection can't be canceled. 2010-11-28 12:15:26 +00:00
Jan Urbański
751bfa1ea6 Support query cancellation.
Add a cancel() method do the connection object that will interrupt
the current query using the libpq PQcancel() function.
2010-11-28 11:50:02 +00:00
Daniele Varrazzo
fdf1ba1aac Dropped notices hack to get COPY errors from V2 protocol. 2010-11-22 00:49:07 +00:00
Daniele Varrazzo
163cf5bfb4 mx.DateTime module initialized as it is supposed to be.
No need to pass the api pointer around. Dropped compiler warnings.
2010-11-19 00:28:49 +00:00
Daniele Varrazzo
3e3aa676a9 datetime module initialized as it is supposed to be.
Dropped compiler warnings. It wouldn't blow up if any api was called.
No need to pass type pointers around.
2010-11-19 00:28:39 +00:00
Daniele Varrazzo
576b01f6a3 Functions exported to drop warnings. 2010-11-19 00:20:49 +00:00
Daniele Varrazzo
67793ed989 Compiler warning dropped. 2010-11-18 23:13:16 +00:00
Daniele Varrazzo
bcacdc8461 Added enum with possilbe isolation level states.
Also, general isolation levels cleanup and tests added.
2010-11-18 00:31:51 +00:00
Daniele Varrazzo
c3c54aab38 Don't clobber exception if conn_switch_isolation_level fails.
Which shouldn't.
2010-11-17 01:43:50 +00:00
Daniele Varrazzo
e1a04bec0e Don't inconditionately run a query at connection to set datestyle to ISO.
Run it only if PQparameterStatus() reports the datestyle is set to
something different.
2010-11-16 18:15:00 +00:00
Daniele Varrazzo
15bba2966f Don't run a query at connection to detect client encoding.
Use PQparameterStatus() instead. This is only guaranteed in protocol 3.
2010-11-16 10:16:52 +00:00
Daniele Varrazzo
a88d7ab424 Dropped support for protocol 2.
Dropped both the setup constant allowing conditional compiling and the
code specific to V2 protocol (mostly COPY and error handling).
2010-11-16 01:08:50 +00:00
Daniele Varrazzo
73265e7ece Refuse connection with server with protocol version 2.
This cuts off server whose version is older than 7.4. But enables us to
remove large portions of code rarely used and tested (e.g. p2 copy) and
will allow us to drop the query we do at each connection to establish
the client encoding and the datestyle.
2010-11-16 01:01:32 +00:00
Jean-Baptiste Quenot
b8ce51d9c2 Mention connection object in debug logs 2010-11-13 03:56:23 +00:00
Daniele Varrazzo
cd19f9115d Fixed notices order (ticket #9). 2010-11-11 11:54:43 +00:00
Daniele Varrazzo
92ee893f0f Functions unused outside the module marked static. 2010-11-10 15:50:05 +00:00
Daniele Varrazzo
a39e98f9e5 Check the presence of a mro.
The mere presence of the Py_TPFLAGS_HAVE_CLASS doesn't ensure it is
there.
2010-11-09 14:28:00 +00:00
Daniele Varrazzo
ed6a4c8b1a Dropped PyArg_ParseTuple() calls in functions taking no arguments. 2010-11-09 03:18:54 +00:00
Daniele Varrazzo
2dc28ee7d8 Less lookups and more efficient calls in microprotocols_adapt().
Also more explicit handling of the exception indicator.
2010-11-09 02:41:43 +00:00
Daniele Varrazzo
753b580d72 Less lookups and more efficient calls in microprotocols_getquoted(). 2010-11-09 02:21:21 +00:00
Daniele Varrazzo
422fede38e Replaced PyObject_CallFunction() with *ObjArgs() where more efficient. 2010-11-09 01:49:22 +00:00
Jason Erickson
c79d20855a Win32 *time_r fix
Fixed the thread safetyness of the Windows *time_r functions.
2010-11-09 00:20:58 +00:00
Daniele Varrazzo
d601ab8239 fixed crash in pdecimal_str with a few Python 2.5.x releases.
is_finite() is not available in 2.5.1, it is in 2.5.5 but is officially
supported only since 2.6.
2010-11-09 00:14:22 +00:00
Daniele Varrazzo
af3681cc1c Fixed repr for Decimal wrapper. 2010-11-09 00:09:19 +00:00
Daniele Varrazzo
916c172cf7 Dropped file imported by mistake. 2010-11-09 00:09:09 +00:00
Daniele Varrazzo
62d3a1533b Use the adapter of an object superclass if available. 2010-11-08 01:35:06 +00:00
Daniele Varrazzo
225b276de5 Use faster function to build tuples in adaptation.
Fixed a refcount bug too.
2010-11-08 01:28:01 +00:00
Daniele Varrazzo
df05ea7a33 Py_TYPE defined as it is in Python 2.6. 2010-11-08 01:28:01 +00:00
Daniele Varrazzo
4125b3fce0 Added compatibility macro for pre 2.6 2010-11-05 12:59:32 +00:00
Daniele Varrazzo
2480f587e1 Added warning note about equivalence inconsistence between Notify and tuples. 2010-11-05 09:34:52 +00:00
Daniele Varrazzo
77c0ab02d8 The Notify type is hashable.
If there is no payload, hash the same way the equivalent 2-tuple does.
Otherwise hash on the payload too.
2010-11-05 09:34:52 +00:00
Daniele Varrazzo
56ae1fe4bf Payload default is the empty string. 2010-11-05 09:34:52 +00:00
Daniele Varrazzo
9c58c01e0f Added comparison between Notify objects and Notify or tuple.
Explicit comparison with the tuple is required if we want to make
Notify() == (pid, channel) work: item access is not enough (and a test
in the suite fails if we get this wrong).
2010-11-05 09:34:52 +00:00
Daniele Varrazzo
90e0e2f47d Added documentation for the Xid object. 2010-11-05 09:34:50 +00:00
Daniele Varrazzo
3e658c33b5 Ensure unicode is accepted as type for transaction ids.
We don't do somersaults to ensure people can use snowmen as transaction
ids anyway: it would require passing the connection to xid_ensure and
down below to use the correct encoding.
2010-11-05 09:34:50 +00:00
Daniele Varrazzo
4f3976681a Added Xid.from_string() constructor.
It exposes the parsing rules used in restore.
2010-11-05 09:34:49 +00:00
Daniele Varrazzo
2f29429e88 Expose the Xid object in the extension module. 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
f0f5f095c7 Fixed handling of commit/rollback prepared in green mode 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
5dbeeba0f2 Raise NotSuppoertdError if tpc is used with PostgreSQL < 8.1 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
ab8e145063 Encoding/decoding in base64 refactored. 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
3312897e5d Added str() and repr() for Xid objects. 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
4fdcfe365c xid_get_tid returns a Python string, not a buffer. 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
774be1d616 Dropped XID_UNPARSED: we use format_id = None for PG xact ids. 2010-11-05 09:34:49 +00:00
Daniele Varrazzo
978cac3a1b XA transaction ids can be decoded from PostgreSQL transaction ids. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
6309e038e5 Dropped pg_xact_id from XidObject 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
c0c116dcc4 Use pgjdbc algorithm to convert XA xids into strings. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
17d70babb1 Keep the GIL while converting the xid into the PostgreSQL transaction id. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
56c02b0f94 Added tpc_recover method. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
09983db6ed Added tpc_commit and tpc_rollback methods. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
4f66de494b Added tpc_prepare and CONN_STATUS_PREPARED. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
4588fa50f2 begin and commit can't be called during a two-phase transaction. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
98c5b1d374 Added tpc_begin() and current xid on connection. 2010-11-05 09:34:48 +00:00
Daniele Varrazzo
60ee39fa3d Copyright of TPC files moved to LGPL V3.
With the permission of James Henstridge.
2010-11-05 09:34:47 +00:00
Daniele Varrazzo
8bfd34faf2 hook up two phase commit tests.
By James Henstridge on 2008-07-24.

Merged from lp:~jamesh/psycopg/two-phase-commit/revision/359
2010-11-05 09:34:47 +00:00
Daniele Varrazzo
7a9d678050 There is no point in allowing subclasses of Xid.
By James Henstridge on 2008-07-24.

Merged from lp:~jamesh/psycopg/two-phase-commit/revision/358
2010-11-05 09:34:47 +00:00
Daniele Varrazzo
22aea9114b implement sequence behaviour, as required for transaction IDs.
By James Henstridge on 2008-07-24.

Merged from lp:~jamesh/psycopg/two-phase-commit/revision/357
2010-11-05 09:34:47 +00:00
Daniele Varrazzo
0021e56d80 Added connection.xid() and related objects.
By James Henstridge on 2008-07-23.

Merged from lp:~jamesh/psycopg/two-phase-commit/revision/356

* psycopg/connection_type.c (psyco_conn_xid): add a
Connection.xid() method that instantiates Xid objects.

* psycopg/psycopgmodule.c (init_psycopg): initialise the Xid
object type.

* psycopg/xid.h:
* psycopg/xid_type.c: Implement a basic transaction ID object for
use in two phase commit.
2010-11-05 09:34:47 +00:00
Daniele Varrazzo
1a0fca09d9 Added documentation for the Notify object. 2010-11-05 09:34:47 +00:00
Daniele Varrazzo
4ec298e112 Notify object exposed in the extensions module. 2010-11-05 09:34:47 +00:00
Daniele Varrazzo
8db9c7085d Added repr method for Notify object. 2010-11-05 09:34:47 +00:00
Daniele Varrazzo
f435d15c95 Adding Notify object with payload. 2010-11-05 09:34:46 +00:00
Daniele Varrazzo
7e482756c5 Use PQfreemem to free memory allocated by the libpq.
Bug reported by Anton Kovalev.
2010-10-08 14:26:40 +01:00
Daniele Varrazzo
6e71b3db05 Dropped PSYCOPG_OWN_QUOTING.
It was deprecated for version 2.1. There are bugs to be fixed made more
complex by its presence and it doesn't keep into account PostgreSQL 9.0
new binary format.

Time to go!
2010-10-08 12:27:47 +01:00
Daniele Varrazzo
baf65a0dda Fixed access to freed memory in conn_get_isolation_level().
Bug reported by Anton Kovalev.
2010-10-08 12:02:53 +01:00
Daniele Varrazzo
bc2aefeacf cursor.mogrify() accepts unicode queries. 2010-10-05 03:13:44 +01:00
Daniele Varrazzo
5b4d366f4e Common code in execute() and mogrify() merged. 2010-10-05 01:43:23 +01:00
Daniele Varrazzo
2081ceffde Don't execute a ROLLBACK on close()/GC.
The command wasn't sent since 2.2.0 due to a bug, but after a ML
discussion this behaviour proved more correct so the bug has become a
feature.
2010-09-23 23:28:30 +01:00
Federico Di Gregorio
557608f715 Applied spelling fixes patch from Peter Eisentraut 2010-07-18 12:14:46 +02:00
Daniele Varrazzo
deb2d9050f Exceptions raised by the columns iterator propagated. 2010-07-10 00:12:50 +01:00
Daniele Varrazzo
3773b50bb3 Propagate iterable exceptions to the executemany caller. 2010-07-09 23:22:35 +01:00
Daniele Varrazzo
305d86f38a Handle time zones with seconds in the UTC offset.
The offset is rounded to the nearest minute.
2010-05-20 02:16:04 +01:00
Jason Erickson
1f1133b871 Micrsoft Visual C Compile Fix
Moved the declarations of variables/pointers to the beginning of the block, where MSVC wants them.
2010-05-17 09:06:14 +02:00
Federico Di Gregorio
6521fb5a44 Fixed error related to calling C typecasters from Python ones 2010-05-15 19:34:56 +02:00
Daniele Varrazzo
c46a1dad63 Fixed TimeFromTicks for second values > 59.5. 2010-05-15 14:27:24 +01:00
Daniele Varrazzo
afea19651c Fixed TimestampFromTicks for second values > 59.5.
Bug reported and fixed by Jozsef Szalay on 2010-05-06 at 14:11:59.999920.
2010-05-15 14:27:24 +01:00
Daniele Varrazzo
5e3f240ac9 Cast datetime into timestamptz when the tzinfo field is set. 2010-05-15 14:27:23 +01:00
Daniele Varrazzo
bf1c76b792 Explicit cast of the SQL representation of time-related objects.
Allow the objects to be recognized as the proper type by Postgres in not
strong contexts: problem reported by Peter Eisentraut.

Added tests to check the types are respected in a complete Py -> PG ->
Py roundtrip without context.
2010-05-15 14:27:23 +01:00
Daniele Varrazzo
e8c2a14362 Added typecasters for arrays of specific MX/Py time-related types. 2010-05-15 14:27:23 +01:00
Daniele Varrazzo
c8aef26e15 Adapt buffer objects using an explicit cast on the string literal.
Don't rely on Postgres casting the literal according to the context:
this doesn't work e.g. passing the object as function argument where a
function with the same name but taking a text exists. It doesn't work
either when the object is in an ARRAY construct.

Added test to check the type is respected in a complete Py -> PG -> Py
roundtrip without context.

Bug and solution reported by Peter Eisentraut.
2010-05-15 14:27:23 +01:00
Daniele Varrazzo
73db6bee01 Keep the connection in blocking mode unless it is not async.
Dropped set/unset nonblocking mode for copy and lobject operations:
lobjects don't work in nonblocking mode so they will hardly be supported
in green/async branches.  Support for copy is still feasible, but it
will be done in other code paths (called by poll).
2010-05-09 20:37:48 +01:00
Daniele Varrazzo
e29424a230 Dropped large object support when psycopg is in green mode.
Async mode and large object are not compatible, albeit I haven't found
an authoritative source yet.
2010-05-09 20:34:02 +01:00
Daniele Varrazzo
2596cf7125 Simplified psyco_wait() function interface. 2010-04-25 23:08:08 +01:00
Daniele Varrazzo
8efa1fa6af Dropped compiling warning. 2010-04-25 23:08:08 +01:00
Daniele Varrazzo
cb40342afa poll implementation for async, sync and green connection unified. 2010-04-23 13:28:49 +01:00
Daniele Varrazzo
0da4befe78 Added function to advance the state after flush attempt. 2010-04-23 13:28:38 +01:00
Daniele Varrazzo
f3b3483df3 Added a function to advance the state after a read attempt.
Dropped calls to PQisBusy/PQconsumeInput in the connection code.
2010-04-23 13:24:36 +01:00
Daniele Varrazzo
1edbd16577 Dropped curs_get_last_result function.
The result is read from a pqpath function and put on the async_cursor by
a function that also checks for is presence and dismiss it after its
usage.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
a66de9808f Added 'pq_get_last_result()' function.
The function reads the last result after an asynchronous query.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
5be0fc52ca Reusable parts of the green polling refactored out.
The functions _conn_poll_connecting() and _conn_poll_query() will be
usable by the async connections too.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
df959c20be Making sync and async connection setup somewhat more consistent. 2010-04-23 13:24:35 +01:00
Daniele Varrazzo
d915cb12a8 Functions to poll in ready state moved on the connection. 2010-04-23 13:24:35 +01:00
Daniele Varrazzo
9f5d835de6 Functions conn_poll_* renamed to conn_poll_connect_*.
These functions are used only during async connections, not for polling
afterwards.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
7af0bf0b54 Set the async_status to ASYNC_DONE after a query with wait callback.
Failing in doing that broke notifications reception.

The responsibility for changing the async_status has been moved to the
poll function: this is consistent with how the async branch is
implemented.

With this commit all the test suite passes in "green" mode.
2010-04-21 16:20:16 +01:00
Daniele Varrazzo
d71520db9a Read the server version only after connection established. 2010-04-21 15:31:07 +01:00
Daniele Varrazzo
8fed0aa57d 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.
2010-04-21 15:21:33 +01:00
Daniele Varrazzo
c1f0d4d46c Read notifications when polling an idle sync connection. 2010-04-21 15:21:33 +01:00
Daniele Varrazzo
4bb0c3bdf6 Use the wait callback in the connection setup queries. 2010-04-21 15:21:33 +01:00
Daniele Varrazzo
0ec73a18b4 'pq_execute_command_locked()' calls the wait callback if set.
The function is called without holding the GIL. Because it is necessary
to execute the Python callback if set, we need to re-acquire the GIL and
tnen release it again. In order to correctly bookkeep the thread state,
the pointer of the _save variable is passed to the function.
2010-04-21 15:21:33 +01:00
Daniele Varrazzo
7a06c0455b Try to restore the connection state after a wait callback error. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
a54932ee9c Added documentation for the green features. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
127f92f9db Changed 'psyco_wait()' to only take the connection. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
0dd5d3f1d9 Correctly flush async queries in 'green' mode. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
8ba0f00d21 Added 'get_wait_callback()' function. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
a7c41a0388 'pq_execute()' uses the user wait callback if provided. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
55270cab9f 'poll()' can raise a Python exception in case of error. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
442b3b2f6c Added 'psyco_exec_green()' to replace 'PQexec' using the user-provided block function. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
6dd6bee217 Added async read support to 'connection.poll()'. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
1607f89bb1 Avoid the locks dance when reading the connection socket number.
It is a fast and non critical operation, so the lock is not required.
Furthermore, called from the wait callback creates a deadlock.
2010-04-21 15:21:32 +01:00
Daniele Varrazzo
389ad08965 Use the wait callback during connection if set. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
04d66a6c82 Added poll implementation for sync connection with external wait. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
1446f046e9 Added wait callback and functions to deal with it. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
02a28ff028 Notifications are automatically read after each query.
Added tests for basic notifications process.
2010-04-21 15:09:14 +01:00
Daniele Varrazzo
12ef826d50 Dropped redundant call to conn_notice_process().
If the connection is sync, notices will be processed by pq_fetch()
downstream.

If the connection is async, here we have only sent the query: no result
is ready yet, and neither notices have had a chance to arrive: they will
be retrieved later by pq_is_busy().

Added tests to check the above statement don't break.
2010-04-21 15:09:14 +01:00
Daniele Varrazzo
bcfcea4b49 Fixed reference leak in notify reception. 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
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
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
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
88fe5f91d2 Fixed parameters parsing in the connection constructor.
Keyword arguments were silently discarded.
2010-04-11 00:30:54 +01:00
Federico Di Gregorio
b8953cb345 Fixed Python 2.4 compatibility breakage 2010-04-09 12:53:38 +02: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
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
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
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
Jan Urbański
d8ab5ac8a1 Make asynchronous connections always use autocommit
Clients using async connections are expected to do their own
transaction management by sending (asynchronously) BEGIN and COMMIT
statements.
As a bonus, it allows to drop one step from the async connection
building, namely getting the default isolation level from the server.
2010-04-05 11:37:06 +02:00
Jan Urbański
062a9602ae Ref the async cursor before storing it in the connection 2010-04-05 11:36:09 +02:00
Jan Urbański
91ef0e09ed Change the API for asynchronous queries to use cursor.poll()
The isread() API was not safe, because the query might have not been
sent fully to the server after calling execute(). To make the async
API complete, a similar mechanism to async connections must be used.

The cursor now has a poll() method that you would use identically to
the poll() method of the connection class.
2010-04-05 11:31:50 +02:00
Jan Urbański
9b259a8a54 Disallow some methods depending on the connection's sync/async mode 2010-04-05 11:31:37 +02:00
Federico Di Gregorio
34317dc4c3 Support asynchronous connection building
After calling psycopg2.connect(dsn, async=True) you can poll the
connection that will tell you whether its file descriptor should be
waited on to become writable or readable or that the connection
attempt has succeeded.

Edited commit by Jan to not expose internal state in extensions.py.
2010-04-05 11:30:03 +02:00
Jan Urbański
1f6ffbba0f Block and clear the result of asynchronous queries where necessary
Remove the big loop in pq_fetch with the select() call, among
others. Code paths that don't support asynchronous queries should now
be adequately guarded.
2010-04-05 11:28:20 +02:00
Federico Di Gregorio
3d2c315049 Checks for pointers should be explicit, i.e., (ptr != NULL) 2010-04-05 11:27:34 +02:00
Jan Urbański
cc37fd1ea9 Add curs_get_last_result, a function to get the last result from a connection 2010-04-05 11:24:57 +02:00
Jan Urbański
75a0299a48 Add pq_flush, a function to flush the output buffer 2010-04-05 11:07:53 +02:00
Federico Di Gregorio
3f2c1f6489 /me does not like empty for loops 2010-04-05 11:07:19 +02:00
Jan Urbański
53748443d8 Make pq_clear_async clear the whole pending result and export it 2010-04-05 11:01:44 +02:00
Jan Urbański
e0d789466a Support large objects truncating.
The lobject.truncate(len=0) method will be available if psycopg2 has
been built against libpq from 8.3 or later (which is when the lobject
truncating support has been introduced).
2010-03-29 09:19:35 +02:00
Federico Di Gregorio
855674faf1 Fixed Python 2.4 segfault related to decimal implementation 2010-02-28 20:52:03 +01:00
Federico Di Gregorio
192034dc38 Fixed problem with decimal.Decimal conversions 2010-02-21 01:04:00 +01:00
Daniele Varrazzo
cf3b7e7e50 Whitespace fixed 2010-02-14 19:45:22 +00:00
Daniele Varrazzo
74403ff5a8 Fixed newline in docstring. 2010-02-14 00:39:48 +01:00
Daniele Varrazzo
04db8e7428 Fixed docstring for 'QueryCanceledError' exception. 2010-02-14 00:35:48 +01:00
Federico Di Gregorio
611606d532 Changes license to LGPL3 + OpenSSL exception on all source files 2010-02-12 23:34:53 +01:00
Federico Di Gregorio
bcc836c661 Now adapt() errors include the type name 2009-11-25 11:51:54 +01:00
Federico Di Gregorio
7b730f3935 Fixed float loss of precision 2009-11-09 09:17:05 +01:00
Jason Erickson
5a3e07a610 Rearranged code to fix recent MSVC errors
Rearranged code to fix recent MSVC errors, such as mutex locking in conn_setup
to after the delcarations of variables.
2009-10-04 23:38:16 +02:00
Jason Erickson
0f00ee129d Moved declarations of varaibles/pointers to the beginning of functions
Moved the declarations of varaibles/pointers to the beginning of the functions,
where MSVC requires them to be defined.
2009-10-04 23:35:29 +02:00
Federico Di Gregorio
7022269b3d Fixed a deadlock when using the same connection from multiple threads 2009-10-04 12:02:02 +02:00
Federico Di Gregorio
3a6911216b Fixed problem with large writes in large objects code 2009-08-09 17:05:16 +02:00
Federico Di Gregorio
36aff2f73d Implemented connection.reset() 2009-08-09 16:19:08 +02:00
Federico Di Gregorio
4c3e2ad94b Fixed problem with lots of columns in COPY operations 2009-08-09 15:13:42 +02:00
Federico Di Gregorio
091102a919 Preparing release 2.0.11 2009-05-09 14:52:16 +02:00
Federico Di Gregorio
3935c019fe Fixed error in fetchXXX methods 2009-05-09 14:28:40 +02:00
Federico Di Gregorio
85fdc828e7 Fix to double free segfault in cursor 2009-04-20 20:19:55 +02:00
Federico Di Gregorio
5db66038fe Fix to double free segfault in connection 2009-04-19 16:51:31 +02:00
Federico Di Gregorio
5dab867db4 Added get_parameter_status() implementation 2009-04-19 16:42:06 +02:00
Federico Di Gregorio
39d6d8ad11 Exposed protocol_version and server_version 2009-04-19 16:36:10 +02:00
Federico Di Gregorio
bd19e3148c Removed calls to PyMem_XXX when not holding the GIL 2009-04-07 09:25:05 +02:00
Federico Di Gregorio
16c2a8fc81 Cleaned conn_notice_callback() to run without the GIL 2009-04-04 19:17:40 +02:00
Federico Di Gregorio
0b0639dae5 Fixed error when adapt()ing None 2009-03-09 21:45:49 +01:00
Federico Di Gregorio
a3ce636be0 Fixed error in register_type() 2009-03-02 10:56:53 +01:00
Federico Di Gregorio
4077711050 More cross-platform build fixes 2009-03-02 09:19:23 +01:00
Federico Di Gregorio
5c0cfa86bf isinf() for Solaris 2009-02-27 11:02:45 +01:00
James Henstridge
9067bde803 * psycopg/utils.c (psycopg_escape_string): same here.
* psycopg/adapter_binary.c (binary_escape): simplify PostgreSQL
	version check.

	* setup.py (psycopg_build_ext.finalize_options): use a single
	define of the PostgreSQL version in a form that can easily be used
	by #ifdefs.
2009-02-17 16:00:52 +09:00
James Henstridge
2a94dfae47 * tests/test_dates.py (DatetimeTests, mxDateTimeTests): full test
coverage for datetime and time strings with and without time zone
	information.

	* psycopg/typecast_datetime.c (typecast_PYDATETIME_cast): adjust
	to handle the changes in typecast_parse_time.
	(typecast_PYTIME_cast): add support for time zone aware time
	values.

	* psycopg/typecast_mxdatetime.c (typecast_MXDATE_cast): make sure
	that values with time zones are correctly processed (even though
	that means ignoring the time zone value).
	(typecast_MXTIME_cast): same here.

	* psycopg/typecast.c (typecast_parse_time): Update method to parse
	second resolution timezone offsets.
2009-02-17 15:03:33 +09:00
James Henstridge
ba8be438bb * psycopg/typecast.c (typecast_parse_time): Fix up handling of
negative timezone offsets with a non-zero minutes field.

	* tests/test_dates.py (DatetimeTests): Add tests for time zone
	parsing.  The test for HH:MM:SS time zones is disabled because we
	don't currently support it.
2009-02-17 12:58:45 +09:00
Federico Di Gregorio
41dd7a1095 Compile again on modern FreeBSD 2009-02-16 10:00:34 +01:00
Federico Di Gregorio
f9fa711f03 Modified executemany() to return modified rows count 2009-02-07 18:02:14 +01:00
Federico Di Gregorio
eb25f9f154 Added adapter to handle float('inf') and float('nan') 2009-01-23 00:09:20 +01:00
Federico Di Gregorio
e22451736a register_type() now works on connection and cursor subclasses 2009-01-22 11:02:38 +01:00
Federico Di Gregorio
78c0765367 Merge from public trunk 2009-01-10 18:51:45 +01:00
Federico Di Gregorio
aeb5080208 Fixed isready() not throwing exception on error 2009-01-10 18:48:08 +01:00
James Henstridge
83b03e5e36 If we are depending on Python 2.4, we don't need to make decimal module
support conditional.
2008-12-27 00:03:11 +09:00
James Henstridge
345a254ca0 Remove conditionals on support for booleans and datetimes, since they
are guaranteed to be available in Python 2.4.
2008-12-26 23:46:35 +09:00
James Henstridge
e7b8d6505e Remove backward compatibility support for Python versions older than
2.4, since we don't really support them any way.
2008-12-26 09:37:44 +09:00
Federico Di Gregorio
5480cf5332 Fixed memory leak in lobject 2008-12-04 16:58:05 +01:00
Federico Di Gregorio
4eb295a8ca Patch from Jason Erickson to build on MSVC 2008-11-26 09:51:53 +01:00
Federico Di Gregorio
5c982d90f0 Unified string quoting 2008-11-25 19:18:17 +01:00
Federico Di Gregorio
4e359f6f05 Applied COPY patch from Alejandro Dubrovsky (missing files and project) 2008-11-25 17:46:15 +01:00
Federico Di Gregorio
c1d6073531 Applied COPY patch from Alejandro Dubrovsky 2008-11-25 17:45:22 +01:00
James Henstridge
cc2aa0a9ca * psycopg/psycopg.h (NotSupportedError_doc): clean up
spelling/grammar a bit, using exception description from the PEP.
2008-09-23 17:22:37 +08:00
Federico Di Gregorio
f6a25ccdf0 Build fix from Jorgen Austvik 2008-08-02 10:30:36 +02:00
Federico Di Gregorio
ceee4c816f Merge from jh 2008-07-26 15:10:02 +02:00
Federico Di Gregorio
e95a4d9d2e get_backend_pid() patch and fixes 2008-07-26 15:09:20 +02:00
James Henstridge
a2f3e4a3ac * psycopg/lobject_type.c (lobject_setup): use
FORMAT_CODE_PY_SSIZE_T in Dprintf() call for 64-bit compatibility
when using Python 2.5 or later.
(lobject_dealloc): same here.
2008-07-23 16:57:10 +08:00
James Henstridge
0aec2840d8 Merge support for cyclic GC in relevant types that psycopg defines. 2008-07-23 16:50:24 +08:00
James Henstridge
2273b79be9 Use Py_CLEAR() in a few more places, and do INCREF's before setting
struct members rather than afterwards.
2008-07-21 13:41:54 +08:00
James Henstridge
e0287c0db4 * psycopg/adapter_qstring.c (qstring_traverse): add cyclic GC
traversal for quoted string adapters.

	* psycopg/adapter_pboolean.c (pboolean_traverse): add cyclic GC
	traversal for boolean adapters.

	* psycopg/adapter_mxdatetime.c (mxdatetime_traverse): add cyclic
	GC traversal for mxdatetime adapters.

	* psycopg/adapter_datetime.c (pydatetime_traverse): add cyclic GC
	traversal for datetime adapters.
2008-07-18 17:42:31 +08:00
James Henstridge
590542e973 * psycopg/adapter_binary.c (binary_traverse): add cyclic GC
traversal for binary adapters.
2008-07-01 11:59:25 +08:00
James Henstridge
47d2414e32 * psycopg/adapter_asis.c (asis_traverse): add cyclic GC traversal
for AsIs adapters.
2008-07-01 09:57:16 +08:00
James Henstridge
fd538a8b17 * psycopg/adapter_list.c (list_traverse): add cyclic GC traversal
for list adapters.
2008-07-01 09:34:51 +08:00
Federico Di Gregorio
e664abb248 Added XXXARRAY imports to psycopg2.extenions 2008-05-30 00:39:50 +02:00
James Henstridge
26693621ef * psycopg/cursor_type.c (cursor_setup): incref before setting
attributes, to make things GC-safe.

	* psycopg/cursor_int.c (curs_reset): make clearing of description
	and casts attributes GC-safe.
2008-05-28 17:45:37 +08:00
James Henstridge
bbd101bb7e * psycopg/typecast.c (typecast_traverse): implement cyclic GC
traversal for typecasters.
2008-05-28 17:22:40 +08:00
James Henstridge
a39fb19eb9 * psycopg/connection_type.c:
* psycopg/cursor_type.c: add support for cyclic GC.

	* psycopg/python.h: add definitions for Py_CLEAR() and Py_VISIT()
	for compatibility with old versions of Python.
2008-05-28 09:00:36 +08:00
Federico Di Gregorio
5a428642f8 COPY problem tests and partial fix 2008-05-27 17:40:19 +02:00
Federico Di Gregorio
6073193314 Fixed memory leak in executemany 2008-05-19 10:14:17 +02:00
James Henstridge
ee235478bd * psycopg/lobject.h (lobjectObject): remove "mode" struct member,
since it was unused.
2008-05-06 18:12:50 +08:00
James Henstridge
9d20f5c09c * psycopg/lobject_*.c: replace uses of the closed struct member,
and change the Python level attribute to a getset.

	* psycopg/lobject.h (lobjectObject): remove the closed member,
	since "fd < 0" gives us the same information.  Reorder the struct
	members for better packing.
2008-05-06 18:07:54 +08:00
James Henstridge
2046ae34fb * psycopg/lobject*: const'ify the code. 2008-05-06 17:09:43 +08:00
James Henstridge
7d66c20edb * tests/test_lobject.py (LargeObjectTests): add more tests,
including behaviour on closed lobjects and stale lobjects.

	* psycopg/lobject_type.c (psyco_lobj_close): don't mark the
	connection closed here because it is done by
	lobject_close_locked().

	* psycopg/lobject_int.c (lobject_open): mark objects as not closed
	if we successfully open them.
	(lobject_close_locked): mark the lobject closed here.
	(lobject_export): ensure we are in a transaction, since
	lo_export() issues multiple queries.

	* psycopg/lobject_type.c (lobject_setup): make lobjects start closed.
2008-05-06 17:04:26 +08:00
James Henstridge
e627948a6b * psycopg/lobject.h: don't export the lobjectType symbol. 2008-05-05 22:51:15 +08:00
Federico Di Gregorio
0319bc8cc4 Fixed build error on SUN 2008-05-05 15:55:51 +02:00
James Henstridge
9a48c261be Add basic tests for large object code. Fix lobject.seek() to actually
work.
2008-05-05 15:33:44 +08:00
James Henstridge
e192c603fa Fix up structmember definitions to match real types. T_LONG is not the
same as T_INT/T_UINT on AMD64 ...
2008-05-05 15:00:50 +08:00
James Henstridge
82557e65a2 Fix up pq_complete_error() calls. 2008-05-05 15:00:34 +08:00
James Henstridge
5beef38bfc Fix double free in case where PGresult is NULL. 2008-05-05 14:16:57 +08:00
James Henstridge
ec20fa8912 Some changes to the lobject code to match changes in pqpath.[ch]. 2008-05-05 12:07:24 +08:00
James Henstridge
3cfe438b74 Add an #endif I accidentally removed 2008-05-05 10:43:38 +08:00
James Henstridge
938c456cee Merge changes from psycopg2/trunk via psycopg2.r243. 2008-05-05 10:37:24 +08:00
Federico Di Gregorio
f3438f2961 Preparing release 2.0.7. 2008-04-14 04:27:22 +00:00
James Henstridge
23866bc35d * psycopg/connection_type.c (connection_dealloc): free
connection->encoding with free() instead of PyMem_Free().

	* psycopg/connection_int.c (conn_connect): use malloc() to
	allocate connection->encoding instead of PyMem_Malloc(), since it
	is freed in other places with free() and assigned to with
	strdup().
2008-03-30 22:15:21 +00:00
James Henstridge
e848585b90 * psycopg/typecast.c (typecast_from_c): fix up some reference
leaks.  This leak affected a bounded set of objects, so doesn't
	account for any gradual leaks.
2008-03-25 23:21:00 +00:00
James Henstridge
af1478feb9 * psycopg/connection_int.c (conn_notice_callback): don't leak
notice messages.
2008-03-19 01:01:26 +00:00
Federico Di Gregorio
8103f44a12 Fixed test segfault due to double decref. 2008-03-17 08:13:16 +00:00
James Henstridge
cceaa7331b * psycopg/typecast.c (typecast_parse_time): give the correct
return value for partially parsed time values.

	* psycopg/typecast_mxdatetime.c (typecast_MXDATE_cast): return
	NULL after setting DataError.  Also, don't treat it as an error if
	typecast_parse_time() returns 0 (as might happen if the remainder
	of the string is " BC").

	* psycopg/typecast_datetime.c (typecast_PYDATE_cast): return NULL
	after setting DataError.
	(typecast_PYDATETIME_cast): same here.
	(typecast_PYTIME_cast): same here.

	* tests/test_dates.py
	(CommonDatetimeTestsMixin.test_parse_incomplete_date): test that
	parsing incomplete date values results in DataError.
	(CommonDatetimeTestsMixin.test_parse_incomplete_time): same for
	times.
	(CommonDatetimeTestsMixin.test_parse_incomplete_time): same for
	datetimes.
2008-03-17 04:06:44 +00:00
James Henstridge
475df5ebd6 2008-03-07 Jason Erickson <jerickso@stickpeople.com>
* psycopg/pqpath.c (pq_raise): if PSYCOPG_EXTENSIONS is not
	defined, raise OperationalError rather than
	TransactionRollbackError for deadlock or serialisation errors for
	protocol versions less than 3.
2008-03-06 18:41:07 +00:00
James Henstridge
89cadcb553 2008-03-07 Jason Erickson <jerickso@stickpeople.com>
* psycopg/psycopgmodule.c (psyco_connect): fix off by one error in
	calculating the length of the DSN.
2008-03-06 16:15:41 +00:00
James Henstridge
e55e2683cf * psycopg/pqpath.c (_pq_fetch_tuples): Don't call Python APIs
without holding the GIL.
2008-03-06 15:12:40 +00:00
James Henstridge
b5f4a5f6c2 Fix off-by-one error in PyMem_Malloc() call in
psyco_conn_set_client_encoding().  Fixes #211
2008-02-13 16:01:10 +00:00
James Henstridge
6c2e3ab49b * Add HIDDEN attribute to datetime related global variables.
* Make const strings static, which essentially makes them labels for the 
  strings.
2008-01-22 00:13:42 +00:00
James Henstridge
fe853d0261 * psycopg/typecast.c (typecast_pydatetime): make array static.
(typecast_mxdatetime): same here.

	* psycopg/typecast_builtins.c (typecast_builtins): make array
	static.

	* psycopg/psycopgmodule.c: add hidden visibility to a bunch of
	global variables here.

	* psycopg/psycopg.h: add set QueryCanceledError and
	TransactionRollbackError to hidden visibility.
2008-01-21 21:41:17 +00:00
James Henstridge
e054004e8f Add more const qualifiers. 2008-01-21 21:01:08 +00:00
James Henstridge
eae563ac96 * psycopg/*.[ch]: add const qualifier to various string arguments
to functions (typecast functions and conn_switch_isolation_level).
2008-01-21 17:34:08 +00:00
James Henstridge
864d107325 * psycypg/*.h: apply HIDDEN to all global variables and functions
that should not be exported from the module.  This results in a 5%
	reduction in code size and shortens the dynamic symbol table.

	* psycopg/config.h: If GCC >= 4.0 is installed, define the HIDDEN
	symbol to apply the "hidden" visibility attribute.
2008-01-21 05:54:01 +00:00
James Henstridge
3265dd172d * tests/test_connection.py (ConnectionTests): add simple tests for
the Connection and Cursor "closed" attributes.

	* psycopg/cursor_type.c (psyco_curs_get_closed): add a "closed"
	attribute to cursors.  It will be True if either the cursor or its
	associated connection are closed.  This fixes bug #164.
2008-01-19 03:32:42 +00:00
James Henstridge
11b017fcbe * psycopg/pqpath.c (pq_raise): remove unused arguments to
function, and simplify.
	(pq_resolve_critical): make function static, since it isn't being
	used outside of pqpath.c any more.
2008-01-19 02:16:57 +00:00
James Henstridge
f64cbeda46 * tests/test_transaction.py (DeadlockSerializationTestCase): port
over some tests for serialisation and deadlock errors,
	demonstrating that TransactionRollbackError is generated.
	(QueryCancelationTests): add a test to show that
	QueryCanceledError is raised on statement timeouts.

	* psycopg2da/adapter.py (_handle_psycopg_exception): rather than
	checking exception messages, check for TransactionRollbackError.

	* psycopg/pqpath.c (exception_from_sqlstate): return
	TransactionRollbackError for 40xxx errors, and QueryCanceledError
	for 57014 errors.
	(pq_raise): If we are using an old server, use
	TransactionRollbackError if the error message contains "could not
	serialize" or "deadlock detected".

	* psycopg/psycopgmodule.c (_psyco_connect_fill_exc): remove
	function, since we no longer need to store pointers to the
	exceptions in the connection.  This also fixes a reference leak.
	(psyco_connect): remove _psyco_connect_fill_exc() function call.

	* psycopg/connection.h (connectionObject): remove exception
	members from struct.

	* psycopg/connection_type.c (connectionObject_getsets): modify the
	exception attributes on the connection object from members to
	getsets.  This reduces the size of the struct.

	* lib/extensions.py: import the two new extensions.

	* psycopg/psycopgmodule.c (exctable): add new QueryCanceledError
	and TransactionRollbackError exceptions.
2008-01-16 05:14:24 +00:00
James Henstridge
46bf23caf4 * tests/__init__.py (test_suite): add date tests to test suite.
* tests/test_dates.py: add tests for date/time typecasting and
	adaption.

	* psycopg/adapter_mxdatetime.c (mxdatetime_str): add support for
	outputting BC dates (which involves switching them to one-based
	dates).  Also remove broken handling of microseconds.

	* psycopg/typecast.c (typecast_parse_date): if the string ends
	with "BC" adjust the year value to be a zero-based BC value as
	used by mx.DateTime (datetime doesn't support BC dates).
	(typecast_parse_time): ignore ' ', 'B' and 'C' in time strings
	rather than treating them as part of the seconds part of the time.
2008-01-16 01:43:50 +00:00
James Henstridge
f18881983b * psycopg/typecast_array.c (typecast_array_scan): set an initial
value for quotes to keep gcc happy.

	* psycopg/*.c: add missing static modifier on many functions.
2008-01-13 16:05:59 +00:00
James Henstridge
7d80c05748 * tests/test_transaction.py
(TransactionTestCase.test_failed_commit): Expect IntegrityError
	instead of OperationalError.

	* psycopg/pqpath.c (exception_from_sqlstate): new function that
	converts an SQLSTATE error code to the corresponding exception
	class.
	(pq_raise): use exception_from_sqlstate() to pick which exception
	to use when working with protocol version 3.
	(pq_complete_error): Let pq_raise() pick an appropriate exception
	rather than forcing OperationalError.
2008-01-11 15:10:21 +00:00
James Henstridge
86597f6939 * psycopg/adapter_binary.c (binary_quote): apply Brandon Rhodes'
patch from ticket #209 to check return value from
	PyObject_AsCharBuffer().  This fixes the segfault.
	(binary_quote): switch from PyObject_AsCharBuffer() to
	PyObject_AsReadBuffer() to support buffer objects that don't
	implement the bf_getcharbuf protocol.

	* tests/types_basic.py (TypesBasicTests.testBinary): Test round
	tripping of bytea buffers.  Currently segfaults.
2008-01-10 22:19:23 +00:00
James Henstridge
729117af8b * psycopg/connection_int.c (conn_close): fix for new
pq_abort_locked() prototype.
	(conn_switch_isolation_level): fix for new pq_abort_locked()
	prototype, and use pq_complete_error() to show error message.
	(conn_set_client_encoding): same here.

	* psycopg/pqpath.c (pq_execute_command_locked): remove static
	modifier.
	(pq_complete_error): same here.
	(pq_abort_locked): add pgres and error arguments.
	(pq_abort): call pq_abort_locked() to reduce code duplication.
2008-01-10 18:14:44 +00:00
James Henstridge
d190d5918a 2007-12-23 James Henstridge <james@jamesh.id.au>
* psycopg/pqpath.c (pq_execute_command_locked): add an error
	argument to hold an error when no PGresult is returned by PQexec,
	rather than using pq_set_critical().
	(pq_complete_error): new function that converts the error returned
	by pq_execute_command_locked() to a Python exception.
	(pq_begin_locked): add error argument.
	(pq_commit): use pq_complete_error().
	(pq_abort): use pq_complete_error().
	(pq_abort_locked): always call pq_set_critical() on error, and
	clear the error message from pq_execute_command_locked().
	(pq_execute): use pq_complete_error() to handle the error from
	pq_begin_locked().

	* psycopg/pqpath.c (pq_begin): remove unused function.

	* psycopg/connection_type.c (psyco_conn_commit): if conn_commit()
	raises an error, just return NULL, since it is now setting an
	exception itself.
	(psyco_conn_rollback): same here.

	* psycopg/connection_int.c (conn_commit): don't drop GIL and lock
	connection before calling pq_commit().
	(conn_rollback): same here.
	(conn_close): use pq_abort_locked().
	(conn_switch_isolation_level): same here.
	(conn_set_client_encoding): same here.

	* psycopg/pqpath.h: add prototype for pq_abort_locked().

	* psycopg/pqpath.c (pq_commit): convert function to run with GIL
	held, and handle errors appropriately.
	(pq_abort): same here.
	(pq_abort_locked): new function to abort a locked connection.

2007-12-22  James Henstridge  <james@jamesh.id.au>

	* psycopg/pqpath.c (pq_raise): add a "pgres" argument so we can
	generate nice errors not related to a particular cursor.
	(pq_execute): use pq_begin_locked() rather than pq_begin().  Use
	pq_raise() to handle any errors from it.

	* psycopg/pqpath.c (pq_execute_command_locked): helper function
	used to execute a command-style query on a locked connection.
	(pq_begin_locked): a variant of pq_begin() that uses
	pq_execute_command_locked().
	(pq_begin): rewrite to use pq_begin_locked().
2008-01-10 06:14:20 +00:00
James Henstridge
5fe08ae83e 2007-12-22 James Henstridge <james@jamesh.id.au>
* psycopg/config.h: only print debug messages if
        psycopg_debug_enabled is true.

        * psycopg/psycopgmodule.c (init_psycopg): set
        psycopg_debug_enabled to true if the $PSYCOPG_DEBUG environment
        variable is set.
2007-12-22 13:03:41 +00:00
Federico Di Gregorio
d31b4add22 Applied win32 patch from Jason Erickson. 2007-12-21 00:18:55 +00:00
James Henstridge
4910f53b7e * psycopg/pqpath.c (pq_execute): uncomment the "curs->pgres ==
NULL" error handler after the PQexec() call.  This is needed to
	catch database disconnects (and probably other errors).  According
	to Federico, it was commented out to avoid a spurious error, so we
	should watch for problems.
2007-12-19 14:33:44 +00:00
James Henstridge
fd5d2d5238 * psycopg/pqpath.c (pq_raise): only remove the first 8 characters
of the exception message if it actually gives the severity.

	* psycopg/pqpath.h (pq_resolve_critical): add prototype, since
	this function is being used from connection_int.c.

	* psycopg/psycopg.h: update psyco_set_error() prototype.

	* psycopg/psycopgmodule.c (psyco_errors_init): set pgerror, pgcode
	and cursor class attributes to None on psycopg2.Error so that the
	attributes will always be available (simplifies error handling).
	(psyco_set_error): add const qualifiers to msg, pgerror and pgcode
	arguments.
	Don't bother setting pgerror, pgcode or cursor to None if they are
	not provided -- the class defaults take care of this.
2007-12-19 14:29:03 +00:00
Daniele Varrazzo
fd1ee6fffc Fixes to let the dbapi20 test suite pass.
Submitted by James Henstridge in ticket #195.
2007-11-11 10:18:43 +00:00
Daniele Varrazzo
75cb5d75d7 Use escape string syntax for string escape if connected to a server
requiring it.

Added a connection flag to store whether E''-style quoting is required: this
avoids repeated PQparameterStatus() calls.

Added a test case to verify correct behavior on strings, unicode and binary 
data. Tested with PG versions from 7.4 to 8.3b2, with any server
'standard_conforming_strings' setting and with 'PSYCOPG_OWN_QUOTING' too.
2007-11-11 08:53:44 +00:00
Daniele Varrazzo
70e555585e Fixed selection of the proper binary string quoting. 2007-11-09 13:00:37 +00:00
Daniele Varrazzo
272140f5c1 Use escape string syntax for binary escape if connected with a
server with ver >= 8.2.

The feature is only enabled when compiling psycopg with libpq
ver >= 8.0.
2007-11-09 05:51:12 +00:00
Daniele Varrazzo
277f57ffb0 - Hard limit on the connection.notices list to avoid them
growing indefinitely.
  Notices are treated as a queue: when the queue is full 
  drop the oldest notice.
2007-11-09 02:28:47 +00:00
Daniele Varrazzo
e1dd9ca843 Fixed bug #192 (Decimal support not safe for use with multiple sub
interpreters) as proposed by Graham Dumpleton.

If running in the main interpreter, use a cached version of the Decimal
object. Else repeat the object lookup.
2007-10-21 03:22:55 +00:00
Daniele Varrazzo
63773ad1e0 Added missing DECREF. 2007-10-18 17:29:15 +00:00
Daniele Varrazzo
c71b7a03d0 Added missing return in case out of memory. 2007-10-18 17:19:16 +00:00
Federico Di Gregorio
07892b29a6 Aggressive threading on fetch (and a new bug!) 2007-09-19 13:39:48 +00:00
Federico Di Gregorio
c9e701baa9 Fixed bug #194 (and added nice MD project not that C/C++ is supported.) 2007-09-08 08:54:30 +00:00
Federico Di Gregorio
46668d214b conn_commit/conn_rollback error handling (closes: #187). 2007-05-29 08:43:34 +00:00
Federico Di Gregorio
a07987cd90 Patchset copy_expert 5/5. 2007-05-29 08:30:24 +00:00
Federico Di Gregorio
b82c2f5cd9 Patchset copy_expert 4/5. 2007-05-29 08:23:35 +00:00
Federico Di Gregorio
c54e9142f4 Patchset copy_expert 3/5. 2007-05-29 08:16:44 +00:00
Federico Di Gregorio
3b2908b51e Patchset copy_expert 2/5. 2007-05-29 08:14:58 +00:00
Federico Di Gregorio
a23de80c6b Patchset copy_expert 1/5. 2007-05-29 08:13:40 +00:00
Federico Di Gregorio
a779c8ef99 .get_transaction_status() implementation. 2007-04-25 22:42:36 +00:00
Federico Di Gregorio
d6e232e2b9 Various fixes, now all examples work. 2007-04-13 14:07:11 +00:00
Federico Di Gregorio
8274a032b1 typecast_binary.c cleanup. 2007-04-13 01:17:54 +00:00
Federico Di Gregorio
967ec370ed int->size_t transition. 2007-04-13 01:16:22 +00:00
Federico Di Gregorio
2a6b523506 Fixed crash and win32 patches. 2007-04-11 04:16:00 +00:00
Federico Di Gregorio
d6f2aa27b7 Fixed mem and ref leak in connect(). 2007-04-10 06:51:35 +00:00
Federico Di Gregorio
e5829292cd Fixed both Python 2.5 and 64 bit problems. 2007-04-10 06:36:18 +00:00
Federico Di Gregorio
2ae0c32031 ZPsycopgDA now uses connection-level type-casters. 2007-02-23 15:23:06 +00:00
Federico Di Gregorio
6598a279e2 Added support for per-cursor and per-connection typecasters. 2007-02-22 15:16:54 +00:00
Federico Di Gregorio
c2e16b8901 Applied patch from #135. 2007-02-11 08:25:33 +00:00
Federico Di Gregorio
09c866221c Password obfuscation done right (closes: #147) 2007-02-11 08:11:22 +00:00
Federico Di Gregorio
3a94e747d7 Encodings from Karsten (part 2.) 2007-01-19 14:47:21 +00:00
Federico Di Gregorio
5642a68adb Encodings from Karsten. 2007-01-19 14:38:01 +00:00
Federico Di Gregorio
1c16009985 Added support for NULL in arrays (closes: #154) 2007-01-19 14:08:06 +00:00
Federico Di Gregorio
b074dd4d8b Encoding fixes. 2007-01-16 23:39:08 +00:00
Federico Di Gregorio
5c425f5294 Check for Python errors during copy (closes: #134). 2007-01-16 12:03:29 +00:00
Federico Di Gregorio
8c2c72a48a Applied patch from #148. 2007-01-16 11:32:01 +00:00
Federico Di Gregorio
e02f569dd3 Password obfuscation to close: #147. 2007-01-16 11:29:07 +00:00
Federico Di Gregorio
d342d37e27 Fixed problem with locales in mx.DateTime adaptation. 2007-01-16 10:47:28 +00:00
Federico Di Gregorio
d061b384d9 Fixed problem with year > 9999. 2007-01-16 07:57:22 +00:00
Federico Di Gregorio
f4dc6936a2 Builds again on win32 (closes: #132). 2006-10-29 03:12:51 +00:00
Federico Di Gregorio
ac5a747e95 Fixed precision and scale. 2006-10-21 07:33:44 +00:00
Federico Di Gregorio
d189203f9f .callproc() patch from Moshe (support for result sets.) 2006-10-03 05:54:22 +00:00
Federico Di Gregorio
96f631d41e Merge from 2.0 branch up to r839. 2006-09-30 06:57:35 +00:00
Federico Di Gregorio
4820213b7f Fixed fractionary seconds >59 problem (closes: #131) 2006-09-30 06:35:12 +00:00
Federico Di Gregorio
168d9c36af Fractionary seconds fix (closes: #130) 2006-09-30 06:16:24 +00:00
Federico Di Gregorio
1fe6269904 Piet Delport patches: final cleanup and PEP 353 macros. 2006-09-23 05:19:30 +00:00
Federico Di Gregorio
1d8af808bf Piet Delport patches: 3 of 3. 2006-09-23 05:15:36 +00:00
Federico Di Gregorio
474d8b9d51 Piet Delport patches: 2 of 3. 2006-09-23 05:14:24 +00:00
Federico Di Gregorio
3009a29b11 Piet Delport patches: 1 of 3. 2006-09-23 05:10:58 +00:00
Federico Di Gregorio
a9d307140e mx fix to build on win32. 2006-09-02 09:00:47 +00:00
Federico Di Gregorio
2007652589 mx fix to build on win32. 2006-09-02 09:00:39 +00:00
Federico Di Gregorio
dbd976bc03 Double mutex destroy fix. 2006-09-02 08:50:58 +00:00
Federico Di Gregorio
afaca71aa9 Double mutex destroy fix. 2006-09-02 08:50:30 +00:00
Federico Di Gregorio
269156d9bf Added some file-like attributes to lobject. 2006-09-02 05:33:03 +00:00
Federico Di Gregorio
64bd7ae61c Large objects landing.. 2006-09-02 04:57:50 +00:00
Federico Di Gregorio
616a1c2042 Preparing 2.0.5.1. 2006-09-02 01:09:31 +00:00
Federico Di Gregorio
36785f753b Work on large objects continue. 2006-09-01 17:15:27 +00:00
Federico Di Gregorio
0b9d13455d Missing file. 2006-09-01 16:44:07 +00:00
Federico Di Gregorio
b8f3cef62f psycopg is enlarging.. 2006-09-01 16:27:02 +00:00
Federico Di Gregorio
64933f2004 Merge from 2_0_x branch up to r814. 2006-09-01 13:46:57 +00:00
Federico Di Gregorio
3e0d8792a8 Preparing 2.0.5. 2006-09-01 12:42:03 +00:00
Federico Di Gregorio
9f9af5f907 Fixed patch from #119. 2006-09-01 12:36:38 +00:00
Federico Di Gregorio
b3fdd80452 Fixed OperationalError in connection objects. 2006-09-01 11:55:27 +00:00
Federico Di Gregorio
ec865ae932 .connect() port parameter as string or int (closes: #120). 2006-09-01 08:29:30 +00:00
Federico Di Gregorio
f88b973bd1 Empty binary buffer segfault fix (closes: #119). 2006-09-01 08:23:51 +00:00
Federico Di Gregorio
8eb118c63f Exposed connection status. 2006-09-01 08:20:11 +00:00
Federico Di Gregorio
53d10a3ddf Fixed compile problems on old gcc. 2006-09-01 08:02:41 +00:00
Federico Di Gregorio
6f0e578686 Null query segfault fix (closes: #117). 2006-09-01 07:45:58 +00:00
Federico Di Gregorio
23112a763d .executemany() fix (closes: #116). 2006-09-01 07:42:30 +00:00
Federico Di Gregorio
f202c7fc81 Preparing release 2.0.4. 2006-08-01 23:36:50 +00:00
Federico Di Gregorio
50e85bba65 Applied colum-selectionpatch (closes: #113). 2006-07-31 00:17:01 +00:00
Federico Di Gregorio
5e590d604f Fixed memory leak (closes: #114). 2006-07-31 00:02:08 +00:00
Federico Di Gregorio
b9f7c24a63 Interval conversion fix. 2006-07-26 05:13:08 +00:00
Federico Di Gregorio
b9fcde1b39 Fixed segfault in Binary/QString. 2006-06-18 05:57:01 +00:00
Federico Di Gregorio
cf7701a151 Little fixes. 2006-06-15 12:39:56 +00:00
Federico Di Gregorio
07be5df881 Fix for #93. 2006-06-11 05:09:59 +00:00
Federico Di Gregorio
0ce5207871 #warning fix. 2006-06-11 04:04:04 +00:00
Federico Di Gregorio
1ac75e3b80 (Really) fixed list adaptation. 2006-06-11 03:40:53 +00:00
Federico Di Gregorio
a9045916f2 Fixed list adaptation. 2006-06-11 03:40:16 +00:00
Federico Di Gregorio
9577f4e2a6 Fixed under-allocation (closes: #110) 2006-06-11 03:27:30 +00:00
Federico Di Gregorio
fb0b523586 Fixed string allocation (loses: #109) 2006-06-11 03:19:18 +00:00
Federico Di Gregorio
bfb00b86fd Better PostgreSQL version check. 2006-05-26 05:22:49 +00:00
Federico Di Gregorio
ec877b0ef9 Final of 8.1.4 securiy patch. 2006-05-24 10:29:35 +00:00
Federico Di Gregorio
5f8eddfcab Second half of 8.1.4 securiy patch. 2006-05-24 10:02:33 +00:00
Federico Di Gregorio
9299073649 First half of 8.1.4 securiy patch. 2006-05-24 09:43:55 +00:00
Federico Di Gregorio
3806f9688b Boolean fix for arrays. 2006-04-24 05:42:02 +00:00
Federico Di Gregorio
559149824b Small 64 bit fix. 2006-03-02 13:47:30 +00:00
Federico Di Gregorio
77398c759e Fixed handle leak on win32 and preparing 2.0 beta 8. 2006-02-11 11:01:17 +00:00
Federico Di Gregorio
94d663c6b6 Fixed memory overflow. 2006-02-11 06:57:34 +00:00
Daniele Varrazzo
202c002c5c * Docstrings added/fixed
* Added __all__ attributes to Python modules to explicit the package API
2006-01-12 18:36:57 +00:00
Federico Di Gregorio
5871596eda Some more tests in sandbox. 2006-01-10 16:13:37 +00:00
Federico Di Gregorio
96ff591d79 Extra attributes for ProgrammingError exception. 2006-01-05 08:13:03 +00:00
Federico Di Gregorio
7db16edad3 Connection encoding case fix (closes: #83). 2006-01-01 09:10:17 +00:00
Federico Di Gregorio
e72f3dba40 Fixed problem with array results that begin with "[...]=". (Closes: #80) 2005-12-11 08:21:20 +00:00
Federico Di Gregorio
61de8690e9 Fixed problem with "fractionary" time zones (Closes: #78). 2005-12-11 07:50:27 +00:00
Federico Di Gregorio
5ea2fa636f Better DictCursor. 2005-12-06 05:55:58 +00:00
Federico Di Gregorio
127c14809c Fixed very stupid typo that resulted in a very big bug (reported by Andrea Arcangeli.) 2005-12-06 05:38:39 +00:00
Federico Di Gregorio
3937ea3ece Added aync.txt to distribution. 2005-11-29 12:01:46 +00:00
Daniele Varrazzo
ad76b5ba3c * psycopg/psycopgmodule.c: fixed exceptions refcount.
* fixed lots of doctrings and added Epydoc-generated docs support.
2005-11-26 07:47:48 +00:00
Federico Di Gregorio
81bc23a54e Fixed problem with type object dealloc. 2005-11-24 03:21:37 +00:00
Federico Di Gregorio
a6be5bf7bc Fixed problem in microseconds conversion (really this time.) 2005-11-20 05:01:13 +00:00
Federico Di Gregorio
03c0a258a2 Fixed problem in microseconds conversion. 2005-11-20 04:54:33 +00:00
Federico Di Gregorio
996bd07c85 Definitely fixed date and time adapting problems (for mx too!) 2005-11-16 17:30:45 +00:00
Federico Di Gregorio
65fe7db04d Does not crash on importing needed modules. (Closes: #32) 2005-11-15 11:51:05 +00:00
Federico Di Gregorio
164eb32817 New time/date locale-safe typecasting code. 2005-11-14 11:57:45 +00:00
Federico Di Gregorio
770e7c34d3 Fixed problem with unitialized value in dsize. 2005-11-07 14:26:41 +00:00
Federico Di Gregorio
e727c49134 Converted typecast class to new-style and implemented much better compare method. 2005-11-03 18:28:04 +00:00
Federico Di Gregorio
c5bc1a3b9a Small changes to interval parsing. 2005-11-03 16:03:06 +00:00
Federico Di Gregorio
f03b94d84b Run-time check for Decimal on Python 2.3. 2005-11-03 01:35:17 +00:00
Federico Di Gregorio
d67b171eed Fixed problem with .callproc(). 2005-10-26 01:10:03 +00:00
Federico Di Gregorio
ef3430d24f Implemented named cursors. 2005-10-22 06:59:31 +00:00
Federico Di Gregorio
49a255059e Releasing 2.0 beta 5. 2005-10-18 14:44:57 +00:00
Federico Di Gregorio
ec31179c9e NOTIFY works again. 2005-10-18 14:07:17 +00:00
Federico Di Gregorio
c7c2c38bcd Epydoc clean. :D 2005-10-18 05:57:02 +00:00
Federico Di Gregorio
3168e7b95d Better epydoc support. 2005-10-18 05:29:42 +00:00
Federico Di Gregorio
7eda959258 We should now build on ZETA. 2005-10-18 03:57:52 +00:00
Federico Di Gregorio
6b0b634bae Code cleanup. 2005-10-18 01:29:47 +00:00
Federico Di Gregorio
a1ed1fb267 Added localtime_r for platforms not providing it. 2005-10-17 16:16:47 +00:00
Federico Di Gregorio
a237209a5e Default tzinfo_factory for cursors. 2005-10-17 16:04:43 +00:00
Federico Di Gregorio
206aa79225 Working on TZ issues. 2005-10-17 15:01:14 +00:00
Federico Di Gregorio
5715a74388 Applied patches to fix docstrings. 2005-10-17 06:17:34 +00:00
Federico Di Gregorio
8e453ce176 Last changes to .set_isolation_level(). 2005-10-08 03:15:17 +00:00
Federico Di Gregorio
6e69ac665f Default isolation level set to 2 if not set in the server. 2005-10-08 03:14:13 +00:00
Federico Di Gregorio
e1688431e0 Isolation level changes. 2005-10-08 03:04:40 +00:00
Federico Di Gregorio
8920c2662b Appliced callproc patch. 2005-10-01 14:58:25 +00:00
Federico Di Gregorio
67720de497 Fixed segfault in connection.set_client_encoding(). 2005-09-30 16:48:41 +00:00
Federico Di Gregorio
39136e1af4 Docstrings fixes. 2005-09-30 16:18:26 +00:00
Federico Di Gregorio
f4b52e8cdd Mingw and ZPsycopgDA fixes. 2005-09-12 02:23:17 +00:00
Federico Di Gregorio
c123389378 Ported mxDateTime formatting changes from 1.1.x. 2005-08-22 15:45:06 +00:00
Federico Di Gregorio
3e3084e4c6 Small changes and fixes for RC 1. 2005-08-07 02:20:46 +00:00
Federico Di Gregorio
20013f6ff9 Fixing gcc 4 warnings. 2005-07-26 14:49:30 +00:00
Federico Di Gregorio
b17acddcf5 1900 years shift fix. 2005-07-21 08:36:55 +00:00
Federico Di Gregorio
5edfdc2a54 INTERVAL overflow fix. 2005-06-24 07:11:44 +00:00
Federico Di Gregorio
0c56bc95df Fixed connection parameters. 2005-06-13 04:25:09 +00:00
Federico Di Gregorio
7d2109f979 Don't segfault on empty queries anymore (closes: #24). 2005-06-13 03:54:24 +00:00