Index: Makefile
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/Makefile,v
retrieving revision 1.38
diff -c -p -r1.38 Makefile
*** Makefile	12 Feb 2003 06:13:04 -0000	1.38
--- Makefile	9 Jul 2003 19:33:48 -0000
***************
*** 4,10 ****
  #
  # Copyright (c) 2001, PostgreSQL Global Development Group
  #
! # $Header: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/Makefile,v 1.38 2003/02/12 06:13:04 barry Exp $
  #
  #-------------------------------------------------------------------------
  
--- 4,10 ----
  #
  # Copyright (c) 2001, PostgreSQL Global Development Group
  #
! # $Header: /cvsroot/pgsql-server/src/interfaces/jdbc/Makefile,v 1.38 2003/02/12 06:13:04 barry Exp $
  #
  #-------------------------------------------------------------------------
  
Index: build.xml
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/build.xml,v
retrieving revision 1.32
diff -c -p -r1.32 build.xml
*** build.xml	27 Feb 2003 05:45:43 -0000	1.32
--- build.xml	9 Jul 2003 19:33:52 -0000
***************
*** 6,12 ****
  
    This file now requires Ant 1.4.1.  2002-04-18
  
!   $Header: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/build.xml,v 1.32 2003/02/27 05:45:43 barry Exp $
  
  -->
  
--- 6,12 ----
  
    This file now requires Ant 1.4.1.  2002-04-18
  
!   $Header: /cvsroot/pgsql-server/src/interfaces/jdbc/build.xml,v 1.32 2003/02/27 05:45:43 barry Exp $
  
  -->
  
Index: org/postgresql/jdbc1/AbstractJdbc1Statement.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java,v
retrieving revision 1.27
diff -c -p -r1.27 AbstractJdbc1Statement.java
*** org/postgresql/jdbc1/AbstractJdbc1Statement.java	9 Jul 2003 05:12:04 -0000	1.27
--- org/postgresql/jdbc1/AbstractJdbc1Statement.java	9 Jul 2003 19:33:56 -0000
*************** public abstract class AbstractJdbc1State
*** 65,73 ****
--- 65,80 ----
  	protected String[] m_sqlFragments;
  	private String[] m_origSqlFragments;
  	private String[] m_executeSqlFragments;
+ 	protected Object[] call_m_binds = new Object[0];
  	protected Object[] m_binds = new Object[0];
  
+ 	protected String[] call_m_bindTypes = new String[0];
  	protected String[] m_bindTypes = new String[0];
+ 	protected int[] m_bindDirection = new int[0];
+ 	private static final int OUT = 1;
+ 	private static final int IN = 2;
+ 	private static final int INOUT = 3;
+ 	
  	protected String m_statementName = null;
          protected boolean m_statementIsCursor = false;
  
*************** public abstract class AbstractJdbc1State
*** 79,92 ****
  	private static final String RESULT_ALIAS = "result";
  	private String originalSql = "";
  	private boolean isFunction;
- 	// functionReturnType contains the user supplied value to check
  	// testReturn contains a modified version to make it easier to
  	// check the getXXX methods..
! 	private int functionReturnType;
! 	private int testReturn;
  	// returnTypeSet is true when a proper call to registerOutParameter has been made
! 	private boolean returnTypeSet;
  	protected Object callResult;
  
  
  	public abstract BaseResultSet createResultSet(Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException;
--- 86,100 ----
  	private static final String RESULT_ALIAS = "result";
  	private String originalSql = "";
  	private boolean isFunction;
  	// testReturn contains a modified version to make it easier to
  	// check the getXXX methods..
! 	private int[] testReturn;
  	// returnTypeSet is true when a proper call to registerOutParameter has been made
! 	private boolean[] returnTypeSet;
! 	private boolean returnsSomething = false;
  	protected Object callResult;
+ 	//used for callable statements. Allows for tracking of modified calls.
+ 	protected boolean inBatch = false;
  
  
  	public abstract BaseResultSet createResultSet(Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor) throws SQLException;
*************** public abstract class AbstractJdbc1State
*** 117,125 ****
  	protected void parseSqlStmt (String p_sql) throws SQLException
  	{
  		String l_sql = p_sql;
- 
  		l_sql = replaceProcessing(l_sql);
- 
  		if (this instanceof CallableStatement)
  		{
  			l_sql = modifyJdbcCall(l_sql);
--- 125,131 ----
*************** public abstract class AbstractJdbc1State
*** 142,155 ****
  			}
  		}
  		v.addElement(l_sql.substring (lastParmEnd, l_sql.length()));
- 
  		m_sqlFragments = new String[v.size()];
! 		m_binds = new Object[v.size() - 1];
! 		m_bindTypes = new String[v.size() - 1];
  
  		for (i = 0 ; i < m_sqlFragments.length; ++i)
  			m_sqlFragments[i] = (String)v.elementAt(i);
- 
  	}
  
    
--- 148,170 ----
  			}
  		}
  		v.addElement(l_sql.substring (lastParmEnd, l_sql.length()));
  		m_sqlFragments = new String[v.size()];
