schemacrawler / SchemaCrawler

Free database schema discovery and comprehension tool
http://www.schemacrawler.com/
Other
1.6k stars 199 forks source link

column.getColumnDataType().getBaseType() returns null #212

Closed adriens closed 5 years ago

adriens commented 5 years ago

Environment

Specify the

  • version of SchemaCrawler that you are using : 15.01.03
  • version of Java that you are using 1.8
  • operating system and version that you are using WIndows
  • relational datavase and version that you are using 'PostgreSQL
  • JDBC driver and version that you are using psql schemacrawler embedded driver

Issue

While fetching columns of a table, the method column.getColumnDataType().getBaseType() always returns null. All other type method are ok, but this one always returns null.

sualeh commented 5 years ago

I tested with Postgres, and it is returning the correct base type for my test schema. You will need to send me a test script to reproduce.

sualeh commented 5 years ago

@adriens - please provide me with a test script to reproduce. I cannot reproduce this issue.

adriens commented 5 years ago

Hi @sualeh , sorry for late answser, i was very busy these last days.

for (final Schema schema : catalog.getSchemas()) {
            for (final Table table : catalog.getTables(schema)) {
                // for each table, count the number of rows
                String lSchema = table.getSchema().getName();
                String lTableName = table.getName();
                String lTableFullName = table.getFullName();
                String lTableRemarks = table.getRemarks();
                String lTableType = table.getTableType().getTableType();

                // fetch columns
                for (final Column column : table.getColumns()) {
                    // names
                    column.getShortName();
                    column.getName();
                    column.getFullName();
                    column.getOrdinalPosition();
                    column.getRemarks();

                    // type centric
                    column.getDefaultValue();
                    column.getSize();

                    // type centric datas : HERE IS THE INTERESTING PART THAT PROVIDES null OBJECTS
                    column.getColumnDataType().getBaseType().getDatabaseSpecificTypeName();
                    column.getColumnDataType().getBaseType().getFullName().toString();
                    column.getColumnDataType().getBaseType().getJavaSqlType().getName(); 

you can find the code commented out in generateTableColumnsCsv in `AdditionalCommand

In my case, I do inherits from BaseSchemaCrawlerCommand

Source file is here : https://github.com/adriens/schemacrawler-additional-command-lints-as-csv/blob/master/src/main/java/com/github/adriens/AdditionalCommand.java

Please let me know if you can reproduce it. I'm targetting PostgreSQL.

sualeh commented 5 years ago

@adriens - actually. I was requesting some DDL scripts to create the database, since I cannot reproduce the issue. Are you able to provide me a small DDL script?

adriens commented 5 years ago

Hmm, you're right, I did not think that it could have something to deal with types.

here is the DDL I used : https://dbseminar.r61.net/system/files/HR_pgsql.sql

adriens commented 5 years ago

Thanks ! 👍

sualeh commented 5 years ago

Actually, I reverted the change. Native types will also have a null base type. I cannot give you a better API experience without changing the API to return an optional.