diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cjr_print.sml | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml index 8ce4433f..c870c3ed 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -418,7 +418,7 @@ fun p_unsql wontLeakStrings env (tAll as (t, loc)) e eLen = fun p_getcol wontLeakStrings env (tAll as (t, loc)) i = case t of TOption t => - box [string "(PQgetisnull (res, i, ", + box [string "(PQgetisnull(res, i, ", string (Int.toString i), string ") ? NULL : ", case t of @@ -440,13 +440,30 @@ fun p_getcol wontLeakStrings env (tAll as (t, loc)) i = string "})"], string ")"] | _ => - p_unsql wontLeakStrings env tAll - (box [string "PQgetvalue(res, i, ", - string (Int.toString i), - string ")"]) - (box [string "PQgetlength(res, i, ", - string (Int.toString i), - string ")"]) + box [string "(PQgetisnull(res, i, ", + string (Int.toString i), + string ") ? ", + box [string "({", + p_typ env tAll, + space, + string "tmp;", + newline, + string "uw_error(ctx, FATAL, \"Unexpectedly NULL field #", + string (Int.toString i), + string "\");", + newline, + string "tmp;", + newline, + string "})"], + string " : ", + p_unsql wontLeakStrings env tAll + (box [string "PQgetvalue(res, i, ", + string (Int.toString i), + string ")"]) + (box [string "PQgetlength(res, i, ", + string (Int.toString i), + string ")"]), + string ")"] datatype sql_type = Int @@ -1571,6 +1588,28 @@ fun p_exp' par env (e, loc) = newline, newline, + string "if (PQnfields(res) != ", + string (Int.toString (length outputs)), + string ") {", + newline, + box [string "int nf = PQnfields(res);", + newline, + string "PQclear(res);", + newline, + string "uw_error(ctx, FATAL, \"", + string (ErrorMsg.spanToString loc), + string ": Query returned %d columns instead of ", + string (Int.toString (length outputs)), + string ":\\n%s\\n%s\", ", + case prepared of + NONE => string "query" + | SOME _ => p_exp env query, + string ", nf, PQerrorMessage(conn));", + newline], + string "}", + newline, + newline, + string "uw_end_region(ctx);", newline, string "uw_push_cleanup(ctx, (void (*)(void *))PQclear, res);", |