From 4a0703283dc6996c55e4d61ae24f4a226ce298c5 Mon Sep 17 00:00:00 2001 From: gmantele <gmantele@ari.uni-heidelberg.de> Date: Tue, 13 Sep 2016 13:05:15 +0200 Subject: [PATCH] [TAP] Follow up of the previous commit, but this time about the SMALLINT type: 68666ccb93872da6c26348960978552717423240 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. --- src/tap/data/ResultSetTableIterator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tap/data/ResultSetTableIterator.java b/src/tap/data/ResultSetTableIterator.java index 938e5ac..5bcbbfc 100644 --- a/src/tap/data/ResultSetTableIterator.java +++ b/src/tap/data/ResultSetTableIterator.java @@ -706,9 +706,12 @@ public class ResultSetTableIterator implements TableIterator { // if the column value is a Timestamp object, format it in ISO8601: if (colValue instanceof Timestamp) 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: 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: else if (colType != null && colValue != null && colType.type == DBDatatype.CHAR && (colType.length == 1 || colType.length <= 0) && colValue instanceof String) colValue = ((String)colValue).charAt(0); -- GitLab