>main :: IO ()
main = withPostgresqlConn "host=localhost user=Rocko port=5432 dbname=Rocko" $ runSqlConn $ do
runMigration migrateAll
let compDay = C.fromGregorian 2011 11 21
match <- selectList
[TestStartDate ==. compDay,
TestEstimatedEnd ==. compDay,
TestStatus /<-. [Passed,Failed]] []
scheduled <- selectList [TestStatus ==. Scheduled] []
-- liftIO $ print scheduled
liftIO $ print match
if (L.null match == True) then (liftIO $ print "date available!!!! ") else (liftIO $ print "date not available")
return ()
I'm trying to determine if a particular Day meets this criteria: is not equal to a TestStartDate, is not equal to a TestEstimatedEnd, and neither Passed not Failed is a member of TestStatus.
However, I want to demonstrate that with the date I picked (which should have a match on an TestEstimatedEnd) fails to do the right thing. It should say , :date not available. So what is wrong with my logic?
> id | firmware | version | startDate | estimatedEnd | status
>----+---------------------------+------------+------------+--------------+-----------
>1 | BCC Admin | 0.0.00.001 | 2011-11-19 | 2011-11-21 | Scheduled
>ghcifoo> main
"date available!!!! "
This is a difficult problem to replicate so what I'm writing is a pretty wild guess, but here goes:
Lets work backwards from the final result
if (L.null match == True) then (liftIO $ print "date available!!!! ") else (liftIO $ print "date not available")
This line clearly evaluated the then
condition. Ergo (L.null match == True)
was True
. My first question is why the == True
clause? L.null match
should work just as well by itself.
Now we know that L.null match
must have been True
, but the line above would seem to indicate that match
contains one record. So at this point I would suspect that L.null
is perhaps not the function you think it is or match doesn't contain what the output is leading us to believe it does. My next debugging suggestion would be to test match
against some other properties (is there a length function maybe?) and see if the problem is with L.null
or match
. Another thought is to move the print statement after the if
. That should not change anything (certainly not in Haskell!), but the response from a database query is occasionally weird. (e.g. not a list but a stream of results that gets consumed as they are used.)
Good Luck!