[Ur] SQL Question

Burton Samograd burton.samograd at gmail.com
Fri Oct 3 14:21:30 EDT 2014


Are you limited to one query per transaction? This type of code causes
compiler errors where a single query doesn't:

fun page () : transaction xbody =

data <- (SELECT * FROM table ...) (fn row => ...)
data2 <- (SELECT * FROM table2 ...) (fn row => ...)

(* Generate part of the page with data *)
{header data}

(* Generate another section with data2 *)
{footer data2}

--
Burton

On Fri, Oct 3, 2014 at 6:56 AM, mutaamba maasha <maasha at gmail.com> wrote:

> (* Hi
>    Yes, occur within transactions, let me know if you want me to go into
>    more detail into why.  I can't place the error as I can't determine
>    the line numbers so I have included the code below which should help
>    you track down your problem.  Hope this helps.
>
>    happy hacking
>
> *)
> style postsList
> style post
> style postTitle
> style postAuthor
> style postBody
> style postBottom
> style postComments
> style postDate
>
> (* there is a typo starting around "Body, :string" *)
> table posts : { Id : int, Title : string, Body : string, Author :
> string, Created : time }
> PRIMARY KEY Id
>
> (* Renamed the function more of a personal preference.
>    The query has to be in a transaction which is  what
>    I think you were asking.
>  *)
> fun list_posts () : transaction xbody =
>     (* changed the variable name ... personal prefrence *)
>     content <- queryX (SELECT * FROM posts)
>                       (* changed the function name ... personal
> preference  *)
>                       (fn row => format_post row.Posts.Title (*
> removed the {[]} as it is used in queries or xml *)
>                                              row.Posts.Body
>                                              row.Posts.Author
>                                              row.Posts.Created);
>     return <xml><div class="postsList">
>       {content}
>     </div></xml>
>
>
> (* changed the function name ... personal preference *)
> and format_post
>         (title : string)
>         (body : string)
>         (authorUserId : string)
>         (created : time) (* changed name but also the type is time *)
>     : xbody =
>     let
>         val numComments = 0
>     in
>         <xml>
>           <div class="post">
>             <div class="postTitle">{[title]}</div>
>             <div class="postAuthor">{[authorUserId]}</div>
>             <div class="postBody">{[body]}</div>
>             <div class="postBottom">
>               <div class="postComments">
>                 <a link={comments ()}>{[numComments]} comments</a>
>               </div>
>               <div class="postDate">{[created]}</div>
>             </div>
>           </div>
>         </xml>
>     end
> (* Using error instead of supplying the implementation of the comment
>    function ... compiles but will throw an runtime error if you try to
>    view the page.  I use this often when I am trying to isolate an
>    compilation error ... I comment out the function definition and
>    replace it with error <xml>some insightful error message</xml> *)
> and comments () : transaction page = error <xml>error : comment
> function not implemented</xml>
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20141003/ff20a9c7/attachment.html>


More information about the Ur mailing list