changeset 738:7fa4871e8272

Prepared statements with blobs
author Adam Chlipala <adamc@hcoop.net>
date Sat, 25 Apr 2009 14:04:38 -0400
parents d049d31a1966
children 4bb7e1c0550a
files src/cjr_print.sml src/prepare.sml
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/cjr_print.sml	Sat Apr 25 13:59:11 2009 -0400
+++ b/src/cjr_print.sml	Sat Apr 25 14:04:38 2009 -0400
@@ -1648,6 +1648,19 @@
                           newline,
                           newline,
 
+                          string "const int paramFormats[] = { ",
+                          p_list_sep (box [string ",", space])
+                                     (fn (_, t) => if isBlob t then string "1" else string "0") ets,
+                          string " };",
+                          newline,
+                          string "const int paramLengths[] = { ",
+                          p_list_sepi (box [string ",", space])
+                                      (fn i => fn (_, Blob) => string ("arg" ^ Int.toString (i + 1) ^ ".size")
+                                                | (_, Nullable Blob) => string ("arg" ^ Int.toString (i + 1)
+                                                                                ^ "?arg" ^ Int.toString (i + 1) ^ "->size:0")
+                                                | _ => string "0") ets,
+                          string " };",
+                          newline,
                           string "const char *paramValues[] = { ",
                           p_list_sepi (box [string ",", space])
                                       (fn i => fn (_, t) => p_ensql t (box [string "arg",
@@ -1666,7 +1679,7 @@
                                 string (Int.toString n),
                                 string "\", ",
                                 string (Int.toString (length (getPargs dml))),
-                                string ", paramValues, NULL, NULL, 0);"],
+                                string ", paramValues, paramLengths, paramFormats, 0);"],
              newline,
              newline,
 
--- a/src/prepare.sml	Sat Apr 25 13:59:11 2009 -0400
+++ b/src/prepare.sml	Sat Apr 25 14:04:38 2009 -0400
@@ -47,6 +47,8 @@
         SOME ("$" ^ Int.toString (n + 1) ^ "::bool" :: ss, n + 1)
       | EFfiApp ("Basis", "sqlifyTime", [e]) =>
         SOME ("$" ^ Int.toString (n + 1) ^ "::timestamp" :: ss, n + 1)
+      | EFfiApp ("Basis", "sqlifyBlob", [e]) =>
+        SOME ("$" ^ Int.toString (n + 1) ^ "::bytea" :: ss, n + 1)
       | EFfiApp ("Basis", "sqlifyChannel", [e]) =>
         SOME ("$" ^ Int.toString (n + 1) ^ "::int8" :: ss, n + 1)
       | EFfiApp ("Basis", "sqlifyClient", [e]) =>