Daniele Varrazzo
9054eeccc0
Set default_transaction_* GUC if session state is changed in autocomit
2017-02-04 15:19:41 +00:00
Daniele Varrazzo
c60682c230
Reuse set_session to implement autocommit, set_isolation_level
2017-02-04 13:26:43 +00:00
Daniele Varrazzo
8527144173
Better separation between interface and state change code
...
The state change function has a C callable signature.
2017-02-04 13:01:11 +00:00
Daniele Varrazzo
c1e016e597
Don't use default_transaction_* for session characteristics
...
Store the state in the connection object and set the params on BEGIN
Some tests fail: a few can be fixed reading transaction_* instead of
default_transaction_*; but the behaviour of tx characteristics with
autocommit is effectively changed. It may be addressed by setting
default_transaction_* if autocommit is set.
2017-02-04 02:38:56 +00:00
Daniele Varrazzo
9863637f30
Dropped compiler warning in debug mode
2017-02-04 02:32:26 +00:00
Daniele Varrazzo
de8b335d80
Merge branch 'master' into sql-compose
2017-02-03 04:56:02 +00:00
Daniele Varrazzo
ce9be69615
Added async_ as an alias for async
...
Added in argument for psycopg2.connect() and connection.__init__, and
for the connection.async attribute.
2017-02-03 04:43:49 +00:00
Daniele Varrazzo
828415d476
Typo: composible -> composable
2017-01-01 06:32:18 +01:00
Daniele Varrazzo
600416aafc
Fixed sql stuff in Py3
2017-01-01 05:59:21 +01:00
Daniele Varrazzo
c4a67fc1c1
Added sql.compose() implementation
2017-01-01 05:23:42 +01:00
Daniele Varrazzo
449bd4485f
Merge branch 'fast-codecs'
2016-12-29 22:15:46 +01:00
Daniele Varrazzo
cb5293be1f
Use the proper API functions to look up codec functions
2016-12-29 22:11:58 +01:00
Daniele Varrazzo
3295beb777
Don't look up for Python encoding
...
Store the encode/decode functions for the right codec in the connection.
The Python encoding name has been dropped of the connection to avoid the
temptation to use it...
2016-12-29 22:11:58 +01:00
Daniele Varrazzo
a81f12f9bd
Don't set tp_compare on Python 3
...
The slot is unused in Py < 3.5, and replaced by pg_as_async in Py 3.5.
2016-12-29 21:43:04 +01:00
Daniele Varrazzo
dfe547856e
Use -1 instead of 0 to say "calculate the length" in many funcs
...
0 is a valid length, isn't it?
2016-12-27 00:29:01 +01:00
Daniele Varrazzo
a255e4e1c6
Store python encoding and decoding functions in the connection
...
Unused for now: will be used instead of 'pyenc', which is to be dropped.
2016-12-27 00:29:01 +01:00
Daniele Varrazzo
17a74cc771
Setting connection encoding refactored
...
Code paths to read encoding on connection and to store the new
connection in the structure after changing it in the backend unified
into a single function.
2016-12-26 16:51:22 +01:00
Daniele Varrazzo
f439ca61d6
conn->codec rename to pyenc
2016-12-26 12:25:13 +01:00
Daniele Varrazzo
7caba160b7
Merge branch 'master' into fast-codecs
2016-12-26 12:06:21 +01:00
Daniele Varrazzo
ffeb7001eb
Fixed refcount problems in named callproc
2016-12-26 04:12:18 +01:00
Daniele Varrazzo
1957389bea
Merge branch 'master' into named-callproc
2016-12-26 03:19:02 +01:00
Daniele Varrazzo
a53b39efe8
Dropped internal escape identifier function
...
Using libpq one as now it's guaranteed to be present.
2016-12-26 03:11:36 +01:00
Daniele Varrazzo
faaef61c27
Merge branch 'master' into named-callproc
2016-12-26 01:49:42 +01:00
Daniele Varrazzo
e27579292a
Avoid deadlock on close if set datestyle failed
2016-12-25 17:45:01 +01:00
Daniele Varrazzo
c2d405116b
Dropped testing print
2016-12-25 17:44:25 +01:00
Christoph Moench-Tegeder
fb1dbc2a9b
do not "SET datestyle" on replication connections
...
A replication connection - marked by the use of the keyword "replication"
in the DSN - does not support SET commands. Trying to sent "SET datestyle"
will result in an exception.
2016-10-21 15:32:11 +02:00
Daniele Varrazzo
121cf3b8f8
Optimize UTF8 and Latin1 decoding
...
Cache a pointer to a fast decoding function when the connection encoding
is set so skip a repeated codec lookup for every string.
2016-10-12 01:10:31 +01:00
Daniele Varrazzo
584c7e6890
Dropped compiler warning in debug mode
2016-10-12 00:28:25 +01:00
Daniele Varrazzo
706ad2f177
Conver network array types into array of strings by default
2016-10-11 02:31:45 +01:00
Daniele Varrazzo
5ddc952dbb
Dropped ifdef guards against obsolete libpq versions
...
One of them was actually wrong: lobject_type.c wouldn't have compiled
pre 8.3 (broken in 6e841a41
, 2 years ago).
2016-08-15 02:55:44 +01:00
Daniele Varrazzo
3d4f6df0de
Enforce dependency on libpq version >= 9.1
...
PGRES_COPY_BOTH was introduced in 9.1: we can ifdef the hell out of
pgpath, but we may as well bury the dead horses instead of beating
them.
They smell funny, too.
2016-08-15 02:55:43 +01:00
Daniele Varrazzo
3b41c3a6f3
Stop compiling with Python 2.5
2016-08-15 01:06:42 +01:00
Daniele Varrazzo
1d950748af
Merge branch 'replication-protocol'
2016-08-14 21:09:54 +01:00
Daniele Varrazzo
e5390fed98
Use inttypes.h definitions
2016-08-14 19:48:31 +01:00
Daniele Varrazzo
12ecb4b2ce
Dropped import of postgres internal/c.h
...
Stops warning (caused by command line definition of PG_VERSION, so it
could have been avoided otherwise), but the file comment says:
Note that the definitions here are not intended to be exposed to clients
of the frontend interface libraries --- so we don't worry much about
polluting the namespace with lots of stuff...
so it doesn't seem a good idea gulping it.
2016-08-14 19:36:48 +01:00
Daniele Varrazzo
2a4d6027a4
Merge branch 'master' into replication-protocol
...
Conflicts:
tests/testconfig.py
2016-08-07 01:53:21 +01:00
Alexander Schrijver
03824a1dba
Throw an exception when a NUL character is used as a parameter.
2016-07-18 22:56:55 +02:00
Daniele Varrazzo
7566af145b
Merge branch 'conn-get-parameters'
2016-07-01 20:12:01 +01:00
Daniele Varrazzo
e41bff8ca4
Merge branch 'bug-424'
2016-07-01 19:28:02 +01:00
Daniele Varrazzo
5bcaf11f9d
Allow adapting bytes using QuotedString on Python 3 too
...
Close #365 .
2016-07-01 19:14:00 +01:00
Daniele Varrazzo
2e8e61b8d4
Test moved to the right module, cleanup, but same problem
2016-07-01 18:01:16 +01:00
Daniele Varrazzo
bada1f1f8e
Work in progress on writable encoding
...
Would help using adapt(unicode) to quote strings without a connection,
see ticket #331 .
Currently in heisenbug state: if test_connection_wins_anyway and
test_encoding_default run (in this order), the latter fail because the
returned value is "'\xe8 '", with an extra space. Skipping the first
test, the second succeed.
The bad value is returned by the libpq:
ql = PQescapeString(to+eq+1, from, len);
just returns len = 2 and an extra space in the string... meh.
2016-07-01 18:00:05 +01:00
Daniele Varrazzo
7aedc61d41
Fixed segfault on repr() for uninitialized connections
...
Close #361 .
2016-07-01 02:11:21 +01:00
Greg Ward
3ed2c54790
Fix scattered grammar/spelling errors in comments, debug output, etc.
2016-06-30 21:09:15 +01:00
Oleksandr Shulgin
d5443c65fd
Fix TODOs in ReplicationMessage inline docs
2016-04-21 15:32:05 +02:00
Gabriel Kihlman
5ce00f8e5b
Avoid a possible null deref, tz might be NULL.
...
Found by clang static analyzer.
2016-04-18 17:28:50 +02:00
Daniele Varrazzo
65ec7e8bcb
Fixed read() exception propagation in copy_from
...
Close issue #412 .
2016-03-10 12:13:52 +00:00
Daniele Varrazzo
8611d91b35
Fixed build on Python 2.5
2016-03-10 12:06:28 +00:00
Daniele Varrazzo
c13956dc10
Fixed compiler warnings about Py_ssize_t printf format
2016-03-10 12:02:23 +00:00
Jason Erickson
d0309333b7
Removed added Dprintf statements
...
Removed extra Dprintf statements added to trouble large objects
2016-03-10 12:02:06 +00:00
Jason Erickson
2cdc8d61a2
Fix Windows 64bit lobject support for very (>2GB) large objects
...
The type 'long' with Windows Visual C is 32bits in size for both 32bit and 64bit platforms. Changed type of variables that could be > 2GB from long to Py_ssize_t.
2016-03-10 12:02:00 +00:00
Oleksandr Shulgin
a7887fab07
Merge remote-tracking branch 'zalando/feature/replication-protocol' into feature/replication-protocol-c-connection-object
2016-03-08 18:56:58 +01:00
Oleksandr Shulgin
2de2ed7c63
Remove some dead code
2016-03-08 18:52:29 +01:00
Oleksandr Shulgin
1d52f34e60
We don't need to expose cursor_init(), call tp_init() on the type instead.
2016-03-08 18:52:21 +01:00
Oleksandr Shulgin
da6e061ee8
Use python-defined make_dsn() for ReplicationConnection class
2016-03-08 18:52:21 +01:00
Oleksandr Shulgin
cb7032554e
Merge branch 'master' into feature/replication-protocol-c-connection-object
2016-03-04 10:52:10 +01:00
Daniele Varrazzo
7aab934ae5
Validate output result from make_dsn()
...
The output is not necessarily munged anyway: if no keyword is passed,
validate the input but return it untouched.
2016-03-03 17:09:15 +00:00
Daniele Varrazzo
d40f81865f
Added parse_dsn() docstring
2016-03-03 03:25:47 +00:00
Oleksandr Shulgin
09a4bb70a1
Allow retrying start_replication after syntax or data error.
2016-01-05 12:31:57 +01:00
mrmilosz
0772d187e9
Return input tuple in cur.callproc, factor code to use PQescapeIdentifier in single place
2015-12-13 01:10:03 -05:00
Daniele Varrazzo
92109e4bba
Correctly handle an empty error message from PQescapeIdentifier
2015-12-12 17:52:56 -05:00
Daniele Varrazzo
54e5349f53
Set an exception in case of PQescapeIdentifier error
...
Ifdeffed surface reduced.
2015-12-12 17:52:56 -05:00
Daniele Varrazzo
4003b7c977
Fixed callproc return value refcount
...
Temporary anyway: I want to go back returning a list (or dict).
2015-12-12 17:51:45 -05:00
Daniele Varrazzo
021f6d22ad
More straightforward param refcount handling in callproc
2015-12-12 17:51:45 -05:00
Daniele Varrazzo
d297976d6d
Raise TypeError if the dict in callproc param contains non-strings
...
Check-and-conversion chain fixed and simplified. 'spname' was a
reference leak.
2015-12-12 17:51:08 -05:00
Daniele Varrazzo
a3eed9c9f5
Added guard on params with no length on callproc
2015-12-12 17:51:08 -05:00
Daniele Varrazzo
04ce14b251
Avoid clobbering the exceptions raised by other calls
2015-12-12 17:49:59 -05:00
mrmilosz
c205f140a0
callproc: tests, docs, and comment/error-reporting touchups.
2015-12-12 17:49:59 -05:00
mrmilosz
37a80e9de8
callproc: checking for libpq 9.0+ on compile. yes: use PQescapeIdentifier. no: error
2015-12-12 17:49:44 -05:00
mrmilosz
3948e909e4
callproc: now more compliant with local coding standards.
2015-12-12 17:49:44 -05:00
mrmilosz
e9bb4a86f9
cursor.callproc: added a missing memory check
2015-12-12 17:49:25 -05:00
mrmilosz
31c95c0922
callproc using a dict now uses connection encoding and sanitizes parameter names
2015-12-12 17:49:25 -05:00
mrmilosz
1205bf9c2b
callproc using a dict now has a type check to make sure the keys are strings.
2015-12-12 17:49:25 -05:00
mrmilosz
23d279945f
cursor.callproc now also accepts dict for PostgreSQL 9+ "named notation"
2015-12-12 17:49:25 -05:00
Oleksandr Shulgin
e61db578cf
Add dbname=replication for physical replication type.
2015-10-30 13:00:55 +01:00
Oleksandr Shulgin
a4cbb088fe
Add connection.get_dsn_parameters()
2015-10-30 11:10:41 +01:00
Oleksandr Shulgin
fbcf99ad07
Move replication connection to C level.
2015-10-27 18:21:24 +01:00
Oleksandr Shulgin
433fb957cb
Merge branch 'feature/connect2' into feature/replication-protocol
2015-10-27 17:37:18 +01:00
Oleksandr Shulgin
7aba8b3ed0
Rework psycopg2.connect() interface.
2015-10-27 17:35:57 +01:00
Oleksandr Shulgin
4b9a6f48f3
Merge branch 'master' into feature/replication-protocol
2015-10-27 12:16:41 +01:00
Oleksandr Shulgin
fe4cb0d493
Fix stale Dprintfs in pqpath.c referring to 'status'
2015-10-26 17:40:39 +01:00
Oleksandr Shulgin
8b79bf43ac
Drop ReplicationCursor.flush_feedback(), rectify pq_*_replication_*() interface.
2015-10-23 18:30:18 +02:00
Oleksandr Shulgin
e69dafbecc
Move the decode
parameter to start_replication()
.
...
It makes more sense this way, because otherwise it must be passed to every call
of `read_message()`.
2015-10-23 11:31:55 +02:00
Oleksandr Shulgin
76c7f4a0b5
Use direct call to consume() callable in pq_copy_both()
2015-10-22 16:17:08 +02:00
Oleksandr Shulgin
089e745af6
Fix cursor_init() declaration for use in replication_cursor_type.c
2015-10-20 12:55:43 +02:00
Oleksandr Shulgin
b3f8e9adb5
Fix send_time printf format in replmsg_repr().
2015-10-20 12:54:22 +02:00
Oleksandr Shulgin
23abe4f501
Add quick start to the replication doc, minor doc fixes.
2015-10-20 12:36:13 +02:00
Oleksandr Shulgin
0bb81fc848
Properly subclass ReplicationCursor on C level.
2015-10-19 20:00:39 +02:00
Oleksandr Shulgin
4ab7cf0157
Replace stop_replication with requirement for an exception.
2015-10-19 15:42:42 +02:00
Oleksandr Shulgin
8e518d4954
Merge branch 'master' into feature/replication-protocol
2015-10-15 12:27:43 +02:00
Oleksandr Shulgin
89bb6b0711
Proper unicode handling in quote_ident.
2015-10-15 11:52:18 +02:00
Oleksandr Shulgin
9ab38ee8c5
Add psyco_curs_datetime_init
2015-10-14 18:39:48 +02:00
Oleksandr Shulgin
28a1a00d1c
Remove commented copy_both code in pqfetch.
2015-10-14 18:39:20 +02:00
Oleksandr Shulgin
822d671e8b
Clear repl_stop flag after the consume loop.
2015-10-14 17:40:39 +02:00
Oleksandr Shulgin
e05b4fd267
Add checks on replication state, have to have a separate check for consume loop.
2015-10-14 17:36:50 +02:00
Oleksandr Shulgin
9295bce154
Add psycopg2.extensions.quote_ident.
2015-10-14 17:00:25 +02:00
Oleksandr Shulgin
a0b42a12ff
Update stop_repl, require replication consumer to be a callable.
2015-10-14 15:15:07 +02:00
Oleksandr Shulgin
fea2260fc5
Fix stop_replication: always raise outside the loop.
2015-10-14 12:50:08 +02:00
Oleksandr Shulgin
0233620c26
Rework replication connection/cursor classes
2015-10-01 19:33:27 +02:00
Oleksandr Shulgin
937a7a9024
Cleanup start replication wrt. slot type a bit.
2015-10-01 19:33:16 +02:00
Oleksandr Shulgin
f872a2aabb
Remove typedef for uint32, include internal/c.h
2015-10-01 19:33:12 +02:00
Oleksandr Shulgin
862eda10c2
Merge remote-tracking branch 'origin/master' into repl
2015-10-01 19:29:17 +02:00
Daniele Varrazzo
c73c1c5771
Decref the ssl module after importing
2015-10-01 17:04:29 +01:00
Daniele Varrazzo
5afeee3613
Added unicode support to parse_dsn
...
Also added support for the argument as a keyword.
2015-10-01 13:20:11 +01:00
Daniele Varrazzo
d1af12187c
Merge branch 'master' into parse-dsn
2015-10-01 11:39:51 +01:00
Daniele Varrazzo
6803341f21
Report NotSupportedError for PGRES_COPY_BOTH and PGRES_SINGLE_TUPLE
...
Fixes #352 .
2015-09-30 12:28:07 +01:00
Daniele Varrazzo
0e3f5214c5
Report the server response status on errors with no message
...
Suggested by Craig Ringer in pull request #353 , should also give more
information for other cases we were reported on flaky servers (AWS,
digital ocean...), see bug #281 .
2015-09-30 12:28:07 +01:00
Photonios
71925fcc00
Fix for MSVC 2015: round has been added to this version
2015-09-22 18:26:14 +02:00
Photonios
ac25ba0a3f
Fix for MSVC 2015: isnan is supported in this version
2015-09-22 18:25:53 +02:00
Oleksandr Shulgin
26fe1f230f
Fix use of PQconsumeInput() in pq_read_replication_message()
...
The libpq's PQconsumeInput() returns 0 in case of an error only, but
we need to know if it was able to actually read something. Work
around this by setting an internal flag before retry.
2015-07-07 19:04:32 +02:00
Oleksandr Shulgin
eac16d048a
Fix missing GC flag in ReplicationMessage type
2015-07-03 15:44:45 +02:00
Oleksandr Shulgin
06f18237f7
Fix missing free in replmsg_dealloc
2015-07-03 11:40:00 +02:00
Oleksandr Shulgin
9c1f2acf3e
Check return value of PQsocket
...
When connection is closed by the server, we might get -1 there.
2015-07-02 14:39:51 +02:00
Oleksandr Shulgin
dab41c699a
Fix PQconsumeInput usage.
...
Only call when no data is available in the internal buffer.
2015-07-02 14:34:09 +02:00
Oleksandr Shulgin
0d731aa12e
Comment on special handling of PGRES_COPY_BOTH
2015-06-30 16:34:17 +02:00
Oleksandr Shulgin
058db56430
Merge remote-tracking branch 'zalando/feature/replication-protocol' into feature/replication-protocol
2015-06-30 10:40:52 +02:00
Oleksandr Shulgin
61e52ce879
Rework replication protocol
...
This change exposes lower level functions for operating the
(logical) replication protocol, while keeping the high-level
start_replication function that does all the job for you in
case of a synchronous connection.
A number of other changes and fixes are put into this commit.
2015-06-30 10:38:18 +02:00
Oleksandr Shulgin
e3c3a2c19e
Merge branch 'master' into feature/replication-message-object
...
Conflicts:
lib/extensions.py
2015-06-30 10:30:32 +02:00
Oleksandr Shulgin
9ed90b1216
Refer cursor from ReplicationMessage object. At the same time, for the sync use LSN instead of msg reference in cursor.
2015-06-11 14:52:01 +02:00
Oleksandr Shulgin
35a3262fe3
Expose ReplicationMessage type in extras
2015-06-11 12:20:52 +02:00
Oleksandr Shulgin
9fc5bf4436
Add handling of send_time field in replmsg
2015-06-10 18:21:06 +02:00
Oleksandr Shulgin
453830f80c
Add ReplicationMessage object
2015-06-05 17:44:09 +02:00
Oleksandr Shulgin
50df864f8c
Add timersub for Win32. Fix gettimeofday on MinGW.
2015-06-04 11:00:08 +02:00
Oleksandr Shulgin
f14521f8cb
Add libpq_support.c and win32_support.c
...
Move libpq-specific code for streaming replication support into a
separate file. Also provide gettimeofday() on Win32, implementation
copied from Postgres core.
2015-06-03 14:10:20 +02:00
Daniele Varrazzo
1f330e9cac
Allow connection.notices and notifies to be replaced.
...
Close #326
2015-06-02 17:02:04 +01:00
Daniele Varrazzo
2ad82b973b
Pending notice list converted into a forward list
...
This allows inserting the elements in order without using list.insert().
2015-06-02 14:25:46 +01:00
Daniele Varrazzo
b326a27774
Dropped unneeded constness on the notice message
...
That's a strdup result, we 0wn it.
2015-06-02 14:24:48 +01:00
Daniele Varrazzo
0a7261268b
Dropped unused notice_filter connection member
2015-06-02 13:11:46 +01:00
Daniele Varrazzo
b0058c0cc8
Fixed adaptation of lists of None
...
Note: lists of lists of None are not supported yet.
2015-06-02 12:48:24 +01:00
Oleksandr Shulgin
cc08e14162
Merge branch 'master' into feature/parse-dsn
...
Conflicts:
lib/extensions.py
2015-06-02 12:42:03 +02:00
Daniele Varrazzo
73d17e3c5e
Dropped PG_VERSION_HEX constant
...
At PostgreSQL 10.0 it would have become awkward.
2015-06-02 10:54:08 +01:00
Oleksandr Shulgin
80da76d43f
Get rid of postgres internal includes; check for Win32 for htonl()
2015-06-02 11:42:56 +02:00
Oleksandr Shulgin
4bb6f9cef2
Add libpq version discovery
2015-06-01 18:05:11 +02:00
Oleksandr Shulgin
6a2f21aa14
Move parse_dsn to extensions, add tests
2015-06-01 15:11:12 +02:00
Oleksandr Shulgin
e32e1b834e
Add support for streaming replication protocol
...
Introduce ReplicationConnection and ReplicationCursor classes, that
incapsulate initiation of special type of PostgreSQL connection and
handling of special replication commands only available in this special
connection mode.
The handling of stream of replication data from the server is modelled
largely after the existing support for "COPY table TO file" command and
pg_recvlogical tool supplied with PostgreSQL (though, it can also be
used for physical replication.)
2015-06-01 11:45:04 +02:00
Oleksandr Shulgin
6c57e4a648
Add parse_dsn module function
...
Calls PQconninfoParse to parse the dsn into a list of keyword and value
structs, then constructs a dictionary from that. Can be useful when one
needs to alter some part of the the connection string reliably, but
doesn't want to get into all the details of parsing a dsn string:
quoting, URL format, etc.
2015-06-01 10:16:07 +02:00
Jan Urbański
a59704cf93
Make sure libcrypto threadsafety callbacks are properly set up
...
Multithreaded programs using libcrypto (part of OpenSSL) need to set up
callbacks to ensure safe execution. Both Python and libpq set up those
callbacks, which might lead to a conflict.
To avoid leaving dangling function pointers when being unloaded, libpq sets up
and removes the callbacks every time a SSL connection it opened and closed. If
another Python thread is performing unrelated SSL operations (like connecting
to a HTTPS server), this might lead to deadlocks, as described in
http://www.postgresql.org/message-id/871tlzrlkq.fsf@wulczer.org
Even if the problem will be remediated in libpq, it's still useful to have it
fixed in psycopg2. The solution is to use Python's own libcrypto callbacks and
completely disable handling them in libpq.
2015-05-03 12:27:36 +01:00
Daniele Varrazzo
ad3e91a56f
Unlock the connection after PQflush error
...
Apparently this has never happened... anyway the code path was wrong.
Fixes #294 .
2015-05-03 12:01:05 +01:00
Hyunjun Kim
4eee1207f9
Fix several typos
2015-05-03 10:30:21 +01:00
Daniele Varrazzo
70fbc8bf1f
Fixed connection.poll() docstring
...
Fixes #312
2015-05-03 10:29:57 +01:00
Daniele Varrazzo
7ea56b112e
Make Column picklable on Python >= 3.3
...
Also expose the type from the extensions module, not from the main
module.
2015-02-08 11:27:10 +00:00
Owen Raccuglia
5af5fb4cc6
Allow pickling of cursor.description
...
This is for people using dtuple.py; a dtuple.DatabaseTuple instance
keeps a reference to cursor.description, which is not picklable because
psycopg2 doesn't export the Column namedtuple it uses.
This commit exports the Column namedtuple, and includes a test to verify
the pickle/unpickle works after exporting Column.
2015-02-08 02:31:33 +00:00
Daniele Varrazzo
7ce7fef322
Propagate read error messages in COPY FROM
...
Fix ticket #270 .
2015-02-08 01:42:21 +00:00
Daniele Varrazzo
d3c1ad5945
Convert Postgres time 24:00 into 00:00
...
Fix ticket #278 .
2015-02-08 00:41:50 +00:00
Daniele Varrazzo
2f862972c9
Guard against overflows when using the lo32 api
...
If psycopg supports lo64 but the server doesn't the user may pass values
that would overflow the api range, resulting in:
lo.seek((2<<30))
*** OperationalError: ERROR: invalid seek offset: -2147483648
Also improved the error messages and guard against INT_MIN for negative
seek offsets.
2014-12-25 15:06:18 +01:00
Daniele Varrazzo
79df47a146
Fixed mismatched types in debug print
2014-12-25 15:06:18 +01:00
Daniele Varrazzo
0205d6ca2e
Use ifdef instead of if to check LO64
2014-12-25 15:06:18 +01:00
Blake Rouse
e5bbde9554
Check server_version before using lo_*64 functions. If less tahn 9.3 old none 64bit functions will be use.
2014-12-25 15:06:18 +01:00
Blake Rouse
cd67d3d2fe
Modify truncate to use lo_truncate64. Use HAVE_LO64 define to use new lo_*64 methods. Check size of offset and length for versions without LO64.
2014-12-25 15:06:18 +01:00
Blake Rouse
e13ec67da3
Use lseek64 and ltell64 to support large object greater than 2gb in size.
2014-12-25 15:06:18 +01:00
Hyunjun Kim
4dbda02145
Cast time into timetz when the tzinfo field is set.
2014-11-13 17:32:06 +09:00
Daniele Varrazzo
1b48033345
Don't try to close the server cursor in error state
...
`close()` is implicitly called by `__exit__()`, so an exit on error
would run a query on a inerr connection, causing another exception
hiding the original one. The fix is on `close()`, not on `__exit__()`,
because the semantic of the latter is simply to call the former.
Closes #262 .
2014-09-16 06:57:34 +01:00
Daniele Varrazzo
2d601ef157
Fixed memory leak with large objects
...
Deallocating closed large objects failed to decrement the connection
refcount. The fact the lobject is closed doesn't matter for refcount.
Issue detected by the always useful scripts/refcounter.py
With an extra bit of unrequested whitespace love.
2014-08-28 02:17:52 +01:00
Daniele Varrazzo
54d904138d
Don't import psycopg2.tz into the C extension
...
This makes possible to import _psycopg directly, after adding the
package directory to the pythonpath. This enables hacks such as:
sys.path.insert(0, '/path/to/psycopg2')
import _psycopg
sys.modules['psycopg2._psycopg'] = _psycopg
sys.path.pop(0)
which can work around e.g. the problem of #201 , freeze that cannot
freeze psycopg2. Well, freeze cannot freeze it because it's just not
designed to deal with C extensions. At least now the frozen application
can hack the pythonpath and work around the limitation by importing
_psycopg as above and then doing the rest of the imports normally.
Keeping long-lived references to python objects is bad anyway: the
tz module couldn't be reloaded before.
2014-08-28 02:17:46 +01:00
Daniele Varrazzo
1d729ab40e
Dropped HAVE_PQFREEMEM flag
...
It was necessary before PG 7.4, in versions which have long been unsupported.
2014-08-24 01:43:12 +01:00
Daniele Varrazzo
68a4308c3d
Dropped PSYCOPG_NEW_BOOLEAN flag
...
Introduced in 2.0 beta 8, 2006 A.D. Went absolutely untouched in 8 years
of refactoring, when Python 2.5 and PostgreSQL 8.1 roamed the earth.
I would say it has stood the test of the time.
2014-08-24 01:25:02 +01:00
Daniele Varrazzo
6e841a41e6
Dropped PSYCOPG_EXTENSIONS flag
...
Building without extensions has been long broken and nobody really cares
about a pure-DBAPI implementation (which could be created using a wrapper
instead).
2014-08-23 19:30:48 +01:00
Alexey Borzenkov
13b0852619
Allow using named with hold cursors in autocommit
2014-08-21 05:35:11 +01:00
Alexey Borzenkov
478e66f761
No implicit transaction on named cursor close
...
Also, don't start an implicit transaction when fetching with
named with hold cursor, since it already returns results
from a previously committed transaction.
2014-08-21 05:35:10 +01:00
Daniele Varrazzo
a2b01cdf42
Dropped simple type wrapper functions
...
These functions don't need to exist: exposing the type in the module is
enough. It is actually better as one may use isinstance and such.
2014-08-15 02:54:31 +01:00
Daniele Varrazzo
1b322a9b19
Fixed segfault in List function
...
This function is never called: it segfaults 100%. To be removed.
2014-08-15 02:54:25 +01:00
Daniele Varrazzo
95165cef7d
Dropped almost-no-op customized objects repr()
...
The default repr is enough: it prints <TypeName at 0xADDR> instead of
<TypeName object at 0xADDR>.
The only people being hurt by this change are the ones using doctests:
they deserve it.
2014-08-15 02:54:10 +01:00
Daniele Varrazzo
669e787919
Name the types after the module they are exposed from
2014-08-15 01:47:19 +01:00
Daniele Varrazzo
56adc590ff
Fixed segfault if COPY statements are executed
...
Close ticket #219
2014-06-06 21:42:21 +02:00
Daniele Varrazzo
115ceea1eb
Don't ignore silently the cursor.callproc
argument without a length
2014-06-06 21:42:21 +02:00
Daniele Varrazzo
d0b35adeb6
Parse the rowcount as long
2014-05-13 14:34:10 +01:00
Daniele Varrazzo
81b5f1fb26
Copy operations correctly set the cursor.rowcount attribute
...
Fixes ticket #180 .
2014-05-05 23:53:50 +01:00
Daniele Varrazzo
69605e54ec
Fixed explicit connection.cursor(cursor_factory=None)
...
Fixes issue #210 .
2014-04-30 17:57:55 +01:00
Daniele Varrazzo
489658cfc5
Close the connection if discovered bad on poll()
2014-04-05 16:03:19 +01:00
Daniele Varrazzo
1654687d1b
Check the connection is really bad on exception before closing it
...
We end up here without a pgres sometimes (e.g. from lobject errors)
2014-04-05 16:03:06 +01:00
Daniele Varrazzo
3752880b7b
Fixed attempt of closing an already closed lobject on dealloc
...
This results in a "null without exception set" in the corrent state, which
is caused by the connection being unexpectedly closed anyway.
2014-04-05 16:03:06 +01:00
Daniele Varrazzo
2e55b35d5d
Don't set an exception witout GIL closing lobjects with a bad conn
...
We ended up in this branch only for an excessively aggressive closing
of the transaction that now I'm going to fix.
2014-04-05 16:03:06 +01:00
Daniele Varrazzo
696d123550
Close a connection if PQexec returned NULL
...
This happens for Socket connections, not for TCP ones, where a result
containing an error is returned and correctly handled by pq_raise()
Closes ticket #196 but not #192 : poll() still doesn't change the
connection closed.
2014-04-05 16:03:06 +01:00
Daniele Varrazzo
a31c1a1722
Allow get_transaction_status on closed connections
...
It's a local operation and the libpq functions has a NULL guard.
2014-04-05 16:02:43 +01:00
Daniele Varrazzo
9036299d54
Avoid printing the typecast name in debug statement
...
The way we were doing it is unsafe and causes assertion failures on Py3.
Fixes ticket #188
2014-04-04 19:25:09 +01:00
Daniele Varrazzo
ca98167ae4
Fixed use of Python object with refcount 0 in cursor_init
...
Caused segfault running test_cursor.CursorTests.test_invalid_name under
Python 3.4 built in debug mode.
2014-04-04 19:20:08 +01:00
Daniele Varrazzo
a8fdc74090
Fixed overflow opening a lobject with an oid not fitting in a signed int
...
Fixes 🎫 `203`.
2014-04-03 02:35:56 +01:00
Daniele Varrazzo
e7fc7f31b9
Fixed dsn and closed attributes in failing connection subclasses.
...
From ticket #192 discussion.
2014-04-03 01:42:35 +01:00
Daniele Varrazzo
7b82be936d
Don't segfault on uninitialized cursor
...
It can happen with bad cursor subclasses not calling super's init. Raise
an exception instead of segfaulting.
Closes #195
2014-02-26 19:41:59 +00:00
Daniele Varrazzo
618f7e41de
Use the do-while 0 idiom for cursor guards macro
2014-02-26 19:31:27 +00:00
Daniele Varrazzo
63e36e22d2
Set the connection async before polling for connection
...
It should fix ticket #194
2014-02-24 15:20:01 +00:00
Daniele Varrazzo
ca99579b76
Set the connection async earlier in green mode
...
The moment it is called shouldn't have really changed, but it's more
explicit when it happens. Previously it was sort of obfuscated behind a
roundtrip through the green callback and poll.
2014-02-24 15:20:01 +00:00
Daniele Varrazzo
85b1914ad6
Fixed dealloc of lobject->smode
...
I put it by mistake into the in the self->conn checked block in the
previous commit.
2013-11-27 13:00:16 +00:00
Daniele Varrazzo
e11d0d39ec
Check connection type in lobject init
...
Fixes ticket #187 .
2013-11-27 12:44:28 +00:00
Daniele Varrazzo
1e623a951c
Meaningful connection errors report a meaningful message
...
Fixes issue #173 .
2013-10-16 17:50:10 +01:00
Daniele Varrazzo
345077d5f7
Fixed pickling of exceptions with no pgerror/pgcode set
...
Fixes ticket #170 .
2013-07-19 16:05:59 +01:00
Daniele Varrazzo
921b676471
Untrack the connection before closing to avoid possible double-free
...
From Gangadharan S.A. Fixes issue #166 .
2013-06-20 16:35:43 +01:00
Piotr Kasprzyk
31b6ec63f8
Fix multiple misspellings
2013-04-26 09:59:40 +01:00
Daniele Varrazzo
e335eb98ce
Long ifdef reformatted for readibility
2013-04-20 02:21:58 +01:00
Daniel Enman
558f7ad929
Remove extra ||
2013-04-18 17:12:14 -03:00
Daniel Enman
cda0b6a8eb
Solaris 10+, and illumos distros have round()
2013-04-18 16:59:26 -03:00
Daniele Varrazzo
b214d10fff
Use NULL instead of an empty string as PyObject_CallMethod format
2013-04-07 17:26:57 +01:00
Daniele Varrazzo
9e15f54fe8
Added cursor_factory connection attribute and connect() parameter
2013-04-07 02:30:12 +01:00
Daniele Varrazzo
408c76fdb6
Fixed build on windows
...
Will fail with error: initializer element is not constant
2013-04-06 01:34:12 +01:00
Daniele Varrazzo
d36024dc1f
Use the Python heap for conn->dsn
2013-04-06 00:42:25 +01:00
Daniele Varrazzo
c63d623f65
Merge branch 'drop-py24' into devel
2013-04-05 01:29:25 +01:00
Daniele Varrazzo
beea32ef03
Use the Py_RETURN_NONE macro
2013-04-05 01:25:05 +01:00
Daniele Varrazzo
67c8250081
Added tp_clear method for objects with GC support
2013-04-05 01:05:12 +01:00
Daniele Varrazzo
1a93279fe7
Dropped bogus return in void function
2013-04-05 01:03:05 +01:00
Daniele Varrazzo
e14440d96d
Dropped GC support for several objects
...
Non-containers don't need GC. It was half-baked anyway
as the tp_clear was often not set. Dropped tp_traverse too
for these objects as unused.
2013-04-05 01:02:47 +01:00
Daniele Varrazzo
95ff64d739
Dropped encoding attribute from list adapter
2013-04-05 00:35:02 +01:00
Daniele Varrazzo
6bc4b23af5
Static-type psycopg_escape_string connection parameter
2013-04-05 00:07:36 +01:00
Daniele Varrazzo
736a78f3f6
Avoid encoding strdup in qstring adapter
...
Dropped encoding parameter in the constructor: it is used
nowhere and not documented. Use directly the connection
encoding if available, else the previous latin1 fallback.
2013-04-05 00:00:42 +01:00
Daniele Varrazzo
7a5a226b49
Set a memory exception in psycopg_escape_string
...
...otherwise all the callers should set it.
2013-04-04 22:48:53 +01:00
Daniele Varrazzo
7328aaf0fb
Dropped GC support from Xid and Notify types
...
These types are immutable and have only atomic types attributes, so it's
impossible to build loops out of them.
2013-04-02 01:50:31 +01:00
Daniele Varrazzo
5aafe38fd7
Some improvements to connection/cursor GC
...
Provide a tp_clear, make sure that GC_UnTrack is called before clearing.
2013-03-21 12:55:17 +00:00
Daniele Varrazzo
3b8abf3fc4
Clean the C members of Error in tp_dealloc instead of tp_clear
...
tp_clear should only be used to break the reference cycles. tp_clear was
causing a segfault because it was called twice (by the gc and by _dealloc) so
self->codec was freed twice.
Amazingly the double free was only causing a segfault on Python 3.3 (released
in late 2012) talking to Postgres 8.1 (released in 2005) in async mode... no
other combination crashed. Thank you buildbot.
2013-03-21 12:34:53 +00:00
Daniele Varrazzo
d5316d7eb2
PyType_GenericAlloc is the default allocator: no need to specify
2013-03-20 23:53:20 +00:00
Daniele Varrazzo
eb280c1da4
Better use of Py_CLEAR and implicit zeroed-out structures
2013-03-20 23:53:20 +00:00
Daniele Varrazzo
b6873ee1ab
Dropped support for Python 2.4
2013-03-20 23:40:13 +00:00
Daniele Varrazzo
e65392e0d8
PyType_GenericAlloc is the default allocator: no need to specify
2013-03-20 22:59:50 +00:00
Daniele Varrazzo
8a59e75d62
Better use of Py_CLEAR and implicit zeroed-out structures
2013-03-20 22:59:50 +00:00
Daniele Varrazzo
3410fee8d1
Fixed leak of cancel key on connection.reset()
...
Moving the final free into the destructor is not necessary but looks
appropriate.
2013-03-20 16:43:16 +00:00
Daniele Varrazzo
9813bac4fe
Added forgotten attributes to visit in error
2013-03-20 15:06:06 +00:00
Daniele Varrazzo
5dfba462da
Dropped "customized" pg_free functions
...
The defaut is already to call PyObject_GC_Del.
2013-03-20 01:48:21 +00:00
Daniele Varrazzo
0830deb790
Dropped IFCLEARPGRES macro
...
PQclear already guards against NULL, so the extra check is redundant
2013-03-20 01:48:17 +00:00
Daniele Varrazzo
16021dae6d
Use Py_CLEAR on self->query instead of if and decref
2013-03-20 01:48:11 +00:00
Daniele Varrazzo
a210859326
Notify and Xid objects and types renamed for consistency
...
They were the only objects starting with uppercase. My fault.
2013-03-20 01:48:05 +00:00
Daniele Varrazzo
73949cd1b8
Merge branch 'diagnostics' into devel
2013-03-20 01:47:14 +00:00
Daniele Varrazzo
b503db9ce6
psycopg2.Error object and type renamed more consistently
2013-03-20 00:03:58 +00:00
Daniele Varrazzo
7177f815a6
Store a PGresult in the Exception error
...
This makes the Diagnostics independent from further operations on the cursor
and allows using it with exceptions not generated by a cursor.
2013-03-19 23:42:54 +00:00
Daniele Varrazzo
394312939e
Added a C structure to psycopg.Error
...
This will allow to store a PGresult in it.
2013-03-19 12:15:49 +00:00
Daniele Varrazzo
97311967e8
Merge branch 'diagnostics' into devel
2013-03-18 02:21:09 +00:00
Daniele Varrazzo
1cf9825035
Diagnostics is more GC friendly
2013-03-18 02:11:45 +00:00
Daniele Varrazzo
678f0dc949
Added documentation about the Diagnostics object
2013-03-18 02:11:45 +00:00
Daniele Varrazzo
819a551d01
Decode Diagnostics result on Python 3
2013-03-18 00:38:28 +00:00
Daniele Varrazzo
42b063b562
Added all supported properties to the Diagnostic object
2013-03-17 23:58:10 +00:00
Matthew Woodcraft
c75a3bbab4
Work-in-progress support for retrieving PG_DIAG result error fields.
2013-03-17 16:41:15 +00:00
Daniele Varrazzo
66d6c68dcc
Properly cleanup memory of broken connections
...
Fixed ticket #148 .
2013-03-16 11:56:38 +00:00
Daniele Varrazzo
16d96fd43c
Merge branch 'py33' into devel
2012-12-22 00:58:17 +01:00
Daniele Varrazzo
a04379210b
Doubt about 'c' buffer solved by Stefan Krah
2012-12-22 00:51:47 +01:00
Daniele Varrazzo
12645db754
Make sure to call subclasses methods on context exit
2012-12-03 03:37:47 +00:00
Daniele Varrazzo
cc605032f5
Added support for with statement for connection and cursor
...
The implementation should be conform to the DBAPI, although the "with"
extension has not been released yet.
2012-12-03 02:50:24 +00:00
Daniele Varrazzo
9f06df1820
Fixed signature for METH_NOARGS functions
2012-12-03 02:49:06 +00:00
Daniele Varrazzo
362c2ae597
Release the GIL around PQgetResult calls after COPY
...
It should fix ticket #140 .
2012-11-24 22:49:36 +00:00
Daniele Varrazzo
71393b9ae9
Discard any result produced by cursor.executemany()
2012-10-11 22:29:03 +01:00
Daniele Varrazzo
5fbf3ef147
Merge branch 'fix-113' into devel
2012-10-11 22:26:51 +01:00
Daniele Varrazzo
b61a2a34c4
Close the connection on error in callback
...
Unfortunately PQcancel blocks, so it's not better than PQgetResult.
It has been suggested to use PQreset in non-blocking way but this would give
the Python program the burden of handling a connection done but not configured
in an unexpected place.
2012-10-06 11:58:52 +01:00
Daniele Varrazzo
2611d62283
Get the result from the connection after the green panic
...
Otherwise the connection won't be usable in case we manage
to put it back on track (libpq reports "another command is
already in progress")
2012-10-06 01:45:24 +01:00
Daniele Varrazzo
644b18a2c9
Dropped compiler warning on Py 2.4
2012-10-06 01:22:05 +01:00
Daniele Varrazzo
76815f1e92
Added compatibility PyErr_WarnEx macro for Python 2.4
2012-10-06 01:16:57 +01:00
Daniele Varrazzo
53b1c70f3a
Attempt to fix issue #113 .
...
If the network is down, trying to read blocking will hang the process hard
(ctrl-c not working). Send a cancel signal instead (as suggested in
http://archives.postgresql.org/pgsql-hackers/2012-07/msg00903.php ) and go
back into a green polling: this should allow a further error (e.g. another
ctrl-c) to break the loop. In this case we cannot assume anything about
the state of the connection, so we close it.
2012-10-06 01:10:41 +01:00
Daniele Varrazzo
2137db89d4
Added function conn_close_locked()
2012-10-06 01:03:12 +01:00
Daniele Varrazzo
469b6f8aff
Return memoryview object of type "c" instead of "B" from bytea
...
In Python 3.3 items are returned as int instead of chars.
I'm not sure the way I did it is correct: worth asking some
hardcore Python dev.
Fixed tests after the stricter memview comparison rules in Py 3.3.
2012-09-21 00:54:37 +01:00
Daniele Varrazzo
62a54f64f7
Fixed infinite loop when parsing '{' as array
2012-09-20 03:24:47 +01:00
Daniele Varrazzo
0e644f6d95
Fixed return value after malformed arrays
2012-09-20 03:24:26 +01:00
Federico Di Gregorio
40a512fe46
Fixed always true comparaison
2012-08-17 14:52:59 +02:00
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