[Ur] SQL Question

Burton Samograd burton.samograd at gmail.com
Fri Oct 3 15:39:37 EDT 2014


Looks like I have to take better care of my variable naming to prevent
clashes.

Thanks.

Burton

On Fri, Oct 3, 2014 at 1:33 PM, mutaamba maasha <maasha at gmail.com> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> (* It seems the problem was the naming of the
>    query result, the query result was colliding
>    with the table.  Let me know if this was the
>    case and if the code below helps.
>
>    Happy hacking
> *)
>
> (* adding the needed styles *)
> style topbar
> style postsList
> style post
> style postTitle
> style postAuthor
> style postBody
> style postBottom
> style postComments
> style postDate
>
> table posts : { Id : int, Title : string, Body : string, Created : time }
>       PRIMARY KEY Id
> table userIdToPostIds : { UserId : int, PostId : int }
>       PRIMARY KEY UserId
> table users : { Id : int, Username : string }
>       PRIMARY KEY Id
>
> (* Adding this here so it compiles *)
> val blogName : string = "The finest culinary selections from the land
> of tofu."
> (* Using modules to so everything fits in one
>    file.  If you are curious about modules you
>    can find out more about them here :
>    http://www.impredicative.com/ur/tutorial/intro.html
>    You want to remove this because you have the
>    files page.ur*
> *)
> signature PAGE = sig
>     val page' : string -> xbody -> page
> end
> structure Page : PAGE = struct
>     fun page' (t : string) (b : xbody) : page=
>         <xml>
>           <head><title>{[t]}</title></head>
>           <body>
>             {[b]}
>           </body>
>         </xml>
> end
> (* The end of the module code/code you should remove *)
>
>
> fun blog () : transaction page =
>     (* Changed the name of the query result - this is most likely
>        what is was causing your problem. *)
>     post_query_1 <- queryX (SELECT Posts.Title, Posts.Body,
> Users.Username, Posts.Created
>                             FROM posts, users, userIdToPostIds
>                             WHERE users.Id = userIdToPostIds.UserId
>                               AND posts.Id = userIdToPostIds.PostId)
>                            (fn row => post' row.Posts.Title
> row.Posts.Body row.Users.Username row.Posts.Created);
>     (* changed the name of the query result *)
>     post_query_2 <- queryX (SELECT Posts.Title, Posts.Body,
> Users.Username,Posts.Created
>                             FROM posts, users, userIdToPostIds
>                             WHERE users.Id = userIdToPostIds.UserId
>                               AND   posts.Id = userIdToPostIds.PostId)
>                            (fn row => post' row.Posts.Title
> row.Posts.Body row.Users.Username row.Posts.Created);
>     return (Page.page' blogName
>                        <xml>
>                          {topbar' ()}
>                          {posts' post_query_1}
>                          {posts' post_query_2}
>                        </xml>)
>
> and topbar' () : xbody =
>     <xml><div class="topbar">{[blogName]}</div></xml>
> (* added type information here *)
> and posts' (posts : xbody) : xbody =
>     <xml><div class="postsList">
>     {posts}
>      </div></xml>
> (* Used the code from the previous email
>    ... I am going to guess it is what you
>    have. *)
> and post' (title : string)
>           (body : string)
>           (username : string)
>           (created : time) : xbody =
>     let
>         val numComments = 0
>     in
>         <xml>
>           <div class="post">
>             <div class="postTitle">{[title]}</div>
>             <div class="postAuthor">{[username]}</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
> and comments () : transaction page = error <xml>error : comment
> function not implemented</xml>
>
>
> fun main () = return <xml></xml>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1
>
> iQIcBAEBAgAGBQJULvn0AAoJEHxRxnzR1VWyyx4QALnOK3VgRpYNWK6wgBUxkPyz
> R+rKe0Vq0KCgzF3MjjyQPLaxwTxdfbg9gaXVZyXkpDnX8RIOhySYFmNOsN6BHGu3
> f8I4uvtS+N4Wsa4FjHzmY35XoyGiDlki6kbE+Yw8Myp7Jv2iY+FXXuQvumS83Wvr
> JXlujVROxY+Iglsqsu3iAh5btw+VaBaNC2SQUQLHrrIeZTvUOsIS5A0+MW7SQn5p
> 6Aj77EDtbA2k0xpCyAADZ54UrSvzHFrMnLEheHAoLjAufNdrzl5+dyFyZukJRndg
> y/cc4dUgkqZhX/wsDEbMBkTqbW1R+vZvNxX0+lUSqDc53LxNYwDQQGgIuVrAqKBf
> yom/3IbvoS4Nkt1MF/2qZU7bptXK59rpBbWTk9zt00FO/nsf2/zR+nDU6Os6rkST
> 4DUTmBGOcGd9/e1RO6UdK819PoVVPOXdy7JsAyzHacp3aTMH3gEkAHia7wAsb/Iz
> wnljBwssuNOPY1vT3s4ul8BXDRCclOsg1cb66EedFiGEnZW1PyD1mYvWeRUjR4IK
> CzRa3xpsliE5XisYuZqEoplQ3gaovPInJ7CZEG3k8w350ts+D85VU2WqKATIG2gr
> gTi9SzzqlTlIS/H2dmlNwvMsEJG38byXuCZQar0ElX7wVg8nANlv4xqAEjIbJ+YH
> 039UXNim4rX2XSgGmg4P
> =6vna
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> 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/0e7fca39/attachment.html>


More information about the Ur mailing list