summaryrefslogtreecommitdiff
path: root/src/postgres.sml
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-07-16 16:29:13 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-07-16 16:29:13 -0400
commitfa6034d3141983cecef030e539f9a333f10d466b (patch)
treee84e8e1578e80ec83ada5acef409f93e11fabb03 /src/postgres.sml
parentd59ec50a871633c463f3e670e964522da39f5020 (diff)
Sequence code compiles in MySQL
Diffstat (limited to 'src/postgres.sml')
-rw-r--r--src/postgres.sml32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/postgres.sml b/src/postgres.sml
index 26825363..24166258 100644
--- a/src/postgres.sml
+++ b/src/postgres.sml
@@ -805,13 +805,28 @@ fun nextvalCommon {loc, query} =
string "PQclear(res);",
newline]
-fun nextval loc =
- box [string "PGconn *conn = uw_get_db(ctx);",
- newline,
- string "PGresult *res = PQexecParams(conn, query, 0, NULL, NULL, NULL, NULL, 0);",
- newline,
- newline,
- nextvalCommon {loc = loc, query = string "query"}]
+open Cjr
+
+fun nextval {loc, seqE, seqName} =
+ let
+ val query = case seqName of
+ SOME s =>
+ string ("SELECT NEXTVAL('" ^ s ^ "')")
+ | _ => box [string "uw_Basis_strcat(ctx, \"SELECT NEXTVAL('\", uw_Basis_strcat(ctx, ",
+ seqE,
+ string ", \"')\"))"]
+ in
+ box [string "char *query = ",
+ query,
+ string ";",
+ newline,
+ string "PGconn *conn = uw_get_db(ctx);",
+ newline,
+ string "PGresult *res = PQexecParams(conn, query, 0, NULL, NULL, NULL, NULL, 0);",
+ newline,
+ newline,
+ nextvalCommon {loc = loc, query = string "query"}]
+ end
fun nextvalPrepared {loc, id, query} =
box [string "PGconn *conn = uw_get_db(ctx);",
@@ -862,7 +877,8 @@ val () = addDbms {name = "postgres",
p_blank = p_blank,
supportsDeleteAs = true,
createSequence = fn s => "CREATE SEQUENCE " ^ s,
- textKeysNeedLengths = false}
+ textKeysNeedLengths = false,
+ supportsNextval = true}
val () = setDbms "postgres"