summaryrefslogtreecommitdiff
path: root/psycopg/pqpath.c
Commit message (Collapse)AuthorAgeFilesLines
* Collect rowcount in executemany even when discarding resultsDaniele Varrazzo2017-11-291-1/+2
| | | | Closes #633.
* Emulate timeradd and timersub on SolarisMy Karlsson2017-10-261-0/+4
| | | | | Solaris does not have timeradd and timersub. Add solaris_support.c which provides emulated versions of them on Solaris.
* Check return code from decoding the connection statusDaniele Varrazzo2017-06-151-2/+6
| | | | | | | | | It fails on Py3 after receiving a SIGABRT. Because we don't handle it here it will resurface later with nonsense such as: SystemError: <some function> returned a result with an error set Close #551
* Don't clobber a Python exception with an unknown errorDaniele Varrazzo2017-04-051-0/+4
| | | | Close #410
* Always raise OperationalError when connection was closed externally.Greg Ward2017-03-141-4/+6
| | | | | | | | | | | | | | | From the DB-API (https://www.python.org/dev/peps/pep-0249/): OperationalError Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, [...] Additionally, psycopg2 was inconsistent, at least in the async case: depending on how the "connection closed" error was reported from the kernel to libpq, it would sometimes raise OperationalError and sometimes DatabaseError. Now it always raises OperationalError.
* Always detect when a connection is closed behind psycopg2's back.Greg Ward2017-03-141-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There's a race condition that only seems to happen over Unix-domain sockets. Sometimes, the closed socket is reported by the kernel to libpq like this (captured with strace): sendto(3, "Q\0\0\0\34select pg_backend_pid()\0", 29, MSG_NOSIGNAL, NULL, 0) = 29 recvfrom(3, "E\0\0\0mSFATAL\0C57P01\0Mterminating "..., 16384, 0, NULL, NULL) = 110 recvfrom(3, 0x12d0330, 16384, 0, 0, 0) = -1 ECONNRESET (Connection reset by peer) That is, psycopg2/libpq sees no error when sending the first query after the connection is closed, but gets an error reading the result. In that case, everything worked fine. But sometimes, the error manifests like this: sendto(3, "Q\0\0\0\34select pg_backend_pid()\0", 29, MSG_NOSIGNAL, NULL, 0) = -1 EPIPE (Broken pipe) recvfrom(3, "E\0\0\0mSFATAL\0C57P01\0Mterminating "..., 16384, 0, NULL, NULL) = 110 recvfrom(3, "", 16274, 0, NULL, NULL) = 0 recvfrom(3, "", 16274, 0, NULL, NULL) = 0 i.e. libpq received an error when sending the query. This manifests as a slightly different exception from a slightly different place. More importantly, in this case connection.closed is left at 0 rather than being set to 2, and that is the bug I'm fixing here. Note that we see almost identical behaviour for sync and async connections, and the fixes are the same. So I added extremely similar test cases. Finally, there is still a bug here: for async connections, we sometimes raise DatabaseError (incorrect) and sometimes raise OperationalError (correct). Will fix that next.
* Fixed MSVC compiler error and warningJason Erickson2017-02-091-2/+2
| | | | | MSVC doesn't like referencing new initialized variables in the variable declaration section.
* Dropped compiler warning about signed/unsigned comparisonsDaniele Varrazzo2017-02-081-2/+2
|
* Fixed BEGIN; SET TRANSACTION with PG 7.4no-set-default-sessionDaniele Varrazzo2017-02-071-8/+16
|
* Set default_transaction_* GUC if session state is changed in autocomitDaniele Varrazzo2017-02-041-2/+4
|
* Don't use default_transaction_* for session characteristicsDaniele Varrazzo2017-02-041-2/+13
| | | | | | | | | 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.
* Don't look up for Python encodingDaniele Varrazzo2016-12-291-8/+29
| | | | | | 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...
* Use -1 instead of 0 to say "calculate the length" in many funcsDaniele Varrazzo2016-12-271-2/+2
| | | | 0 is a valid length, isn't it?
* conn->codec rename to pyencDaniele Varrazzo2016-12-261-6/+6
|
* Enforce dependency on libpq version >= 9.1Daniele Varrazzo2016-08-151-1/+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.
* Use inttypes.h definitionsDaniele Varrazzo2016-08-141-1/+1
|
* Merge branch 'master' into replication-protocolDaniele Varrazzo2016-08-071-5/+9
|\ | | | | | | | | Conflicts: tests/testconfig.py
| * Fix scattered grammar/spelling errors in comments, debug output, etc.Greg Ward2016-06-301-4/+4
| |
| * Fixed read() exception propagation in copy_fromDaniele Varrazzo2016-03-101-1/+5
| | | | | | | | Close issue #412.
* | Allow retrying start_replication after syntax or data error.Oleksandr Shulgin2016-01-051-2/+5
| |
* | Merge branch 'master' into feature/replication-protocolOleksandr Shulgin2015-10-271-2/+2
|\ \ | |/
| * Fix stale Dprintfs in pqpath.c referring to 'status'Oleksandr Shulgin2015-10-261-2/+2
| |
* | Drop ReplicationCursor.flush_feedback(), rectify pq_*_replication_*() interface.Oleksandr Shulgin2015-10-231-40/+29
| |
* | Move the `decode` parameter to `start_replication()`.Oleksandr Shulgin2015-10-231-7/+5
| | | | | | | | | | It makes more sense this way, because otherwise it must be passed to every call of `read_message()`.
* | Use direct call to consume() callable in pq_copy_both()Oleksandr Shulgin2015-10-221-5/+3
| |
* | Properly subclass ReplicationCursor on C level.Oleksandr Shulgin2015-10-191-44/+53
| |
* | Replace stop_replication with requirement for an exception.Oleksandr Shulgin2015-10-191-6/+1
| |
* | Remove commented copy_both code in pqfetch.Oleksandr Shulgin2015-10-141-7/+2
| |
* | Update stop_repl, require replication consumer to be a callable.Oleksandr Shulgin2015-10-141-4/+4
| |
* | Rework replication connection/cursor classesOleksandr Shulgin2015-10-011-40/+53
| |
* | Merge remote-tracking branch 'origin/master' into replOleksandr Shulgin2015-10-011-4/+21
|\ \ | |/
| * Report NotSupportedError for PGRES_COPY_BOTH and PGRES_SINGLE_TUPLEDaniele Varrazzo2015-09-301-2/+17
| | | | | | | | Fixes #352.
| * Report the server response status on errors with no messageDaniele Varrazzo2015-09-301-2/+4
| | | | | | | | | | | | 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.
* | Fix use of PQconsumeInput() in pq_read_replication_message()Oleksandr Shulgin2015-07-071-11/+25
| | | | | | | | | | | | 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.
* | Check return value of PQsocketOleksandr Shulgin2015-07-021-6/+9
| | | | | | | | When connection is closed by the server, we might get -1 there.
* | Fix PQconsumeInput usage.Oleksandr Shulgin2015-07-021-4/+9
| | | | | | | | Only call when no data is available in the internal buffer.
* | Comment on special handling of PGRES_COPY_BOTHOleksandr Shulgin2015-06-301-0/+4
| |
* | Rework replication protocolOleksandr Shulgin2015-06-301-183/+179
| | | | | | | | | | | | | | | | | | 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.
* | Refer cursor from ReplicationMessage object. At the same time, for the sync ↵Oleksandr Shulgin2015-06-111-6/+6
| | | | | | | | use LSN instead of msg reference in cursor.
* | Add handling of send_time field in replmsgOleksandr Shulgin2015-06-101-3/+5
| |
* | Add ReplicationMessage objectOleksandr Shulgin2015-06-051-12/+40
| |
* | Add timersub for Win32. Fix gettimeofday on MinGW.Oleksandr Shulgin2015-06-041-4/+3
| |
* | Add libpq_support.c and win32_support.cOleksandr Shulgin2015-06-031-79/+4
| | | | | | | | | | | | Move libpq-specific code for streaming replication support into a separate file. Also provide gettimeofday() on Win32, implementation copied from Postgres core.
* | Get rid of postgres internal includes; check for Win32 for htonl()Oleksandr Shulgin2015-06-021-16/+30
| |
* | Add support for streaming replication protocolOleksandr Shulgin2015-06-011-0/+312
|/ | | | | | | | | | | | 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.)
* Unlock the connection after PQflush errorDaniele Varrazzo2015-05-031-0/+4
| | | | | | Apparently this has never happened... anyway the code path was wrong. Fixes #294.
* Propagate read error messages in COPY FROMDaniele Varrazzo2015-02-081-3/+21
| | | | Fix ticket #270.
* Dropped PSYCOPG_EXTENSIONS flagDaniele Varrazzo2014-08-231-6/+0
| | | | | | Building without extensions has been long broken and nobody really cares about a pure-DBAPI implementation (which could be created using a wrapper instead).
* No implicit transaction on named cursor closeAlexey Borzenkov2014-08-211-2/+2
| | | | | | Also, don't start an implicit transaction when fetching with named with hold cursor, since it already returns results from a previously committed transaction.
* Fixed segfault if COPY statements are executedDaniele Varrazzo2014-06-061-1/+15
| | | | Close ticket #219