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

Question mark in query breaks ToString #122

Open
Blanen opened this issue Aug 3, 2018 · 2 comments
Open

Question mark in query breaks ToString #122

Blanen opened this issue Aug 3, 2018 · 2 comments

Comments

@Blanen
Copy link
Contributor

Blanen commented Aug 3, 2018

? is a legal character in SQLServer, sadly.

Building following query would not work currently:

SELECT TOP(10) [A].[B] AS [TEST?] FROM [C]

But SQLServer is completely fine with this.

What breaks this is the fact that questionmarks are current used as placeholders for "bindings" such as TOP(?). And then later gets filled in here:

return Helper.ReplaceAll(RawSql, "?", i =>

But because the amount of question marks in the query is higher than the amount of bindings, an exception gets triggered here:

throw new Exception($"Failed to retrieve a binding at the index {i}, the total bindings count is {Bindings.Count}");

Currently, I'm not aware of a character that wouldn't be a legal SQLServer character in this type of query to use as binding. Maybe something like SQLKATABINDING has to be used instead, if you include that in your query you must just be trying to break it.

Honestly, it would be fine if this is kept this way and that's made clear but I doubt it's intended behavior.

Sorry that I have all these stupid edge-case issues, ha.

@ahmad-moussawi
Copy link
Contributor

Nice catch, the problem here is that even in Raw Statements the user is allowed to enter the ? as a parameter placeholder,

db.Query("Users").WhereRaw("Id = ?", new [] { 1 });

using longer placeholder would make this more tedious, so mentioning this in the docs would be helpful.

@chetannavin
Copy link

I have to allow using ? in SELECT, Any possible work around? Please help here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants