git.iko.soy/typeable/postgresql-simple
on master help sign in
Fix unmatched cases in instance ToField Values
commitc867b4780ce7755eb1ab1bad038d5ac9c98193a3 authorLeon P Smith <leon@melding-monads.com> dateSat 22 Mar 2014, 20:13 (13 years ago) parenta3c2b86
1 file changed+7−2
src/Database/PostgreSQL/Simple/ToField.hs+7−2
src/Database/PostgreSQL/Simple/ToField.hs+7−2
@@ -291,7 +291,7 @@ instance ToRow a => ToField (Values a) where
291291 toField (Values types rows) =
292292 case rows of
293293 [] -> case types of
294− [] -> error err
294+ [] -> error norows
295295 (_:_) -> values $ typedRow (repeat (lit "null"))
296296 types
297297 [lit " LIMIT 0)"]
@@ -299,7 +299,9 @@ instance ToRow a => ToField (Values a) where
299299 [] -> values $ untypedRows rows [litC ')']
300300 (_:_) -> values $ typedRows rows types [litC ')']
301301 where
302− err = "Database.PostgreSQL.Simple.toField :: Values -> Action either values or types must be non-empty"
302+ funcname = "Database.PostgreSQL.Simple.toField :: Values a -> Action"
303+ norows = funcname ++ " either values or types must be non-empty"
304+ emptyrow = funcname ++ " each row must contain at least one column"
303305 lit = Plain . fromByteString
304306 litC = Plain . fromChar
305307 values x = Many (lit "(VALUES ": x)
@@ -315,6 +317,7 @@ instance ToRow a => ToField (Values a) where
315317 (litC ',')
316318 (litC ')' : rest)
317319 (zip vals typs) )
320+ typedRow _ _ _ = error emptyrow
318321
319322 untypedRow :: [Action] -> [Action] -> [Action]
320323 untypedRow (val:vals) rest =
@@ -324,8 +327,10 @@ instance ToRow a => ToField (Values a) where
324327 (litC ',')
325328 (litC ')' : rest)
326329 vals
330+ untypedRow _ _ = error emptyrow
327331
328332 typedRows :: ToRow a => [a] -> [QualifiedIdentifier] -> [Action] -> [Action]
333+ typedRows [] _ _ = error funcname
329334 typedRows (val:vals) types rest =
330335 typedRow (toRow val) types (litC ',' : untypedRows vals rest)
331336