querybuilder icon indicating copy to clipboard operation
querybuilder copied to clipboard

Calling SelectRaw and passing in an empty string results in an extra trailing comma at the end of the SELECT right before the FROM

Open jspinella opened this issue 3 years ago • 2 comments

I'm on the fence about this being an issue but I didn't see it in closed or open issues so... worst-case y'all just close this.

If I do a .SelectRaw("") SqlKata will generate code that has an extra comma at the end of the SELECT list, resulting in a bad query e.g. SELECT ColumnA, ColumnB, FROM.... The solution is to pass null instead of an empty string e.g. with .SelectRaw(stringVariableThatMightBeNull), the generated query does not have the erroneous comma and passing null into SelectRaw() does not cause an unhandled exception, which is great!

I can't think of a case where passing in an empty string and getting that extra comma is desirable, but I realize this is a super-super-super low-priority "issue", a nice-to-have more than anything else.

jspinella avatar Feb 15 '21 20:02 jspinella

Thanks for reporting, would you mind pushing a PR for this?

ahmad-moussawi avatar May 22 '21 14:05 ahmad-moussawi

I've just tried to reproduce.. this was so long ago I am not sure I have reverted the code to the exact state where I was observing the extra comma, but based on my description above, it appears this is not an issue after all. I may play around with it a bit more but if you don't hear from me in the next couple of days it's probably safe to close this. It's possible a helper method was responsible for adding the extra comma? If so that code has since changed so that it doesn't do that anymore.

jspinella avatar May 22 '21 17:05 jspinella