diff src/mysql.sml @ 1954:1802eb00a0ae

MySQL: catch deadlocks during queries
author Adam Chlipala <adam@chlipala.net>
date Sun, 05 Jan 2014 20:20:09 -0500
parents 0992323fa264
children 469e02eea43a
line wrap: on
line diff
--- a/src/mysql.sml	Sat Jan 04 19:02:14 2014 -0500
+++ b/src/mysql.sml	Sun Jan 05 20:20:09 2014 -0500
@@ -854,11 +854,20 @@
          newline,
          newline,
 
-         string "if (mysql_stmt_execute(stmt)) uw_error(ctx, FATAL, \"",
-         string (ErrorMsg.spanToString loc),
-         string ": Error executing query: %s\\n%s\", ",
-         query,
-         string ", mysql_error(conn->conn));",
+         string "if (mysql_stmt_execute(stmt)) {",
+         newline,
+         box [string "if (mysql_errno(conn->conn) == 1213)",
+              newline,
+              box [string "uw_error(ctx, UNLIMITED_RETRY, \"Deadlock detected\");",
+                   newline],
+              newline,
+              string "uw_error(ctx, FATAL, \"",
+              string (ErrorMsg.spanToString loc),
+              string ": Error executing query: %s\\n%s\", ",
+              query,
+              string ", mysql_error(conn->conn));",
+              newline],
+         string "}",
          newline,
          newline,