From d475845ceef7c1998a7d5091aaef5c55bb229b99 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Fri, 29 Nov 2013 08:12:57 -0500 Subject: Postgres: remove DML error code logging and (hopefully) fix the real problem, not checking for concurrency faults on SELECTs --- src/postgres.sml | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/postgres.sml') diff --git a/src/postgres.sml b/src/postgres.sml index e8e3046e..44101527 100644 --- a/src/postgres.sml +++ b/src/postgres.sml @@ -602,7 +602,23 @@ fun queryCommon {loc, query, cols, doCols} = string "if (PQresultStatus(res) != PGRES_TUPLES_OK) {", newline, - box [string "PQclear(res);", + box [string "if (!strcmp(PQresultErrorField(res, PG_DIAG_SQLSTATE), \"40001\")) {", + box [newline, + string "PQclear(res);", + newline, + string "uw_error(ctx, UNLIMITED_RETRY, \"Serialization failure\");", + newline], + string "}", + newline, + string "if (!strcmp(PQresultErrorField(res, PG_DIAG_SQLSTATE), \"40P01\")) {", + box [newline, + string "PQclear(res);", + newline, + string "uw_error(ctx, UNLIMITED_RETRY, \"Deadlock detected\");", + newline], + string "}", + newline, + string "PQclear(res);", newline, string "uw_error(ctx, FATAL, \"", string (ErrorMsg.spanToString loc), @@ -768,19 +784,13 @@ fun dmlCommon {loc, dml, mode} = string "}", newline, case mode of - Settings.Error => box [string "{", - newline, - string "char *sqlstate = uw_strdup(ctx, PQresultErrorField(res, PG_DIAG_SQLSTATE));", - newline, - string "PQclear(res);", + Settings.Error => box [string "PQclear(res);", newline, string "uw_error(ctx, FATAL, \"", string (ErrorMsg.spanToString loc), - string ": DML failed:\\n%s\\n%s: %s\", ", + string ": DML failed:\\n%s\\n%s\", ", dml, - string ", sqlstate, PQerrorMessage(conn));", - newline, - string "}"] + string ", PQerrorMessage(conn));"] | Settings.None => box [string "uw_set_error_message(ctx, PQerrorMessage(conn));", newline, newline, -- cgit v1.2.3