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

Curly Brackets compiled into Square Brackets: Request to disable column identifier #430

Closed
EyreC opened this issue Nov 21, 2020 · 4 comments

Comments

@EyreC
Copy link

EyreC commented Nov 21, 2020

This works:

var query = new Query("tableName");
query.Select("id").WhereNot("title", "[{}]")

And yields:
SELECT id FROM tableName WHERE title != '[{}]'

However, curly braces in the SelectRaw or WhereRaw get compiled into square brackets:

var whereRawQuery = new Query("tableName");
query.Select("id").WhereRaw("title != '[{}]')

This compiles into:
SELECT id FROM tableName WHERE title != '[[]]'

Equivalently the following also occurs:

Query selectBracket = new Query("tableName"); 
selectBracket.SelectRaw("id, (select id, title from otherTable where title != '[{}]' for json path) ");

This compiles into:
SELECT id (select id, title from otherTable where title != '[[]]' for json path) FROM tableName

Note the '[{}]' is now '[[]]'.

My guess is that the has something to do with how SqlKata identifies columns.If this is the case, would it be possible to optionally disable this text replacement?

I am trying to persuade my organisation to use SqlKata more extensively, but we'd likely still need to make use of the .Raw functions in SqlKata while things get ported over.

@ahmad-moussawi
Copy link
Contributor

ahmad-moussawi commented Nov 21, 2020 via email

@EyreC
Copy link
Author

EyreC commented Nov 22, 2020

The backslash is not valid escape syntax for the curly brace in C# - I get a compile error attempting to use it. The escape sequence for a curly place is to duplicate it like this:
[{{}}]
Usually I'd do this if I was using a string literal and the curly braces were reserved for specifying variables. However this just gets compiled into
[[[]]]

Are you able to escape the curly brace @ahmad-moussawi ? If so, where and how do you do so?

@ahmad-moussawi
Copy link
Contributor

Yes check this #407 similar to your case.
and here a live example
Escape curly braces in Raw Expression

@EyreC
Copy link
Author

EyreC commented Nov 25, 2020

I've managed to do that, thank you @ahmad-moussawi

@EyreC EyreC closed this as completed Nov 25, 2020
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

2 participants