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

ByteString values #44

Open
zoranbosnjak opened this issue Aug 10, 2018 · 0 comments
Open

ByteString values #44

zoranbosnjak opened this issue Aug 10, 2018 · 0 comments

Comments

@zoranbosnjak
Copy link

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.
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.

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