summaryrefslogtreecommitdiff
path: root/psycopg/psycopgmodule.c
diff options
context:
space:
mode:
authorJames Henstridge <james@jamesh.id.au>2008-01-16 05:14:24 +0000
committerJames Henstridge <james@jamesh.id.au>2008-01-16 05:14:24 +0000
commitf64cbeda4606d8af3ca063736f313f81506c56bb (patch)
tree0f0de0dddb735963bb348e2e6eae4371ecfe47b2 /psycopg/psycopgmodule.c
parent46bf23caf47c3f08194e524312b5afbe0c449b70 (diff)
downloadpsycopg2-f64cbeda4606d8af3ca063736f313f81506c56bb.tar.gz
* 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.
Diffstat (limited to 'psycopg/psycopgmodule.c')
-rw-r--r--psycopg/psycopgmodule.c47
1 files changed, 20 insertions, 27 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 26cc500..a212ba4 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -100,32 +100,6 @@ _psyco_connect_fill_dsn(char *dsn, char *kw, char *v, size_t i)
return i;
}
-static void
-_psyco_connect_fill_exc(connectionObject *conn)
-{
- /* fill the connection object with the exceptions */
- conn->exc_Error = Error;
- Py_INCREF(Error);
- conn->exc_Warning = Warning;
- Py_INCREF(Warning);
- conn->exc_InterfaceError = InterfaceError;
- Py_INCREF(InterfaceError);
- conn->exc_DatabaseError = DatabaseError;
- Py_INCREF(DatabaseError);
- conn->exc_InternalError = InternalError;
- Py_INCREF(InternalError);
- conn->exc_ProgrammingError = ProgrammingError;
- Py_INCREF(ProgrammingError);
- conn->exc_IntegrityError = IntegrityError;
- Py_INCREF(IntegrityError);
- conn->exc_DataError = DataError;
- Py_INCREF(DataError);
- conn->exc_NotSupportedError = NotSupportedError;
- Py_INCREF(NotSupportedError);
- conn->exc_OperationalError = OperationalError;
- Py_INCREF(OperationalError);
-}
-
static PyObject *
psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
{
@@ -215,7 +189,6 @@ psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
/* allocate connection, fill with errors and return it */
if (factory == NULL) factory = (PyObject *)&connectionType;
conn = PyObject_CallFunction(factory, "s", dsn);
- if (conn) _psyco_connect_fill_exc((connectionObject*)conn);
}
goto cleanup;
@@ -433,6 +406,9 @@ static void psyco_encodings_fill(PyObject *dict)
PyObject *Error, *Warning, *InterfaceError, *DatabaseError,
*InternalError, *OperationalError, *ProgrammingError,
*IntegrityError, *DataError, *NotSupportedError;
+#ifdef PSYCOPG_EXTENSIONS
+PyObject *QueryCanceledError, *TransactionRollbackError;
+#endif
/* mapping between exception names and their PyObject */
static struct {
@@ -455,6 +431,13 @@ static struct {
{ "psycopg2.DataError", &DataError, &DatabaseError, DataError_doc },
{ "psycopg2.NotSupportedError", &NotSupportedError, &DatabaseError,
NotSupportedError_doc },
+#ifdef PSYCOPG_EXTENSIONS
+ { "psycopg2.extensions.QueryCanceledError", &QueryCanceledError,
+ &OperationalError, OperationalError_doc },
+ { "psycopg2.extensions.TransactionRollbackError",
+ &TransactionRollbackError, &OperationalError,
+ TransactionRollbackError_doc },
+#endif
{NULL} /* Sentinel */
};
@@ -507,6 +490,11 @@ psyco_errors_fill(PyObject *dict)
PyDict_SetItemString(dict, "IntegrityError", IntegrityError);
PyDict_SetItemString(dict, "DataError", DataError);
PyDict_SetItemString(dict, "NotSupportedError", NotSupportedError);
+#ifdef PSYCOPG_EXTENSIONS
+ PyDict_SetItemString(dict, "QueryCanceledError", QueryCanceledError);
+ PyDict_SetItemString(dict, "TransactionRollbackError",
+ TransactionRollbackError);
+#endif
}
void
@@ -522,6 +510,11 @@ psyco_errors_set(PyObject *type)
PyObject_SetAttrString(type, "IntegrityError", IntegrityError);
PyObject_SetAttrString(type, "DataError", DataError);
PyObject_SetAttrString(type, "NotSupportedError", NotSupportedError);
+#ifdef PSYCOPG_EXTENSIONS
+ PyObject_SetAttrString(type, "QueryCanceledError", QueryCanceledError);
+ PyObject_SetAttrString(type, "TransactionRollbackError",
+ TransactionRollbackError);
+#endif
}
/* psyco_error_new