diff options
author | Adam Chlipala <adam@chlipala.net> | 2013-11-27 15:42:24 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2013-11-27 15:42:24 -0500 |
commit | fa6d107f2648a3904e0810b43c296321c857aae7 (patch) | |
tree | 2142c7d0c902c046baaf580dda6023e7e6d2c221 /src | |
parent | 160ebb4779e0e6990fc7c500681b626b50422db7 (diff) |
Postgres: print SQLSTATE on DML failure, to help figure out when new special cases should be added
Diffstat (limited to 'src')
-rw-r--r-- | src/postgres.sml | 12 |
1 files 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, |