diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-08-31 15:36:15 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-08-31 15:36:15 -0400 |
commit | 1d2a33433b530bdfe2c4cf7c7f0e6bc7190d87c5 (patch) | |
tree | 438e4fa54e6e8a7a8450cc051c374262c0d60250 | |
parent | dcd7b7d304959739432b3e2497491c36f14f2b4f (diff) |
Monoize HAVING
-rw-r--r-- | src/mono_opt.sml | 4 | ||||
-rw-r--r-- | src/monoize.sml | 10 | ||||
-rw-r--r-- | tests/group_by.ur | 4 |
3 files changed, 14 insertions, 4 deletions
diff --git a/src/mono_opt.sml b/src/mono_opt.sml index 1430dfe2..3946684a 100644 --- a/src/mono_opt.sml +++ b/src/mono_opt.sml @@ -84,7 +84,9 @@ val urlifyString = String.translate (fn #" " => "+" 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 diff --git a/src/monoize.sml b/src/monoize.sml index 9846d8ba..35d474e6 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -637,7 +637,15 @@ fun monoExp (env, st, fm) (all as (e, loc)) = (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 () diff --git a/tests/group_by.ur b/tests/group_by.ur index 93655568..dbc7415b 100644 --- a/tests/group_by.ur +++ b/tests/group_by.ur @@ -5,7 +5,7 @@ val q1 = (SELECT * FROM t1 GROUP BY t1.B) 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 @@ val q6 = (SELECT t1.A, t2.D FROM t1, t2 WHERE t1.C = 0.0 GROUP BY t2.D, t1.A HAV 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 |