On collectOnClauses, match from clauses in the correct order.

Previously it tried matching on the right branch just after
matching on the current node, which means that on the default
right fixity everything was reversed.

Note: SQLite didn't give any error messages for this bug!
This commit is contained in:
Felipe Lessa 2012-09-05 16:53:55 -03:00
parent c0f5993be7
commit 0c694e92a5

View File

@ -85,11 +85,14 @@ collectOnClauses = go []
Nothing -> (f:) <$> findMatching acc expr
findMatching [] expr = Left expr
tryMatch expr (FromJoin l k r Nothing) =
return (FromJoin l k r (Just expr))
tryMatch expr (FromJoin l k r j@(Just _)) =
((\r' -> FromJoin l k r' j) <$> tryMatch expr r) `mplus`
((\l' -> FromJoin l' k r j) <$> tryMatch expr l)
tryMatch expr (FromJoin l k r onClause) =
matchR `mplus` matchC `mplus` matchL -- right to left
where
matchR = (\r' -> FromJoin l k r' onClause) <$> tryMatch expr r
matchL = (\l' -> FromJoin l' k r onClause) <$> tryMatch expr l
matchC = case onClause of
Nothing -> return (FromJoin l k r (Just expr))
Just _ -> mzero
tryMatch _ _ = mzero