When I tried the method DatabaseMetaData.getTables() (or getProcedures()), I always get back empty TABLE_NAME-columns (or PROCEDURE_NAME-columns).
When I manually did the underlying query:
SELECT CASE WHEN TABLE_CATALOG='' THEN NULL ELSE TABLE_CATALOG END AS TABLE_CAT, CASE WHEN TABLE_SCHEMA='' THEN NULL ELSE TABLE_SCHEMA END AS TABLE_SCHEM, TABLE_NAME, 'TABLE' AS TABLE_TYPE, NULL AS REMARKS, NULL AS TYPE_CAT, NULL AS TYPE_SCHEM, NULL AS TYPE_NAME, NULL AS SELF_REFERENCING_COL_NAME, NULL AS REF_GENERATION
FROM INFORMATION_SCHEMA.TABLES AS T
WHERE 1=1
I've got
TABLE_CAT
TABLE_CAT
TABLE_SCHEM
TABLE_SCHEM
REMARKS
TABLE_TYPE
REMARKS
TYPE_CAT
TYPE_SCHEM
TYPE_NAME
null
null
tableName1
TABLE
null
null
tableName2
TABLE
When I changed the usages of CASE WHEN into COALESCE() it was working and gave the expected result:
SELECT COALESCE(TABLE_CATALOG, '') AS TABLE_CAT, COALESCE(TABLE_SCHEMA, '') AS TABLE_SCHEM, TABLE_NAME, 'TABLE' AS TABLE_TYPE, NULL AS REMARKS, NULL AS TYPE_CAT, NULL AS TYPE_SCHEM, NULL AS TYPE_NAME, NULL AS SELF_REFERENCING_COL_NAME, NULL AS REF_GENERATION FROM INFORMATION_SCHEMA.TABLES WHERE 1=1
TABLE_CAT
TABLE_SCHEM
TABLE_NAME
TABLE_TYPE
REMARKS
TYPE_CAT
TYPE_SCHEM
TYPE_NAME
SELF_REFERENCING_COL_NAME
REF_GENERATION
''
''
tableName1
TABLE
''
''
tableName2
TABLE
I don't have the time to file a proper pull request, but if someone could please change the constant
nl.topicus.jdbc.CloudSpannerDatabaseMetaDataConstants#SELECT_TABLES_COLUMNS
into
public static final String SELECT_TABLES_COLUMNS =
"SELECT COALESCE(TABLE_CATALOG, '') AS TABLE_CAT, COALESCE(TABLE_SCHEMA, '') AS TABLE_SCHEM, TABLE_NAME, 'TABLE' AS TABLE_TYPE, NULL AS REMARKS, NULL AS TYPE_CAT, NULL AS TYPE_SCHEM, NULL AS TYPE_NAME, NULL AS SELF_REFERENCING_COL_NAME, NULL AS REF_GENERATION ";
When I tried the method DatabaseMetaData.getTables() (or getProcedures()), I always get back empty TABLE_NAME-columns (or PROCEDURE_NAME-columns).
When I manually did the underlying query:
I've got
When I changed the usages of CASE WHEN into COALESCE() it was working and gave the expected result:
SELECT COALESCE(TABLE_CATALOG, '') AS TABLE_CAT, COALESCE(TABLE_SCHEMA, '') AS TABLE_SCHEM, TABLE_NAME, 'TABLE' AS TABLE_TYPE, NULL AS REMARKS, NULL AS TYPE_CAT, NULL AS TYPE_SCHEM, NULL AS TYPE_NAME, NULL AS SELF_REFERENCING_COL_NAME, NULL AS REF_GENERATION FROM INFORMATION_SCHEMA.TABLES WHERE 1=1
I don't have the time to file a proper pull request, but if someone could please change the constant nl.topicus.jdbc.CloudSpannerDatabaseMetaDataConstants#SELECT_TABLES_COLUMNS into
Thanks alot.