2626import java .sql .Types ;
2727import java .util .Vector ;
2828
29- /* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.37 2003/09/17 05:07:37 barry Exp $
29+ /* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.38 2003/09/18 04:14:27 barry Exp $
3030 * This class defines methods of the jdbc1 specification. This class is
3131 * extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
3232 * methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
@@ -893,6 +893,9 @@ public void setNull(int parameterIndex, int sqlType) throws SQLException
893893case Types .TIMESTAMP :
894894l_pgType =PG_TIMESTAMPTZ ;
895895break ;
896+ case Types .BIT :
897+ l_pgType =PG_BOOLEAN ;
898+ break ;
896899case Types .BINARY :
897900case Types .VARBINARY :
898901case Types .LONGVARBINARY :
@@ -930,7 +933,7 @@ public void setBoolean(int parameterIndex, boolean x) throws SQLException
930933 */
931934public void setByte (int parameterIndex ,byte x )throws SQLException
932935{
933- bind (parameterIndex ,Integer .toString (x ),PG_TEXT );
936+ bind (parameterIndex ,Integer .toString (x ),PG_INT2 );
934937}
935938
936939/*
@@ -1457,6 +1460,21 @@ public void clearParameters() throws SQLException
14571460}
14581461}
14591462
1463+ // Helper method that extracts numeric values from an arbitary Object.
1464+ private String numericValueOf (Object x )
1465+ {
1466+ if (x instanceof Boolean )
1467+ return ((Boolean )x ).booleanValue () ?"1" :"0" ;
1468+ else if (x instanceof Integer ||x instanceof Long ||
1469+ x instanceof Double ||x instanceof Short ||
1470+ x instanceof Number ||x instanceof Float )
1471+ return x .toString ();
1472+ else
1473+ //ensure the value is a valid numeric value to avoid
1474+ //sql injection attacks
1475+ return new BigDecimal (x .toString ()).toString ();
1476+ }
1477+
14601478/*
14611479 * Set the value of a parameter using an object; use the java.lang
14621480 * equivalent objects for integral values.
@@ -1486,35 +1504,25 @@ public void setObject(int parameterIndex, Object x, int targetSqlType, int scale
14861504switch (targetSqlType )
14871505{
14881506case Types .INTEGER :
1489- if (x instanceof Boolean )
1490- bind (parameterIndex ,((Boolean )x ).booleanValue () ?"1" :"0" ,PG_BOOLEAN );
1491- else if (x instanceof Integer ||x instanceof Long ||
1492- x instanceof Double ||x instanceof Short ||
1493- x instanceof Number ||x instanceof Float )
1494- bind (parameterIndex ,x .toString (),PG_INTEGER );
1495- else
1496- //ensure the value is a valid numeric value to avoid
1497- //sql injection attacks
1498- bind (parameterIndex ,new BigDecimal (x .toString ()).toString (),PG_INTEGER );
1507+ bind (parameterIndex ,numericValueOf (x ),PG_INTEGER );
14991508break ;
15001509case Types .TINYINT :
15011510case Types .SMALLINT :
1511+ bind (parameterIndex ,numericValueOf (x ),PG_INT2 );
1512+ break ;
15021513case Types .BIGINT :
1514+ bind (parameterIndex ,numericValueOf (x ),PG_INT8 );
1515+ break ;
15031516case Types .REAL :
15041517case Types .FLOAT :
1518+ bind (parameterIndex ,numericValueOf (x ),PG_FLOAT );
1519+ break ;
15051520case Types .DOUBLE :
1521+ bind (parameterIndex ,numericValueOf (x ),PG_DOUBLE );
1522+ break ;
15061523case Types .DECIMAL :
15071524case Types .NUMERIC :
1508- if (x instanceof Boolean )
1509- bind (parameterIndex , ((Boolean )x ).booleanValue () ?"1" :"0" ,PG_BOOLEAN );
1510- else if (x instanceof Integer ||x instanceof Long ||
1511- x instanceof Double ||x instanceof Short ||
1512- x instanceof Number ||x instanceof Float )
1513- bind (parameterIndex ,x .toString (),PG_NUMERIC );
1514- else
1515- //ensure the value is a valid numeric value to avoid
1516- //sql injection attacks
1517- bind (parameterIndex ,new BigDecimal (x .toString ()).toString (),PG_NUMERIC );
1525+ bind (parameterIndex ,numericValueOf (x ),PG_NUMERIC );
15181526break ;
15191527case Types .CHAR :
15201528case Types .VARCHAR :
@@ -1559,7 +1567,7 @@ else if (x instanceof String)
15591567}
15601568else if (x instanceof Number )
15611569{
1562- bind (parameterIndex , ((Number )x ).intValue ()== 1 ?"'1'" :"'0'" ,PG_BOOLEAN );
1570+ bind (parameterIndex , ((Number )x ).intValue ()!= 0 ?"'1'" :"'0'" ,PG_BOOLEAN );
15631571}
15641572else
15651573{
@@ -1572,7 +1580,10 @@ else if (x instanceof Number)
15721580setObject (parameterIndex ,x );
15731581break ;
15741582case Types .OTHER :
1575- setString (parameterIndex , ((PGobject )x ).getValue (),PG_TEXT );
1583+ if (x instanceof PGobject )
1584+ setString (parameterIndex , ((PGobject )x ).getValue (), ((PGobject )x ).getType ());
1585+ else
1586+ throw new PSQLException ("postgresql.prep.type" ,PSQLState .INVALID_PARAMETER_TYPE );
15761587break ;
15771588default :
15781589throw new PSQLException ("postgresql.prep.type" ,PSQLState .INVALID_PARAMETER_TYPE );