Open
Description
Its an edge case perhaps, binding an unparseable string to a numeric type doesn't cause an exception and continues, giving unexpected behavior which in this case SELECT with an empty result. The database shows the original value, so the transaction had been rolled back already by the time the SELECT came through.
-- $ cat Main.hs
module Main where
import qualified Database.HDBC as DB
import Database.HDBC.PostgreSQL (withPostgreSQL)
import Database.HDBC.SqlValue
-- Setup:
-- ghc-pkg list
-- ...
-- HDBC-2.3.1.2
-- HDBC-postgresql-2.3.2.1
-- ...
-- createdb testdb
-- CREATE TABLE test1 (a NUMERIC(10,2));
-- CREATE USER test1user PASSWORD 'test1pass';
-- GRANT ALL ON test1 TO test1user;
main :: IO ()
main = do
withPostgreSQL "host=localhost port=5432 dbname=testdb user=test1user password=test1pass" $ \lnk -> do
_ <- DB.quickQuery' lnk "INSERT INTO test1 (a) VALUES (100);" []
res <- DB.quickQuery' lnk "SELECT a FROM test1;" []
putStrLn $ show res
DB.commit lnk
DB.withTransaction lnk $
\link -> do
_ <- DB.quickQuery' link "UPDATE test1 SET a = $1;" [ SqlString "Not a number" ]
res' <- DB.quickQuery' link "SELECT a FROM test1;" []
putStrLn $ show res'
-- $ rm Main.o
-- $ rm Main.hi
-- $ rm Main
-- $ ghc --make Main.hs
-- [1 of 1] Compiling Main ( Main.hs, Main.o )
-- Linking Main ...
-- $ ./Main
-- [[SqlRational (100 % 1)]]
-- []
Metadata
Metadata
Assignees
Labels
No labels