querybuilder
querybuilder copied to clipboard
Question mark in 'Like' statements
I have an issue when try to use "?" not as a parameter in the 'Like' statement, but as part of word. For example "message like '%blabla?%". Currently I got an exception because 'Sqlkata' uses question mark as a parameter placeholder. So I need a way to escape question mark. Or, actually, when I opened the source code of 'Complier.cs' I found something interesting. Here we have:
protected virtual string parameterPlaceholder { get; set; } = "?";
It is good opportunity to override it and use some other symbol or even word for the binding parameter, but, for some reason this property isn't used elsewhere. For example:
ctx.RawSql = Helper.ExpandParameters(ctx.RawSql, "?", ctx.Bindings.ToArray());
case Variable variable2:
object variable1 = ctx.Query.FindVariable(variable2.Name);
ctx.Bindings.Add(variable1);
return "?";
default:
ctx.Bindings.Add(parameter);
return "?";
So could you please reuse 'parameterPlaceholder' parameter in all other places so that it can only be changed in one place, without having to override all of these methods? Or add possibility to escape it in queries
Would like to see it processed too or at least to see a workaround for this.
Someone, anyone?
I think you are looking for this.
new Query("Table").WhereLike("Column", @"%blabla\?%", escapeCharacter=@"\")
If the escaping isn't happening as a priority then that is a bug, and should be fixed.