Commit Graph

796 Commits

Author SHA1 Message Date
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