changeset 468:4efab85405be

Ensql'ing nullables
author Adam Chlipala <adamc@hcoop.net>
date Thu, 06 Nov 2008 15:52:13 -0500
parents 3f1b9231a37b
children b393c2fc80f8
files src/cjr_print.sml src/monoize.sml src/prepare.sml tests/sql_option.ur tests/sql_option.urs
diffstat 5 files changed, 32 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/cjr_print.sml	Thu Nov 06 15:37:38 2008 -0500
+++ b/src/cjr_print.sml	Thu Nov 06 15:52:13 2008 -0500
@@ -474,6 +474,13 @@
       | EFfiApp ("Basis", "sqlifyString", [e]) => [(e, String)]
       | EFfiApp ("Basis", "sqlifyBool", [e]) => [(e, Bool)]
       | EFfiApp ("Basis", "sqlifyTime", [e]) => [(e, Time)]
+
+      | EFfiApp ("Basis", "sqlifyIntN", [e]) => [(e, Nullable Int)]
+      | EFfiApp ("Basis", "sqlifyFloatN", [e]) => [(e, Nullable Float)]
+      | EFfiApp ("Basis", "sqlifyStringN", [e]) => [(e, Nullable String)]
+      | EFfiApp ("Basis", "sqlifyBoolN", [e]) => [(e, Nullable Bool)]
+      | EFfiApp ("Basis", "sqlifyTimeN", [e]) => [(e, Nullable Time)]
+
       | ECase (e, _, _) => [(e, Bool)]
 
       | _ => raise Fail "CjrPrint: getPargs"
--- a/src/monoize.sml	Thu Nov 06 15:37:38 2008 -0500
+++ b/src/monoize.sml	Thu Nov 06 15:52:13 2008 -0500
@@ -983,7 +983,7 @@
             let
                 val (e, fm) = monoExp (env, st, fm) e
             in
-                ((L'.EDml (liftExpInExp 0 e), loc),
+                ((L'.EDml e, loc),
                  fm)
             end
 
--- a/src/prepare.sml	Thu Nov 06 15:37:38 2008 -0500
+++ b/src/prepare.sml	Thu Nov 06 15:52:13 2008 -0500
@@ -47,6 +47,18 @@
         SOME ("$" ^ Int.toString (n + 1) ^ "::bool" :: ss, n + 1)
       | EFfiApp ("Basis", "sqlifyTime", [e]) =>
         SOME ("$" ^ Int.toString (n + 1) ^ "::timestamp" :: ss, n + 1)
+
+      | EFfiApp ("Basis", "sqlifyIntN", [e]) =>
+        SOME ("$" ^ Int.toString (n + 1) ^ "::int8" :: ss, n + 1)
+      | EFfiApp ("Basis", "sqlifyFloatN", [e]) =>
+        SOME ("$" ^ Int.toString (n + 1) ^ "::float8" :: ss, n + 1)
+      | EFfiApp ("Basis", "sqlifyStringN", [e]) =>
+        SOME ("$" ^ Int.toString (n + 1) ^ "::text" :: ss, n + 1)
+      | EFfiApp ("Basis", "sqlifyBoolN", [e]) =>
+        SOME ("$" ^ Int.toString (n + 1) ^ "::bool" :: ss, n + 1)
+      | EFfiApp ("Basis", "sqlifyTimeN", [e]) =>
+        SOME ("$" ^ Int.toString (n + 1) ^ "::timestamp" :: ss, n + 1)
+
       | ECase (e,
                [((PCon (_, PConFfi {mod = "Basis", con = "True", ...}, _), _),
                  (EPrim (Prim.String "TRUE"), _)),
--- a/tests/sql_option.ur	Thu Nov 06 15:37:38 2008 -0500
+++ b/tests/sql_option.ur	Thu Nov 06 15:52:13 2008 -0500
@@ -4,9 +4,13 @@
     dml (INSERT INTO t (O) VALUES (NULL));
     return <xml>Done</xml>
 
-(*fun add42 () =
-    dml (INSERT INTO t (O) VALUES (42));
-    return <xml>Done</xml>*)
+fun add3 () =
+    dml (INSERT INTO t (O) VALUES ({Some 3}));
+    return <xml>Done</xml>
+
+fun addN r =
+    dml (INSERT INTO t (O) VALUES ({Some (readError r.N)}));
+    return <xml>Done</xml>
 
 fun main () : transaction page =
     xml <- queryX (SELECT * FROM t)
@@ -17,6 +21,8 @@
       {xml}
 
       <a link={addNull ()}>Add a null</a><br/>
+      <a link={add3 ()}>Add a 3</a><br/>
+      <form>
+        Add <textbox{#N}/> <submit action={addN}/>
+      </form>
     </body></xml>
-
-(*      <a link={add42 ()}>Add a 42</a><br/>*)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sql_option.urs	Thu Nov 06 15:52:13 2008 -0500
@@ -0,0 +1,1 @@
+val main : unit -> transaction page