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.
pq_abort_locked() prototype.
(conn_switch_isolation_level): fix for new pq_abort_locked()
prototype, and use pq_complete_error() to show error message.
(conn_set_client_encoding): same here.
* psycopg/pqpath.c (pq_execute_command_locked): remove static
modifier.
(pq_complete_error): same here.
(pq_abort_locked): add pgres and error arguments.
(pq_abort): call pq_abort_locked() to reduce code duplication.
* psycopg/pqpath.c (pq_execute_command_locked): add an error
argument to hold an error when no PGresult is returned by PQexec,
rather than using pq_set_critical().
(pq_complete_error): new function that converts the error returned
by pq_execute_command_locked() to a Python exception.
(pq_begin_locked): add error argument.
(pq_commit): use pq_complete_error().
(pq_abort): use pq_complete_error().
(pq_abort_locked): always call pq_set_critical() on error, and
clear the error message from pq_execute_command_locked().
(pq_execute): use pq_complete_error() to handle the error from
pq_begin_locked().
* psycopg/pqpath.c (pq_begin): remove unused function.
* psycopg/connection_type.c (psyco_conn_commit): if conn_commit()
raises an error, just return NULL, since it is now setting an
exception itself.
(psyco_conn_rollback): same here.
* psycopg/connection_int.c (conn_commit): don't drop GIL and lock
connection before calling pq_commit().
(conn_rollback): same here.
(conn_close): use pq_abort_locked().
(conn_switch_isolation_level): same here.
(conn_set_client_encoding): same here.
* psycopg/pqpath.h: add prototype for pq_abort_locked().
* psycopg/pqpath.c (pq_commit): convert function to run with GIL
held, and handle errors appropriately.
(pq_abort): same here.
(pq_abort_locked): new function to abort a locked connection.
2007-12-22 James Henstridge <james@jamesh.id.au>
* psycopg/pqpath.c (pq_raise): add a "pgres" argument so we can
generate nice errors not related to a particular cursor.
(pq_execute): use pq_begin_locked() rather than pq_begin(). Use
pq_raise() to handle any errors from it.
* psycopg/pqpath.c (pq_execute_command_locked): helper function
used to execute a command-style query on a locked connection.
(pq_begin_locked): a variant of pq_begin() that uses
pq_execute_command_locked().
(pq_begin): rewrite to use pq_begin_locked().
* psycopg/config.h: only print debug messages if
psycopg_debug_enabled is true.
* psycopg/psycopgmodule.c (init_psycopg): set
psycopg_debug_enabled to true if the $PSYCOPG_DEBUG environment
variable is set.
NULL" error handler after the PQexec() call. This is needed to
catch database disconnects (and probably other errors). According
to Federico, it was commented out to avoid a spurious error, so we
should watch for problems.
of the exception message if it actually gives the severity.
* psycopg/pqpath.h (pq_resolve_critical): add prototype, since
this function is being used from connection_int.c.
* psycopg/psycopg.h: update psyco_set_error() prototype.
* psycopg/psycopgmodule.c (psyco_errors_init): set pgerror, pgcode
and cursor class attributes to None on psycopg2.Error so that the
attributes will always be available (simplifies error handling).
(psyco_set_error): add const qualifiers to msg, pgerror and pgcode
arguments.
Don't bother setting pgerror, pgcode or cursor to None if they are
not provided -- the class defaults take care of this.
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.
interpreters) as proposed by Graham Dumpleton.
If running in the main interpreter, use a cached version of the Decimal
object. Else repeat the object lookup.