! 		if (this instanceof CallableStatement)
! 		{
! 			call_m_binds = new Object[v.size()-1];
! 			call_m_bindTypes = new String[v.size()-1];
! 			m_bindDirection = new int[v.size()-1];
! 			testReturn = new int[v.size()-1];
! 			returnTypeSet = new boolean[v.size()-1];
! 		}
! 		else 
! 		{
! 			m_binds = new Object[v.size() - 1];
! 			m_bindTypes = new String[v.size() - 1];
! 		}
  
  		for (i = 0 ; i < m_sqlFragments.length; ++i)
  			m_sqlFragments[i] = (String)v.elementAt(i);
  	}
  
    
*************** public abstract class AbstractJdbc1State
*** 197,203 ****
  	 */
  	public java.sql.ResultSet executeQuery() throws SQLException
  	{
!                 this.execute();
  
  		while (result != null && !result.reallyResultSet())
  			result = (BaseResultSet) result.getNext();
--- 212,218 ----
  	 */
  	public java.sql.ResultSet executeQuery() throws SQLException
  	{
! 		this.execute();
  
  		while (result != null && !result.reallyResultSet())
  			result = (BaseResultSet) result.getNext();
*************** public abstract class AbstractJdbc1State
*** 243,249 ****
  	public int executeUpdate() throws SQLException
  	{
  		this.execute();
! 		if (result.reallyResultSet())
  			throw new PSQLException("postgresql.stat.result");
  		return this.getUpdateCount();
  	}
--- 258,265 ----
  	public int executeUpdate() throws SQLException
  	{
  		this.execute();
! 		//modified to accomdate void returning functions.
! 		if (result.reallyResultSet() && !(this instanceof CallableStatement) && !returnsSomething)
  			throw new PSQLException("postgresql.stat.result");
  		return this.getUpdateCount();
  	}
*************** public abstract class AbstractJdbc1State
*** 290,303 ****
  	 */
  	public boolean execute() throws SQLException
  	{
! 		if (isFunction && !returnTypeSet)
! 			throw new PSQLException("postgresql.call.noreturntype");
! 		if (isFunction)
! 		{ // set entry 1 to dummy entry..
! 			m_binds[0] = ""; // dummy entry which ensured that no one overrode
! 			m_bindTypes[0] = PG_TEXT;
! 			// and calls to setXXX (2,..) really went to first arg in a function call..
  		}
  
  		// New in 7.1, if we have a previous resultset then force it to close
  		// This brings us nearer to compliance, and helps memory management.
--- 306,331 ----
  	 */
  	public boolean execute() throws SQLException
  	{
! 		//if (isFunction && !returnTypeSet)
! 	//		throw new PSQLException("postgresql.call.noreturntype");
! 		if (this instanceof CallableStatement)
! 		{
! 			for (int i=0;i<returnTypeSet.length;i++)
! 			{
! 				if ((m_bindDirection[i]==OUT || m_bindDirection[i]==INOUT) && returnTypeSet[i]==false)
! 					throw new PSQLException("postgresql.call.notbound", String.valueOf(i));
! 			}
  		}
+ //		if (isFunction)
+ //		{ // set entry 1 to dummy entry..
+ //			m_binds[0] = ""; // dummy entry which ensured that no one overrode
+ //			m_bindTypes[0] = PG_TEXT;
+ //			// and calls to setXXX (2,..) really went to first arg in a function call..
+ //		}
+ 
+ 		if (this instanceof CallableStatement && !inBatch)
+ 			this.modifycall();
+ 
  
  		// New in 7.1, if we have a previous resultset then force it to close
  		// This brings us nearer to compliance, and helps memory management.
*************** public abstract class AbstractJdbc1State
*** 435,457 ****
  
  		// New in 7.1, pass Statement so that ExecSQL can customise to it                
  		result = QueryExecutor.execute(m_sqlFragments,
!                                                m_binds,
!                                                this);
  
  		//If we are executing a callable statement function set the return data
! 		if (isFunction)
  		{
  			if (!result.reallyResultSet())
  				throw new PSQLException("postgresql.call.noreturnval");
  			if (!result.next ())
  				throw new PSQLException ("postgresql.call.noreturnval");
! 			callResult = result.getObject(1);
! 			int columnType = result.getMetaData().getColumnType(1);
! 			if (columnType != functionReturnType)
! 				throw new PSQLException ("postgresql.call.wrongrtntype",
! 										 new Object[]{
! 											 "java.sql.Types=" + columnType, "java.sql.Types=" + functionReturnType });
! 			result.close ();
  			return true;
  		}
  		else
--- 463,480 ----
  
  		// New in 7.1, pass Statement so that ExecSQL can customise to it                
  		result = QueryExecutor.execute(m_sqlFragments,
! 						m_binds,
! 						this);
! 
  
  		//If we are executing a callable statement function set the return data
! 		if (this instanceof CallableStatement)
  		{
  			if (!result.reallyResultSet())
  				throw new PSQLException("postgresql.call.noreturnval");
  			if (!result.next ())
  				throw new PSQLException ("postgresql.call.noreturnval");
! 			getCallResult();
  			return true;
  		}
  		else
*************** public abstract class AbstractJdbc1State
*** 920,926 ****
  	 */
  	public void setByte(int parameterIndex, byte x) throws SQLException
  	{
! 		bind(parameterIndex, Integer.toString(x), PG_TEXT);
  	}
  
  	/*
--- 943,949 ----
  	 */
  	public void setByte(int parameterIndex, byte x) throws SQLException
  	{
! 		bind(parameterIndex, "'" + Integer.toString(x) + "'", PG_TEXT);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 933,939 ****
  	 */
  	public void setShort(int parameterIndex, short x) throws SQLException
  	{
! 		bind(parameterIndex, Integer.toString(x), PG_INT2);
  	}
  
  	/*
--- 956,962 ----
  	 */
  	public void setShort(int parameterIndex, short x) throws SQLException
  	{
! 		bind(parameterIndex, "'" + Integer.toString(x) + "'", PG_INT2);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 946,952 ****
  	 */
  	public void setInt(int parameterIndex, int x) throws SQLException
  	{
! 		bind(parameterIndex, Integer.toString(x), PG_INTEGER);
  	}
  
  	/*
--- 969,975 ----
  	 */
  	public void setInt(int parameterIndex, int x) throws SQLException
  	{
! 		bind(parameterIndex, "'" + Integer.toString(x) + "'", PG_INTEGER);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 959,965 ****
  	 */
  	public void setLong(int parameterIndex, long x) throws SQLException
  	{
! 		bind(parameterIndex, Long.toString(x), PG_INT8);
  	}
  
  	/*
--- 982,988 ----
  	 */
  	public void setLong(int parameterIndex, long x) throws SQLException
  	{
! 		bind(parameterIndex, "'" + Long.toString(x) + "'", PG_INT8);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 972,978 ****
  	 */
  	public void setFloat(int parameterIndex, float x) throws SQLException
  	{
! 		bind(parameterIndex, Float.toString(x), PG_FLOAT);
  	}
  
  	/*
--- 995,1001 ----
  	 */
  	public void setFloat(int parameterIndex, float x) throws SQLException
  	{
! 		bind(parameterIndex, "'" + Float.toString(x) + "'", PG_FLOAT);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 985,991 ****
  	 */
  	public void setDouble(int parameterIndex, double x) throws SQLException
  	{
! 		bind(parameterIndex, Double.toString(x), PG_DOUBLE);
  	}
  
  	/*
--- 1008,1014 ----
  	 */
  	public void setDouble(int parameterIndex, double x) throws SQLException
  	{
! 		bind(parameterIndex, "'" + Double.toString(x) + "'", PG_DOUBLE);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 1003,1009 ****
  			setNull(parameterIndex, Types.DECIMAL);
  		else
  		{
! 			bind(parameterIndex, x.toString(), PG_NUMERIC);
  		}
  	}
  
--- 1026,1032 ----
  			setNull(parameterIndex, Types.DECIMAL);
  		else
  		{
! 			bind(parameterIndex, "'" + x.toString() + "'", PG_NUMERIC);
  		}
  	}
  
*************** public abstract class AbstractJdbc1State
*** 1464,1486 ****
  		switch (targetSqlType)
  		{
  			case Types.INTEGER:
  				if (x instanceof Boolean)
! 					bind(parameterIndex,((Boolean)x).booleanValue() ? "1" :"0", PG_BOOLEAN);
  				else
! 					bind(parameterIndex, x.toString(), PG_INTEGER);
  				break;
- 			case Types.TINYINT:
- 			case Types.SMALLINT:
  			case Types.BIGINT:
  			case Types.REAL:
  			case Types.FLOAT:
  			case Types.DOUBLE:
  			case Types.DECIMAL:
  			case Types.NUMERIC:
  				if (x instanceof Boolean)
! 					bind(parameterIndex, ((Boolean)x).booleanValue() ? "1" : "0", PG_BOOLEAN);
  				else
! 					bind(parameterIndex, x.toString(), PG_NUMERIC);
  				break;
  			case Types.CHAR:
  			case Types.VARCHAR:
--- 1487,1514 ----
  		switch (targetSqlType)
  		{
  			case Types.INTEGER:
+ 			case Types.TINYINT:
+ 			case Types.SMALLINT:
  				if (x instanceof Boolean)
! 					bind(parameterIndex,((Boolean)x).booleanValue() ? "'1'" :"'0'", PG_BOOLEAN);
  				else
! 					bind(parameterIndex, "'" + String.valueOf(new Float(x.toString()).intValue()) + "'", PG_INTEGER);
  				break;
  			case Types.BIGINT:
+ 				if (x instanceof Boolean)
+ 					bind(parameterIndex,((Boolean)x).booleanValue() ? "'1'" : "'0'", PG_BOOLEAN);
+ 				else
+ 					bind(parameterIndex, "'" + String.valueOf(new Double(x.toString()).longValue()) + "'" , PG_INTEGER);
+ 				break;
  			case Types.REAL:
  			case Types.FLOAT:
  			case Types.DOUBLE:
  			case Types.DECIMAL:
  			case Types.NUMERIC:
  				if (x instanceof Boolean)
! 					bind(parameterIndex, ((Boolean)x).booleanValue() ? "'1'" : "'0'", PG_BOOLEAN);
  				else
! 					bind(parameterIndex, "'" + x.toString() + "'", PG_NUMERIC);
  				break;
  			case Types.CHAR:
  			case Types.VARCHAR:
*************** public abstract class AbstractJdbc1State
*** 1606,1627 ****
  	 */
  	public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException
  	{
- 		if (parameterIndex != 1)
- 			throw new PSQLException ("postgresql.call.noinout");
- 		if (!isFunction)
- 			throw new PSQLException ("postgresql.call.procasfunc", originalSql);
- 
  		// functionReturnType contains the user supplied value to check
  		// testReturn contains a modified version to make it easier to
  		// check the getXXX methods..
! 		functionReturnType = sqlType;
! 		testReturn = sqlType;
! 		if (functionReturnType == Types.CHAR ||
! 				functionReturnType == Types.LONGVARCHAR)
! 			testReturn = Types.VARCHAR;
! 		else if (functionReturnType == Types.FLOAT)
! 			testReturn = Types.REAL; // changes to streamline later error checking
! 		returnTypeSet = true;
  	}
  
  	/*
--- 1634,1651 ----
  	 */
  	public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException
  	{
  		// functionReturnType contains the user supplied value to check
  		// testReturn contains a modified version to make it easier to
  		// check the getXXX methods..
! 		if (parameterIndex > ((this instanceof CallableStatement) ? call_m_binds.length : m_binds.length))
! 			throw new PSQLException("postgresql.prep.range");
! 		if (m_bindDirection[parameterIndex-1] == IN || m_bindDirection[parameterIndex-1] == INOUT)
! 			m_bindDirection[parameterIndex-1] = INOUT;
! 		else
! 			m_bindDirection[parameterIndex-1] = OUT;
! 		testReturn[parameterIndex-1] = sqlType;
! 		returnTypeSet[parameterIndex-1] = true;
! 		returnsSomething = true;
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 1668,1675 ****
  	 */
  	public String getString(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, Types.VARCHAR, "String");
! 		return (String)callResult;
  	}
  
  
--- 1692,1700 ----
  	 */
  	public String getString(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex,compatible(Types.VARCHAR), "String");
! 		callResult = call_m_binds[parameterIndex-1];
! 		return (String)call_m_binds[parameterIndex-1];
  	}
  
  
*************** public abstract class AbstractJdbc1State
*** 1682,1691 ****
  	 */
  	public boolean getBoolean(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, Types.BIT, "Boolean");
! 		if (callResult == null)
  			return false;
! 		return ((Boolean)callResult).booleanValue ();
  	}
  
  	/*
--- 1707,1717 ----
  	 */
  	public boolean getBoolean(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, compatible(Types.BOOLEAN), "Boolean");
! 		callResult = call_m_binds[parameterIndex-1];
! 		if (call_m_binds[parameterIndex-1] == null)
  			return false;
! 		return ((Boolean)call_m_binds[parameterIndex-1]).booleanValue ();
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 1697,1706 ****
  	 */
  	public byte getByte(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, Types.TINYINT, "Byte");
! 		if (callResult == null)
  			return 0;
! 		return (byte)((Integer)callResult).intValue ();
  	}
  
  	/*
--- 1723,1734 ----
  	 */
  	public byte getByte(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex,compatible(Types.TINYINT), "Byte");
! 		callResult = call_m_binds[parameterIndex-1];
! 		if (call_m_binds[parameterIndex-1] == null)
  			return 0;
! 		String s = call_m_binds[parameterIndex-1].toString();
! 		return Byte.parseByte(s);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 1712,1721 ****
  	 */
  	public short getShort(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, Types.SMALLINT, "Short");
! 		if (callResult == null)
  			return 0;
! 		return (short)((Integer)callResult).intValue ();
  	}
  
  
--- 1740,1751 ----
  	 */
  	public short getShort(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, compatible(Types.SMALLINT), "Short");
! 		callResult = call_m_binds[parameterIndex-1];
! 		if (call_m_binds[parameterIndex-1] == null)
  			return 0;
! 		String s = call_m_binds[parameterIndex-1].toString();
! 		return Short.parseShort(s);
  	}
  
  
*************** public abstract class AbstractJdbc1State
*** 1728,1737 ****
  	 */
  	public int getInt(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, Types.INTEGER, "Int");
! 		if (callResult == null)
  			return 0;
! 		return ((Integer)callResult).intValue ();
  	}
  
  	/*
--- 1758,1769 ----
  	 */
  	public int getInt(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, compatible(Types.INTEGER), "Int");
! 		callResult = call_m_binds[parameterIndex-1];
! 		if (call_m_binds[parameterIndex-1] == null)
  			return 0;
! 		String s = call_m_binds[parameterIndex-1].toString();
! 		return Integer.parseInt(s);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 1743,1752 ****
  	 */
  	public long getLong(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, Types.BIGINT, "Long");
! 		if (callResult == null)
  			return 0;
! 		return ((Long)callResult).longValue ();
  	}
  
  	/*
--- 1775,1786 ----
  	 */
  	public long getLong(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, compatible(Types.BIGINT), "Long");
! 		callResult = call_m_binds[parameterIndex-1];
! 		if (call_m_binds[parameterIndex-1] == null)
  			return 0;
! 		String s = call_m_binds[parameterIndex-1].toString();
! 		return Long.parseLong(s);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 1758,1767 ****
  	 */
  	public float getFloat(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, Types.REAL, "Float");
! 		if (callResult == null)
  			return 0;
! 		return ((Float)callResult).floatValue ();
  	}
  
  	/*
--- 1792,1803 ----
  	 */
  	public float getFloat(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, compatible(Types.FLOAT), "Float");
! 		callResult = call_m_binds[parameterIndex-1];
! 		if (call_m_binds[parameterIndex-1] == null)
  			return 0;
! 		String s = call_m_binds[parameterIndex-1].toString();
! 		return Float.parseFloat(s);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 1773,1782 ****
  	 */
  	public double getDouble(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, Types.DOUBLE, "Double");
! 		if (callResult == null)
  			return 0;
! 		return ((Double)callResult).doubleValue ();
  	}
  
  	/*
--- 1809,1820 ----
  	 */
  	public double getDouble(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, compatible(Types.DOUBLE), "Double");
! 		callResult = call_m_binds[parameterIndex-1];
! 		if (call_m_binds[parameterIndex-1] == null)
  			return 0;
! 		String s = call_m_binds[parameterIndex-1].toString();
! 		return Double.parseDouble(s);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 1793,1800 ****
  	public BigDecimal getBigDecimal(int parameterIndex, int scale)
  	throws SQLException
  	{
! 		checkIndex (parameterIndex, Types.NUMERIC, "BigDecimal");
! 		return ((BigDecimal)callResult);
  	}
  
  	/*
--- 1831,1839 ----
  	public BigDecimal getBigDecimal(int parameterIndex, int scale)
  	throws SQLException
  	{
! 		checkIndex (parameterIndex, compatible(Types.NUMERIC), "BigDecimal");
! 		callResult = call_m_binds[parameterIndex-1];
! 		return ((BigDecimal)call_m_binds[parameterIndex-1]);
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 1807,1814 ****
  	 */
  	public byte[] getBytes(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, Types.VARBINARY, Types.BINARY, "Bytes");
! 		return ((byte [])callResult);
  	}
  
  
