I seem to be having issues trying to insert a Bool value into a bit field in MSSQL. I'm receiv'ing the following error when I execute the INSERT:
SqlError {seState = "["22018"]", seNativeError = -1, seErrorMsg = "execute execute: ["0: [Microsoft][ODBC Driver 13 for SQL Server]Invalid character value for cast specification"]"}
I have no issues reading out bit values using SELECT, although it looks like these values are being pulled into a SqlChar instead of a SqlBool so not sure if that's a clue. The SqlChar is converted to Bool on my record type, so at least it's compatible.
When I convert my record type into [SqlValue], the value for the Bool is represented as a SqlBool False instead of SqlChar '\NUL' and this fails on INSERT.
Below is some sample code that illustrates the issue:
type ItemId = Integer
data TodoItem = TodoItem { itemId :: ItemId, description :: String, dueDate :: LocalTime, completed :: Bool } deriving (Show, Generic)
instance FromJSON TodoItem
instance ToJSON TodoItem
-- Maps the record type to SqlValues
fromItem :: TodoItem -> [SqlValue]
fromItem = flip (\x -> map (\f -> f x)) $ [toSql . description, toSql . dueDate, toSql . completed]
insertItem :: IConnection conn => IO conn -> TodoItem -> IO ()
insertItem ioconn item = do
conn <- ioconn
stmt <- prepare conn "INSERT INTO Items (Description, DueDate, Completed) VALUES (?, ?, ?)"
execute stmt $ fromItem item
commit conn
I seem to be having issues trying to insert a
Boolvalue into abitfield in MSSQL. I'm receiv'ing the following error when I execute the INSERT:I have no issues reading out bit values using SELECT, although it looks like these values are being pulled into a
SqlCharinstead of aSqlBoolso not sure if that's a clue. TheSqlCharis converted toBoolon my record type, so at least it's compatible.When I convert my record type into
[SqlValue], the value for theBoolis represented as aSqlBool Falseinstead ofSqlChar '\NUL'and this fails on INSERT.Below is some sample code that illustrates the issue: