Closed toburger closed 2 years ago
Workaround for issue #356
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.<>cDisplayClass6_0.
b0(Int32 i) at SqlKata.Helper.<>cDisplayClass4_0. 0(String item, Int32 index) at System.Linq.Enumerable.SelectIterator[TSource,TResult](IEnumerableb 1 source, Func
3 selector)+MoveNext() at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable1 source, TAccumulate seed, Func
3 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
@toburger I see that there is still some reference of the ?
still hardcoded, in the Firebird and SQLiteCompiler,
https://github.com/sqlkata/querybuilder/commit/2e58816329162689746d792af76c76f35b028a90
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
Sorry, don't know what happened. It has closed the PR automatically. I've made a new PR here with your changes applied: #616
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...
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:
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:Now the query works as expected after all desired occurrences of
?
are replaced with$$
in your code.