--- 1846,1854 ----
  	 */
  	public byte[] getBytes(int parameterIndex) throws SQLException
  	{
! 		checkIndex (parameterIndex, compatible(Types.VARBINARY), compatible(Types.BINARY), "Bytes");
! 		callResult = call_m_binds[parameterIndex-1];
! 		return ((byte [])call_m_binds[parameterIndex-1]);
  	}
  
  
*************** public abstract class AbstractJdbc1State
*** 1822,1828 ****
  	public java.sql.Date getDate(int parameterIndex) throws SQLException
  	{
  		checkIndex (parameterIndex, Types.DATE, "Date");
! 		return (java.sql.Date)callResult;
  	}
  
  	/*
--- 1862,1869 ----
  	public java.sql.Date getDate(int parameterIndex) throws SQLException
  	{
  		checkIndex (parameterIndex, Types.DATE, "Date");
! 		callResult = call_m_binds[parameterIndex-1];
! 		return (java.sql.Date)call_m_binds[parameterIndex-1];
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 1835,1841 ****
  	public java.sql.Time getTime(int parameterIndex) throws SQLException
  	{
  		checkIndex (parameterIndex, Types.TIME, "Time");
! 		return (java.sql.Time)callResult;
  	}
  
  	/*
--- 1876,1883 ----
  	public java.sql.Time getTime(int parameterIndex) throws SQLException
  	{
  		checkIndex (parameterIndex, Types.TIME, "Time");
! 		callResult = call_m_binds[parameterIndex-1];
! 		return (java.sql.Time)call_m_binds[parameterIndex-1];
  	}
  
  	/*
*************** public abstract class AbstractJdbc1State
*** 1848,1855 ****
  	public java.sql.Timestamp getTimestamp(int parameterIndex)
  	throws SQLException
  	{
! 		checkIndex (parameterIndex, Types.TIMESTAMP, "Timestamp");
! 		return (java.sql.Timestamp)callResult;
  	}
  
  	// getObject returns a Java object for the parameter.
--- 1890,1898 ----
  	public java.sql.Timestamp getTimestamp(int parameterIndex)
  	throws SQLException
  	{
! 		checkIndex (parameterIndex, compatible(Types.TIMESTAMP), "Timestamp");
! 		callResult = call_m_binds[parameterIndex-1];
! 		return (java.sql.Timestamp)call_m_binds[parameterIndex-1];
  	}
  
  	// getObject returns a Java object for the parameter.
*************** public abstract class AbstractJdbc1State
*** 1875,1882 ****
  	public Object getObject(int parameterIndex)
  	throws SQLException
  	{
! 		checkIndex (parameterIndex);
! 		return callResult;
  	}
  
  	//This method is implemeted in jdbc2
--- 1918,1957 ----
  	public Object getObject(int parameterIndex)
  	throws SQLException
  	{
! 		callResult = call_m_binds[parameterIndex-1];
! 		switch (testReturn[parameterIndex-1])
! 		{
! 			case Types.BIT:
! 			case Types.BOOLEAN:
! 				return new Boolean(getBoolean(parameterIndex));
! 			case Types.VARCHAR:
! 			case Types.CHAR:
! 			case Types.LONGVARCHAR:
! 				return getString(parameterIndex);
! 			case Types.VARBINARY:
! 			case Types.BINARY:
! 			case Types.LONGVARBINARY:
! 				return getBytes(parameterIndex);
! 			case Types.DATE:
! 				return getDate(parameterIndex);
! 			case Types.DOUBLE:
! 				return (call_m_binds[parameterIndex-1]==null) ? null : new Double(getDouble(parameterIndex));
! 			case Types.NUMERIC:
! 				return getBigDecimal(parameterIndex,0);
! 			case Types.FLOAT:
! 			case Types.REAL:
! 				return (call_m_binds[parameterIndex-1]==null) ? null : new Float(getFloat(parameterIndex));
! 			case Types.INTEGER:
! 				return (call_m_binds[parameterIndex-1]==null) ? null : new Integer(getInt(parameterIndex));
! 			case Types.SMALLINT:
! 				return (call_m_binds[parameterIndex-1]==null) ? null : new Short(getShort(parameterIndex));
! 			case Types.TIME:
! 				return getTime(parameterIndex);
! 			case Types.TIMESTAMP:
! 				return getTimestamp(parameterIndex);
! 			default:
! 				return call_m_binds[parameterIndex-1];
! 		}
  	}
  
  	//This method is implemeted in jdbc2
*************** public abstract class AbstractJdbc1State
*** 1923,1934 ****
  	 */
  	protected void bind(int paramIndex, Object s, String type) throws SQLException
  	{
! 		if (paramIndex < 1 || paramIndex > m_binds.length)
  			throw new PSQLException("postgresql.prep.range");
  		if (paramIndex == 1 && isFunction) // need to registerOut instead
  			throw new PSQLException ("postgresql.call.funcover");
! 		m_binds[paramIndex - 1] = s;
! 		m_bindTypes[paramIndex - 1] = type;
  	}
  
  	/**
--- 1998,2022 ----
  	 */
  	protected void bind(int paramIndex, Object s, String type) throws SQLException
  	{
! 		if (paramIndex < 1 || paramIndex > ((this instanceof CallableStatement) ? call_m_binds.length : m_binds.length))
  			throw new PSQLException("postgresql.prep.range");
  		if (paramIndex == 1 && isFunction) // need to registerOut instead
  			throw new PSQLException ("postgresql.call.funcover");
! 		if (this instanceof CallableStatement)
! 		{
! 			if (m_bindDirection[paramIndex-1] == OUT || m_bindDirection[paramIndex-1] == INOUT)
! 				m_bindDirection[paramIndex-1] = INOUT;
! 			else
! 				m_bindDirection[paramIndex-1] = IN;
! 			call_m_binds[paramIndex - 1] = s;
! 			call_m_bindTypes[paramIndex - 1] = type;
! 			returnTypeSet[paramIndex - 1] = true;
! 		}
! 		else
! 		{
! 			m_binds[paramIndex-1] = s;
! 			m_bindTypes[paramIndex-1] = type;
! 		}
  	}
  
  	/**
*************** public abstract class AbstractJdbc1State
*** 1994,2003 ****
  	protected void checkIndex (int parameterIndex, int type1, int type2, String getName)
  	throws SQLException
  	{
! 		checkIndex (parameterIndex);		
! 		if (type1 != this.testReturn && type2 != this.testReturn)
  			throw new PSQLException("postgresql.call.wrongget",
! 						new Object[]{"java.sql.Types=" + testReturn,
  							     getName,
  							     "java.sql.Types=" + type1});
  	}
--- 2082,2093 ----
  	protected void checkIndex (int parameterIndex, int type1, int type2, String getName)
  	throws SQLException
  	{
! //		checkIndex (parameterIndex);		
! 		type1 = compatible(type1);
! 		type2 = compatible(type2);
! 		if (type1 != compatible(this.testReturn[parameterIndex-1]) && type2 != compatible(this.testReturn[parameterIndex-1]))
  			throw new PSQLException("postgresql.call.wrongget",
! 						new Object[]{"java.sql.Types=" + testReturn[parameterIndex-1],
  							     getName,
  							     "java.sql.Types=" + type1});
  	}
*************** public abstract class AbstractJdbc1State
*** 2007,2016 ****
  	protected void checkIndex (int parameterIndex, int type, String getName)
  	throws SQLException
  	{
! 		checkIndex (parameterIndex);
! 		if (type != this.testReturn)
  			throw new PSQLException("postgresql.call.wrongget",
! 						new Object[]{"java.sql.Types=" + testReturn,
  							     getName,
  							     "java.sql.Types=" + type});
  	}
--- 2097,2107 ----
  	protected void checkIndex (int parameterIndex, int type, String getName)
  	throws SQLException
  	{
! //		checkIndex (parameterIndex);
! 		type = compatible(type);
! 		if (type != compatible(testReturn[parameterIndex-1]))
  			throw new PSQLException("postgresql.call.wrongget",
! 						new Object[]{"java.sql.Types=" + testReturn[parameterIndex-1],
  							     getName,
  							     "java.sql.Types=" + type});
  	}
*************** public abstract class AbstractJdbc1State
*** 2021,2030 ****
  	 */
  	private void checkIndex (int parameterIndex) throws SQLException
  	{
! 		if (!isFunction)
! 			throw new PSQLException("postgresql.call.noreturntype");
! 		if (parameterIndex != 1)
! 			throw new PSQLException("postgresql.call.noinout");
  	}
  
  
