Skip to content

ByteString values #44

Description

@zoranbosnjak

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions