fskorgen opened a new issue, #8223:
URL: https://github.com/apache/hop/issues/8223

   ### Apache Hop version?
   
   2.19
   
   ### Java version?
   
   21
   
   ### Operating system
   
   Windows
   
   ### What happened?
   
   **Affected:** 2.19.0 and earlier.
   
   `Database.getQueryFieldsFromDatabaseMetaData` is the fallback used when a 
database reports
   `isSupportsPreparedStatementMetadataRetrieval() == false` — Oracle, H2, 
Exasol4, Gupta, SybaseIQ.
   The method cannot consume a standard `DatabaseMetaData.getColumns()` result:
   
   - The **column name pattern is `""`**. Per the JDBC contract an empty 
pattern matches nothing, so
     the result set is empty whatever else is right. Verified on H2: 
`getColumns("", "", "T", "")`
     returns 0 rows, while `getColumns(null, null, "T", "%")` returns the 2 
real columns.
   - With no SQL passed in it also uses `databaseMeta.getName()` — the 
**connection name** — as the
     table-name pattern.
   - It switches on `columns.getString("SOURCE_DATA_TYPE")` as though that 
column held Hop type names
     (`"Integer"`, `"BigDecimal"`, `"Internet Address"`). In JDBC, 
`SOURCE_DATA_TYPE` is a `short`
     holding the base type of a DISTINCT/REF column, and it is NULL for 
ordinary columns. Verified on
     H2: the value is null for both columns, and `switch` on a null String 
throws
     `NullPointerException`.
   - It reads `SOURCE_MASK`, `SOURCE_DECIMAL_SYMBOL`, `SOURCE_GROUPING_SYMBOL` 
and
     `SOURCE_CURRENCY_SYMBOL`, none of which exist in 
`DatabaseMetaData.getColumns()`. Verified on H2:
     `Column "SOURCE_MASK" not found [42122-240]`.
   - The returned `ResultSet` is not closed.
   
   Any one of the metadata-contract errors is enough to stop the method. In 
practice it only ever
   "works" by throwing `Error in Database.getQueryFields()`, being caught, and 
falling through to
   `getQueryFieldsFallback` — which is why nobody has noticed.
   
   ### Steps to reproduce
   
   Open a connection to an in-memory H2 
(`isSupportsPreparedStatementMetadataRetrieval()` is false),
   create `create table t (a int, b varchar(10))` and call 
`getQueryFieldsFromDatabaseMetaData("select
   * from t")`. The call fails rather than returning the two fields; each of 
the metadata-contract
   errors above can be observed on its own by calling 
`DatabaseMetaData.getColumns` with the same
   arguments the method uses.
   
   ### Suggested fix
   
   Either restrict the method to the data-service connections whose result set 
actually carries those
   columns, or delete it and go straight to the fallback for these databases.
   
   
   ### Issue Priority
   
   Priority: 3
   
   ### Issue Component
   
   Component: Database


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to