Commit Graph

62 Commits

Author SHA1 Message Date
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
f06f557111 Add one more test for errors involving two cursors 2010-04-20 23:01:10 +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
Federico Di Gregorio
249b3ef88f Merged tests from piro and jan async fixes branches 2010-04-14 10:01:37 +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
Daniele Varrazzo
595dc7effa Added a test to check poll() correctly calls PQflush.
When a large query is sent to the backend (and probably in high
concurrency situations), writing the query could block. In
this case PQflush() should be called until it returns 0. The test checks
this is done correctly.
2010-04-11 01:05:31 +01:00
Daniele Varrazzo
47ff5a6b01 test_async made properly executable. 2010-04-11 00:06:54 +01:00
Federico Di Gregorio
0a33ed01f5 Added test for refcounting/gc bug reported by Michael Tharp 2010-04-08 18:42:20 +02:00
Daniele Varrazzo
d197346ce3 Added test to check that connections subclasses can be asynchronous. 2010-04-08 12:51:33 +01:00
Daniele Varrazzo
b114e25c31 Added some COPY tests. 2010-04-07 23:41:32 +01:00
Jan Urbański
e15bc9da05 Adapt the tests to recent changes
Some methods were forbidden in asynchronous mode, the isolation level
of an asynchronous connection is not always 0 and these changes
influenced expected test results.
2010-04-05 16:28:39 +02:00
Jan Urbański
eb646f71fa Add tests for the asynchronous API 2010-04-05 11:32:03 +02:00
Jan Urbański
e0d789466a Support large objects truncating.
The lobject.truncate(len=0) method will be available if psycopg2 has
been built against libpq from 8.3 or later (which is when the lobject
truncating support has been introduced).
2010-03-29 09:19:35 +02:00
Federico Di Gregorio
192034dc38 Fixed problem with decimal.Decimal conversions 2010-02-21 01:04:00 +01:00
Federico Di Gregorio
611606d532 Changes license to LGPL3 + OpenSSL exception on all source files 2010-02-12 23:34:53 +01:00
Federico Di Gregorio
bcc836c661 Now adapt() errors include the type name 2009-11-25 11:51:54 +01:00
Federico Di Gregorio
d40a5321f2 Fixed test broken by float precision fix 2009-11-25 10:38:31 +01:00
Federico Di Gregorio
390a9c2451 Added support for UUID arrays 2009-10-04 12:34:02 +02:00
Federico Di Gregorio
3a6911216b Fixed problem with large writes in large objects code 2009-08-09 17:05:16 +02:00
Federico Di Gregorio
36aff2f73d Implemented connection.reset() 2009-08-09 16:19:08 +02:00
Federico Di Gregorio
e1fae0fcac Fixed bug in RealDictCursor when prefetching 2009-05-09 14:44:59 +02:00
Federico Di Gregorio
f1e532151f Removed unecessary import 2009-04-04 19:14:53 +02:00
Federico Di Gregorio
8e54f7dcce Fixed test_dates failures in older version of Python 2009-04-01 20:52:58 +02:00
Federico Di Gregorio
e8ef973ddf Fixed lobject test failures 2009-04-01 20:49:00 +02:00
Federico Di Gregorio
5b04203c9f Fixed error in register_type() 2009-03-02 10:59:52 +01:00
James Henstridge
2a94dfae47 * tests/test_dates.py (DatetimeTests, mxDateTimeTests): full test
coverage for datetime and time strings with and without time zone
	information.

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

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

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

	* tests/test_dates.py (DatetimeTests): Add tests for time zone
	parsing.  The test for HH:MM:SS time zones is disabled because we
	don't currently support it.
