# HG changeset patch # User Adam Chlipala # Date 1385584944 18000 # Node ID e2345c438f089617c2605ceb30120b000111d279 # Parent 52e88e139b2560333456ab0f93c193b2f2af2e97 Postgres: print SQLSTATE on DML failure, to help figure out when new special cases should be added diff -r 52e88e139b25 -r e2345c438f08 src/postgres.sml --- a/src/postgres.sml Wed Nov 27 15:28:55 2013 -0500 +++ b/src/postgres.sml Wed Nov 27 15:42:24 2013 -0500 @@ -768,13 +768,19 @@ 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,