From f00f54541df6722f06057da89da38ba906252058 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 5 Jan 2014 20:20:09 -0500 Subject: MySQL: catch deadlocks during queries --- src/mysql.sml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mysql.sml b/src/mysql.sml index a119321c..3b59d1c1 100644 --- a/src/mysql.sml +++ b/src/mysql.sml @@ -854,11 +854,20 @@ fun queryCommon {loc, query, cols, doCols} = 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, -- cgit v1.2.3