git.iko.soy/typeable/postgresql-simple
on master help sign in
Fix unmatched cases in instance ToField Values
c867b47Leon P Smith
src/Database/PostgreSQL/Simple/ToField.hs+7−2
@@ -291,7 +291,7 @@ instance ToRow a => ToField (Values a) where
291 toField (Values types rows) =
291 toField (Values types rows) =
292 case rows of
292 case rows of
293 [] -> case types of
293 [] -> case types of
294− [] -> error err
294+ [] -> error norows
295 (_:_) -> values $ typedRow (repeat (lit "null"))
295 (_:_) -> values $ typedRow (repeat (lit "null"))
296 types
296 types
297 [lit " LIMIT 0)"]
297 [lit " LIMIT 0)"]
@@ -299,7 +299,9 @@ instance ToRow a => ToField (Values a) where
299 [] -> values $ untypedRows rows [litC ')']
299 [] -> values $ untypedRows rows [litC ')']
300 (_:_) -> values $ typedRows rows types [litC ')']
300 (_:_) -> values $ typedRows rows types [litC ')']
301 where
301 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"
303 lit = Plain . fromByteString
305 lit = Plain . fromByteString
304 litC = Plain . fromChar
306 litC = Plain . fromChar
305 values x = Many (lit "(VALUES ": x)
307 values x = Many (lit "(VALUES ": x)
@@ -315,6 +317,7 @@ instance ToRow a => ToField (Values a) where
315 (litC ',')
317 (litC ',')
316 (litC ')' : rest)
318 (litC ')' : rest)
317 (zip vals typs) )
319 (zip vals typs) )
320+ typedRow _ _ _ = error emptyrow
318
321
319 untypedRow :: [Action] -> [Action] -> [Action]
322 untypedRow :: [Action] -> [Action] -> [Action]
320 untypedRow (val:vals) rest =
323 untypedRow (val:vals) rest =
@@ -324,8 +327,10 @@ instance ToRow a => ToField (Values a) where
324 (litC ',')
327 (litC ',')
325 (litC ')' : rest)
328 (litC ')' : rest)
326 vals
329 vals
330+ untypedRow _ _ = error emptyrow
327
331
328 typedRows :: ToRow a => [a] -> [QualifiedIdentifier] -> [Action] -> [Action]
332 typedRows :: ToRow a => [a] -> [QualifiedIdentifier] -> [Action] -> [Action]
333+ typedRows [] _ _ = error funcname
329 typedRows (val:vals) types rest =
334 typedRows (val:vals) types rest =
330 typedRow (toRow val) types (litC ',' : untypedRows vals rest)
335 typedRow (toRow val) types (litC ',' : untypedRows vals rest)
331
336