diff src/postgres.sml @ 2270:1e3ba868f8bf

Merge.
author Ziv Scully <ziv@mit.edu>
date Mon, 19 Oct 2015 14:42:22 -0400
parents 00cf8214c2e3
children 251dd276f45f
line wrap: on
line diff
--- a/src/postgres.sml	Thu Oct 15 00:52:04 2015 -0400
+++ b/src/postgres.sml	Mon Oct 19 14:42:22 2015 -0400
@@ -617,7 +617,13 @@
          newline,
          newline,
 
-         string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating query result.\");",
+         string "if (res == NULL) {",
+         box [newline,
+              string "uw_try_reconnecting_and_restarting(ctx);",
+              newline,
+              string "uw_error(ctx, FATAL, \"Can't allocate query result; database server may be down.\");",
+              newline],
+         string "}",
          newline,
          newline,
 
@@ -782,7 +788,13 @@
                                                                             string "\""]}]
 
 fun dmlCommon {loc, dml, mode} =
-    box [string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating DML result.\");",
+    box [string "if (res == NULL) {",
+         box [newline,
+              string "uw_try_reconnecting_and_restarting(ctx);",
+              newline,
+              string "uw_error(ctx, FATAL, \"Can't allocate DML result; database server may be down.\");",
+              newline],
+         string "}",
          newline,
          newline,
 
@@ -818,7 +830,13 @@
 
                                         string "res = PQexec(conn, \"ROLLBACK TO s\");",
                                         newline,
-                                        string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating DML result.\");",
+                                        string "if (res == NULL) {",
+                                        box [newline,
+                                             string "uw_try_reconnecting_and_restarting(ctx);",
+                                             newline,
+                                             string "uw_error(ctx, FATAL, \"Can't allocate DML ROLLBACK result; database server may be down.\");",
+                                             newline],
+                                        string "}",
                                         newline,
                                         newline,
 
@@ -851,7 +869,13 @@
                               newline,
                               string "res = PQexec(conn, \"RELEASE s\");",
                               newline,
-                              string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating DML result.\");",
+                              string "if (res == NULL) {",
+                              box [newline,
+                                   string "uw_try_reconnecting_and_restarting(ctx);",
+                                   newline,
+                                   string "uw_error(ctx, FATAL, \"Can't allocate DML RELEASE result; database server may be down.\");",
+                                   newline],
+                              string "}",
                               newline,
                               newline,
 
@@ -877,7 +901,13 @@
         Error => box []
       | None => box [string "res = PQexec(conn, \"SAVEPOINT s\");",
                      newline,
-                     string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating DML result.\");",
+                     string "if (res == NULL) {",
+                     box [newline,
+                          string "uw_try_reconnecting_and_restarting(ctx);",
+                          newline,
+                          string "uw_error(ctx, FATAL, \"Can't allocate DML SAVEPOINT result; database server may be down.\");",
+                          newline],
+                     string "}",
                      newline,
                      newline,
                      string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
@@ -938,7 +968,13 @@
                                           string "\""], mode = mode}]
 
 fun nextvalCommon {loc, query} =
-    box [string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating nextval result.\");",
+    box [string "if (res == NULL) {",
+         box [newline,
+              string "uw_try_reconnecting_and_restarting(ctx);",
+              newline,
+              string "uw_error(ctx, FATAL, \"Can't allocate NEXTVAL result; database server may be down.\");",
+              newline],
+         string "}",
          newline,
          newline,
 
@@ -1020,7 +1056,13 @@
                                                 string "\""]}]
 
 fun setvalCommon {loc, query} =
-    box [string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating setval result.\");",
+    box [string "if (res == NULL) {",
+         box [newline,
+              string "uw_try_reconnecting_and_restarting(ctx);",
+              newline,
+              string "uw_error(ctx, FATAL, \"Can't allocate SETVAL result; database server may be down.\");",
+              newline],
+         string "}",
          newline,
          newline,