Closed nscuro closed 2 months ago
Why not present a valid testcase that demonstrates something? As per https://www.datanucleus.org/documentation/problem_reporting.html#jdo
getNumberOfSubExpressions, getSubExpression, isParameter, invoke were added as delegated back in this commit https://github.com/datanucleus/datanucleus-rdbms/commit/dddee142870e086dae5647845d65a93bb5c2b209
Since no testcase is provided for this issue then nothing to say about whether it "fixes" it or otherwise. Closing. If the issue is not fixed then kindly provide a testcase as per the problem reporting guide.
Bug Report
The
UpdateStmtAllowTableAliasInSet
option of data store adapters (e.g.PostgreSQLAdapter
) is not honored forDelegatedExpression
s likeEnumExpression
. This causes compilation of invalid SQL queries for databases like PostgreSQL.The following JDO Bulk Update query:
fails to be executed against a PostgreSQL database, due to the following exception:
In this case
status
is an enum (EnumExpression
at query compile time).PostgreSQL does not allow for table names in
SET
expressions, and DataNucleus correctly handles this, except forSQLExpression
s extendingDelegatedExpression
.I have traced the issue down to
QueryToSQLMapper#compileUpdate
, wheresetOmitTableFromString
is called for allColumnExpression
s of a givenSQLExpression
:https://github.com/datanucleus/datanucleus-rdbms/blob/fb0bcf27f9c0e8ffc558e1737601254f9570d044/src/main/java/org/datanucleus/store/rdbms/query/QueryToSQLMapper.java#L1084-L1092
Note that
getSubExpression
does not consider thedelegate
expression ofDelegatedExpression
s. SosetOmitTableFromString
is never applied to sub expressions ofdelegate
.Towards the end of
compileUpdate
, the following is executed:https://github.com/datanucleus/datanucleus-rdbms/blob/fb0bcf27f9c0e8ffc558e1737601254f9570d044/src/main/java/org/datanucleus/store/rdbms/query/QueryToSQLMapper.java#L1142
eq
is directly delegated to theDelegatedExpression
'sdelegate
:https://github.com/datanucleus/datanucleus-rdbms/blob/fb0bcf27f9c0e8ffc558e1737601254f9570d044/src/main/java/org/datanucleus/store/rdbms/sql/expression/DelegatedExpression.java#L40-L47
Due to this, the final
BooleanExpression
is usingColumnExpression
s on whichsetOmitTableFromString
has never been called. Thus, the error described above is happening.Should
DelegatedExpression
not also delegate calls togetNumberOfSubExpressions
andgetSubExpression
to itsdelegate
? Alternatively, shouldsetOmitTableFromString
be called for all sub expressions of the parent and delegate expression?