changeset 2239:f70a91f7810d

Add limited support for parsing SQL arithmetic.
author Ziv Scully <ziv@mit.edu>
date Tue, 07 Jul 2015 00:07:24 -0700
parents 7f92d70a326e
children 88cc0f44c940
files caching-tests/test.ur src/sql.sml src/sqlcache.sml
diffstat 3 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/caching-tests/test.ur	Mon Jul 06 01:31:04 2015 -0700
+++ b/caching-tests/test.ur	Tue Jul 07 00:07:24 2015 -0700
@@ -11,11 +11,10 @@
          | Some row => <xml>{[row.Tab.Val]}</xml>}
     </body></xml>
 
-
 fun flush id =
-     dml (UPDATE tab
-          SET Id = 29, Val = 42
-          WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
+    dml (UPDATE tab
+         SET Val = Val * (Id + 2) / Val - 3
+         WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]});
     return <xml><body>
       Changed {[id]}!
     </body></xml>
--- a/src/sql.sml	Mon Jul 06 01:31:04 2015 -0700
+++ b/src/sql.sml	Tue Jul 07 00:07:24 2015 -0700
@@ -325,6 +325,11 @@
                      constK "SUM",
                      constK "AVG"]
 
+fun arithmetic pExp = follow (const "(")
+                             (follow pExp
+                                     (follow (altL (map const [" + ", " - ", " * ", " / "]))
+                                             (follow pExp (const ")"))))
+
 val unmodeled = altL [const "COUNT(*)",
                       const "CURRENT_TIMESTAMP"]
 
@@ -340,6 +345,7 @@
            wrap uw_ident Computed,
            wrap known SqKnown,
            wrap func SqFunc,
+           wrap (arithmetic sqexp) (fn _ => Unmodeled),
            wrap unmodeled (fn () => Unmodeled),
            wrap (if !sqlcacheMode then sqlifySqlcache else sqlify) Inj,
            wrap (follow (const "COALESCE(") (follow sqexp (follow (const ",")
--- a/src/sqlcache.sml	Mon Jul 06 01:31:04 2015 -0700
+++ b/src/sqlcache.sml	Tue Jul 07 00:07:24 2015 -0700
@@ -410,15 +410,13 @@
         List.foldr (fn (SOME eqs, SOME acc) => SOME (IM.unionWith #1 (eqs, acc)) | _ => NONE)
                    (SOME IM.empty)
 
+    val simplify =
+        map TS.listItems
+        o removeRedundant (fn (x, y) => TS.isSubset (y, x))
+        o map (fn xs => TS.addList (TS.empty, xs))
+
     fun dnf (fQuery, fDml) =
-        let
-            val simplify =
-                map TS.listItems
-                o removeRedundant (fn (x, y) => TS.isSubset (y, x))
-                o map (fn xs => TS.addList (TS.empty, xs))
-        in
-            normalize simplify negateCmp Disj (Combo (Conj, [markQuery fQuery, markDml fDml]))
-        end
+        normalize simplify negateCmp Disj (Combo (Conj, [markQuery fQuery, markDml fDml]))
 
     val conflictMaps = List.mapPartial (mergeEqs o map eqsOfClass o equivClasses) o dnf