Skip to content
Snippets Groups Projects
Commit 4a070328 authored by gmantele's avatar gmantele
Browse files

[TAP] Follow up of the previous commit, but this time about the SMALLINT type:

68666ccb
It happens that the JDBC driver returned an Integer instead of a Short for a
Postgres SMALLINT column. This is not a problem for all formats because of
implicit cast, except for FITS which requires an exact correct type. This
commit ensure that columns declared as SMALLINT in the metadata are always
casted as Short.
parent 68666ccb
No related branches found
No related tags found
No related merge requests found
...@@ -706,9 +706,12 @@ public class ResultSetTableIterator implements TableIterator { ...@@ -706,9 +706,12 @@ public class ResultSetTableIterator implements TableIterator {
// if the column value is a Timestamp object, format it in ISO8601: // if the column value is a Timestamp object, format it in ISO8601:
if (colValue instanceof Timestamp) if (colValue instanceof Timestamp)
colValue = ISO8601Format.format(((Timestamp)colValue).getTime()); colValue = ISO8601Format.format(((Timestamp)colValue).getTime());
// if the type is Integer but it is declared as a SMALLINT cast the value (absolutely required for the FITS format):
else if (colValue instanceof Integer && colType != null && colValue != null && colType.type == DBDatatype.SMALLINT)
colValue = new Short(((Integer)colValue).shortValue());
// if the column value is a Boolean object, format it as a SMALLINT: // if the column value is a Boolean object, format it as a SMALLINT:
else if (colValue instanceof Boolean) else if (colValue instanceof Boolean)
colValue = ((Boolean)colValue) ? (short)1 : (short)0; colValue = ((Boolean)colValue) ? new Short((short)1) : new Short((short)0);
// if the column should be only a character: // if the column should be only a character:
else if (colType != null && colValue != null && colType.type == DBDatatype.CHAR && (colType.length == 1 || colType.length <= 0) && colValue instanceof String) else if (colType != null && colValue != null && colType.type == DBDatatype.CHAR && (colType.length == 1 || colType.length <= 0) && colValue instanceof String)
colValue = ((String)colValue).charAt(0); colValue = ((String)colValue).charAt(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment