Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent UPDATE failure, unintended empty SELECT afterwards. #29

Open
elblake opened this issue Jul 30, 2013 · 0 comments
Open

Silent UPDATE failure, unintended empty SELECT afterwards. #29

elblake opened this issue Jul 30, 2013 · 0 comments

Comments

@elblake
Copy link

elblake commented Jul 30, 2013

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)]]
-- []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant