changeset 259:d1b679dbbc25

Monoize HAVING
author Adam Chlipala <adamc@hcoop.net>
date Sun, 31 Aug 2008 15:36:15 -0400
parents 40c33706d887
children 645d0e8da643
files src/mono_opt.sml src/monoize.sml tests/group_by.ur
diffstat 3 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/mono_opt.sml	Sun Aug 31 15:32:31 2008 -0400
+++ b/src/mono_opt.sml	Sun Aug 31 15:36:15 2008 -0400
@@ -84,7 +84,9 @@
 val sqlifyInt = attrifyInt
 val sqlifyFloat = attrifyFloat
 
-fun sqlifyString s = "E'" ^ String.toString s ^ "'"
+fun sqlifyString s = "E'" ^ String.translate (fn #"'" => "\\'"
+                                               | ch => str ch)
+                                             (String.toString s) ^ "'"
         
 fun exp e =
     case e of
--- a/src/monoize.sml	Sun Aug 31 15:32:31 2008 -0400
+++ b/src/monoize.sml	Sun Aug 31 15:36:15 2008 -0400
@@ -637,7 +637,15 @@
                                                                                     (map (fn (x', _) =>
                                                                                              sc (x ^ "." ^ x'))
                                                                                          xts)) grouped)
-                                               ]
+                                               ],
+
+                                           (L'.ECase (gf "Having",
+                                                      [((L'.PPrim (Prim.String "TRUE"), loc),
+                                                        sc ""),
+                                                       ((L'.PWild, loc),
+                                                        strcat loc [sc " HAVING ", gf "Having"])],
+                                                      {disc = s,
+                                                       result = s}), loc)
                               ]), loc),
                      fm)
                   | _ => poly ()
--- a/tests/group_by.ur	Sun Aug 31 15:32:31 2008 -0400
+++ b/tests/group_by.ur	Sun Aug 31 15:36:15 2008 -0400
@@ -5,7 +5,7 @@
 val q2 = (SELECT * FROM t1, t2 GROUP BY t1.B, t2.D, t1.A)
 
 val q3 = (SELECT * FROM t1 WHERE t1.A = 0 GROUP BY t1.B)
-val q4 = (SELECT * FROM t1 WHERE t1.A = 0 GROUP BY t1.C HAVING t1.C < 0.2)
+val q4 = (SELECT * FROM t1 WHERE t1.A = 0 GROUP BY t1.B HAVING t1.B <> 'Bad')
 
 val q5 = (SELECT t1.A, t2.D FROM t1, t2 GROUP BY t2.D, t1.A)
 val q6 = (SELECT t1.A, t2.D FROM t1, t2 WHERE t1.C = 0.0 GROUP BY t2.D, t1.A HAVING t1.A = t1.A AND t2.D = 17)
@@ -14,7 +14,7 @@
 datatype list a = Nil | Cons of a * list a
 
 val r1 : transaction (list {B : string}) =
-        query q1
+        query q4
         (fn fs acc => return (Cons (fs.T1, acc)))
         Nil