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
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, the readBack won't compare equal.
importData.ByteStringimportDatabase.HDBC--import Database.HDBC.Sqlite3 (connectSqlite3)importDatabase.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.
The text was updated successfully, but these errors were encountered:
This is a simple test program to save and read a bytestring to/from a database. It works fine with
sqlite
, but not withpostgresql
. There are 2 problems:SqlError {seState = "22021", seNativeError = 7, seErrorMsg = "execute: PGRES_FATAL_ERROR: ERROR: invalid byte sequence for encoding \"UTF8\": 0x80\n"}
testData
to some shorter value, thereadBack
won't compare equal.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.The text was updated successfully, but these errors were encountered: