querybuilder icon indicating copy to clipboard operation
querybuilder copied to clipboard

Question mark in query breaks ToString

Open Blanen opened this issue 5 years ago • 2 comments

? 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:

https://github.com/sqlkata/querybuilder/blob/ac897e0f430f13d494b79bbe00835282ef609bf9/QueryBuilder/SqlResult.cs#L53

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

https://github.com/sqlkata/querybuilder/blob/ac897e0f430f13d494b79bbe00835282ef609bf9/QueryBuilder/SqlResult.cs#L57

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.

Blanen avatar Aug 03 '18 14:08 Blanen