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

Improve support for query parameter binding #1504

Closed
dazey3 opened this issue May 4, 2022 · 0 comments
Closed

Improve support for query parameter binding #1504

dazey3 opened this issue May 4, 2022 · 0 comments
Assignees

Comments

@dazey3
Copy link
Contributor

dazey3 commented May 4, 2022

Currently, EclipseLink disables parameter binding for queries that contain certain functions (ABS, SQRT, MOD, ect ), when running against DB2. However, usage of un-typed parameter markers within many of these functions is actually permitted on DB2. The first part of this issue adds support to EclipseLink so that SQL functions that allow un-typed parameters on DB2 will use parameter markers; if the JPQL and/or Criteria API use parameters.

JPQL Example:

 Query query = em.createQuery("SELECT s.id FROM SimpleEntity s WHERE s.intVal1 = ABS(?1) AND s.intVal2 = ?2");
 query.setParameter(1, -36);
 query.setParameter(2, 42);
 query.getResultList();

Current SQL syntax for DB2:

SELECT ID FROM SIMPLEENTITY WHERE ((INTVAL1 = ABS(-36)) AND (INTVAL2 = 42))

EclipseLink parses the "ABS" function and disables parameter binding for DB2. However, it is legal for an untyped parameter marker to be passed to the "ABS" function on DB2.

NEW SQL syntax for DB2:

SELECT ID, INTVAL1, INTVAL2, STRVAL1, STRVAL2 FROM SIMPLEENTITY WHERE ((INTVAL1 = SQRT(ABS(?))) AND (INTVAL2 = ?))

Additionally, EclipseLink currently only supports disabling or allowing parameter binding for the entire query. This means that if a single, untyped parameter marker is not allowed within a query, then EclipseLink can only disable binding for the entire query. The second part of this issue adds support for EclipseLink to allow partial binding of parameters; making the determination on when to bind/not to bind on an individual level and not a query level.

JPQL Example:

 Query query = em.createQuery("SELECT ?1 FROM SimpleEntity s WHERE s.intVal1 = ?2");
 query.setParameter(1, 1);
 query.setParameter(2, 3);
 query.getResultList();

Current SQL syntax for DB2:

SELECT 1 FROM SIMPLEENTITY WHERE (INTVAL1 = 3)

EclipseLink parses the SELECT clause and since there is a ParameterExpression as a SELECT argument, all parameter binding is disabled for the entire query. While it is correct that on DB2 it is illegal to pass an untyped parameter marker as a SELECT argument, that is not true for the "=" usage in the WHERE clause.

NEW SQL syntax for DB2:

SELECT 1 FROM SIMPLEENTITY WHERE (INTVAL1 = ?)
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

No branches or pull requests

1 participant