changeset 1543:6f046b4bad24

Add antiquote for ORDER BY directions
author Adam Chlipala <adam@chlipala.net>
date Fri, 19 Aug 2011 14:20:24 -0400
parents dc4c61363d0a
children a99b743a3087
files doc/manual.tex src/urweb.grm tests/ascdesc.ur tests/ascdesc.urp
diffstat 4 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/doc/manual.tex	Fri Aug 19 08:59:01 2011 -0400
+++ b/doc/manual.tex	Fri Aug 19 14:20:24 2011 -0400
@@ -2100,7 +2100,7 @@
   \textrm{Unary operators} & u &::=& \mt{NOT} \\
   \textrm{Binary operators} & b &::=& \mt{AND} \mid \mt{OR} \mid \neq \mid < \mid \leq \mid > \mid \geq \\
   \textrm{Aggregate functions} & a &::=& \mt{COUNT} \mid \mt{AVG} \mid \mt{SUM} \mid \mt{MIN} \mid \mt{MAX} \\
-  \textrm{Directions} & o &::=& \mt{ASC} \mid \mt{DESC} \\
+  \textrm{Directions} & o &::=& \mt{ASC} \mid \mt{DESC} \mid \{e\} \\
   \textrm{SQL integer} & N &::=& n \mid \{e\} \\
 \end{array}$$
 
--- a/src/urweb.grm	Fri Aug 19 08:59:01 2011 -0400
+++ b/src/urweb.grm	Fri Aug 19 14:20:24 2011 -0400
@@ -1921,6 +1921,7 @@
 diropt :                                (EVar (["Basis"], "sql_asc", Infer), dummy)
        | ASC                            (EVar (["Basis"], "sql_asc", Infer), s (ASCleft, ASCright))
        | DESC                           (EVar (["Basis"], "sql_desc", Infer), s (DESCleft, DESCright))
+       | LBRACE eexp RBRACE             (eexp)
 
 lopt   :                                 (EVar (["Basis"], "sql_no_limit", Infer), dummy)
        | LIMIT ALL                       (EVar (["Basis"], "sql_no_limit", Infer), dummy)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/ascdesc.ur	Fri Aug 19 14:20:24 2011 -0400
@@ -0,0 +1,10 @@
+table t : { A : int }
+
+fun sortEm b =
+    queryX1 (SELECT * FROM t ORDER BY t.A {if b then sql_asc else sql_desc})
+    (fn r => <xml>{[r.A]}; </xml>)
+
+fun main () : transaction page = return <xml><body>
+  <a link={sortEm True}>Ascending</a><br/>
+  <a link={sortEm False}>Descending</a>
+</body></xml>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/ascdesc.urp	Fri Aug 19 14:20:24 2011 -0400
@@ -0,0 +1,4 @@
+database dbname=test
+sql ascdesc.sql
+
+ascdesc
\ No newline at end of file