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

Fix places where the parameterPlaceholder is hardcoded to a ? #592

Closed
wants to merge 0 commits into from

Conversation

toburger
Copy link
Contributor

@toburger toburger commented Aug 2, 2022

There are places where the parameterPlaceholder variable isn't used and the ? (question mark) is hardcoded in code.

This prevents the redefinition of the parameterPlaceholder to another value.

Practical usage:

It is not possible to define JSON (Postgres) specific queries because some of the keywords use the question mark.

Example:

query.WhereRaw(@$"data->>'Tagging'::jsonb @? '$.{tagkey}\[*\] ? (@.Id == ""{tag}"")'")

The ? gets interpreted as a parameter and throws an exception.

With the changes in place the parameterPlaceholder can be redefined to use another value, for example the $$ value can be used insetad by inheriting a new class from e.g. PostgresCompiler:

class MyPostgresCompiler : PostgresCompiler
{
    public MyPostgresCompiler()
    {
        parameterPlaceholder = "$$";
    }
}

Now the query works as expected after all desired occurrences of ? are replaced with $$ in your code.

@toburger
Copy link
Contributor Author

toburger commented Aug 2, 2022

Workaround for issue #356

@kamisoft-fr
Copy link

kamisoft-fr commented Sep 19, 2022

Same problem here :)

I have a json column containing an object with question mark field like this:

{
"json_param": "question mark string ?"
}

if I create a sqlkata WhereRaw query like :

query.WhereRaw("my_json_column @> '{"json_param" : "question mark string ?"}'");

I get the stack:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at SqlKata.Helper.<>c__DisplayClass6_0.b__0(Int32 i)
at SqlKata.Helper.<>c__DisplayClass4_0.b__0(String item, Int32 index)
at System.Linq.Enumerable.SelectIterator[TSource,TResult](IEnumerable1 source, Func3 selector)+MoveNext()
at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable1 source, TAccumulate seed, Func3 func)
at SqlKata.Helper.ReplaceAll(String subject, String match, Func`2 callback)
at SqlKata.Compilers.Compiler.CompileRaw(Query query)
at SqlKata.Compilers.Compiler.Compile(Query query)

@ahmad-moussawi , can you take a look at it ?
thanks

@ahmad-moussawi
Copy link
Contributor

@toburger I see that there is still some reference of the ? still hardcoded, in the Firebird and SQLiteCompiler,
2e58816
can you push an update to address those?
or alternatively give me the permission to modify this PR https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork

@toburger
Copy link
Contributor Author

Sorry, don't know what happened. It has closed the PR automatically.
I've made a new PR here with your changes applied: #616

kamisoft-fr added a commit to kamisoft-fr/querybuilder that referenced this pull request Nov 3, 2022
… is hardcoded to a ?

Added compiler to the constructor of SqlResult
Made ParameterPlaceholder public
@kamisoft-fr
Copy link

Hi, just created the PR #628 for the SqlResult class still containing the question mark hardcoded
I know that I made a breaking change on the class, but I did't found another way for the moment...

kamisoft-fr added a commit to kamisoft-fr/querybuilder that referenced this pull request Oct 10, 2023
… is hardcoded to a ?

Added compiler to the constructor of SqlResult
Made ParameterPlaceholder public
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

Successfully merging this pull request may close these issues.

3 participants