Open rsmckinney opened 1 year ago
For instance, if I call
getColumnType(int)
and get backTypes.DATE
, the JDBC specification states that I can expect values of typejava.sql.Date
for that column. However, if I callgetObject(int)
for a row including that column, sqlite returns a value of typejava.lang.String
.
from what i recall when i looked into this, it's because the first one is looking at the table definition, while the second one is looking at the actual value for that row. There is no guarantee that they will match, since SQLite doesn't enforce types.
So you can define a column as 'datetime', and store a float inside.
@gotson That’s a separate issue re no type-safety.
In this case what I am saying is if a column is typed as Types.DATE
, getObject(int)
should always return a Java.sql.Date
regardless of how the value was set. The method should attempt to coerce whatever is stored in that column to a Date
. It should throw an exception if that can’t be done. If the user wants the value as some other data type, he can call getInt() etc. for specific coercions. This is how JDBC specifies getObject
methods.
@gotson That’s a separate issue re no type-safety.
In this case what I am saying is if a column is typed as
Types.DATE
,getObject(int)
should always return aJava.sql.Date
regardless of how the value was set. The method should attempt to coerce whatever is stored in that column to aDate
. It should throw an exception if that can’t be done. If the user wants the value as some other data type, he can call getInt() etc. for specific coercions. This is how JDBC specifiesgetObject
methods.
Could you provide a unit test showing the behaviour you think is wrong ?
I don't have time to write unit tests for sqlite. Here again from the OP is a complete description and example:
The problem is calls to ResultSetMetadata#getColumnType(int) don't align with calls to ResultSet#getObject(int). Generally, Sqlite's implementation of getObject(int) does not adhere to Table B.3.
For instance, if I call getColumnType(int) and get back Types.DATE, the JDBC specification states that I can expect values of type java.sql.Date for that column. However, if I call getObject(int) for a row including that column, sqlite returns a value of type java.lang.String.
I don't have time to write unit tests for sqlite
If you don't, why would we? You're just throwing issues without much details or repro, then you are saying you don't have any time to invest in this.
There is plenty enough detail here for a “maintainer” to grok. If you aren’t interested in fixing stuff here, you might consider a different hobby.
TLDR: Column values obtained from
getObject
should match the types fromgetColumnType(int)
, but they often do not.Referring to JDBC 4.x Specification. (Same mappings exist in JDBC 3 Specification)
According to the spec:
The problem is calls to
ResultSetMetadata#getColumnType(int)
don't align with calls toResultSet#getObject(int)
. Generally, Sqlite's implementation ofgetObject(int)
does not adhere to Table B.3.For instance, if I call
getColumnType(int)
and get backTypes.DATE
, the JDBC specification states that I can expect values of typejava.sql.Date
for that column. However, if I callgetObject(int)
for a row including that column, sqlite returns a value of typejava.lang.String
.Similarly, calls to
getColumn(int, Class<?>)
are not covered. IfgetColumnType(int)
returnsTypes.CLOB
andgetObject(int, Class<?>)
is called withjava.sql.Clob
for the same column, aSQLFeatureNotSupportedException("not implemented by SQLite JDBC driver")
results becausegetColumn(int, Class<?>)
does not handlejava.sql.Clob
.This behavior does not appear to comply with the specification (both 3 & 4), but more importantly this behavior complicates writing type-safe code generators that work with sqlite db connections.