- -- freely with empty away/home lines:
- forM_ (xml_over_under_casinos game) $ \c -> do
- -- Start by inderting the casino.
- ou_casino_id <- insert_xml_or_select c
-
- -- Now add the over/under entry with the casino's id.
- let ogl = OddsGameLine {
- ogl_odds_games_id = game_id,
- ogl_odds_casinos_id = ou_casino_id,
- ogl_over_under = (xml_casino_line c),
- ogl_away_line = Nothing,
- ogl_home_line = Nothing }
-
- insert_ ogl
+ -- freely with empty away/home lines.
+ --
+ -- Before we continue, we drop all casinos that are missing
+ -- either a client_id or name field.
+ --
+ let ou_casinos = filter nonempty_casino $ xml_over_under_casinos game
+
+ forM_ ou_casinos $ \c ->
+ -- Since we already filtered out the casinos without a
+ -- client_id or a name, the database conversion should always
+ -- return (Just something).
+ case (from_xml c) of
+ Nothing -> return () -- Should never happen, we filtered them out.
+ Just casino -> do
+ -- Start by inserting the casino.
+ ou_casino_id <- insert_or_select casino
+
+ -- Now add the over/under entry with the casino's id.
+ let ogl = OddsGameLine {
+ ogl_odds_games_id = game_id,
+ ogl_odds_casinos_id = ou_casino_id,
+ ogl_over_under = (xml_casino_line c),
+ ogl_away_line = Nothing,
+ ogl_home_line = Nothing }
+
+ insert_ ogl