aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/postgres.sml
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2013-11-27 15:42:24 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2013-11-27 15:42:24 -0500
commit304ab490be019a3de447a5064f4598549d9cd36d (patch)
tree2142c7d0c902c046baaf580dda6023e7e6d2c221 /src/postgres.sml
parentee27f397f8ae80bfdb230f8c06a2025289d0db56 (diff)
Postgres: print SQLSTATE on DML failure, to help figure out when new special cases should be added
Diffstat (limited to 'src/postgres.sml')
-rw-r--r--src/postgres.sml12
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,