Skip to content

Commit

Permalink
db: Handle empty list in insertManyUncheckedUnique
Browse files Browse the repository at this point in the history
If the list of records to be inserted the generated SQL for the insert
was incorrect and threw a syntax error. The fix is to check if the list
is non-empty and do nothing if it is empty.

Close: #869
  • Loading branch information
erikd committed Oct 5, 2021
1 parent df938f8 commit bc396a6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cardano-db/src/Cardano/Db/Insert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module Cardano.Db.Insert


import Control.Exception.Lifted (Exception, handle, throwIO)
import Control.Monad (void, when)
import Control.Monad (unless, void, when)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Trans.Control (MonadBaseControl)
import Control.Monad.Trans.Reader (ReaderT)
Expand Down Expand Up @@ -242,8 +242,9 @@ insertManyUncheckedUnique
, OnlyOneUniqueKey record
)
=> String -> [record] -> ReaderT SqlBackend m ()
insertManyUncheckedUnique vtype records = do
handle exceptHandler (rawExecute query values)
insertManyUncheckedUnique vtype records =
unless (null records) $
handle exceptHandler (rawExecute query values)
where
query :: Text
query =
Expand Down

0 comments on commit bc396a6

Please sign in to comment.