From 304ab490be019a3de447a5064f4598549d9cd36d Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Wed, 27 Nov 2013 15:42:24 -0500 Subject: Postgres: print SQLSTATE on DML failure, to help figure out when new special cases should be added --- src/postgres.sml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/postgres.sml b/src/postgres.sml index ce7a78dd..e8e3046e 100644 --- a/src/postgres.sml +++ b/src/postgres.sml @@ -768,13 +768,19 @@ fun dmlCommon {loc, dml, mode} = string "}", newline, case mode of - Settings.Error => box [string "PQclear(res);", + Settings.Error => box [string "{", + newline, + string "char *sqlstate = uw_strdup(ctx, PQresultErrorField(res, PG_DIAG_SQLSTATE));", + newline, + string "PQclear(res);", newline, string "uw_error(ctx, FATAL, \"", string (ErrorMsg.spanToString loc), - string ": DML failed:\\n%s\\n%s\", ", + string ": DML failed:\\n%s\\n%s: %s\", ", dml, - string ", PQerrorMessage(conn));"] + string ", sqlstate, PQerrorMessage(conn));", + newline, + string "}"] | Settings.None => box [string "uw_set_error_message(ctx, PQerrorMessage(conn));", newline, newline, -- cgit v1.2.3