Fix rendering of xmltable and boolean handling for older versions of DB2

This commit is contained in:
Christian Beikov 2024-11-20 19:47:24 +01:00
parent 29b00d6754
commit c0804d366c
3 changed files with 16 additions and 5 deletions

View File

@ -37,7 +37,8 @@ public class DB2XmlTableFunction extends XmlTableFunction {
protected void renderXmlTable(SqlAppender sqlAppender, XmlTableArguments arguments, AnonymousTupleTableGroupProducer tupleType, String tableIdentifierVariable, SqlAstTranslator<?> walker) { protected void renderXmlTable(SqlAppender sqlAppender, XmlTableArguments arguments, AnonymousTupleTableGroupProducer tupleType, String tableIdentifierVariable, SqlAstTranslator<?> walker) {
sqlAppender.appendSql( "xmltable(" ); sqlAppender.appendSql( "xmltable(" );
// DB2 doesn't like parameters for the xpath expression // DB2 doesn't like parameters for the xpath expression
walker.render( arguments.xpath(), SqlAstNodeRenderingMode.INLINE_PARAMETERS ); final String xpath = walker.getLiteralValue( arguments.xpath() );
sqlAppender.appendSingleQuoteEscapedString( "$d" + xpath );
sqlAppender.appendSql( " passing " ); sqlAppender.appendSql( " passing " );
if ( !arguments.isXmlType() ) { if ( !arguments.isXmlType() ) {
sqlAppender.appendSql( "xmlparse(document " ); sqlAppender.appendSql( "xmlparse(document " );
@ -45,8 +46,9 @@ public class DB2XmlTableFunction extends XmlTableFunction {
// DB2 needs parameters to be casted here // DB2 needs parameters to be casted here
walker.render( arguments.xmlDocument(), SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER ); walker.render( arguments.xmlDocument(), SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER );
if ( !arguments.isXmlType() ) { if ( !arguments.isXmlType() ) {
sqlAppender.appendSql( ")" ); sqlAppender.appendSql( ')' );
} }
sqlAppender.appendSql( " as \"d\"" );
renderColumns( sqlAppender, arguments.columnsClause(), walker ); renderColumns( sqlAppender, arguments.columnsClause(), walker );
sqlAppender.appendSql( ')' ); sqlAppender.appendSql( ')' );
} }
@ -69,7 +71,10 @@ public class DB2XmlTableFunction extends XmlTableFunction {
} }
static boolean isBoolean(JdbcMapping type) { static boolean isBoolean(JdbcMapping type) {
return type.getJdbcType().isBoolean(); return switch ( type.getCastType() ) {
case BOOLEAN, TF_BOOLEAN, YN_BOOLEAN, INTEGER_BOOLEAN -> true;
default -> false;
};
} }
private static class DB2XmlTableSetReturningFunctionTypeResolver extends XmlTableSetReturningFunctionTypeResolver { private static class DB2XmlTableSetReturningFunctionTypeResolver extends XmlTableSetReturningFunctionTypeResolver {

View File

@ -417,7 +417,10 @@ public class HANAXmlTableFunction extends XmlTableFunction {
} }
static boolean isBoolean(JdbcMapping type) { static boolean isBoolean(JdbcMapping type) {
return type.getJdbcType().isBoolean(); return switch ( type.getCastType() ) {
case BOOLEAN, TF_BOOLEAN, YN_BOOLEAN, INTEGER_BOOLEAN -> true;
default -> false;
};
} }
private static class DB2XmlTableSetReturningFunctionTypeResolver extends XmlTableSetReturningFunctionTypeResolver { private static class DB2XmlTableSetReturningFunctionTypeResolver extends XmlTableSetReturningFunctionTypeResolver {

View File

@ -203,6 +203,9 @@ public class SybaseASEXmlTableFunction extends XmlTableFunction {
} }
public static boolean isBoolean(JdbcMapping type) { public static boolean isBoolean(JdbcMapping type) {
return type.getJavaTypeDescriptor().getJavaTypeClass() == Boolean.class; return switch ( type.getCastType() ) {
case BOOLEAN, TF_BOOLEAN, YN_BOOLEAN, INTEGER_BOOLEAN -> true;
default -> false;
};
} }
} }