querybuilder icon indicating copy to clipboard operation
querybuilder copied to clipboard

Question mark in 'Like' statements

Open oleksandr-sidenko opened this issue 3 years ago • 3 comments

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

oleksandr-sidenko avatar Dec 15 '20 15:12 oleksandr-sidenko

Would like to see it processed too or at least to see a workaround for this.

mykola-klymyuk-eleks avatar Dec 15 '20 16:12 mykola-klymyuk-eleks

Someone, anyone?

klym1 avatar Dec 16 '20 09:12 klym1

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.

Steven-Beasley avatar Dec 20 '20 12:12 Steven-Beasley