Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when reading SQL files #12

Closed
ivelten opened this issue Nov 17, 2020 · 4 comments
Closed

Error when reading SQL files #12

ivelten opened this issue Nov 17, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@ivelten
Copy link

ivelten commented Nov 17, 2020

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
Copy link
Owner

Tarmil commented Nov 18, 2020

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.

@Tarmil Tarmil added the bug Something isn't working label Nov 18, 2020
@ivelten
Copy link
Author

ivelten commented Nov 18, 2020

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

@Tarmil
Copy link
Owner

Tarmil commented Nov 18, 2020

Sure, go ahead!

@Tarmil
Copy link
Owner

Tarmil commented May 22, 2022

Released in v0.4.

@Tarmil Tarmil closed this as completed May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants