db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1505734 - in /db/derby/code/branches/10.8: ./ java/client/org/apache/derby/client/net/ java/drda/org/apache/derby/impl/drda/ java/engine/org/apache/derby/iapi/jdbc/ java/engine/org/apache/derby/iapi/sql/ java/engine/org/apache/derby/impl/j...
Date Mon, 22 Jul 2013 17:17:08 GMT
Author: mamta
Date: Mon Jul 22 17:17:07 2013
New Revision: 1505734

URL: http://svn.apache.org/r1505734
Log:
DERBY-5459(Result set metadata are out of sync on client after underlying table is altered)

Backporting to 10.8. Fix contributed by Dag.


Modified:
    db/derby/code/branches/10.8/   (props changed)
    db/derby/code/branches/10.8/java/client/org/apache/derby/client/net/NetStatementReply.java
    db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/DRDAStatement.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/jdbc/EnginePreparedStatement.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
    db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/GenericStatement.java
    db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtMetaDataTest.java
    db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java

Propchange: db/derby/code/branches/10.8/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1205426

Modified: db/derby/code/branches/10.8/java/client/org/apache/derby/client/net/NetStatementReply.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/client/org/apache/derby/client/net/NetStatementReply.java?rev=1505734&r1=1505733&r2=1505734&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/client/org/apache/derby/client/net/NetStatementReply.java
(original)
+++ db/derby/code/branches/10.8/java/client/org/apache/derby/client/net/NetStatementReply.java
Mon Jul 22 17:17:07 2013
@@ -489,6 +489,12 @@ public class NetStatementReply extends N
                 //
                 // this will override the same call made from parsePrepareDescribe
                 //  this will not work, this is not the DA for the stored proc params
+                //
+                // DERBY-5459. We may now receive a new SQLDARD (unrequested, a
+                // DRDA protocol extension) when a query is opened iff the
+                // underlying server's prepared statement has been recompiled
+                // since the client first received metadata when preparing the
+                // statement.
                 statementI.completePrepareDescribeOutput(columnMetaData, netSqlca);
                 peekCP = parseTypdefsOrMgrlvlovrs();
             }

Modified: db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=1505734&r1=1505733&r2=1505734&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Mon
Jul 22 17:17:07 2013
@@ -824,6 +824,7 @@ class DRDAConnThread extends Thread {
 					try {
 						database.getConnection().clearWarnings();
 						sqldaType = parsePRPSQLSTT();
+                        database.getCurrentStatement().sqldaType = sqldaType;
 						if (sqldaType > 0)		// do write SQLDARD
 							writeSQLDARD(database.getCurrentStatement(),
 										 (sqldaType ==  CodePoint.TYPSQLDA_LIGHT_OUTPUT),
@@ -867,6 +868,27 @@ class DRDAConnThread extends Thread {
 							writeOPNQRYRM(false, stmt);
 							checkWarning(null, ps, null, 0, false, true);
 
+                            long sentVersion = stmt.versionCounter;
+                            long currentVersion =
+                                    ((EnginePreparedStatement)stmt.ps).
+                                    getVersionCounter();
+
+                            if (stmt.sqldaType ==
+                                    CodePoint.TYPSQLDA_LIGHT_OUTPUT &&
+                                    currentVersion != sentVersion) {
+                                // DERBY-5459. The prepared statement has a
+                                // result set and has changed on the server
+                                // since we last informed the client about its
+                                // shape, so re-send metadata.
+                                //
+                                // NOTE: This is an extension of the standard
+                                // DRDA protocol since we send the SQLDARD
+                                // even if it isn't requested in this case.
+                                // This is OK because there is already code on the
+                                // client to handle an unrequested SQLDARD at
+                                // this point in the protocol.
+                                writeSQLDARD(stmt, true, null);
+                            }
 							writeQRYDSC(stmt, false);
 
 							stmt.rsSuspend();

Modified: db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/DRDAStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/DRDAStatement.java?rev=1505734&r1=1505733&r2=1505734&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/DRDAStatement.java (original)
+++ db/derby/code/branches/10.8/java/drda/org/apache/derby/impl/drda/DRDAStatement.java Mon
Jul 22 17:17:07 2013
@@ -284,6 +284,19 @@ class DRDAStatement
 	boolean needsToSendParamData = false;
 	boolean explicitlyPrepared = false;    //Prepared with PRPSQLSTT (reusable) 
 
+    /**
+     * If this changes, we need to re-send result set metadata to client, since
+     * a change indicates the engine has recompiled the prepared statement.
+     */
+    long versionCounter;
+
+    /**
+     * Saved value returned from {@link DRDAConnThread#from
+     * parsePRPSQLSTT}. Used to determine if the statment is such that we may
+     * need to re-send metadata at execute time, see {@link #versionCounter}.
+     */
+    int sqldaType;
+
 	// constructor
 	/**
 	 * DRDAStatement constructor
@@ -678,7 +691,10 @@ class DRDAStatement
 			ps.setCursorName(cursorName);
 		if (isolationSet)
 			database.setPrepareIsolation(saveIsolationLevel);
-				return ps;
+
+        versionCounter = ((EnginePreparedStatement)ps).getVersionCounter();
+
+        return ps;
 	}
 
 	/**

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java?rev=1505734&r1=1505733&r2=1505734&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
(original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
Mon Jul 22 17:17:07 2013
@@ -549,4 +549,9 @@ public abstract class BrokeredPreparedSt
 
 		return newStatement;
 	}
+
+    public final long getVersionCounter() throws SQLException {
+        return ((EnginePreparedStatement)getPreparedStatement()).
+                getVersionCounter();
+    }
 }

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/jdbc/EnginePreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/jdbc/EnginePreparedStatement.java?rev=1505734&r1=1505733&r2=1505734&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/jdbc/EnginePreparedStatement.java
(original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/jdbc/EnginePreparedStatement.java
Mon Jul 22 17:17:07 2013
@@ -39,4 +39,12 @@ public interface EnginePreparedStatement
     
     public void setCharacterStream(int parameterIndex, Reader reader)
         throws SQLException;
+
+    /**
+     * Get the version of the prepared statement. If this has not been changed,
+     * the caller may assume that a recompilation has not taken place, i.e.
+     * meta-data are (also) unchanged.
+     * @return version counter
+     */
+    public long getVersionCounter() throws SQLException;
 }

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java?rev=1505734&r1=1505733&r2=1505734&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
(original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
Mon Jul 22 17:17:07 2013
@@ -270,4 +270,10 @@ public interface PreparedStatement
 	*/
 	public SQLWarning getCompileTimeWarnings();
 
+    /**
+     * Get the version counter. A change in the value indicates a recompile
+     * has happened.
+     * @return version counter
+     */
+    public long getVersionCounter();
 }

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?rev=1505734&r1=1505733&r2=1505734&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
(original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
Mon Jul 22 17:17:07 2013
@@ -1948,4 +1948,8 @@ public abstract class EmbedPreparedState
             throw dataTypeConversion(parameterIndex, "java.sql.Blob");
         }
     }
+
+    public final long getVersionCounter() throws SQLException {
+        return preparedStatement.getVersionCounter();
+    }
 }

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java?rev=1505734&r1=1505733&r2=1505734&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
(original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
Mon Jul 22 17:17:07 2013
@@ -173,6 +173,11 @@ public class GenericPreparedStatement
 	*/
 	private Cacheable cacheHolder;
 
+    /**
+     * Incremented for each (re)compile.
+     */
+    private long versionCounter;
+
 	//
 	// constructors
 	//
@@ -1241,4 +1246,12 @@ recompileOutOfDatePlan:
 	{
 		return requiredPermissionsList;
 	}
+
+    public final long getVersionCounter() {
+        return versionCounter;
+    }
+
+    public final void incrementVersionCounter() {
+        ++versionCounter;
+    }
 }

Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/GenericStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/GenericStatement.java?rev=1505734&r1=1505733&r2=1505734&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/GenericStatement.java
(original)
+++ db/derby/code/branches/10.8/java/engine/org/apache/derby/impl/sql/GenericStatement.java
Mon Jul 22 17:17:07 2013
@@ -571,6 +571,7 @@ public class GenericStatement
 					preparedStmt.setConstantAction( qt.makeConstantAction() );
 					preparedStmt.setSavedObjects( cc.getSavedObjects() );
 					preparedStmt.setRequiredPermissionsList(cc.getRequiredPermissionsList());
+                    preparedStmt.incrementVersionCounter();
 					preparedStmt.setActivationClass(ac);
 					preparedStmt.setNeedsSavepoint(qt.needsSavepoint());
 					preparedStmt.setCursorInfo((CursorInfo)cc.getCursorInfo());

Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtMetaDataTest.java?rev=1505734&r1=1505733&r2=1505734&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtMetaDataTest.java
(original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtMetaDataTest.java
Mon Jul 22 17:17:07 2013
@@ -115,23 +115,35 @@ public class PrepStmtMetaDataTest extend
         assertEquals(java.sql.Types.INTEGER, rsmd.getColumnType(1));
         assertEquals("C11", rsmd.getColumnName(1));
 
-        // DERBY-2402 Client does not report added columns.
-        // Take out check when DERBY-2402 is fixed
-        if (usingDerbyNetClient())
-            return;
-
         s.executeUpdate("alter table bug4579 add column c12 int");
+
+        if (usingDerbyNetClient()) {
+            // DERBY-2402 Client does not report added columns.
+            // Take out check when DERBY-2402 is fixed
+            //
+        } else {
+            rsmd = ps.getMetaData();
+            assertEquals(2, rsmd.getColumnCount());
+            assertEquals(java.sql.Types.INTEGER, rsmd.getColumnType(1));
+            assertEquals("C11", rsmd.getColumnName(1));
+            assertEquals(java.sql.Types.INTEGER, rsmd.getColumnType(2));
+            assertEquals("C12", rsmd.getColumnName(2));
+        }
+
+        // ResultSetMetaData for select * after alter table and
+        // executeQuery.
+        s.executeUpdate("alter table bug4579 add column c13 int");
+        ResultSet rs = ps.executeQuery();
         rsmd = ps.getMetaData();
-        assertEquals(2, rsmd.getColumnCount());
+        assertEquals(3, rsmd.getColumnCount());
         assertEquals(java.sql.Types.INTEGER, rsmd.getColumnType(1));
         assertEquals("C11", rsmd.getColumnName(1));
         assertEquals(java.sql.Types.INTEGER, rsmd.getColumnType(2));
         assertEquals("C12", rsmd.getColumnName(2));
+        assertEquals(java.sql.Types.INTEGER, rsmd.getColumnType(3));
+        assertEquals("C13", rsmd.getColumnName(3));
 
-        // ResultSetMetaData for select * after alter table and
-        // executeQuery.
-        s.executeUpdate("alter table bug4579 add column c13 int");
-        ResultSet rs = ps.executeQuery();
+        // Check ps metadata again
         rsmd = ps.getMetaData();
         assertEquals(3, rsmd.getColumnCount());
         assertEquals(java.sql.Types.INTEGER, rsmd.getColumnType(1));
@@ -140,6 +152,7 @@ public class PrepStmtMetaDataTest extend
         assertEquals("C12", rsmd.getColumnName(2));
         assertEquals(java.sql.Types.INTEGER, rsmd.getColumnType(3));
         assertEquals("C13", rsmd.getColumnName(3));
+
         rs.close();
         ps.close();
         s.executeUpdate("drop table bug4579");

Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java?rev=1505734&r1=1505733&r2=1505734&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
(original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/lang/AlterTableTest.java
Mon Jul 22 17:17:07 2013
@@ -199,19 +199,12 @@ public final class AlterTableTest extend
         // select * prepared statements do see added columns after 
         // alter table
 
-        if (usingEmbedded()) // client/server doesn't keep cursor open.
-        {
-            rs = pSt.executeQuery();
-            JDBC.assertColumnNames(rs, new String[]{"C1", "C2"});
-            JDBC.assertFullResultSet(rs, new String[][]{
-                        {"1", null},
-                        {"2", null}
-                    });
-        } else {
-            rs = pSt.executeQuery();
-            JDBC.assertColumnNames(rs, new String[]{"C1"});
-            JDBC.assertFullResultSet(rs, new String[][]{{"1"}, {"2"}});
-        }
+        rs = pSt.executeQuery();
+        JDBC.assertColumnNames(rs, new String[]{"C1", "C2"});
+        JDBC.assertFullResultSet(rs, new String[][]{
+                {"1", null},
+                {"2", null}
+            });
 
         // add non-nullable column to 0 row table and verify
         st.executeUpdate("alter table t0 add column c2 int not null default 0");



Mime
View raw message