--- 2112,2121 ----
  	 */
  	private void checkIndex (int parameterIndex) throws SQLException
  	{
! //		if (!isFunction)
! //			throw new PSQLException("postgresql.call.noreturntype");
! //		if (parameterIndex != 1)
! //			throw new PSQLException("postgresql.call.noinout");
  	}
  
  
*************** public abstract class AbstractJdbc1State
*** 2156,2161 ****
--- 2247,2344 ----
  		return tmpts;
  	}
  			
+         private int compatible(int sqlType)
+         {
+                 switch (sqlType)
+                 {
+                         case Types.INTEGER:
+                         case Types.TINYINT:
+                         case Types.SMALLINT:
+                         case Types.BIGINT:
+                                 return Types.INTEGER;
+                         case Types.VARCHAR:
+                         case Types.LONGVARCHAR:
+                         case Types.CHAR:
+                                 return Types.VARCHAR;
+                         case Types.FLOAT:
+                         case Types.REAL:
+                         case Types.DOUBLE:
+                         case Types.DECIMAL:
+                         case Types.NUMERIC:
+                                 return Types.REAL;
+                         case Types.BINARY:
+                         case Types.VARBINARY:
+                         case Types.LONGVARBINARY:
+                                 return Types.BINARY;
+                         case Types.BIT:
+                         case Types.BOOLEAN:
+                                 return Types.BOOLEAN;
+                         default:
+                                 return sqlType;
+                 }
+         }
+ 
+ 
+ 	protected void modifycall()
+         {
+                 Vector v = new Vector();
+                 if (!isFunction)
+                         v.addElement(m_sqlFragments[0].substring(0,m_sqlFragments[0].indexOf("(")+1));
+                 else
+                         v.addElement(m_sqlFragments[0] + m_sqlFragments[1].substring(0,m_sqlFragments[1].indexOf("(")+1));
+                 m_sqlFragments[0] = (isFunction) ? m_sqlFragments[0]+m_sqlFragments[1] : m_sqlFragments[0];
+                 for (int i=0; i<m_bindDirection.length;i++)
+                 {
+                         if (m_bindDirection[i]==IN || m_bindDirection[i]==INOUT)
+                                 v.addElement(new String(","));
+                 }
+                 if (v.size()>1)
+                         v.setElementAt(new String(") as "+RESULT_ALIAS),v.size()-1);
+                 else
+                         v.setElementAt((String)v.elementAt(0)+new String(") as "+RESULT_ALIAS),0);
+ 
+ 
+                 m_sqlFragments = new String[v.size()];
+                 m_binds = new Object[v.size()-1];
+                 m_bindTypes = new String[v.size()-1];
+                 int index=0;
+                 for (int i=0;i<m_bindDirection.length;i++)
+                 {
+                         if (m_bindDirection[i]==IN || m_bindDirection[i]==INOUT)
+                         {
+                                 m_binds[index] = call_m_binds[i];
+                                 m_bindTypes[index] = call_m_bindTypes[i];
+                                 index++;
+                         }
+                 }
+                 for (int i=0;i<m_sqlFragments.length;++i)
+                 {
+                         m_sqlFragments[i] = (String)v.elementAt(i);
+                 }
+                 //fixes no void returning functions
+                 if (!returnsSomething && !isFunction && m_sqlFragments[0].indexOf("*")>0)
+                         m_sqlFragments[0] = m_sqlFragments[0].substring(0,m_sqlFragments[0].indexOf("*")-1) + m_sqlFragments[0].substring(m_sqlFragments[0].indexOf("m")+1,m_sqlFragments[0].length());
+         }
+ 
+         private void getCallResult() throws SQLException
+         {
+                 int index=1;
+                 for (int i=0;i<call_m_binds.length;i++)
+                 {
+                         if (m_bindDirection[i]==OUT || m_bindDirection[i]==INOUT)
+                         {
+                                 call_m_binds[i] = result.getObject(index);
+                                 int columnType = result.getMetaData().getColumnType(index);
+                                 columnType = compatible(columnType);
+                                 if (columnType != compatible(testReturn[i]))
+                                 throw new PSQLException ("postgresql.call.wrongrtntype",
+                                                                          new Object[]{
+                                                                                  "java.sql.Types=" + columnType, "java.sql.Types=" + testReturn[i] });
+                                 index++;
+                         }
+                 }
+                 result.close();
+         }		
  	
  	private static final String PG_TEXT = "text";
  	private static final String PG_INTEGER = "integer";
