summaryrefslogtreecommitdiff
path: root/psycopg/pqpath.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/pqpath.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/pqpath.c')
-rw-r--r--psycopg/pqpath.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c
index a7f7a7c..02f7be5 100644
--- a/psycopg/pqpath.c
+++ b/psycopg/pqpath.c
@@ -107,9 +107,13 @@ exception_from_sqlstate(const char *sqlstate)
case '4':
switch (sqlstate[1]) {
case '0': /* Class 40 - Transaction Rollback */
+#ifdef PSYCOPG_EXTENSIONS
+ return TransactionRollbackError;
+#else
return OperationalError;
+#endif
case '2': /* Class 42 - Syntax Error or Access Rule Violation */
- case '4': /* Class 44 — WITH CHECK OPTION Violation */
+ case '4': /* Class 44 - WITH CHECK OPTION Violation */
return ProgrammingError;
}
break;
@@ -119,7 +123,12 @@ exception_from_sqlstate(const char *sqlstate)
Class 55 - Object Not In Prerequisite State
Class 57 - Operator Intervention
Class 58 - System Error (errors external to PostgreSQL itself) */
- return OperationalError;
+#ifdef PSYCOPG_EXTENSIONS
+ if (!strcmp(sqlstate, "57014"))
+ return QueryCanceledError;
+ else
+#endif
+ return OperationalError;
case 'F': /* Class F0 - Configuration File Error */
return InternalError;
case 'P': /* Class P0 - PL/pgSQL Error */
@@ -188,6 +197,9 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres,
|| !strncmp(err, "ERROR: ExecAppend: Fail to add null", 36)
|| strstr(err, "referential integrity violation"))
exc = IntegrityError;
+ else if (strstr(err, "could not serialize") ||
+ strstr(err, "deadlock detected"))
+ exc = TransactionRollbackError;
else
exc = ProgrammingError;
}