From: Kris Jurka Date: Thu, 21 Oct 2004 19:13:55 +0000 (+0000) Subject: Correctly cast the return value of a CallableStatement when getShort X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=4a63af29345d489443d9167ae0fede3890490cd8;p=users%2Fbernd%2Fpostgres.git Correctly cast the return value of a CallableStatement when getShort is called. getByte presents a can't happen situation as no function can return a TINYINT because pg doesn't have an equivalent type. Make this throw an exception if we get to this point. Thanks to Christian Niles. --- diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java index 33277a3589..61c3bc69bf 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java @@ -1864,9 +1864,12 @@ public abstract class AbstractJdbc1Statement implements BaseStatement public byte getByte(int parameterIndex) throws SQLException { checkIndex (parameterIndex, Types.TINYINT, "Byte"); - if (callResult == null) - return 0; - return (byte)((Integer)callResult).intValue (); + // We expect the above checkIndex call to fail because + // we don't have an equivalent pg type for TINYINT. + // Possibly "char" (not char(N)), could be used, but + // for the moment we just bail out. + // + throw new PSQLException("postgresql.unusual", PSQLState.UNEXPECTED_ERROR); } /* @@ -1881,7 +1884,7 @@ public abstract class AbstractJdbc1Statement implements BaseStatement checkIndex (parameterIndex, Types.SMALLINT, "Short"); if (callResult == null) return 0; - return (short)((Integer)callResult).intValue (); + return (short)((Short)callResult).intValue (); }