[Ur] SQL Question
mutaamba maasha
maasha at gmail.com
Fri Oct 3 08:56:30 EDT 2014
(* 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>
More information about the Ur
mailing list