You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.hsmoduleMainwhereimportqualifiedDatabase.HDBCasDBimportDatabase.HDBC.PostgreSQL (withPostgreSQL)
importDatabase.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)]]-- []
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: