Problem: 
 - Closing a statement should cause it to throw exceptions when
execute/set/get methods are called on it.

Fix: 
 - Flag is set when the statement is closed. It is checked whenever an
execute/get/set method is called.

Cheers,

Kim
? cloudscape.LOG
Index: org/postgresql/errors.properties
===================================================================
RCS file: 
/projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/errors.properties,v
retrieving revision 1.20
diff -c -p -c -p -r1.20 errors.properties
*** org/postgresql/errors.properties    29 May 2003 03:21:32 -0000      1.20
--- org/postgresql/errors.properties    30 Jun 2003 15:07:17 -0000
*************** postgresql.call.funcover:Cannot execute 
*** 97,99 ****
--- 97,100 ----
  postgresql.call.wrongget:Parameter of type {0} was registered but call to get{1} 
(sqltype={2}) was made.
  postgresql.call.noreturnval:A CallableStatement Function was executed with nothing 
returned.
  postgresql.call.wrongrtntype:A CallableStatement Function was executed and the 
return was of type ({0}) however type={1} was registered.
+ postgresql.stmt.closed:This Statement has been closed and cannot be used to set or 
retrieve values any longer. It also cannot be used to execute queries.
Index: org/postgresql/jdbc1/AbstractJdbc1Statement.java
===================================================================
RCS file: 
/projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java,v
retrieving revision 1.24
diff -c -p -c -p -r1.24 AbstractJdbc1Statement.java
*** org/postgresql/jdbc1/AbstractJdbc1Statement.java    29 May 2003 04:52:44 -0000     
 1.24
--- org/postgresql/jdbc1/AbstractJdbc1Statement.java    30 Jun 2003 15:07:19 -0000
*************** public abstract class AbstractJdbc1State
*** 88,93 ****
--- 88,94 ----
        private boolean returnTypeSet;
        protected Object callResult;
  
+       private boolean isClosed = false;
  
        public abstract BaseResultSet createResultSet(Field[] fields, Vector tuples, 
String status, int updateCount, long insertOID, boolean binaryCursor) throws 
SQLException;
  
