Tarmil / FSharp.Data.LiteralProviders

F# Type providers generating literals from the compile-time environment
MIT License
135 stars 6 forks source link

Error when reading SQL files #12

Closed ivelten closed 2 years ago

ivelten commented 4 years ago

I tried to use Text literal provider to load Sql files for queries using Dapper in F#. But I am having a strange behavior where the Sql file is loaded with a syntax error, altough the Sql file itself runs fine.

Trying to understand the problem, I copied the value of the Literal produced by the provider and pasted it into Sql Management Studio and tried executing it. I got the same syntax error: SqlException: Incorrect syntax near ''.

Trying to understand the reason, I noticed that the Provider loads the Sql file with an unknown character before the first character. For example, a file with a content like select * from dbo.Customers is loaded with some unrecognized character before the s from select keyword.

To reproduce the problem, you can simply try loading a Sql script file into the provider and try executing the literal generated by it's text into SqlCommand .

For now, the workaround I am using is calling Substring(1) after the provider literal Text:

let sql = TextFile<"Implementations/GetParameterValue.sql">.Text.Substring(1)
Tarmil commented 4 years ago

This sounds like a byte order mark issue. The provider recognizes the encoding, but then provides the content of the file "as is", including BOM. We should strip the BOM.

ivelten commented 4 years ago

@Tarmil yes you are right about that. If you don't mind, I could work on a Pull Request for it.

Tarmil commented 4 years ago

Sure, go ahead!

Tarmil commented 2 years ago

Released in v0.4.