FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix places where the `parameterPlaceholder` is hardcoded to a `?` by toburger · Pull Request #592 · sqlkata/querybuilder · GitHub

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

Closed
toburger wants to merge 0 commit into
sqlkata:masterfrom
toburger:master
Closed

Fix places where the parameterPlaceholder is hardcoded to a ?#592
toburger wants to merge 0 commit into
sqlkata:masterfrom
toburger:master

Conversation

toburger commented Aug 2, 2022
edited
Loading

Copy link
Copy Markdown
Contributor

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 commented Aug 2, 2022

Copy link
Copy Markdown
Contributor Author

Workaround for issue #356

kamisoft-fr commented Sep 19, 2022
edited
Loading

Copy link
Copy Markdown

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

Copy link
Copy Markdown
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

Copy link
Copy Markdown
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

Copy link
Copy Markdown

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
kamisoft-fr added a commit to kamisoft-fr/querybuilder that referenced this pull request Apr 22, 2026
kamisoft-fr added a commit to kamisoft-fr/querybuilder that referenced this pull request Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL