? temp.diff Index: org/postgresql/errors.properties =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/errors.properties,v retrieving revision 1.21 diff -c -p -r1.21 errors.properties *** org/postgresql/errors.properties 30 Jun 2003 16:38:30 -0000 1.21 --- org/postgresql/errors.properties 8 Jul 2003 15:08:32 -0000 *************** postgresql.call.wrongrtntype:A CallableS *** 100,102 **** --- 100,103 ---- postgresql.input.fetch.gt0:Fetch size must be a value greater than or equal to 0. postgresql.input.query.gt0:Query Timeout must be a value greater than or equal to 0. postgresql.input.rows.gt0:Maximum number of rows must be a value greater than or equal to 0. + postgresql.call.notbound:Index {0} has not been bound to an input or output. Index: org/postgresql/jdbc1/AbstractJdbc1Statement.java =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java,v retrieving revision 1.26 diff -c -p -r1.26 AbstractJdbc1Statement.java *** org/postgresql/jdbc1/AbstractJdbc1Statement.java 30 Jun 2003 21:10:55 -0000 1.26 --- org/postgresql/jdbc1/AbstractJdbc1Statement.java 8 Jul 2003 15:08:34 -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 ((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; ! else ! m_bindDirection[parameterIndex-1] = OUT; ! testReturn[parameterIndex-1] = sqlType; ! returnTypeSet[parameterIndex-1] = true; ! returnsSomething = true; } /* *************** public abstract class AbstractJdbc1State *** 1650,1657 **** */ public String getString(int parameterIndex) throws SQLException { ! checkIndex (parameterIndex, Types.VARCHAR, "String"); ! return (String)callResult; } --- 1669,1677 ---- */ 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 *** 1664,1673 **** */ public boolean getBoolean(int parameterIndex) throws SQLException { ! checkIndex (parameterIndex, Types.BIT, "Boolean"); ! if (callResult == null) return false; ! return ((Boolean)callResult).booleanValue (); } /* --- 1684,1694 ---- */ 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 *** 1679,1688 **** */ public byte getByte(int parameterIndex) throws SQLException { ! checkIndex (parameterIndex, Types.TINYINT, "Byte"); ! if (callResult == null) return 0; ! return (byte)((Integer)callResult).intValue (); } /* --- 1700,1711 ---- */ 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 *** 1694,1703 **** */ public short getShort(int parameterIndex) throws SQLException { ! checkIndex (parameterIndex, Types.SMALLINT, "Short"); ! if (callResult == null) return 0; ! return (short)((Integer)callResult).intValue (); } --- 1717,1728 ---- */ 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 *** 1710,1719 **** */ public int getInt(int parameterIndex) throws SQLException { ! checkIndex (parameterIndex, Types.INTEGER, "Int"); ! if (callResult == null) return 0; ! return ((Integer)callResult).intValue (); } /* --- 1735,1746 ---- */ 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 *** 1725,1734 **** */ public long getLong(int parameterIndex) throws SQLException { ! checkIndex (parameterIndex, Types.BIGINT, "Long"); ! if (callResult == null) return 0; ! return ((Long)callResult).longValue (); } /* --- 1752,1763 ---- */ 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 *** 1740,1749 **** */ public float getFloat(int parameterIndex) throws SQLException { ! checkIndex (parameterIndex, Types.REAL, "Float"); ! if (callResult == null) return 0; ! return ((Float)callResult).floatValue (); } /* --- 1769,1780 ---- */ 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 *** 1755,1764 **** */ public double getDouble(int parameterIndex) throws SQLException { ! checkIndex (parameterIndex, Types.DOUBLE, "Double"); ! if (callResult == null) return 0; ! return ((Double)callResult).doubleValue (); } /* --- 1786,1797 ---- */ 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 *** 1775,1782 **** public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { ! checkIndex (parameterIndex, Types.NUMERIC, "BigDecimal"); ! return ((BigDecimal)callResult); } /* --- 1808,1816 ---- 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 *** 1789,1796 **** */ public byte[] getBytes(int parameterIndex) throws SQLException { ! checkIndex (parameterIndex, Types.VARBINARY, Types.BINARY, "Bytes"); ! return ((byte [])callResult); } --- 1823,1831 ---- */ 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 *** 1804,1810 **** public java.sql.Date getDate(int parameterIndex) throws SQLException { checkIndex (parameterIndex, Types.DATE, "Date"); ! return (java.sql.Date)callResult; } /* --- 1839,1846 ---- 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 *** 1817,1823 **** public java.sql.Time getTime(int parameterIndex) throws SQLException { checkIndex (parameterIndex, Types.TIME, "Time"); ! return (java.sql.Time)callResult; } /* --- 1853,1860 ---- 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 *** 1830,1837 **** 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. --- 1867,1875 ---- 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 *** 1857,1864 **** public Object getObject(int parameterIndex) throws SQLException { ! checkIndex (parameterIndex); ! return callResult; } //This method is implemeted in jdbc2 --- 1895,1934 ---- 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 *** 1905,1916 **** */ 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; } /** --- 1975,1999 ---- */ 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; ! 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 *** 1976,1985 **** 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}); } --- 2059,2070 ---- 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 *** 1989,1998 **** 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}); } --- 2074,2084 ---- 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 *** 2003,2012 **** */ private void checkIndex (int parameterIndex) throws SQLException { ! if (!isFunction) ! throw new PSQLException("postgresql.call.noreturntype"); ! if (parameterIndex != 1) ! throw new PSQLException("postgresql.call.noinout"); } --- 2089,2098 ---- */ 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 *** 2031,2040 **** { return m_useServerPrepare; } private static final String PG_TEXT = "text"; ! private static final String PG_INTEGER = "integer"; private static final String PG_INT2 = "int2"; private static final String PG_INT8 = "int8"; private static final String PG_NUMERIC = "numeric"; --- 2117,2219 ---- { return m_useServerPrepare; } + + 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; i1) + 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;i0) + 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