diff src/postgres.sml @ 1918:c3c84fd38815

Postgres: remove DML error code logging and (hopefully) fix the real problem, not checking for concurrency faults on SELECTs
author Adam Chlipala <adam@chlipala.net>
date Fri, 29 Nov 2013 08:12:57 -0500
parents e2345c438f08
children 2f33d9a51765
line wrap: on
line diff
--- a/src/postgres.sml	Thu Nov 28 11:06:11 2013 -0500
+++ b/src/postgres.sml	Fri Nov 29 08:12:57 2013 -0500
@@ -602,7 +602,23 @@
 
          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 @@
               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,