3

I am using HDBC sqlite3 haskell driver to access local sqlite3 database which

PRAGMA encoding

is

UTF-8

And as result, for example for

SELECT id, title FROM some_table

I'm always getting the result like this:

[[SqlByteString "1", SqlByteString "\210\129\123\211"], ... ]

That's weird! Yes, title contains 'national' symbols and yes, I'm sure that id has type of INTEGER.

So the questions are:

  1. Why 1 unicode symbol are threated as 2 ascii-like symbols?
  2. Why integer columns results bytestring values?
Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
pechenie
  • 1,908
  • 2
  • 18
  • 17

1 Answers1

2

SQLite is an untyped database, so the fields in your database don't really have a type at all. You should be converting them to a more Haskellish value by using fromSql or safeFromSql from Database.HDBC.SqlValue.

dave4420
  • 46,404
  • 6
  • 118
  • 152
  • 1
    But in the "Real World Haskell" book (http://book.realworldhaskell.org/read/using-databases.html) they using sqlite3 engine in chapter 21 and their examples do return correct (like SqlInt or SqlString) values. Why? – pechenie Mar 07 '11 at 08:44
  • 2
    Their examples return `SqlString` and `SqlNull` but not `SqlInt` --- look more closely at what is returned (`SqlString "0"` etc). I presume the implementation has changed at some point to use `SqlByteString` instead of `SqlString`, I don't know why. – dave4420 Mar 07 '11 at 12:31