changeset 1005:c6e948ec79e9

Saving changes to user list
author Adam Chlipala <adamc@hcoop.net>
date Tue, 20 Oct 2009 13:08:42 -0400
parents a87495bcaeec
children 5a0f6ec208ce
files demo/more/bulkEdit.ur demo/more/bulkEdit.urs demo/more/conference.urp
diffstat 3 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/demo/more/bulkEdit.ur	Tue Oct 20 12:48:53 2009 -0400
+++ b/demo/more/bulkEdit.ur	Tue Oct 20 13:08:42 2009 -0400
@@ -4,6 +4,8 @@
                  con keyName :: Name
                  con keyType :: Type
                  val showKey : show keyType
+                 val readKey : read keyType
+                 val injKey : sql_injectable keyType
 
                  con visible :: {(Type * Type)}
                  constraint [keyName] ~ visible
@@ -21,6 +23,11 @@
 
     open M
 
+    fun ensql [avail] (r : $(map snd visible)) : $(map (sql_exp avail [] []) (map fst visible)) =
+        map2 [meta] [snd] [fn ts :: (Type * Type) => sql_exp avail [] [] ts.1]
+             (fn [ts] meta v => @sql_inject meta.Inject (meta.Parse v))
+             [_] folder visible r
+
     fun main () =
         items <- queryX (SELECT t.{keyName}, t.{{map fst visible}} FROM t)
                  (fn r => <xml><entry><tr>
@@ -45,7 +52,15 @@
                  (fn [nm :: Name] [p :: (Type * Type)] [rest :: {(Type * Type)}] [[nm] ~ rest] m =>
                      <xml><th>{[m.Nam]}</th></xml>) [_] folder visible}</tr>
             <subforms{#Users}>{items}</subforms>
+            <tr> <td><submit value="Save" action={save}/></td> </tr>
           </table></form>
         </body></xml>
 
+    and save r =
+        List.app (fn user => dml (update [map fst visible] !
+                                  (ensql (user -- keyName))
+                                  t
+                                  (WHERE t.{keyName} = {[readError user.keyName]}))) r.Users;
+        main ()
+
 end
--- a/demo/more/bulkEdit.urs	Tue Oct 20 12:48:53 2009 -0400
+++ b/demo/more/bulkEdit.urs	Tue Oct 20 13:08:42 2009 -0400
@@ -2,6 +2,8 @@
                  con keyName :: Name
                  con keyType :: Type
                  val showKey : show keyType
+                 val readKey : read keyType
+                 val injKey : sql_injectable keyType
 
                  con visible :: {(Type * Type)}
                  constraint [keyName] ~ visible
--- a/demo/more/conference.urp	Tue Oct 20 12:48:53 2009 -0400
+++ b/demo/more/conference.urp	Tue Oct 20 13:08:42 2009 -0400
@@ -1,5 +1,6 @@
 
 $/option
+$/list
 meta
 bulkEdit
 conference