1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-18 17:41:14 +03:00

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.
This commit is contained in:
Kris Jurka 2004-10-21 19:13:55 +00:00
parent 62a6019c49
commit d06384c6d7

View File

@ -26,7 +26,7 @@ import java.sql.Timestamp;
import java.sql.Types; import java.sql.Types;
import java.util.Vector; import java.util.Vector;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.41.2.7 2004/09/13 08:02:41 jurka Exp $ /* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.41.2.8 2004/10/21 19:13:55 jurka Exp $
* This class defines methods of the jdbc1 specification. This class is * This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2 * extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement * methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
@ -1864,9 +1864,12 @@ public abstract class AbstractJdbc1Statement implements BaseStatement
public byte getByte(int parameterIndex) throws SQLException public byte getByte(int parameterIndex) throws SQLException
{ {
checkIndex (parameterIndex, Types.TINYINT, "Byte"); checkIndex (parameterIndex, Types.TINYINT, "Byte");
if (callResult == null) // We expect the above checkIndex call to fail because
return 0; // we don't have an equivalent pg type for TINYINT.
return (byte)((Integer)callResult).intValue (); // 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"); checkIndex (parameterIndex, Types.SMALLINT, "Short");
if (callResult == null) if (callResult == null)
return 0; return 0;
return (short)((Integer)callResult).intValue (); return (short)((Short)callResult).intValue ();
} }