diff options
author | Adam Chlipala <adam@chlipala.net> | 2018-03-13 15:30:11 -0400 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2018-03-13 15:30:11 -0400 |
commit | de2d8358dda08bfaf491d815df91d0c1ba33e7c9 (patch) | |
tree | f819be05586e191199befbcbf87b5743e3cdcc9c /src/postgres.sml | |
parent | e2d548c69e2a83ace5123ade21262aa27336fb6b (diff) |
Handle empty SELECT clauses
Diffstat (limited to 'src/postgres.sml')
-rw-r--r-- | src/postgres.sml | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/postgres.sml b/src/postgres.sml index 404384d2..fac913f0 100644 --- a/src/postgres.sml +++ b/src/postgres.sml @@ -612,6 +612,13 @@ fun p_getcol {loc, wontLeakStrings, col = i, typ = t} = getter t end +(* We turn 0-output queries into 1-output queries to satisfy SQL. + * This function adjusts our length expectations. *) +fun bumpedLength ls = + case ls of + [] => 1 + | _ => length ls + fun queryCommon {loc, query, cols, doCols} = box [string "int n, i;", newline, @@ -658,7 +665,7 @@ fun queryCommon {loc, query, cols, doCols} = newline, string "if (PQnfields(res) != ", - string (Int.toString (length cols)), + string (Int.toString (bumpedLength cols)), string ") {", newline, box [string "int nf = PQnfields(res);", @@ -668,7 +675,7 @@ fun queryCommon {loc, query, cols, doCols} = string "uw_error(ctx, FATAL, \"", string (ErrorMsg.spanToString loc), string ": Query returned %d columns instead of ", - string (Int.toString (length cols)), + string (Int.toString (bumpedLength cols)), string ":\\n%s\\n%s\", nf, ", query, string ", PQerrorMessage(conn));", |