[Ur] SQL Count
Adam Chlipala
adamc at impredicative.com
Tue Mar 2 21:05:52 EST 2010
David Snider wrote:
> fun isValid r =
> oneRow (SELECT COUNT(*) FROM users
> WHERE Username = {[r.Username]}
> AND Password = {[r.Password]}) = 1
>
> It seems to be treating COUNT(*) as a comment. How do I get a record
> count?
Just include spaces before and after the asterisk. There are also a few
other problems here:
- You'll need to include an [AS] name for the expression column you're
creating. Every [SELECT]ed column that isn't a projection of a column
from a table must have an [AS] name in Ur/Web.
- [oneRow] will never return an integer. You probably want [oneRowE1].
- The result of a query can never be used as a direct operand to the
equality operator. This is because query operations must live inside
the [transaction] monad. If you're not familiar with the basic
techniques of monadic programming, I'd recommend finding a tutorial on
monads in Haskell.
More information about the Ur
mailing list