Issue with SqlChar in Convertible instance of SqlValue
jeffhappily opened this issue · 1 comments
I'm having this issue where I have one table column with type tinyint
but when I specify a Word8
type in my persistent models file, I get an error saying that
Failed to parse Haskell type `Word8`; expected integer from database, but received: PersistText \"\\STX\"
After some debugging, I found out that the library actually converts SqlChar
to Persistent
using this function called charChk
where it converts \0
and \1
to boolean and other values to text
charChk :: Char -> PersistValue
charChk '\0' = PersistBool False
charChk '\1' = PersistBool True
charChk c = PersistText $ T.singleton c
But as far as I can tell from hdbc-odbc, the SqlChar
is actually being used to handle BindColBit
and BindColTinyInt
which are both meant to be used as an 8-bit number https://github.com/hdbc/hdbc-odbc/blob/06833d77799f16634d2038bcdc308c35d4752cdd/Database/HDBC/ODBC/Statement.hsc#L873-L880
I think a good fix here would be to convert the Char
to PersistInt64
instead, as persistent
handles nicely to convert PersistInt64
to either Word
, Int
or even Bool
type.
I can open a PR if you'd like.
Related to #18
Thanks for taking a look at this.
The change you suggest makes sense and if you can open a PR I would appreciate it.