summaryrefslogtreecommitdiff
path: root/src/postgres.sml
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2010-09-05 14:00:57 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2010-09-05 14:00:57 -0400
commitee175ea1f9151123e47d9cbfee0c6329b2e5d934 (patch)
treeb1f65d2c756f6867bc59eb1a0bb424deefacfabe /src/postgres.sml
parent1d30544730c4785eef4aabc4a224c03fe1b26983 (diff)
tryDml
Diffstat (limited to 'src/postgres.sml')
-rw-r--r--src/postgres.sml26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/postgres.sml b/src/postgres.sml
index 12e928c5..bf1e8536 100644
--- a/src/postgres.sml
+++ b/src/postgres.sml
@@ -708,7 +708,7 @@ fun queryPrepared {loc, id, query, inputs, cols, doCols, nested = _} =
string (String.toCString query),
string "\""]}]
-fun dmlCommon {loc, dml} =
+fun dmlCommon {loc, dml, mode} =
box [string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating DML result.\");",
newline,
newline,
@@ -723,13 +723,15 @@ fun dmlCommon {loc, dml} =
newline],
string "}",
newline,
- string "PQclear(res);",
- newline,
- string "uw_error(ctx, FATAL, \"",
- string (ErrorMsg.spanToString loc),
- string ": DML failed:\\n%s\\n%s\", ",
- dml,
- string ", PQerrorMessage(conn));",
+ case mode of
+ Settings.Error => box [string "PQclear(res);",
+ newline,
+ string "uw_error(ctx, FATAL, \"",
+ string (ErrorMsg.spanToString loc),
+ string ": DML failed:\\n%s\\n%s\", ",
+ dml,
+ string ", PQerrorMessage(conn));"]
+ | Settings.None => string "uw_errmsg = PQerrorMessage(conn);",
newline],
string "}",
newline,
@@ -738,15 +740,15 @@ fun dmlCommon {loc, dml} =
string "PQclear(res);",
newline]
-fun dml loc =
+fun dml (loc, mode) =
box [string "PGconn *conn = uw_get_db(ctx);",
newline,
string "PGresult *res = PQexecParams(conn, dml, 0, NULL, NULL, NULL, NULL, 0);",
newline,
newline,
- dmlCommon {loc = loc, dml = string "dml"}]
+ dmlCommon {loc = loc, dml = string "dml", mode = mode}]
-fun dmlPrepared {loc, id, dml, inputs} =
+fun dmlPrepared {loc, id, dml, inputs, mode} =
box [string "PGconn *conn = uw_get_db(ctx);",
newline,
string "const int paramFormats[] = { ",
@@ -787,7 +789,7 @@ fun dmlPrepared {loc, id, dml, inputs} =
newline,
dmlCommon {loc = loc, dml = box [string "\"",
string (String.toCString dml),
- string "\""]}]
+ string "\""], mode = mode}]
fun nextvalCommon {loc, query} =
box [string "if (res == NULL) uw_error(ctx, FATAL, \"Out of memory allocating nextval result.\");",