diff src/cjr_print.sml @ 743:cd67c3a942e3

Handling nullable blobs
author Adam Chlipala <adamc@hcoop.net>
date Sun, 26 Apr 2009 10:53:36 -0400
parents 43553c93dd8c
children e42f08f96eb5
line wrap: on
line diff
--- a/src/cjr_print.sml	Sun Apr 26 10:45:59 2009 -0400
+++ b/src/cjr_print.sml	Sun Apr 26 10:53:36 2009 -0400
@@ -392,7 +392,7 @@
          "uw_" ^ ident m ^ "_" ^ ident con,
          "uw_" ^ ident con)
 
-fun p_unsql wontLeakStrings env (tAll as (t, loc)) e =
+fun p_unsql wontLeakStrings env (tAll as (t, loc)) e eLen =
     case t of
         TFfi ("Basis", "int") => box [string "uw_Basis_stringToInt_error(ctx, ", e, string ")"]
       | TFfi ("Basis", "float") => box [string "uw_Basis_stringToFloat_error(ctx, ", e, string ")"]
@@ -403,6 +403,11 @@
             box [string "uw_strdup(ctx, ", e, string ")"]
       | TFfi ("Basis", "bool") => box [string "uw_Basis_stringToBool_error(ctx, ", e, string ")"]
       | TFfi ("Basis", "time") => box [string "uw_Basis_stringToTime_error(ctx, ", e, string ")"]
+      | TFfi ("Basis", "blob") => box [string "uw_Basis_stringToBlob_error(ctx, ",
+                                       e,
+                                       string ", ",
+                                       eLen,
+                                       string ")"]
       | TFfi ("Basis", "channel") => box [string "uw_Basis_stringToChannel_error(ctx, ", e, string ")"]
       | TFfi ("Basis", "client") => box [string "uw_Basis_stringToClient_error(ctx, ", e, string ")"]
 
@@ -434,18 +439,14 @@
                            newline,
                            string "})"],
              string ")"]
-
-      | TFfi ("Basis", "blob") => box [string "uw_Basis_stringToBlob_error(ctx, PQgetvalue(res, i, ",
-                                       string (Int.toString i),
-                                       string "), PQgetlength(res, i, ",
-                                       string (Int.toString i),
-                                       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 ")"])
 
 datatype sql_type =
          Int
@@ -526,7 +527,7 @@
       | Nullable t => box [string "(",
                            e,
                            string " == NULL ? NULL : ",
-                           p_ensql t (box [string "*", e]),
+                           p_ensql t (box [string "(*", e, string ")"]),
                            string ")"]
 
 fun notLeaky env allowHeapAllocated =
@@ -1821,7 +1822,8 @@
 
                  string "n = ",
                  p_unsql true env (TFfi ("Basis", "int"), loc)
-                         (string "PQgetvalue(res, 0, 0)"),
+                         (string "PQgetvalue(res, 0, 0)")
+                         (box []),
                  string ";",
                  newline,
                  string "PQclear(res);",