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

Allow escaping of '?' using '??' in SQL expression #1935

Merged
merged 5 commits into from
Nov 15, 2023

Conversation

pvarga88
Copy link
Contributor

@pvarga88 pvarga88 commented Aug 30, 2023

Using SQL operator, it is not possible to use '?' as a native operator (e.g. on Postgres). This PR is to allow using '??' as an escape mechanism, similar to the escaping mechanism used by Postgres JDBC.

This is to fix issue #836

@pvarga88
Copy link
Contributor Author

pvarga88 commented Sep 6, 2023

Is there anything I need to do to have this looked at by maintainers? or just patience?

@rfelcman
Copy link
Contributor

Could You please provide there examples of SQL (jsonb) query where ? is used as an operator?
Maybe JPA based example should be nice too?
These should be used as starting point for the tests which we want for functional changes.
I'm not sure if this code change related with Postgres is placed to the right area. It should be stored in Postgres platform area.
But I'm not sure if org.eclipse.persistence.internal.databaseaccess.Platform offers some API for this.
Some Postgres JSON features were introduced by #1389 .

@pvarga88
Copy link
Contributor Author

pvarga88 commented Oct 13, 2023

The fix is not specific to Postgres, nor JSON, really. I just happen to run into this because Postgres uses '?' as an operator in many of its operators on JSONB:
https://www.postgresql.org/docs/11/functions-json.html

Oracle also uses '?' as an operator within its JSON_EXISTS
https://docs.oracle.com/en/database/oracle/oracle-database/21/adjsn/condition-JSON_EXISTS.html

As for an example, the following JPA query is not possible on Postgres without this fix:
SQL('?->stanza ?? ?', myentity.myjsonfield, :searchval")

↑ Note that I used two question marks where I want a literal question mark, rather than specifying a parameter in a parameterized query. This works with my proposed fix in this PR.

@rfelcman
Copy link
Contributor

@pvarga88
Copy link
Contributor Author

I'll give it a go but I don't have the full environment to test the tests so it may take a few trial and error commits.

@pvarga88
Copy link
Contributor Author

Done. Test case added.

Copy link
Contributor

@rfelcman rfelcman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update copyright year in TestJson.java into
....Copyright (c) 2022, 2023....

Copy link
Contributor

@rfelcman rfelcman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rfelcman rfelcman merged commit 63b0fb0 into eclipse-ee4j:master Nov 15, 2023
6 checks passed
@pvarga88
Copy link
Contributor Author

@rfelcman I would like to backport this to 4.0. Is there a policy or process for that or do I just submit a separate PR to the 4.0 branch?

@rfelcman
Copy link
Contributor

@rfelcman I would like to backport this to 4.0. Is there a policy or process for that or do I just submit a separate PR to the 4.0 branch?

Just create new PR against 4.0 branch.

pvarga88 added a commit to pvarga88/eclipselink that referenced this pull request May 29, 2024
Allow escaping of '?' using '??' in SQL expression and testEscapedQuestionMarkInSQLOperator to test ?? in SQL operator
@pvarga88
Copy link
Contributor Author

Thank you.
Created #2156

rfelcman pushed a commit that referenced this pull request May 30, 2024
Allow escaping of '?' using '??' in SQL expression and testEscapedQuestionMarkInSQLOperator to test ?? in SQL operator
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.

2 participants