xerial / sqlite-jdbc

SQLite JDBC Driver
Apache License 2.0
2.85k stars 619 forks source link

JDBC driver impl of DatabaseMetadata#getTypeInfo() is rather incomplete #937

Open rsmckinney opened 1 year ago

rsmckinney commented 1 year ago

The result returned from DatabaseMetadata#getTypeInfo() is a very small (useless) subset of the SQL types sqlite provides.

  1. Run the following on any database:
    ResultSet rs = dbMetaData.getTypeInfo();
    while (rs.next())
    out.println(rs.getString("TYPE_NAME") + "\t" + JDBCType.valueOf(rs.getInt("DATA_TYPE")).getName());
  2. Result:
    BLOB    BLOB
    INTEGER INTEGER
    NULL    NULL
    REAL    REAL
    TEXT    VARCHAR
  3. As you can see, these mappings only cover a small fraction of the available sqlite SQL types. I was hoping to use this to overcome https://github.com/xerial/sqlite-jdbc/issues/935.
  4. Given all the shortcuts taken in this driver wrt type-safety, one has to conclude the implementers don't consider type-safety a worthwhile aspect. If that is the case, please let me know so I can account for that in my project (and stop filing issues here). Thanks.
gotson commented 1 year ago

Sqlite only supports 5 types of data. That function is supposed to return what types are supported, not all jdbc types.

It seems you don't have much understanding on the sqlite type and affinity system, I suggest you read their documentation first.

rsmckinney commented 1 year ago

This issue is a JDBC issue, where types are meaningful. I fully understand SQLite’s loose type system. This issue is about complying with JDBC where table column metadata must agree with query column metadata. Otherwise, your current driver implementation is useless to code generators.

rsmckinney commented 1 year ago

Let me give you an example.

A Java class generated from a table based on metadata obtained from your driver would result in accessors returning strings and integers for columns typed as DATE, TIMESTAMP, TIME, etc. does that sound right to you?