Daniele Varrazzo
a79a5292e7
Added support with cursors without scroll clause
...
Using nothing is different from NO SCROLL, see DECLARE notes
in PG docs.
2012-08-15 09:44:44 +01:00
Daniele Varrazzo
fa4994e471
Added scrollable cursor implementation
...
Patch provided by Jon Nelson (ticket #108 ).
2012-08-15 00:30:54 +01:00
Daniele Varrazzo
91c2ff9296
Fixed tpc_recover() with RealDictStuff
...
Same problem and correction of ticket #114 .
2012-08-14 23:29:19 +01:00
Daniele Varrazzo
f9a13eb563
connection.reset() implemented using DISCARD ALL
2012-06-25 16:37:11 +01:00
Daniele Varrazzo
e8fb84306d
Fixed cursor name as unicode string on Python 3
2012-05-27 08:58:55 +01:00
Daniele Varrazzo
7982a6ac0b
Dropped GIL release around function calling PyMem_Malloc
...
Closes ticket #110 .
2012-05-22 17:22:57 +01:00
Daniele Varrazzo
27421f1e41
Name can be passed as None to cursor()
...
Makes invocation from subclasses and generic code easier.
Code simplified by using default values for keyword arguments
and avoiding needless conversions back and forth between Python and C
strings. Also added connection type check to cursor's init.
2012-04-11 17:32:10 +01:00
Daniele Varrazzo
c63891af8d
Fixed bad error return code from cursor's init
2012-04-11 17:26:11 +01:00
Federico Di Gregorio
550130b19e
Merge remote-tracking branch 'piro/devel' into devel
...
Conflicts:
psycopg/lobject_int.c
2012-03-08 12:28:52 +01:00
Daniele Varrazzo
b8c75d9de0
Merge branch 'gcc-python-plugin' into devel
2012-03-05 02:48:11 +00:00
Daniele Varrazzo
37aa62ca52
Merge branch 'close-idempotent' into devel
2012-03-05 02:47:52 +00:00
Daniele Varrazzo
8707d8c399
Fixed iterator refcount in case of memory error during COPY
2012-03-05 02:09:20 +00:00
Daniele Varrazzo
735d50c782
Check if the object wrapped in binary is not None before trying the other types
...
Otherwise it seems we clobber some result with NULL.
2012-03-05 02:08:45 +00:00
Daniele Varrazzo
a9dc1b83ad
Methods callbacks signatures match the flags they are exported with
2012-03-05 01:26:28 +00:00
Daniele Varrazzo
531084d561
Stricter types usage in several PyArg_ParseTuple calls
2012-03-04 18:01:08 +00:00
Daniele Varrazzo
0e832b97ea
Proper type check in prepare() methods for list, binary, qstring
2012-03-04 17:59:51 +00:00
Daniele Varrazzo
84f2a370f6
close() methods don't raise errors if called on closed objects
2012-03-04 05:10:07 +00:00
Daniele Varrazzo
76cc838a93
Expressions rewritten in a more normal way
...
(double)'0'? :)
2012-03-04 04:47:21 +00:00
Daniele Varrazzo
5bbfd38dfb
Check for errors in float adaptation
2012-03-04 04:43:14 +00:00
Daniele Varrazzo
6cece00958
Check failed list creation in array adaptation
2012-03-04 04:42:44 +00:00
Daniele Varrazzo
be35df3818
Fixed typecasters refcount
2012-03-04 04:41:36 +00:00
Daniele Varrazzo
dc4c3d3143
Guard from failed keys creation during adaptation
2012-03-04 04:40:44 +00:00
Daniele Varrazzo
18085201c8
Guard from NULL dereference if Xid allocation fails
2012-03-04 04:39:41 +00:00
Daniele Varrazzo
31812c01e6
Further modeling of exception raising
2012-03-04 04:38:44 +00:00
Daniele Varrazzo
d93732558d
Raise an exception in case of failed localtime_r call
2012-03-04 04:17:03 +00:00
Daniele Varrazzo
4d15b973b0
Attempt to enforce signature for the "O&" converter functions
...
It seems causing a traceback in the static checker. Enforcing it simplifies
the code, but doesn't help the checker.
2012-03-01 02:53:29 +00:00
Daniele Varrazzo
e1266d52cd
More functions annotated for static analysis
...
Also more return values checked for values < 0 for errors, instead of
checking == 0 and leaving the positive side unchecked
2012-03-01 02:53:28 +00:00
Daniele Varrazzo
5bfb6cdefe
Use more compact macros to annotate functions for the static checker
2012-03-01 02:53:28 +00:00
Daniele Varrazzo
f2e4a8ed78
Functions setting exception return a negative value on error
...
This works around another shortcoming of the static checker; also to be
discussed with the author.
2012-03-01 02:53:28 +00:00
Daniele Varrazzo
9432787279
Work around a false positive returned by the static checker
...
To be submitted to the author.
2012-03-01 02:53:28 +00:00
Daniele Varrazzo
a167822e26
Use the newly provided attributes to validate exceptions raising
...
Be more consistent in using 0 for success, <0 for failure, and to check
for values < 0 instead of specific -1.
2012-03-01 02:53:28 +00:00
Marti Raudsepp
b97599166e
Update all links to PostgreSQL docs to the current version.
...
I also checked all links and anchors to make sure they're still valid.
2012-02-28 18:28:07 +02:00
Daniele Varrazzo
67712e4226
Fixed possible NULL dereferencing in fetchmany()/fetchall()
2012-02-24 22:26:02 +00:00
Daniele Varrazzo
6d76e81166
Fixed possible NULL dereferencing in callproc()
2012-02-24 22:26:02 +00:00
Daniele Varrazzo
94a53b48df
Building rows simplified
...
Dropped repeated checks for tuple_factory.
Internal functions refactored a bit.
2012-02-24 22:26:02 +00:00
Daniele Varrazzo
efee049338
Added error check in _mogrify for failed tuple creation
2012-02-24 22:26:02 +00:00
Daniele Varrazzo
0ee641361b
Flag a few other functions returning borrowed refs
2012-02-24 22:26:01 +00:00
Daniele Varrazzo
4ecfd48671
Fixed possible NULL dereferencing in notice process
2012-02-24 22:25:56 +00:00
Daniele Varrazzo
a6df55f4e3
Flag the psycopg_ensure_*() functions as stealing a ref
2012-02-24 10:41:02 +00:00
Daniele Varrazzo
5f3f35a2c2
Mark getnextarg function as returning a borrowed reference
2012-02-24 04:25:08 +00:00
Daniele Varrazzo
fc78fb09c0
Dropped unused pq_resolve_critical() return value
2012-02-24 04:00:12 +00:00
Daniele Varrazzo
4eea8bc912
Dropped redundant check on the status before rollback
...
The check is better done inside the critical section.
2012-02-24 03:28:20 +00:00
Daniele Varrazzo
5fcbe7bd0f
Check/set connection status at commit inside the critical section
...
Failing to do so was causing the issue reported in ticket #103 . The issue
as reported was fixed when SET ISOLATION LEVEL was dropped, but the real
problem wasn't fixed.
2012-02-24 03:28:20 +00:00
Daniele Varrazzo
3b36100ec1
Dropped hardcoded list of exceptions in init functions
...
Use the already available exctable array.
This stops the gcc-python-plugin complaining about access to potentially
uninitialized memory.
2012-02-23 20:09:28 +00:00
Daniele Varrazzo
09be4dc5d1
Fixed potential failures while setting exceptions attributes
2012-02-23 19:48:46 +00:00
Daniele Varrazzo
7d67ecbed3
Fixed potential NULL incref
2012-02-23 19:47:36 +00:00
Daniele Varrazzo
1b27820389
Fixed refcount of exceptions dicts
2012-02-23 19:36:30 +00:00
Daniele Varrazzo
08fbd86495
Check errors in module typecasters init
2012-02-23 19:20:51 +00:00
Daniele Varrazzo
ff61cf25b6
Fixed refcount of None if namedtuples are not available
2012-02-23 18:50:06 +00:00
Daniele Varrazzo
026899e0c1
Check errors when populating encodings map
2012-02-23 18:50:06 +00:00
Daniele Varrazzo
db987250c8
Avoid installing Error.__reduce_ex__ on Python 2.4
...
It is not used by the pickle protocol, and if called manually fails in an
unsettling way, probably because the exceptions were old-style classes.
2012-01-14 18:01:15 +00:00
Daniele Varrazzo
43daba38e7
Make Error and subclasses picklable
...
Useful for multiprocessing interaction.
Closes ticket #90 .
2012-01-14 17:34:09 +00:00
Daniele Varrazzo
6f21111a92
Docs/cleanup for the lo_creat patch
2012-01-10 21:51:34 +00:00
Giovanni Mascellani
e1700fe28b
Use lo_creat() instead of lo_create() when creating large objects without new_oid.
...
This enhances the compatibility with the pgpool-II replication middleware,
that doesn't support lo_create() calls.
2012-01-10 20:49:58 +00:00
Giovanni Mascellani
8ec9b0f3d9
Use lo_creat() instead of lo_create() when creating large objects without new_oid.
...
This enhances the compatibility with the pgpool-II replication middleware,
that doesn't support lo_create() calls.
2012-01-10 11:12:06 +01:00
Daniele Varrazzo
dcc60131a9
fetchmany accepts None as size, meaning the default arraysize
...
without this care, extending fetchmany in subclasses becomes tricky.
Closes ticket #84 .
2012-01-10 01:32:45 +00:00
Daniele Varrazzo
09a8e7bf1f
Fixed cursor.fetchmany docstring
2012-01-10 01:28:14 +00:00
Daniele Varrazzo
d6e0b284e7
Map error classes 20 and HV to more specific exceptions
2011-12-16 12:26:27 +00:00
Daniele Varrazzo
ba7a0a3008
Raise DatabaseError instead of error with bad exception informations
...
We can actually raise these exceptions in weird situations,
e.g. see ticket #82 .
2011-12-15 17:50:31 +00:00
Daniele Varrazzo
b5de04d2ff
Put back a distinct ISOLATION_LEVEL_READ_UNCOMMITTED value
2011-12-15 12:53:48 +00:00
Federico Di Gregorio
d2d94e203f
Reverted isolation level values to backward compatible values
...
This basically removes the READ UNCOMMITED level (that internally
PostgreSQL maps to READ COMMITED anyway) to keep the numeric values
compattible with old psycopg versions. For full details and discussion
see this thread:
http://archives.postgresql.org/psycopg/2011-12/msg00008.php
2011-12-15 12:25:19 +01:00
Daniele Varrazzo
088978e7b1
Typo fixed writeable -> writable
...
Closes ticket #79 .
2011-12-11 02:55:29 +00:00
Daniele Varrazzo
ad3a198919
Fixed reference leak with arguments referenced more than once in queries
...
Plus, some more care in objects life cycle, mostly in exceptions handling.
Closes ticket #81 .
2011-12-11 02:52:06 +00:00
Daniele Varrazzo
d2b67364fd
connect() supports generic keyword arguments passed to the dsn
2011-11-17 01:51:25 +00:00
Daniele Varrazzo
dc94a3cb2d
Check for connection closed before getting the isolation level
...
Closes ticket #74
Also added test to check regressions in isolation_level,
set_isolation_level, set_session, autocommit.
2011-11-16 23:51:05 +00:00
Daniele Varrazzo
a76d0525d1
Dropped unused variable
2011-11-01 07:42:22 +00:00
Daniele Varrazzo
2671472de8
Dropped leftover extra char, already accounted for before
2011-10-20 11:11:57 +01:00
Daniele Varrazzo
60b49f5c45
Avoid PyOS_snprintf to calculate the copy command buffer size
...
On windows it returns -1 instead of sometihing portable. So just ditch
the static buffer and just use a dynamic one to compose the command.
Also squashed a couple of buglets in copy_to: copyfile was decremented
before being set to null, size_t was used instead of Py_ssize_t.
2011-10-19 21:01:53 +01:00
Daniele Varrazzo
ff8158d7c0
Simplification in the COPY command composition
...
Dropped the branch if NULL is specified or not: just use the default \N.
Also fixed copy_from/copy_to docstrings.
2011-10-19 20:31:09 +01:00
Daniele Varrazzo
dde4c0de3d
Decimal adapter registration moved from C to Python
...
Fixes Decimal adaptation in sub-interpreter, where the Decimal class has
a different identity from the one in the main interpreter.
Closes ticket #52 .
2011-10-14 22:35:56 +01:00
Daniele Varrazzo
c4e6d7d982
Fixed typecasting of arrays containing consecutive backslashes
2011-09-22 18:14:16 +01:00
Daniele Varrazzo
e3054ac9f3
Added new_array_type() function
...
Allows the creation of a generic array typecaster from Python.
2011-09-22 15:51:21 +01:00
Daniele Varrazzo
8fb08efae7
Allocate dynamically memory for the list of columns in COPY
...
Some bloke finds the limit of 8K too restrictive... ticket #68 .
2011-09-12 02:21:59 +01:00
Federico Di Gregorio
880aa07a58
WITH HOLD documentation a argument parsing changes
...
Now any true value will do for the withhold parameter.
2011-08-10 19:21:12 +02:00
Federico Di Gregorio
a59d88c703
Merge remote-tracking branch 'piro/devel' into devel
2011-08-10 18:36:24 +02:00
Federico Di Gregorio
479bdf7458
New 'withhold' parameter for connection.cursor()
2011-08-10 18:25:46 +02:00
Daniele Varrazzo
de6f2ac387
Grab the GIL when checking for errors occurred
...
The problem was causing a segfault on BEGIN if the server is disconnected
after the connection is created.
2011-08-09 11:44:30 +01:00
Federico Di Gregorio
2f6336ea78
First try at curs.withhold implementation
2011-07-05 10:28:34 +02:00
Daniele Varrazzo
d2b28abced
Method set_transaction() renamed to set_session()
...
In fact it doesn't change "the transaction", as there has to be no
transaction when invoked. The effect instead is to execute SET SESSION
CHARACTERISTICS.
2011-06-08 14:22:11 +01:00
Daniele Varrazzo
1a51cfe274
Better error message if deferrable is used in PG < 9.1
2011-06-08 10:59:27 +01:00
Daniele Varrazzo
0a1bbb56cd
Dropped redundant semicolons at the end of internal queries
...
For consistency with other queries, and probably we give less work to do
to the server parser (a ridiculously tiny amount).
2011-06-08 09:22:35 +01:00
Daniele Varrazzo
6d907df14d
Fixed documentation for COPY methods
...
The size parameter in copy_from was undocumented (ticket #59 ).
2011-06-07 11:16:10 +01:00
Daniele Varrazzo
9b5ac79513
Fixed default size for read copy buffer
...
The original commit stated it should have been 8192.
2011-06-07 11:16:06 +01:00
Daniele Varrazzo
679af4a975
Fixed copyfile refcount in copy_expert
...
In case of early error, jumping to exit would have decref'd the borrowed
reference to file.
Issue spotted by Dave Malcolm, thanks!
2011-06-07 01:20:25 +01:00
Daniele Varrazzo
b6e710b0fc
Fixed refcount bug in copy_to() and copy_expert() methods too
2011-06-07 00:08:29 +01:00
Daniele Varrazzo
1888bf41c0
Added patch for refcount bug in copy_from
...
By Dave Malcolm. https://bugzilla.redhat.com/show_bug.cgi?id=711095
(slightly edited to increment the refcount before storing the pointer
in the cursor).
2011-06-07 00:08:29 +01:00
Jason Erickson
dd7ee7093a
No strcasecmp function with MSVC
...
The MSVC compiler does not have the strcasecmp(x, y) function, which is a
case insensitve string compare function. Instead, MSVC has a similar function,
lstrcmpi(x, y). Modified config.h to use this function when building with
MSVC.
2011-06-05 23:33:28 +01:00
Daniele Varrazzo
442a0606fe
Merge branch 'guc-cleanup' into devel
2011-06-05 16:31:25 +01:00
Daniele Varrazzo
709df38d79
Don't clobber an eventual Python exception set by a green thread
2011-06-05 16:30:37 +01:00
Daniele Varrazzo
869d48b6f0
Use the pqpath functions to get/set GUC parameters
...
Functions conn_setup(), conn_get_isolation_level(), conn_set_transaction(),
conn_switch_isolation_level(), conn_set_client_encoding() reimplemented
using the pqpath funtitons.
Dropped analogous function in the connection, as it had to take the lock,
thus it was hard to build consistent pieces of functionality with it.
2011-06-05 16:26:01 +01:00
Daniele Varrazzo
8f876d4b5d
Avoid a deadlock using concurrent green threads on the same connection
...
Use the async_cursor property to store an indication that something is
running (even if it is not necessarily a cursor running the query).
2011-06-05 16:22:54 +01:00
Daniele Varrazzo
cf6a4ec062
Added pqpath functions to get/set the value for GUC parameters
...
The aim of these function is to allow the connection to make a better use
of the pqpath functions instead of using PQexec for these small things.
Also, the functions are to be called with the connection lock: this makes
composing higher level functions using them easier.
2011-06-05 15:36:02 +01:00
Daniele Varrazzo
a0d16fcfb2
Avoid a ton of warnings when building on mingw
...
mingw doesn't support visibility hidden even if gcc can.
2011-06-04 22:19:56 +01:00
Daniele Varrazzo
c8ec747903
Don't fail import if mx.DateTime module is not found at import time
...
A better fix for ticket #53 .
2011-06-04 14:16:24 +01:00
Daniele Varrazzo
05659c0d16
Cleanup of notice processing
...
The function is always called in the context of functions grabbing the
connection lock, so just use the same critical section instead of releasing
and re-acquiring it. It is not a problem as serious as the notifies process
(ticket #55 ) as the notices are a psycopg structure, not libpq. However the
change allows again processing notices/notifies in the same place,
which makes sense conceptually, plus we save some lock dance.
2011-06-04 01:49:03 +01:00
Daniele Varrazzo
d9c0b8166f
Process notifies when data is received, not when the result is parsed
...
Notifies process access the connection, is not limited to the result, so
There is the possibility of loss of protocol sync in multithread programs.
Closes ticket #55 .
2011-06-04 01:31:36 +01:00
Daniele Varrazzo
0eb5e0430e
Merge branch 'transaction-control' into devel
2011-06-03 01:48:24 +01:00
Daniele Varrazzo
4d3c6865ee
Use only the isolation levels available on old PG versions
2011-06-03 00:40:54 +01:00
Daniele Varrazzo
c2d1f1f2e6
Dropped isolation level from the connection object
...
Don't issue a SET TRANSACTION ISOLATION LEVEL at every begin: use PG's
GUC default, eventually set by set_transaction.
Dropped the last query at connection, yay!
Method set_isolation_level() and property isolation_level refactored using
the new structures, keeping the previous semantic.
2011-06-03 00:10:24 +01:00
Daniele Varrazzo
389f2cf1d0
Added autocommit property on connection
2011-06-02 01:16:22 +01:00
Daniele Varrazzo
ea03ffbf76
Added partial implementation for set_transaction
...
autocommit to be implemented yet.
2011-06-01 09:07:02 +01:00
Daniele Varrazzo
531292bca5
Merge branch 'neg-escape' into devel
2011-05-30 22:09:23 +01:00
Daniele Varrazzo
281427f450
Fixed escape for negative numbers prefixed by minus operator
...
Closes ticket #57 .
2011-05-30 22:00:20 +01:00
Daniele Varrazzo
19ec8809fd
Use all the isolation levels accepted by PostgreSQL
...
In PG 9.1 repeatable read and serializable are distinct levels.
2011-05-11 13:01:20 +01:00
Daniele Varrazzo
834c7d1288
Fixed a few docstrings mixed up
2011-05-11 12:59:31 +01:00
Daniele Varrazzo
c08799b0b0
Fixed SystemError clobbering libpq errors raised without SQLSTATE
...
Bug vivisectioned by Eric Snow
<http://archives.postgresql.org/psycopg/2011-04/msg00019.php >.
2011-04-24 02:59:28 +01:00
Daniele Varrazzo
19653a88ec
Store a normalized version of the PG encoding in the connection
...
This way looking up into extensions.encodings will not break.
2011-04-08 13:48:11 +01:00
Daniele Varrazzo
88803695ac
Normalize the encoding name at connection
...
The encoding can be set by PGCLIENTENCODING, which may be an alternative
spelling. Bug reported by Peter Eisentraut.
At this point the idea of considering one of the random spellings such as
EUC_CN as somewhat "blessed" is debunked. So just store the cleaned-up
version of the encoding in the mapping table. Note that the cleaned-up
version was needed by the unicode adapter: this requirement has been
surpassed as the connection now contains a copy of the Python codec name
set whenever the client encoding is set.
2011-04-08 13:48:11 +01:00
Daniele Varrazzo
e0cd6f0f00
Added tests for our own bytea parser
...
Because the parse function is not supposed to be exposed in Python,
use ctypes to directly inspect the C function.
2011-03-26 12:59:14 +00:00
Daniele Varrazzo
66c543b16c
Parse bytea output format ourselves instead of using the libpq
...
PG 9.0 uses the hex format by default, and clients < 9.0 can't parse that
format, requiring client update and great care in what is linked at runtime,
and generally giving headache to users and transitively us.
2011-03-26 12:59:14 +00:00
Daniele Varrazzo
fcbe0466a6
Correctly detect an empty query sent to the backend
...
Closes ticket #46 .
2011-03-04 20:30:43 +00:00
Daniele Varrazzo
f1d69f6dec
Fixed detection of empty error from pq_raise
...
Avoid a system error in case err is set to an empty string.
2011-03-04 20:20:56 +00:00
Daniele Varrazzo
194447fbbf
Merge branch 'msvc-cleanup' into devel
...
Merged Jason Erickson devel branch after collapsing a few commits together
where it made sense.
2011-02-25 10:29:19 +00:00
Jason Erickson
7c2fa77c4b
Windows MSVC: Fixed warning of incompatible types
...
Fixed incompatible type warning from XidObject * to PyObject * by
casting.
2011-02-25 10:25:12 +00:00
Jason Erickson
961e855bbd
Windows MSVC: Fix Compiler Warning: getpid
...
Fix a compiler warning when using PSYCOPG_DEBUG on MSVC where getpid is
undefined.
2011-02-25 10:25:12 +00:00
Jason Erickson
631883f62f
Windows MSVC: Fix data loss compiler warnings
...
Fixed MSVC compiler warnings where it was indicating a conversion
from a larger data type to smaller data type might have data loss.
2011-02-25 10:25:12 +00:00
Daniele Varrazzo
29ac03ef04
Check for failed allocation in the notice callback
2011-02-24 10:14:06 +00:00
Daniele Varrazzo
894d3f653c
Raise an exception if the libpq fails to decode bytea in hex format
2011-02-23 14:04:27 +00:00
Daniele Varrazzo
f96b68d8c6
Fixed docstring for connection.lobject()
2011-02-23 01:53:56 +00:00
Daniele Varrazzo
1db9c9b8ce
The cursor name can be a non-valid PostgreSQL identifier
2011-02-23 01:53:25 +00:00
Daniele Varrazzo
66555c5f11
Fixed call of memory functions without the GIL
2011-02-23 00:48:10 +00:00
Daniele Varrazzo
20f714f17c
Added error checking to _pq_fetch_tuples()
2011-02-23 00:32:23 +00:00
Daniele Varrazzo
c1715f66fe
More careful memory management
...
- Check return value of PyErr_Malloc and set an exception in case of error
- Avoid exposing variables with refcount 0 as connection attributes.
- PyErr_Free guards itself for NULL input
2011-02-23 00:32:23 +00:00
Daniele Varrazzo
beffb02d56
Stricter declaration and correct use of psyco_set_error
...
It has long been used in wrong ways, with the function receiving a
connection or lobject instead of a cursor. It has always been unnoticed
(nobody has noticed the wrong object attached to the exception in the
wrong cases) but it started crashing the interpreter with Python 3.2 on
Windows.
Thanks to Jason Erickson for finding the problem and helping fixing it.
2011-02-21 00:31:09 +00:00
Daniele Varrazzo
d74f777339
Check for memory errors in the connection init
2011-02-20 18:57:04 +00:00
Benjamin Poulain
5ee60571a5
Add a type converter to handle untyped empty arrays.
...
Empty array can be returned untyped by postgres. To handle
this case, a special handler is added for the type UNKNOWNOID.
If the value return by the database is strictly equal to "{}",
the value is converted. Otherwise, the conversion fallback on
the default handler.
2011-02-20 12:28:10 +00:00
Daniele Varrazzo
4bc4f85229
Merge remote branch 'jason/devel' into devel
...
Conflicts:
psycopg/notify_type.c
2011-02-19 16:25:31 +00:00
Daniele Varrazzo
556b4d461e
Documentation cleanup
...
Added several links to the Python documentation using the 'intersphinx'
extension.
2011-02-19 16:16:28 +00:00
Daniele Varrazzo
6098ced761
Assume there may be files returning Unicode in Python 2 too
...
This is the case in Python 2.7 with files implementing io.TextIOBase.
2011-02-19 14:24:15 +00:00
Daniele Varrazzo
8a08114314
Correctly handle exceptions with non-ascii chars in the message
...
Previous implementation would have barfed in canse of non-utf-8 data in
the message.
2011-02-19 14:16:53 +00:00
Jason Erickson
4bc47d47a5
Python 3.2 hash() return value is arch dependant
...
Python 3.2 hash() function will now return a 64bit value when run on a 64bit
architecture, where as previously, it would always return a 32bit value.
Modified the code to use the now Py_hash_t typedef and for Python versions
less than 3.2, hard code Py_hash_t to long and Py_uhash_t to unsigned long.
2011-02-18 23:57:25 -07:00
Daniele Varrazzo
837f1e5e4f
Set hidden visibility to a few functions not public
2011-02-19 00:25:23 +00:00
Daniele Varrazzo
c620f18be1
Provide cursor.description as named tuple if possible
...
If namedtuple() is not available, use regular tuples.
2011-02-19 00:05:43 +00:00
Daniele Varrazzo
836f8a1aa1
Make Binary(None) work as expected, adapting to NULL
...
Issue reported by Stefano Dal Pra.
2011-02-18 14:19:57 +00:00
Daniele Varrazzo
99b3c72312
Some cleanup in mogrify
...
- Raise an exception on incomplete placeholders.
- Minor speedups.
- Don't change the string in place (??!!) if the placeholder is not s
and the value is null.
The latter point can be done because downstream we don't accept anything
different from s anyway (in the Bytes_Format function).
Notice that now the format string is constant whatever the arguments.
This means that executemany is still more inefficient than it should be
as mogrify may work only on the parameters. However this is an
implementation only worthwhile if we start supporting real parameters.
Let's talk about that for the next release.
2011-02-18 02:33:42 +00:00
Daniele Varrazzo
b6d6fbbe8c
Use a global object for NULL
...
Small optimization as NULL is a frequent value to build.
2011-02-17 20:09:52 +00:00
Daniele Varrazzo
c51165e2aa
Indentation fixed
2011-02-17 19:53:04 +00:00
Daniele Varrazzo
63ac6cdde5
Added cursor.itersize
...
The value is used to control the number of records to fetch per network
roundtrip in named cursors iteration. Used to avoid the inefficient
arraysize default of 1 without giving this value the magic meaning of
2000.
2011-02-17 12:36:02 +00:00
Daniele Varrazzo
bccbcf42d0
Added adaptation for objects supporting the new-style buffer interface
...
Supporting this interface is required to adapt memoryview on Python 2.7 as they
don't support the old style. But because the old style is long deprecated it
makes sense to start supporting the new one.
2011-02-16 01:30:25 +00:00
Daniele Varrazzo
3ae2f221b3
Adapt bytearray and memoryview to bytes if available
2011-02-15 17:30:43 +00:00
Daniele Varrazzo
e4a84b9ce9
Fixed error message on Binary(str) in Python 3
2011-02-15 15:53:07 +00:00
Daniele Varrazzo
c1fe0b675a
Dropped correct roundtrip of empty array
...
The feature in itself is not extremely useful and instead PostgreSQL is
not always able to cast away from text[], which is a regression see
(ticket #42 ).
2011-02-15 10:27:47 +00:00
Daniele Varrazzo
8ab7fa596c
Merge remote branch 'jason/devel' into devel
2011-02-12 20:19:07 +00:00
Marti Raudsepp
9cb72a38da
Add negative infinity support for Python->pg conversion
2011-02-12 20:19:02 +00:00
Jason Erickson
560f52106c
Windows manifest changes based upon architecture
...
Apparently, using * for the architecture has the potential to not work on
on some amd64 systems. Added checks and split the manifest based upon
architecture.
2011-02-11 10:01:38 -07:00
Jason Erickson
b075017ad9
Pulled down changes from dvarrazzo branch on gh
...
Pulled the master branch from of Daniele's psycopg branch on github and
merged the changes.
2011-02-10 15:59:31 -07:00
Jason Erickson
8d28509f49
Change win32 build to reinsert VC Library Manifest
...
Added a change at the end of the build process that would reinsert the VC library manifest. This patch will fix issues when an embedded program does not have a manifest pointing to the VC 2008 runtime library, such as in an apache/mod_python situation.
Signed-off-by: Jason Erickson <jerickso@stickpeople.com>
2011-02-10 13:17:14 -07:00
Federico Di Gregorio
da27142882
Merge branch 'python3' into python2
2011-02-06 16:47:05 +01:00
Daniele Varrazzo
fab31e9441
Fetch 'arraysize' records per roundtrip in named cursors iteration
...
Closes ticket #33 .
2011-02-05 15:24:00 +01:00
Daniele Varrazzo
b544354db2
COPY sends unicode to a file if it derives from io.TextIoBase
...
Fixes ticket #36 .
2011-02-05 15:12:37 +01:00
Daniele Varrazzo
b358c54f02
More efficient cursor.iter: fetch many records at time.
2011-02-04 12:22:07 +00:00
Daniele Varrazzo
d40b394c50
Merge branch 'python2' into python3
2011-02-01 02:27:45 +00:00
Daniele Varrazzo
a2dcf504b5
Hopefully really fixed crash in datetime adapter.
...
Verified with gcc 4.3. Notice that on gcc 4.4 the bug was not present.
2011-02-01 02:00:47 +00:00
Daniele Varrazzo
789dda1173
lobject read and write can deal with both bytes and unicode
...
On write, unicode is encoded in connection encoding.
On read, respect the lobject mode 't' or 'b'.
2011-01-10 00:46:51 +00:00
Daniele Varrazzo
ba1d77a297
Large object mode parsing refactored
...
Added parsing of text/binary mode.
2011-01-10 00:46:51 +00:00
Daniele Varrazzo
79048ff19a
Merge branch 'python2' into python3
...
Conflicts:
NEWS-2.3
tests/__init__.py
tests/test_lobject.py
tests/test_quote.py
tests/testutils.py
2011-01-10 00:46:02 +00:00
Daniele Varrazzo
48588e5f69
Invalidate large objects after a two-phase commit operation
2011-01-10 00:20:55 +00:00
Daniele Varrazzo
935c25730a
Fixed segfault in large object close.
...
Check that the connection is not closed/faulty before attempting lo_close.
2011-01-10 00:11:14 +00:00
Daniele Varrazzo
9deb16484d
Don't define a CObject API in Python 3.2
...
The API is not available: a PyCapsule should be used. Nobody seems
needing it for now.
2011-01-08 01:24:16 +00:00
Daniele Varrazzo
b8c8cddc2d
Fixed argument parsing in lobject.read
...
Using an int instead of a Py_ssize_t randomly crashed Python 3.1 64 bit.
2011-01-04 02:27:02 +01:00
Daniele Varrazzo
80bd6e2794
Merge branch 'python2' into python3
...
Conflicts:
NEWS-2.3
psycopg/connection_type.c
tests/test_connection.py
tests/types_basic.py
2011-01-03 21:43:02 +01:00
Daniele Varrazzo
abd7991968
Fixed refcount bug with connection destroyed in a 2PC transaction
2011-01-03 21:34:49 +01:00
Daniele Varrazzo
5f6e773575
Broken circular reference in async execution
...
If a connection is destroyed before an async operation is completed, the
`async_cursor` member creates a reference loop, leaving the connection and
the cursor alive. `async_cursor` is now a weak reference.
2011-01-03 21:34:49 +01:00
Daniele Varrazzo
19ff51ae75
The cursor is weakly referenceable
2011-01-03 21:34:49 +01:00
Daniele Varrazzo
04cf90cc21
The connection is weakly referenceable
2011-01-03 21:34:49 +01:00
Daniele Varrazzo
5888b03608
Fixed "historical" reference leak in TimestampFromTicks
...
Added an internal function with C signature to avoid the creation of a
tuple to be later unpacked. When the tuple was decref'd, Python 2.4 64
bits regularly segfaulted; Python 2.5 less regularly; don't know about
other versions.
2011-01-03 21:34:49 +01:00
Daniele Varrazzo
39dd577c90
Use the proper printf placeholders to avoid warnings on 64 bit builds
2011-01-03 20:44:57 +01:00
Daniele Varrazzo
b276e3b05d
Fixed compiling on Python versions before 2.6
...
Added a few macros not defined in Py 2.4. Don't know about 2.5.
2011-01-03 19:18:50 +01:00
Daniele Varrazzo
9eae66e8cf
Added Py3 compatibility macro for Py_TPFLAGS_HAVE_WEAKREFS
2011-01-03 16:56:26 +01:00
Daniele Varrazzo
929d62053a
Merge branch 'python2' into python3
...
Conflicts:
NEWS-2.3
setup.py
2011-01-02 03:28:00 +01:00
Daniele Varrazzo
159cda3688
Added cursor.cast() method
...
The method exposes the typecasters lookup algorithm. Useful to create
recursive typecasters.
2011-01-01 22:55:10 +01:00
Daniele Varrazzo
3e94375cf7
Merge branch 'python2' into python3
...
Conflicts:
ChangeLog
NEWS-2.3
lib/extensions.py
psycopg/microprotocols.c
setup.py
2011-01-01 17:14:54 +01:00
Daniele Varrazzo
30921b58a8
Dropped conversion from None to NULL in adapter.
...
It was an error as the string is not conform to the protocol. The error
is masked by the None fast path in _mogrify, but surfaces when adapting
a tuple contains a None.
2010-12-31 18:55:33 +01:00
Daniele Varrazzo
ac25816962
Use the same Bytes_Format function for both Python 2 and 3.
...
This makes the behaviour between the two versions similar. It also have
the effect of a more specific error message in case an user specifies a
placeholder different from 's'.
2010-12-31 03:22:19 +01:00
Daniele Varrazzo
2930ed3d59
Dropped support for all format specifiers except s in PyBytes_Format.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
6882ac31d4
Dropped warnings in PyBytes_Format function.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
96a950d3eb
Fixed 2-phase commit support in Python 3.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
89fb60de4b
Column names in copy methods can be unicode.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
73917c15e1
Fixed COPY FROM to deal with decoded files.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
bc28cc8b00
Use unicode keys as strings in Py3.
...
This fixes pyformat style argument passing. Unicode and bytes don't
compare equal (even if they hash the same).
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
061079c918
In Py3, decode the tuple values before passing to the typecaster.
...
Not sure this is the best way to go: it is now impossible to write a
binary typecaster in Python; furthermore it is the opposite approach of
the codecs, which should return bytes.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
f6fefbea64
Function psycopg_ensure_bytes converted in a "filter" stealing a ref.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
3214c23f51
Fixed adaptation in several adapters.
...
The getquoted methods always return bytes. The str() convert this
representation to string on the fly.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
2e22eef727
Added utility function to convert bytes to string in Python 3.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
d3f3f1caf0
Added utility method to return a string in the connection encoding.
...
In Py2 the result is plain string, in Py3 an unicode decoded in the
connection encoding.
2010-12-31 03:18:27 +01:00
Daniele Varrazzo
56e4c2bd55
Redefining the microprotocol on Py3 as returning bytes.
2010-12-31 03:18:26 +01:00
Daniele Varrazzo
014b6a6d5b
Use psycopg_ensure_bytes() to unify Py2/3 code paths.
2010-12-31 03:18:26 +01:00
Daniele Varrazzo
89e4d4c7bb
Empty lists correctly roundtrip.
2010-12-31 03:18:26 +01:00
Daniele Varrazzo
b5ef5ef21d
Added typecasters repr().
2010-12-31 03:18:26 +01:00
Daniele Varrazzo
b4685bba4a
Added utility function to get bytes from a str/unicode.
2010-12-31 03:18:26 +01:00
Daniele Varrazzo
03dde732f6
Datetime adaptation in bytes.
2010-12-31 03:18:26 +01:00
Daniele Varrazzo
87a7ebac10
Query mogrification in bytes.
2010-12-31 03:18:26 +01:00
Daniele Varrazzo
c3196ebd9d
Added PyBytes_Format function.
2010-12-31 03:18:26 +01:00
Daniele Varrazzo
cb6b52945b
The library can be compiled with Python 3.
...
Just compiled! No test run yet and many points to review, marked in the
code.
The patch is largely Martin von Löwis work, simplified after refactoring
in the previous commits and adapted to the new code (as the patch was
originally for Psycopg 2.0.9)
2010-12-21 04:24:36 +00:00
Daniele Varrazzo
e182201e6e
Added Python codec name to the connection.
...
This allows dropping repeated dictionary lookups with unicode
query/parameters.
2010-12-21 04:02:14 +00:00
Daniele Varrazzo
ae06fb03e7
Added psycopg_strdup utility function.
2010-12-21 04:02:14 +00:00
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