>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
This line clearly evaluated the
thencondition. Ergo(L.null match == True)wasTrue. My first question is why the== Trueclause?L.null matchshould work just as well by itself.Now we know that
L.null matchmust have beenTrue, but the line above would seem to indicate thatmatchcontains one record. So at this point I would suspect thatL.nullis 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 testmatchagainst some other properties (is there a length function maybe?) and see if the problem is withL.nullormatch. Another thought is to move the print statement after theif. 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!