Open
Description
This is a simple test program to save and read a bytestring to/from a database. It works fine with sqlite
, but not with postgresql
. There are 2 problems:
- It raises an exception on insert
SqlError {seState = "22021", seNativeError = 7, seErrorMsg = "execute: PGRES_FATAL_ERROR: ERROR: invalid byte sequence for encoding \"UTF8\": 0x80\n"}
- If I reduce
testData
to some shorter value, thereadBack
won't compare equal.
import Data.ByteString
import Database.HDBC
--import Database.HDBC.Sqlite3 (connectSqlite3)
import Database.HDBC.PostgreSQL (connectPostgreSQL)
testData :: ByteString
testData = pack [0..255]
main :: IO ()
main = do
--conn <- connectSqlite3 "test1.db"
conn <- connectPostgreSQL "host=localhost dbname=test user=test"
_ <- run conn "CREATE TABLE test (value BYTEA)" []
commit conn
_ <- run conn "INSERT INTO test VALUES (?)" [toSql testData]
commit conn
readBack <- do
rv <- quickQuery' conn "SELECT * from test" []
return $ fromSql $ Prelude.head $ Prelude.head rv
print $ testData == readBack
disconnect conn
It looks like a database expects UTF8
. But I just want to use raw ByteString. There might as well be a problem in a testprogram. If this is the case, please advice what would be a correct way to do it.
Metadata
Metadata
Assignees
Labels
No labels