2009-02-17 12:58:45 +09:00
James Henstridge
3466b3b72d Add tests for time zone parsing, for "HH", "HH:MM" and "HH:MM:SS" forms.
Currently the second fails for negative offsets due to bugs in the 
parser, and the third fails because it doesn't even try to parse second 
offset values (as Python doesn't either).
2009-02-17 12:39:57 +09:00
Federico Di Gregorio
eb25f9f154 Added adapter to handle float('inf') and float('nan') 2009-01-23 00:09:20 +01:00
Federico Di Gregorio
4c8e80038e Added inet support 2008-09-24 01:27:52 +02:00
Federico Di Gregorio
56f6001d6d Support for NULLs in UUID 2008-09-23 09:11:11 +02:00
Federico Di Gregorio
b92601306e Added suppport for UUID and related test. 2008-09-19 21:25:16 +02:00
James Henstridge
7d66c20edb * tests/test_lobject.py (LargeObjectTests): add more tests,
including behaviour on closed lobjects and stale lobjects.

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

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

	* psycopg/lobject_type.c (lobject_setup): make lobjects start closed.
2008-05-06 17:04:26 +08:00
James Henstridge
9a48c261be Add basic tests for large object code. Fix lobject.seek() to actually
work.
2008-05-05 15:33:44 +08:00
James Henstridge
331c942800 2008-04-21 James Henstridge <james@jamesh.id.au>
* tests/test_quote.py (QuotingTestCase.test_unicode): If the
	server encoding is not UTF8, skip the unicode test and emit a
	warning.
2008-04-20 23:19:42 +00:00
James Henstridge
2f3f4c1258 2008-04-21 Jorgen Austvik <Jorgen.Austvik@sun.com>
* tests/*.py: use the DSN constructed in tests/__init__.py.

	* tests/__init__.py: allow setting the host, port and user for the
	DSN used by the tests through the environment.
2008-04-20 23:12:21 +00:00
James Henstridge
cceaa7331b * psycopg/typecast.c (typecast_parse_time): give the correct
return value for partially parsed time values.

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

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

	* tests/test_dates.py
	(CommonDatetimeTestsMixin.test_parse_incomplete_date): test that
	parsing incomplete date values results in DataError.
	(CommonDatetimeTestsMixin.test_parse_incomplete_time): same for
	times.
	(CommonDatetimeTestsMixin.test_parse_incomplete_time): same for
	datetimes.
2008-03-17 04:06:44 +00:00
James Henstridge
3265dd172d * tests/test_connection.py (ConnectionTests): add simple tests for
the Connection and Cursor "closed" attributes.

	* psycopg/cursor_type.c (psyco_curs_get_closed): add a "closed"
	attribute to cursors.  It will be True if either the cursor or its
	associated connection are closed.  This fixes bug #164.
2008-01-19 03:32:42 +00:00
James Henstridge
bc663111b6 Split the binary tests out a bit. 2008-01-16 18:08:12 +00:00
James Henstridge
f64cbeda46 * tests/test_transaction.py (DeadlockSerializationTestCase): port
over some tests for serialisation and deadlock errors,
	demonstrating that TransactionRollbackError is generated.
	(QueryCancelationTests): add a test to show that
	QueryCanceledError is raised on statement timeouts.

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

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

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

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

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

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

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

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

	* psycopg/typecast.c (typecast_parse_date): if the string ends
	with "BC" adjust the year value to be a zero-based BC value as
	used by mx.DateTime (datetime doesn't support BC dates).
	(typecast_parse_time): ignore ' ', 'B' and 'C' in time strings
	rather than treating them as part of the seconds part of the time.
2008-01-16 01:43:50 +00:00
James Henstridge
7d80c05748 * tests/test_transaction.py
(TransactionTestCase.test_failed_commit): Expect IntegrityError
	instead of OperationalError.

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

	* tests/types_basic.py (TypesBasicTests.testBinary): Test round
	tripping of bytea buffers.  Currently segfaults.
2008-01-10 22:19:23 +00:00
Daniele Varrazzo
67afd678b0 Added 'make check' target, running all the available tests.
Most of the updates have been provided by James Henstridge.

Closes ticket #195.
2007-11-11 10:40:12 +00:00
Daniele Varrazzo
75cb5d75d7 Use escape string syntax for string escape if connected to a server
requiring it.

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

Added a test case to verify correct behavior on strings, unicode and binary 
data. Tested with PG versions from 7.4 to 8.3b2, with any server
'standard_conforming_strings' setting and with 'PSYCOPG_OWN_QUOTING' too.
2007-11-11 08:53:44 +00:00
Daniele Varrazzo
a6ea092acc - Tabs fixed. 2007-11-11 03:58:45 +00:00