*************** public abstract class AbstractJdbc1State
*** 116,121 ****
--- 117,123 ----
  
        protected void parseSqlStmt (String p_sql) throws SQLException
        {
+               checkClosed();
                String l_sql = p_sql;
  
                l_sql = replaceProcessing(l_sql);
*************** public abstract class AbstractJdbc1State
*** 162,167 ****
--- 164,170 ----
         */
        public java.sql.ResultSet executeQuery(String p_sql) throws SQLException
        {
+               checkClosed();
                String l_sql = replaceProcessing(p_sql);
                m_sqlFragments = new String[] {l_sql};
                m_binds = new Object[0];
*************** public abstract class AbstractJdbc1State
*** 197,202 ****
--- 200,206 ----
         */
        public java.sql.ResultSet executeQuery() throws SQLException
        {
+               checkClosed();
                  this.execute();
  
                while (result != null && !result.reallyResultSet())
*************** public abstract class AbstractJdbc1State
*** 217,222 ****
--- 221,227 ----
         */
        public int executeUpdate(String p_sql) throws SQLException
        {
+               checkClosed();
                String l_sql = replaceProcessing(p_sql);
                m_sqlFragments = new String[] {l_sql};
                m_binds = new Object[0];
*************** public abstract class AbstractJdbc1State
*** 242,247 ****
--- 247,253 ----
         */
        public int executeUpdate() throws SQLException
        {
+               checkClosed();
                this.execute();
                if (result.reallyResultSet())
                        throw new PSQLException("postgresql.stat.result");
*************** public abstract class AbstractJdbc1State
*** 261,266 ****
--- 267,273 ----
         */
        public boolean execute(String p_sql) throws SQLException
        {
+               checkClosed();
                String l_sql = replaceProcessing(p_sql);
                m_sqlFragments = new String[] {l_sql};
                m_binds = new Object[0];
*************** public abstract class AbstractJdbc1State
*** 290,295 ****
--- 297,303 ----
         */
        public boolean execute() throws SQLException
        {
+               checkClosed();
                if (isFunction && !returnTypeSet)
                        throw new PSQLException("postgresql.call.noreturntype");
                if (isFunction)
*************** public abstract class AbstractJdbc1State
*** 481,486 ****
--- 489,495 ----
         */
        public void setCursorName(String name) throws SQLException
        {
+               checkClosed();
                connection.setCursorName(name);
        }
  
*************** public abstract class AbstractJdbc1State
*** 495,500 ****
--- 504,510 ----
         */
        public int getUpdateCount() throws SQLException
        {
+               checkClosed();
                if (result == null)
                        return -1;
                if (isFunction)
*************** public abstract class AbstractJdbc1State
*** 513,518 ****
--- 523,529 ----
         */
        public boolean getMoreResults() throws SQLException
        {
+               checkClosed();
                result = (BaseResultSet) result.getNext();
                return (result != null && result.reallyResultSet());
        }
*************** public abstract class AbstractJdbc1State
*** 542,547 ****
--- 553,559 ----
         */
        public int getMaxRows() throws SQLException
        {
+               checkClosed();
                return maxrows;
        }
  
*************** public abstract class AbstractJdbc1State
*** 554,559 ****
--- 566,572 ----
         */
        public void setMaxRows(int max) throws SQLException
        {
+               checkClosed();
                maxrows = max;
        }
  
*************** public abstract class AbstractJdbc1State
*** 566,571 ****
--- 579,585 ----
         */
        public void setEscapeProcessing(boolean enable) throws SQLException
        {
+               checkClosed();
                replaceProcessingEnabled = enable;
        }
  
*************** public abstract class AbstractJdbc1State
*** 579,584 ****
--- 593,599 ----
         */
        public int getQueryTimeout() throws SQLException
        {
+               checkClosed();
                return timeout;
        }
  
*************** public abstract class AbstractJdbc1State
*** 590,595 ****
--- 605,611 ----
         */
        public void setQueryTimeout(int seconds) throws SQLException
        {
+               checkClosed();
                timeout = seconds;
        }
  
*************** public abstract class AbstractJdbc1State
*** 638,643 ****
--- 654,660 ----
         */
        public int getMaxFieldSize() throws SQLException
        {
+               checkClosed();
                return 8192;            // We cannot change this
        }
  
*************** public abstract class AbstractJdbc1State
*** 650,655 ****
--- 667,673 ----
         */
        public void setMaxFieldSize(int max) throws SQLException
        {
+               checkClosed();
                throw new PSQLException("postgresql.stat.maxfieldsize");
        }
  
*************** public abstract class AbstractJdbc1State
*** 714,719 ****
--- 732,741 ----
                if (m_useServerPrepare && m_statementName != null) {
                        connection.execSQL("DEALLOCATE " + m_statementName);
                }
+               //need to null call_m_binds as well if CallableStatement patch goes in
+               m_binds = null;
+               callResult = null;
+               isClosed = true;
  
                // Disasociate it from us (For Garbage Collection)
                result = null;
*************** public abstract class AbstractJdbc1State
*** 843,848 ****
--- 865,871 ----
         */
        public void setNull(int parameterIndex, int sqlType) throws SQLException
        {
+               checkClosed();
          String l_pgType;
                switch (sqlType)
                {
*************** public abstract class AbstractJdbc1State
*** 905,910 ****
--- 928,934 ----
         */
        public void setBoolean(int parameterIndex, boolean x) throws SQLException
        {
+               checkClosed();
                bind(parameterIndex, x ? "'t'" : "'f'", PG_BOOLEAN);
        }
  
*************** public abstract class AbstractJdbc1State
*** 918,923 ****
--- 942,948 ----
         */
        public void setByte(int parameterIndex, byte x) throws SQLException
        {
+               checkClosed();
                bind(parameterIndex, Integer.toString(x), PG_TEXT);
        }
  
*************** public abstract class AbstractJdbc1State
*** 931,936 ****
--- 956,962 ----
         */
        public void setShort(int parameterIndex, short x) throws SQLException
        {
+               checkClosed();
                bind(parameterIndex, Integer.toString(x), PG_INT2);
        }
  
*************** public abstract class AbstractJdbc1State
*** 944,949 ****
--- 970,976 ----
         */
        public void setInt(int parameterIndex, int x) throws SQLException
        {
+               checkClosed();
                bind(parameterIndex, Integer.toString(x), PG_INTEGER);
        }
  
*************** public abstract class AbstractJdbc1State
*** 957,962 ****
--- 984,990 ----
         */
        public void setLong(int parameterIndex, long x) throws SQLException
        {
+               checkClosed();
                bind(parameterIndex, Long.toString(x), PG_INT8);
        }
  
*************** public abstract class AbstractJdbc1State
*** 970,975 ****
--- 998,1004 ----
         */
        public void setFloat(int parameterIndex, float x) throws SQLException
        {
+               checkClosed();
                bind(parameterIndex, Float.toString(x), PG_FLOAT);
        }
  
*************** public abstract class AbstractJdbc1State
*** 983,988 ****
--- 1012,1018 ----
         */
        public void setDouble(int parameterIndex, double x) throws SQLException
        {
+               checkClosed();
                bind(parameterIndex, Double.toString(x), PG_DOUBLE);
        }
  
*************** public abstract class AbstractJdbc1State
*** 997,1002 ****
--- 1027,1033 ----
         */
        public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException
        {
+               checkClosed();
                if (x == null)
                        setNull(parameterIndex, Types.DECIMAL);
                else
*************** public abstract class AbstractJdbc1State
*** 1017,1028 ****
--- 1048,1061 ----
         */
        public void setString(int parameterIndex, String x) throws SQLException
        {
+               checkClosed();
                setString(parameterIndex, x, PG_TEXT);
        }
  
        public void setString(int parameterIndex, String x, String type) throws 
SQLException
        {
                // if the passed string is null, then set this column to null
+               checkClosed();
                if (x == null)
                        setNull(parameterIndex, Types.VARCHAR);
                else
*************** public abstract class AbstractJdbc1State
*** 1065,1070 ****
--- 1098,1104 ----
         */
        public void setBytes(int parameterIndex, byte x[]) throws SQLException
        {
+               checkClosed();
                if (connection.haveMinimumCompatibleVersion("7.2"))
                {
                        //Version 7.2 supports the bytea datatype for byte arrays
*************** public abstract class AbstractJdbc1State
*** 1099,1104 ****
--- 1133,1139 ----
         */
        public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
        {
+               checkClosed();
                if (null == x)
                {
                        setNull(parameterIndex, Types.DATE);
*************** public abstract class AbstractJdbc1State
*** 1119,1124 ****
--- 1154,1160 ----
         */
        public void setTime(int parameterIndex, Time x) throws SQLException
        {
+               checkClosed();
                if (null == x)
                {
                        setNull(parameterIndex, Types.TIME);
*************** public abstract class AbstractJdbc1State
*** 1139,1144 ****
--- 1175,1181 ----
         */
        public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
        {
+               checkClosed();
                if (null == x)
                {
                        setNull(parameterIndex, Types.TIMESTAMP);
*************** public abstract class AbstractJdbc1State
*** 1252,1257 ****
--- 1289,1295 ----
         */
        public void setAsciiStream(int parameterIndex, InputStream x, int length) 
throws SQLException
        {
+               checkClosed();
                if (connection.haveMinimumCompatibleVersion("7.2"))
                {
                        //Version 7.2 supports AsciiStream for all PG text types 
(char, varchar, text)
*************** public abstract class AbstractJdbc1State
*** 1301,1306 ****
--- 1339,1345 ----
         */
        public void setUnicodeStream(int parameterIndex, InputStream x, int length) 
throws SQLException
        {
+               checkClosed();
                if (connection.haveMinimumCompatibleVersion("7.2"))
                {
                        //Version 7.2 supports AsciiStream for all PG text types 
(char, varchar, text)
*************** public abstract class AbstractJdbc1State
*** 1349,1354 ****
--- 1388,1394 ----
         */
        public void setBinaryStream(int parameterIndex, InputStream x, int length) 
throws SQLException
        {
+               checkClosed();
                if (connection.haveMinimumCompatibleVersion("7.2"))
                {
                        //Version 7.2 supports BinaryStream for for the PG bytea type
*************** public abstract class AbstractJdbc1State
*** 1454,1459 ****
--- 1494,1500 ----
         */
        public void setObject(int parameterIndex, Object x, int targetSqlType, int 
scale) throws SQLException
        {
+               checkClosed();
                if (x == null)
                {
                        setNull(parameterIndex, targetSqlType);
*************** public abstract class AbstractJdbc1State
*** 1524,1529 ****
--- 1565,1571 ----
         */
        public void setObject(int parameterIndex, Object x) throws SQLException
        {
+               checkClosed();
                if (x == null)
                {
                        setNull(parameterIndex, Types.OTHER);
*************** public abstract class AbstractJdbc1State
*** 1579,1584 ****
--- 1621,1627 ----
         */
        public void registerOutParameter(int parameterIndex, int sqlType) throws 
SQLException
        {
+               checkClosed();
                if (parameterIndex != 1)
                        throw new PSQLException ("postgresql.call.noinout");
                if (!isFunction)
*************** public abstract class AbstractJdbc1State
*** 1641,1646 ****
--- 1684,1690 ----
         */
        public String getString(int parameterIndex) throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.VARCHAR, "String");
                return (String)callResult;
        }
*************** public abstract class AbstractJdbc1State
*** 1655,1660 ****
--- 1699,1705 ----
         */
        public boolean getBoolean(int parameterIndex) throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.BIT, "Boolean");
                if (callResult == null)
                        return false;
*************** public abstract class AbstractJdbc1State
*** 1670,1675 ****
--- 1715,1721 ----
         */
        public byte getByte(int parameterIndex) throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.TINYINT, "Byte");
                if (callResult == null)
                        return 0;
*************** public abstract class AbstractJdbc1State
*** 1685,1690 ****
--- 1731,1737 ----
         */
        public short getShort(int parameterIndex) throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.SMALLINT, "Short");
                if (callResult == null)
                        return 0;
*************** public abstract class AbstractJdbc1State
*** 1701,1706 ****
--- 1748,1754 ----
         */
        public int getInt(int parameterIndex) throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.INTEGER, "Int");
                if (callResult == null)
                        return 0;
*************** public abstract class AbstractJdbc1State
*** 1716,1721 ****
--- 1764,1770 ----
         */
        public long getLong(int parameterIndex) throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.BIGINT, "Long");
                if (callResult == null)
                        return 0;
*************** public abstract class AbstractJdbc1State
*** 1731,1736 ****
--- 1780,1786 ----
         */
        public float getFloat(int parameterIndex) throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.REAL, "Float");
                if (callResult == null)
                        return 0;
*************** public abstract class AbstractJdbc1State
*** 1746,1751 ****
--- 1796,1802 ----
         */
        public double getDouble(int parameterIndex) throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.DOUBLE, "Double");
                if (callResult == null)
                        return 0;
*************** public abstract class AbstractJdbc1State
*** 1766,1771 ****
--- 1817,1823 ----
        public BigDecimal getBigDecimal(int parameterIndex, int scale)
        throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.NUMERIC, "BigDecimal");
                return ((BigDecimal)callResult);
        }
*************** public abstract class AbstractJdbc1State
*** 1780,1785 ****
--- 1832,1838 ----
         */
        public byte[] getBytes(int parameterIndex) throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.VARBINARY, Types.BINARY, "Bytes");
                return ((byte [])callResult);
        }
*************** public abstract class AbstractJdbc1State
*** 1794,1799 ****
--- 1847,1853 ----
         */
        public java.sql.Date getDate(int parameterIndex) throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.DATE, "Date");
                return (java.sql.Date)callResult;
        }
*************** public abstract class AbstractJdbc1State
*** 1807,1812 ****
--- 1861,1867 ----
         */
        public java.sql.Time getTime(int parameterIndex) throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.TIME, "Time");
                return (java.sql.Time)callResult;
        }
*************** public abstract class AbstractJdbc1State
*** 1821,1826 ****
--- 1876,1882 ----
        public java.sql.Timestamp getTimestamp(int parameterIndex)
        throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.TIMESTAMP, "Timestamp");
                return (java.sql.Timestamp)callResult;
        }
*************** public abstract class AbstractJdbc1State
*** 1848,1853 ****
--- 1904,1910 ----
        public Object getObject(int parameterIndex)
        throws SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex);
                return callResult;
        }
*************** public abstract class AbstractJdbc1State
*** 1914,1919 ****
--- 1971,1977 ----
         */
        private String modifyJdbcCall(String p_sql) throws SQLException
        {
+               checkClosed();
                //Check that this is actually a call which should start with a {
          //if not do nothing and treat this as a standard prepared sql
                if (!p_sql.trim().startsWith("{")) {
*************** public abstract class AbstractJdbc1State
*** 2003,2009 ****
  
  
      public void setUseServerPrepare(boolean flag) throws SQLException {
!         //Server side prepared statements were introduced in 7.3
          if (connection.haveMinimumServerVersion("7.3")) {
                        //If turning server prepared statements off deallocate 
statement
                        //and reset statement name
--- 2061,2068 ----
  
  
      public void setUseServerPrepare(boolean flag) throws SQLException {
!         checkClosed();
!       //Server side prepared statements were introduced in 7.3
          if (connection.haveMinimumServerVersion("7.3")) {
                        //If turning server prepared statements off deallocate 
statement
                        //and reset statement name
*************** public abstract class AbstractJdbc1State
*** 2021,2026 ****
--- 2080,2092 ----
        public boolean isUseServerPrepare()
        {
                return m_useServerPrepare;
+       }
+ 
+       private void checkClosed() throws SQLException
+       {
+               //need to add to errors.properties.
+               if (isClosed)
+                       throw new PSQLException("postgresql.stmt.closed");
        }
  
  
Index: org/postgresql/jdbc2/AbstractJdbc2Statement.java
===================================================================
RCS file: 
/projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java,v
retrieving revision 1.14
diff -c -p -c -p -r1.14 AbstractJdbc2Statement.java
*** org/postgresql/jdbc2/AbstractJdbc2Statement.java    29 May 2003 04:52:44 -0000     
 1.14
--- org/postgresql/jdbc2/AbstractJdbc2Statement.java    30 Jun 2003 15:07:19 -0000
*************** public abstract class AbstractJdbc2State
*** 58,63 ****
--- 58,64 ----
  
        public void addBatch(String p_sql) throws SQLException
        {
+               checkClosed();
                if (batch == null)
                        batch = new Vector();
          Object[] l_statement = new Object[] {new String[] {p_sql}, new Object[0], 
new String[0]};
*************** public abstract class AbstractJdbc2State
*** 71,76 ****
--- 72,78 ----
  
        public int[] executeBatch() throws SQLException
        {
+               checkClosed();
                if (batch == null)
                        batch = new Vector();
                int size = batch.size();
*************** public abstract class AbstractJdbc2State
*** 124,144 ****
--- 126,150 ----
  
        public Connection getConnection() throws SQLException
        {
+               checkClosed();
                return (Connection) connection;
        }
  
        public int getFetchDirection() throws SQLException
        {
+               checkClosed();
                throw new PSQLException("postgresql.psqlnotimp");
        }
  
        public int getResultSetConcurrency() throws SQLException
        {
+               checkClosed();
                return concurrency;
        }
  
        public int getResultSetType() throws SQLException
        {
+               checkClosed();
                return resultsettype;
        }
  
*************** public abstract class AbstractJdbc2State
*** 151,171 ****
--- 157,181 ----
  
        public void setFetchSize(int rows) throws SQLException
        {
+               checkClosed();
                super.fetchSize = rows;
        }
  
        public void setResultSetConcurrency(int value) throws SQLException
        {
+               checkClosed();
                concurrency = value;
        }
  
        public void setResultSetType(int value) throws SQLException
        {
+               checkClosed();
                resultsettype = value;
        }
  
        public void addBatch() throws SQLException
        {
+               checkClosed();
                if (batch == null)
                        batch = new Vector();
  
*************** public abstract class AbstractJdbc2State
*** 185,190 ****
--- 195,201 ----
  
        public ResultSetMetaData getMetaData() throws SQLException
        {
+               checkClosed();
                ResultSet rs = getResultSet();
                if (rs != null)
                        return rs.getMetaData();
*************** public abstract class AbstractJdbc2State
*** 195,205 ****
--- 206,218 ----
  
        public void setArray(int i, java.sql.Array x) throws SQLException
        {
+               checkClosed();
                setString(i, x.toString());
        }
  
        public void setBlob(int i, Blob x) throws SQLException
        {
+               checkClosed();
                InputStream l_inStream = x.getBinaryStream();
                LargeObjectManager lom = connection.getLargeObjectAPI();
                int oid = lom.create();
*************** public abstract class AbstractJdbc2State
*** 241,246 ****
--- 254,260 ----
  
        public void setCharacterStream(int i, java.io.Reader x, int length) throws 
SQLException
        {
+               checkClosed();
                if (connection.haveMinimumCompatibleVersion("7.2"))
                {
                        //Version 7.2 supports CharacterStream for for the PG text 
types
*************** public abstract class AbstractJdbc2State
*** 296,301 ****
--- 310,316 ----
  
        public void setClob(int i, Clob x) throws SQLException
        {
+               checkClosed();
                InputStream l_inStream = x.getAsciiStream();
                int l_length = (int) x.length();
                LargeObjectManager lom = connection.getLargeObjectAPI();
*************** public abstract class AbstractJdbc2State
*** 327,332 ****
--- 342,348 ----
  
        public void setNull(int i, int t, String s) throws SQLException
        {
+               checkClosed();
                setNull(i, t);
        }
  
*************** public abstract class AbstractJdbc2State
*** 337,342 ****
--- 353,359 ----
  
        public void setDate(int i, java.sql.Date d, java.util.Calendar cal) throws 
SQLException
        {
+               checkClosed();
                if (cal == null)
                        setDate(i, d);
                else
*************** public abstract class AbstractJdbc2State
*** 348,353 ****
--- 365,371 ----
  
        public void setTime(int i, Time t, java.util.Calendar cal) throws SQLException
        {
+               checkClosed();
                if (cal == null)
                        setTime(i, t);
                else
*************** public abstract class AbstractJdbc2State
*** 359,364 ****
--- 377,383 ----
  
        public void setTimestamp(int i, Timestamp t, java.util.Calendar cal) throws 
SQLException
        {
+               checkClosed();
                if (cal == null)
                        setTimestamp(i, t);
                else
*************** public abstract class AbstractJdbc2State
*** 377,382 ****
--- 396,402 ----
  
        public java.math.BigDecimal getBigDecimal(int parameterIndex) throws 
SQLException
        {
+               checkClosed();
                checkIndex (parameterIndex, Types.NUMERIC, "BigDecimal");
                return ((BigDecimal)callResult);
        }
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to