*************** public abstract class AbstractJdbc1State
*** 2168,2173 ****
--- 2351,2357 ----
  	private static final String PG_DATE = "date";
  	private static final String PG_TIME = "time";
  	private static final String PG_TIMESTAMPTZ = "timestamptz";
+ 	private static final String PG_TIMESTAMP = "timestamp";
      private static final String PG_BYTEA = "bytea";
  
  
Index: org/postgresql/jdbc2/AbstractJdbc2Statement.java
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v
retrieving revision 1.15
diff -c -p -r1.15 AbstractJdbc2Statement.java
*** org/postgresql/jdbc2/AbstractJdbc2Statement.java	30 Jun 2003 16:38:30 -0000	1.15
--- org/postgresql/jdbc2/AbstractJdbc2Statement.java	9 Jul 2003 19:33:56 -0000
*************** public abstract class AbstractJdbc2State
*** 76,87 ****
  		int size = batch.size();
  		int[] result = new int[size];
  		int i = 0;
  		try
  		{
-             //copy current state of statement
  			String[] l_origSqlFragments = m_sqlFragments;
! 			Object[] l_origBinds = m_binds;
! 			String[] l_origBindTypes = m_bindTypes;
  
  			for (i = 0;i < size;i++) {
  				//set state from batch
--- 76,99 ----
  		int size = batch.size();
  		int[] result = new int[size];
  		int i = 0;
+ 		super.inBatch=true;
  		try
  		{
  			String[] l_origSqlFragments = m_sqlFragments;
! 			Object[] l_origBinds;
! 			String[] l_origBindTypes;
! 			
!             //copy current state of statement
! 		    	if (this instanceof CallableStatement)
! 			{
! 				l_origBinds = call_m_binds;
! 				l_origBindTypes = call_m_bindTypes;	
! 			}
! 			else
! 			{
! 				l_origBinds = m_binds;
! 				l_origBindTypes = m_bindTypes;	
! 			}
  
  			for (i = 0;i < size;i++) {
  				//set state from batch
*************** public abstract class AbstractJdbc2State
*** 94,102 ****
  
  			//restore state of statement
  			m_sqlFragments = l_origSqlFragments;
! 			m_binds = l_origBinds;
! 			m_bindTypes = l_origBindTypes;
! 
  		}
  		catch (SQLException e)
  		{
--- 106,121 ----
  
  			//restore state of statement
  			m_sqlFragments = l_origSqlFragments;
! 			if (this instanceof CallableStatement)
! 			{
! 				call_m_binds = l_origBinds;
! 				call_m_bindTypes = l_origBindTypes;
! 			}
! 			else
! 			{				
! 				m_binds = l_origBinds;
! 				m_bindTypes = l_origBindTypes;
! 			}
  		}
  		catch (SQLException e)
  		{
*************** public abstract class AbstractJdbc2State
*** 114,119 ****
--- 133,139 ----
  		{
  			batch.removeAllElements();
  		}
+ 		super.inBatch = false;
  		return result;
  	}
  
*************** public abstract class AbstractJdbc2State
*** 169,175 ****
  	{
  		if (batch == null)
  			batch = new Vector();
! 
  		//we need to create copies, otherwise the values can be changed
  		Object[] l_newSqlFragments = null;
  		if (m_sqlFragments != null) { 
--- 189,197 ----
  	{
  		if (batch == null)
  			batch = new Vector();
! 		if (this instanceof CallableStatement)
! 			modifycall();
! 	
  		//we need to create copies, otherwise the values can be changed
  		Object[] l_newSqlFragments = null;
  		if (m_sqlFragments != null) { 
*************** public abstract class AbstractJdbc2State
*** 379,385 ****
  	public java.math.BigDecimal getBigDecimal(int parameterIndex) throws SQLException
  	{
  		checkIndex (parameterIndex, Types.NUMERIC, "BigDecimal");
! 		return ((BigDecimal)callResult);
  	}
  
  	public Blob getBlob(int i) throws SQLException
--- 401,407 ----
  	public java.math.BigDecimal getBigDecimal(int parameterIndex) throws SQLException
  	{
  		checkIndex (parameterIndex, Types.NUMERIC, "BigDecimal");
! 		return ((BigDecimal)call_m_binds[parameterIndex-1]);
  	}
  
  	public Blob getBlob(int i) throws SQLException
