You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ma...@apache.org on 2010/07/14 05:21:35 UTC

svn commit: r963933 - in /db/derby/code/branches/10.5: ./ java/engine/org/apache/derby/iapi/sql/ java/engine/org/apache/derby/iapi/sql/dictionary/ java/engine/org/apache/derby/impl/jdbc/ java/engine/org/apache/derby/impl/sql/ java/engine/org/apache/der...

Author: mamta
Date: Wed Jul 14 03:21:33 2010
New Revision: 963933

URL: http://svn.apache.org/viewvc?rev=963933&view=rev
Log:
Backport DERBY-4610 (Error attempting delete with cascade and triggers) to 10.5 codeline


Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/LanguageFactory.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/ResultDescription.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/ResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/dictionary/DataDescriptorGenerator.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericLanguageFactory.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericResultDescription.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DMLVTIResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteCascadeResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteVTIResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/InsertVTIResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoPutResultSetImpl.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/StatementTriggerExecutor.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderImpl.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TriggerEventActivator.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TriggerInfo.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UnionResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UpdateVTIResultSet.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/WriteCursorConstantAction.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 14 03:21:33 2010
@@ -1,2 +1,2 @@
-/db/derby/code/branches/10.6:957000,962738
-/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915733,916075,916897,918152,918359,921028,927430,928065,934474,936215,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952581,954748,955001,955634,956075,956445,956659,958163,959550,962716
+/db/derby/code/branches/10.6:942027,957000,962738
+/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915733,916075,916897,918152,918359,921028,927430,928065,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952581,954748,955001,955634,956075,956445,956659,958163,959550,962716

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/LanguageFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/LanguageFactory.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/LanguageFactory.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/LanguageFactory.java Wed Jul 14 03:21:33 2010
@@ -55,6 +55,22 @@ public interface LanguageFactory
 	ParameterValueSet newParameterValueSet(ClassInspector ci, int numParms, boolean hasReturnParam);
 
 	/**
+	 * Get a new result description from the input result
+	 * description.  Picks only the columns in the column
+	 * array from the inputResultDescription.
+	 *
+ 	 * @param inputResultDescription the input rd
+	 * @param theCols non null array of ints
+	 *
+	 * @return ResultDescription the rd
+	 */
+	public ResultDescription getResultDescription
+	(
+		ResultDescription	inputResultDescription,
+		int[]				theCols
+	);
+
+	/**
 	 * Get a new result description
 	 *
  	 * @param cols an array of col descriptors

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/ResultDescription.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/ResultDescription.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/ResultDescription.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/ResultDescription.java Wed Jul 14 03:21:33 2010
@@ -66,6 +66,22 @@ public interface ResultDescription
 	 *			column in the ResultSet.
 	 */
 	ResultColumnDescriptor	getColumnDescriptor(int position);
+
+	/**
+	 * Get a new result description that has been truncated
+	 * from input column number.   If the input column is
+	 * 5, then columns 5 to getColumnCount() are removed.
+	 * The new ResultDescription points to the same
+	 * ColumnDescriptors (this method performs a shallow
+	 * copy. The saved JDBC ResultSetMetaData will
+     * not be copied.
+	 *
+	 * @param truncateFrom the starting column to remove,
+	 * 1-based.
+	 *
+	 * @return a new ResultDescription
+	 */
+	public ResultDescription truncateColumns(int truncateFrom);
     
     /**
      * Set the JDBC ResultSetMetaData for this ResultDescription.

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/ResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/ResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/ResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/ResultSet.java Wed Jul 14 03:21:33 2010
@@ -84,6 +84,17 @@ public interface ResultSet
 	 * @return	The number of rows affect by the statement, so far.
 	 */
 	int	modifiedRowCount();
+
+	/**
+	 * Returns a ResultDescription object, which describes the results
+	 * of the statement this ResultSet is in. This will *not* be a
+	 * description of this particular ResultSet, if this is not the
+	 * outermost ResultSet.
+	 *
+	 * @return	A ResultDescription describing the results of the
+	 *		statement.
+	 */
+	ResultDescription	getResultDescription();
 	
 	Activation getActivation();
 

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/dictionary/DataDescriptorGenerator.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/dictionary/DataDescriptorGenerator.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/dictionary/DataDescriptorGenerator.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/sql/dictionary/DataDescriptorGenerator.java Wed Jul 14 03:21:33 2010
@@ -21,14 +21,30 @@
 
 package org.apache.derby.iapi.sql.dictionary;
 
-import java.sql.Timestamp;
+import org.apache.derby.iapi.services.monitor.Monitor;
+import org.apache.derby.iapi.error.StandardException;
+
+import org.apache.derby.iapi.sql.dictionary.*;
+
+import org.apache.derby.iapi.types.TypeId;
+import org.apache.derby.iapi.sql.depend.Dependent;
+import org.apache.derby.iapi.sql.depend.Provider;
+import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.sql.execute.ConstantAction;
+import org.apache.derby.iapi.sql.execute.ExecPreparedStatement;
+import org.apache.derby.iapi.services.uuid.UUIDFactory;
+import org.apache.derby.iapi.services.io.FormatableBitSet;
 
+import org.apache.derby.catalog.AliasInfo;
+import org.apache.derby.catalog.DefaultInfo;
+import org.apache.derby.catalog.Dependable;
+import org.apache.derby.catalog.DependableFinder;
 import org.apache.derby.catalog.ReferencedColumns;
-import org.apache.derby.catalog.UUID;
 import org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl;
-import org.apache.derby.iapi.error.StandardException;
-import org.apache.derby.iapi.services.io.FormatableBitSet;
-import org.apache.derby.iapi.services.uuid.UUIDFactory;
+import org.apache.derby.catalog.UUID;
+import org.apache.derby.catalog.Statistics;
+import java.sql.Timestamp;
+import java.io.InputStream;
 
 /**
  * This is an implementation of the DataDescriptorGenerator interface
@@ -52,7 +68,6 @@ public class DataDescriptorGenerator 
 	public	DataDescriptorGenerator( DataDictionary dataDictionary )
 	{
 		this.dataDictionary = dataDictionary;
-        uuidf = dataDictionary.getUUIDFactory();
 	}
 
 	/**
@@ -398,6 +413,8 @@ public class DataDescriptorGenerator 
 	  */
 	protected UUIDFactory getUUIDFactory()
 	{
+		if (uuidf == null)
+			uuidf = Monitor.getMonitor().getUUIDFactory();
 		return uuidf;
 	}
 

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java Wed Jul 14 03:21:33 2010
@@ -255,7 +255,7 @@ public abstract class EmbedResultSet ext
 		}
 
 		// Fill in the column types
-		resultDescription = theResults.getActivation().getResultDescription();
+		resultDescription = theResults.getResultDescription();
 		
 		// Only incur the cost of allocating and maintaining
 		// updated column information if the columns can be updated.
@@ -2226,19 +2226,20 @@ public abstract class EmbedResultSet ext
       checksBeforeUpdateOrDelete(methodName, columnIndex);
 
       //1)Make sure for updateXXX methods, the column position is not out of range
-      if (columnIndex < 1 || columnIndex > resultDescription.getColumnCount())
+      ResultDescription rd = theResults.getResultDescription();
+      if (columnIndex < 1 || columnIndex > rd.getColumnCount())
         throw Util.generateCsSQLException(SQLState.LANG_INVALID_COLUMN_POSITION,
-					new Integer(columnIndex), String.valueOf(resultDescription.getColumnCount()));
+					new Integer(columnIndex), String.valueOf(rd.getColumnCount()));
 
       //2)Make sure the column corresponds to a column in the base table and it is not a derived column
-      if (resultDescription.getColumnDescriptor(columnIndex).getSourceTableName() == null)
+      if (rd.getColumnDescriptor(columnIndex).getSourceTableName() == null)
         throw Util.generateCsSQLException(SQLState.COLUMN_NOT_FROM_BASE_TABLE,
 					methodName);
 
       //3)If column not updatable then throw an exception
       if (!getMetaData().isWritable(columnIndex))
         throw Util.generateCsSQLException(SQLState.LANG_COLUMN_NOT_UPDATABLE_IN_CURSOR,
-					resultDescription.getColumnDescriptor(columnIndex).getName(),
+					theResults.getResultDescription().getColumnDescriptor(columnIndex).getName(),
 					getCursorName());
 	}
 
@@ -3591,11 +3592,12 @@ public abstract class EmbedResultSet ext
                         activation.getPreparedStatement().getTargetTable();
                 // got the underlying (schema.)table name
                 insertSQL.append(getFullBaseTableName(targetTable));
+                ResultDescription rd = theResults.getResultDescription();
 
                 insertSQL.append(" (");
                 // in this for loop we are constructing list of column-names 
                 // and values (?) ,... part of the insert sql
-                for (int i=1; i<=resultDescription.getColumnCount(); i++) { 
+                for (int i=1; i<=rd.getColumnCount(); i++) { 
                     if (foundOneColumnAlready) {
                         insertSQL.append(",");
                         valuesSQL.append(",");
@@ -3603,7 +3605,7 @@ public abstract class EmbedResultSet ext
                     // using quotes around the column name 
                     // to preserve case sensitivity
                     insertSQL.append(quoteSqlIdentifier(
-                            resultDescription.getColumnDescriptor(i).getName()));
+                            rd.getColumnDescriptor(i).getName()));
                     if (columnGotUpdated[i-1]) { 
                         valuesSQL.append("?");
                     } else {
@@ -3631,7 +3633,7 @@ public abstract class EmbedResultSet ext
 
                 // in this for loop we are assigning values for parameters 
                 //in sql constructed earlier VALUES (?, ..)
-                for (int i=1, paramPosition=0; i<=resultDescription.getColumnCount(); i++) { 
+                for (int i=1, paramPosition=0; i<=rd.getColumnCount(); i++) { 
                     // if the column got updated, do following
                     if (columnGotUpdated[i-1]) {  
                         act.getParameterValueSet().
@@ -3688,14 +3690,15 @@ public abstract class EmbedResultSet ext
             ExecCursorTableReference targetTable = activation.getPreparedStatement().getTargetTable();
             updateWhereCurrentOfSQL.append(getFullBaseTableName(targetTable));//got the underlying (schema.)table name
             updateWhereCurrentOfSQL.append(" SET ");
-      
-            for (int i=1; i<=resultDescription.getColumnCount(); i++) { //in this for loop we are constructing columnname=?,... part of the update sql
+            ResultDescription rd = theResults.getResultDescription();
+
+            for (int i=1; i<=rd.getColumnCount(); i++) { //in this for loop we are constructing columnname=?,... part of the update sql
                 if (columnGotUpdated[i-1]) { //if the column got updated, do following
                     if (foundOneColumnAlready)
                         updateWhereCurrentOfSQL.append(",");
                     //using quotes around the column name to preserve case sensitivity
                     updateWhereCurrentOfSQL.append(quoteSqlIdentifier(
-                            resultDescription.getColumnDescriptor(i).getName()) + "=?");
+                            rd.getColumnDescriptor(i).getName()) + "=?");
                     foundOneColumnAlready = true;
                 }
             }
@@ -3711,7 +3714,7 @@ public abstract class EmbedResultSet ext
             statementContext.setActivation(act);
 
             //in this for loop we are assigning values for parameters in sql constructed earlier with columnname=?,... 
-            for (int i=1, paramPosition=0; i<=resultDescription.getColumnCount(); i++) { 
+            for (int i=1, paramPosition=0; i<=rd.getColumnCount(); i++) { 
                 if (columnGotUpdated[i-1])  //if the column got updated, do following
                     act.getParameterValueSet().getParameterForSet(paramPosition++).setValue(updateRow.getColumn(i));
             }

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericLanguageFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericLanguageFactory.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericLanguageFactory.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericLanguageFactory.java Wed Jul 14 03:21:33 2010
@@ -100,6 +100,25 @@ public class GenericLanguageFactory impl
 	}
 
 	/**
+	 * Get a new result description from the input result
+	 * description.  Picks only the columns in the column
+	 * array from the inputResultDescription.
+	 *
+ 	 * @param inputResultDescription  the input rd
+	 * @param theCols array of ints, non null
+	 *
+	 * @return ResultDescription the rd
+	 */
+	public ResultDescription getResultDescription
+	(
+		ResultDescription	inputResultDescription,
+		int[]				theCols
+	)
+	{
+		return new GenericResultDescription(inputResultDescription, theCols);
+	} 
+
+	/**
 	 * Get a new result description
 	 *
  	 * @param cols an array of col descriptors

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericResultDescription.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericResultDescription.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericResultDescription.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericResultDescription.java Wed Jul 14 03:21:33 2010
@@ -79,7 +79,7 @@ public final class GenericResultDescript
      * A map which maps a column name to a column number.
      * Entries only added when accessing columns with the name.
      */
-    private transient Map columnNameMap;
+    private Map columnNameMap;
 	
 	/**
 	 * Niladic constructor for Formatable
@@ -101,6 +101,31 @@ public final class GenericResultDescript
 		this.statementType = statementType;
 	}
 
+	/**
+	 * Build a GenericResultDescription 
+	 *
+	 * @param rd the result description
+	 * @param theCols the columns to take from the input rd
+	 */
+	public GenericResultDescription
+	(
+		ResultDescription	rd, 
+		int[]				theCols
+	) 
+	{
+		if (SanityManager.DEBUG)
+		{
+			SanityManager.ASSERT(theCols != null, "theCols argument to GenericResultDescription is null");
+		}
+
+		this.columns = new ResultColumnDescriptor[theCols.length];
+		for (int i = 0; i < theCols.length; i++)
+		{
+			columns[i] = rd.getColumnDescriptor(theCols[i]);
+		}
+		this.statementType = rd.getStatementType();
+	}
+
 	//
 	// ResultDescription interface
 	//
@@ -131,6 +156,36 @@ public final class GenericResultDescript
 		return columns[position-1];
 	}
 
+	/**
+	 * Get a new result description that has been truncated
+	 * from input column number.   If the input column is
+	 * 5, then columns 5 to getColumnCount() are removed.
+	 * The new ResultDescription points to the same
+	 * ColumnDescriptors (this method performs a shallow
+	 * copy.
+	 *
+	 * @param truncateFrom the starting column to remove
+	 *
+	 * @return a new ResultDescription
+	 */
+	public ResultDescription truncateColumns(int truncateFrom)	
+	{
+		if (SanityManager.DEBUG) 
+		{
+			if (!(truncateFrom > 0 && columns != null))
+			{
+				SanityManager.THROWASSERT("bad truncate value: "+truncateFrom+" is too low");
+			}
+			if (truncateFrom > columns.length)
+			{
+				SanityManager.THROWASSERT("bad truncate value: "+truncateFrom+" is too high");
+			}
+		}
+		ResultColumnDescriptor[] newColumns = new ResultColumnDescriptor[truncateFrom-1];
+		System.arraycopy(columns, 0, newColumns, 0, newColumns.length);
+		return new GenericResultDescription(newColumns, statementType);
+	}
+
 
 	//////////////////////////////////////////////
 	//

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/BasicNoPutResultSetImpl.java Wed Jul 14 03:21:33 2010
@@ -30,6 +30,7 @@ import org.apache.derby.iapi.services.i1
 import org.apache.derby.iapi.services.io.FormatableBitSet;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.sql.Activation;
+import org.apache.derby.iapi.sql.ResultDescription;
 import org.apache.derby.iapi.sql.ResultSet;
 import org.apache.derby.iapi.sql.Row;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
@@ -87,6 +88,8 @@ implements NoPutResultSet
 	protected final Activation	    activation;
 	private final boolean				statisticsTimingOn;
 
+	ResultDescription resultDescription;
+
 	private transient TransactionController	tc;
 
 	private int[] baseColumnMap;
@@ -96,6 +99,7 @@ implements NoPutResultSet
 	    <BR>
 		Sets beginTime for all children to use to measue constructor time.
 	 *
+	 *  @param  resultDescription the result description. May be null.
 	 *	@param	activation			The activation
 	 *	@param	optimizerEstimatedRowCount	The optimizer's estimate of the
 	 *										total number of rows for this
@@ -103,13 +107,15 @@ implements NoPutResultSet
 	 *	@param	optimizerEstimatedCost		The optimizer's estimated cost for
 	 *										this result set
 	 */
-	BasicNoPutResultSetImpl(Activation activation,
+	BasicNoPutResultSetImpl(ResultDescription resultDescription,
+							Activation activation,
 							double optimizerEstimatedRowCount,
 							double optimizerEstimatedCost)
 	{
 		this.activation = activation;
 		if (statisticsTimingOn = getLanguageConnectionContext().getStatisticsTiming())
 		    beginTime = startExecutionTime = getCurrentTimeMillis();
+		this.resultDescription = resultDescription;
 		this.optimizerEstimatedRowCount = optimizerEstimatedRowCount;
 		this.optimizerEstimatedCost = optimizerEstimatedCost;
 	}
@@ -614,6 +620,13 @@ implements NoPutResultSet
 	 */
 
 	/**
+     * Returns the description of the table's rows
+	 */
+	public ResultDescription getResultDescription() {
+	    return resultDescription;
+	}
+
+	/**
 	 * Get the execution time in milliseconds.
 	 *
 	 * @return long		The execution time in milliseconds.

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DMLVTIResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DMLVTIResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DMLVTIResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DMLVTIResultSet.java Wed Jul 14 03:21:33 2010
@@ -51,9 +51,19 @@ abstract class DMLVTIResultSet extends D
 	UpdatableVTIConstantAction	constants;
 	TransactionController 	tc;
 
+    ResultDescription 		resultDescription;
 	private int						numOpens;
 	boolean				firstExecute;
 
+	/**
+     * Returns the description of the inserted rows.
+     * REVISIT: Do we want this to return NULL instead?
+	 */
+	public ResultDescription getResultDescription()
+	{
+	    return resultDescription;
+	}
+
     /**
 	 *
 	 * @exception StandardException		Thrown on error
@@ -67,6 +77,8 @@ abstract class DMLVTIResultSet extends D
 		constants = (UpdatableVTIConstantAction) constantAction;
 
         tc = activation.getTransactionController();
+
+        resultDescription = sourceResultSet.getResultDescription();
 	}
 	
 	/**

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteCascadeResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteCascadeResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteCascadeResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteCascadeResultSet.java Wed Jul 14 03:21:33 2010
@@ -53,12 +53,15 @@ import java.util.Enumeration;
  * it should be done based on whether the resultset has dependent resultsets or not.
  *
  */
-class DeleteCascadeResultSet extends DeleteResultSet
+public class DeleteCascadeResultSet extends DeleteResultSet
 {
 
 
 	public ResultSet[] dependentResultSets;
 	private int noDependents =0;
+	private CursorResultSet parentSource;
+	private FKInfo parentFKInfo;
+	private long fkIndexConglomNumber;
 	private String resultSetId;
 	private boolean mainNodeForTable = true;
 	private boolean affectedRows = false;
@@ -68,7 +71,7 @@ class DeleteCascadeResultSet extends Del
      * class interface
 	 * @exception StandardException		Thrown on error
      */
-    DeleteCascadeResultSet
+    public DeleteCascadeResultSet
 	(
 		NoPutResultSet		source,
 		Activation			activation,
@@ -84,8 +87,13 @@ class DeleteCascadeResultSet extends Del
 			  (ConstantAction)activation.getPreparedStatement().getSavedObject(constantActionItem)),
 			  activation);
 
-		if(constantActionItem != -1)
+		ConstantAction passedInConstantAction;
+		if(constantActionItem == -1)
+			passedInConstantAction = activation.getConstantAction(); //root table
+		else
 		{
+			passedInConstantAction = 
+				(ConstantAction) activation.getPreparedStatement().getSavedObject(constantActionItem);
 			resultDescription = constants.resultDescription;
 		}
 		cascadeDelete = true;

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteResultSet.java Wed Jul 14 03:21:33 2010
@@ -81,6 +81,15 @@ class DeleteResultSet extends DMLWriteRe
 	ExecRow		deferredRLRow = null;
 	int	numberOfBaseColumns = 0;
 
+	/**
+     * Returns the description of the deleted rows.
+     * REVISIT: Do we want this to return NULL instead?
+	 */
+	public ResultDescription getResultDescription()
+	{
+	    return resultDescription;
+	}
+
     /*
      * class interface
      *
@@ -121,7 +130,7 @@ class DeleteResultSet extends DMLWriteRe
 		noTriggersOrFks = ((fkInfoArray == null) && (triggerInfo == null));
 		baseRowReadList = constants.getBaseRowReadList();
 		if(source != null)
-			resultDescription = activation.getResultDescription();
+			resultDescription = source.getResultDescription();
 		else
 			resultDescription = constants.resultDescription;
 
@@ -291,13 +300,18 @@ class DeleteResultSet extends DMLWriteRe
 			if(cascadeDelete)
 			{
 				rowHolder = new TemporaryRowHolderImpl(activation, properties, 
-						 false);
+						(resultDescription != null) ?
+							resultDescription.truncateColumns(rlColumnNumber) :
+							null, false);
 
 
 			}else
 			{
 
-				rowHolder = new TemporaryRowHolderImpl(activation, properties);
+				rowHolder = new TemporaryRowHolderImpl(activation, properties, 
+						(resultDescription != null) ?
+							resultDescription.truncateColumns(rlColumnNumber) :
+							null);
 
 			}
 

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteVTIResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteVTIResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteVTIResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/DeleteVTIResultSet.java Wed Jul 14 03:21:33 2010
@@ -100,7 +100,8 @@ class DeleteVTIResultSet extends DMLVTIR
 			activation.clearIndexScanInfo();
             if( null == rowHolder)
                 rowHolder =
-                    new TemporaryRowHolderImpl(activation, new Properties());
+                    new TemporaryRowHolderImpl(activation, new Properties(),
+                                               (ResultDescription) null);
 		}
 
         try

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java Wed Jul 14 03:21:33 2010
@@ -38,13 +38,17 @@ import org.apache.derby.iapi.reference.S
  * a trigger.  It is subclassed by row and statement
  * executors.
  */
-abstract class GenericTriggerExecutor
+public abstract class GenericTriggerExecutor
 {
-	final InternalTriggerExecutionContext	tec;
-	final TriggerDescriptor					triggerd;
-	final Activation						activation;
-	final LanguageConnectionContext			lcc;
-
+	protected InternalTriggerExecutionContext	tec;
+	protected TriggerDescriptor					triggerd;
+	protected Activation						activation;
+	protected LanguageConnectionContext			lcc;
+
+	private	boolean			whenClauseRetrieved;
+	private	boolean			actionRetrieved;
+	private SPSDescriptor	whenClause; 
+	private SPSDescriptor	action;
 
 	private ExecPreparedStatement	ps;
 	private Activation 				spsActivation;
@@ -90,12 +94,22 @@ abstract class GenericTriggerExecutor
 
 	protected SPSDescriptor getWhenClause() throws StandardException
 	{
-		return triggerd.getWhenClauseSPS();
+		if (!whenClauseRetrieved)
+		{
+			whenClauseRetrieved = true;
+			whenClause = triggerd.getWhenClauseSPS();
+		}
+		return whenClause;
 	}
 
 	protected SPSDescriptor getAction() throws StandardException
 	{
-		return triggerd.getActionSPS(lcc);
+		if (!actionRetrieved)
+		{
+			actionRetrieved = true;
+			action = triggerd.getActionSPS(lcc);
+		}
+		return action;
 	}
 
 	/**

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/IndexChanger.java Wed Jul 14 03:21:33 2010
@@ -408,7 +408,8 @@ public class IndexChanger
 			** row holder (the description is needed when the row
 			** holder is going to be handed to users for triggers).
 			*/
-			rowHolder = new TemporaryRowHolderImpl(activation, properties);
+			rowHolder = new TemporaryRowHolderImpl(activation, properties,
+												   (ResultDescription) null);
 		}
 
 		/*

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java Wed Jul 14 03:21:33 2010
@@ -98,6 +98,7 @@ class InsertResultSet extends DMLWriteRe
 
 	// divined at run time
 
+    private	ResultDescription 		resultDescription;
 	private RowChanger 				rowChanger;
 
 	private	TransactionController 	tc;
@@ -167,6 +168,15 @@ class InsertResultSet extends DMLWriteRe
 	private boolean					setIdentity;
 	
 
+	/**
+     * Returns the description of the inserted rows.
+     * REVISIT: Do we want this to return NULL instead?
+	 */
+	public ResultDescription getResultDescription()
+	{
+	    return resultDescription;
+	}
+
 	// TargetResultSet interface
 
 	/**
@@ -334,7 +344,7 @@ class InsertResultSet extends DMLWriteRe
 				triggerInfo.hasTrigger(true, true) :
 				false;
 
-        ResultDescription resultDescription = activation.getResultDescription();
+        resultDescription = sourceResultSet.getResultDescription();
 
 		// Is this a bulkInsert or regular insert?
 		String insertMode = constants.getProperty("insertMode");
@@ -944,13 +954,15 @@ class InsertResultSet extends DMLWriteRe
 			/*
 			** If deferred we save a copy of the entire row.
 			*/
-			rowHolder = new TemporaryRowHolderImpl(activation, properties);
+			rowHolder = new TemporaryRowHolderImpl(activation, properties,
+												   resultDescription);
 			rowChanger.setRowHolder(rowHolder);
 		}
 
 		int[] columnIndexes = null;
 		if (firstExecute && activation.getAutoGeneratedKeysResultsetMode())
 		{
+			ResultDescription rd;
 			Properties properties = new Properties();
 			columnIndexes = activation.getAutoGeneratedKeysColumnIndexes();
 
@@ -963,8 +975,9 @@ class InsertResultSet extends DMLWriteRe
 				columnIndexes = generatedColumnPositionsArray();
 			}
 
+			rd = lcc.getLanguageFactory().getResultDescription(resultDescription,columnIndexes);
 			autoGeneratedKeysRowsHolder =
-				new TemporaryRowHolderImpl(activation, properties);
+				new TemporaryRowHolderImpl(activation, properties, rd);
 		}
 
 
@@ -1254,7 +1267,8 @@ class InsertResultSet extends DMLWriteRe
 		if (hasBeforeRowTrigger && rowHolder != null)
 		{
 			rowHolder =
-				new TemporaryRowHolderImpl(activation, properties);
+				new TemporaryRowHolderImpl(activation, properties,
+										   resultDescription);
 		}
 
 		// Add any new properties or change the values of any existing properties

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/InsertVTIResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/InsertVTIResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/InsertVTIResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/InsertVTIResultSet.java Wed Jul 14 03:21:33 2010
@@ -126,7 +126,8 @@ class InsertVTIResultSet extends DMLVTIR
 			** If deferred we save a copy of the entire row.
 			*/
 			rowHolder =
-				new TemporaryRowHolderImpl(activation, properties);
+				new TemporaryRowHolderImpl(activation, properties,
+										   resultDescription);
 		}
 
 		while ( row != null )

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoPutResultSetImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoPutResultSetImpl.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoPutResultSetImpl.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoPutResultSetImpl.java Wed Jul 14 03:21:33 2010
@@ -89,7 +89,8 @@ extends BasicNoPutResultSetImpl
 						double optimizerEstimatedRowCount,
 						double optimizerEstimatedCost)
 	{
-		super(activation,
+		super(null,
+				activation,
 				optimizerEstimatedRowCount,
 				optimizerEstimatedCost);
 
@@ -103,6 +104,13 @@ extends BasicNoPutResultSetImpl
 	// NoPutResultSet interface
 
 	/**
+     * Returns the description of the table's rows
+	 */
+	public ResultDescription getResultDescription() {
+	    return activation.getResultDescription();
+	}
+
+	/**
 		Return my cursor name for JDBC. Can be null.
 	*/
 	public String getCursorName() {

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/NoRowsResultSetImpl.java Wed Jul 14 03:21:33 2010
@@ -128,6 +128,14 @@ abstract class NoRowsResultSetImpl imple
 	 * Returns zero.
 	 */
 	public int	modifiedRowCount() { return 0; }
+
+	/**
+	 * Returns null.
+	 */
+	public ResultDescription	getResultDescription()
+	{
+	    return (ResultDescription)null;
+	}
 	
 	public final Activation getActivation()
 	{

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java Wed Jul 14 03:21:33 2010
@@ -33,7 +33,7 @@ import org.apache.derby.iapi.sql.Activat
  * a row trigger.  It is instantiated at execution time.
  * There is one per row trigger.
  */
-class RowTriggerExecutor extends GenericTriggerExecutor
+public class RowTriggerExecutor extends GenericTriggerExecutor
 {
 	/**
 	 * Constructor

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/StatementTriggerExecutor.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/StatementTriggerExecutor.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/StatementTriggerExecutor.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/StatementTriggerExecutor.java Wed Jul 14 03:21:33 2010
@@ -33,7 +33,7 @@ import org.apache.derby.iapi.sql.Activat
  * a statement trigger.  It is instantiated at execution
  * time.  There is one per statement trigger.
  */
-class StatementTriggerExecutor extends GenericTriggerExecutor
+public class StatementTriggerExecutor extends GenericTriggerExecutor
 {
 	/**
 	 * Constructor

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderImpl.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderImpl.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderImpl.java Wed Jul 14 03:21:33 2010
@@ -72,7 +72,7 @@ class TemporaryRowHolderImpl implements 
 	private ConglomerateController	cc;
 	private Properties				properties;
 	private ScanController			scan;
-
+	private	ResultDescription		resultDescription;
 	/** Activation object with local state information. */
 	Activation						activation;
 
@@ -103,14 +103,17 @@ class TemporaryRowHolderImpl implements 
 	 * @param activation the activation
 	 * @param properties the properties of the original table.  Used
 	 *		to help the store use optimal page size, etc.
+	 * @param resultDescription the result description.  Relevant for the getResultDescription
+	 * 		call on the result set returned by getResultSet.  May be null
 	 */
-	TemporaryRowHolderImpl
+	public TemporaryRowHolderImpl
 	(
 		Activation				activation, 
-		Properties 				properties
+		Properties 				properties, 
+		ResultDescription		resultDescription
 	) 
 	{
-		this(activation, properties,
+		this(activation, properties, resultDescription,
 			 DEFAULT_OVERFLOWTHRESHOLD, false, false);
 	}
 	
@@ -121,16 +124,19 @@ class TemporaryRowHolderImpl implements 
 	 * @param activation the activation
 	 * @param properties the properties of the original table.  Used
 	 *		to help the store use optimal page size, etc.
+	 * @param resultDescription the result description.  Relevant for the getResultDescription
+	 * 		call on the result set returned by getResultSet.  May be null
 	 * @param isUniqueStream - true , if it has to be temporary row holder unique stream
 	 */
-	TemporaryRowHolderImpl
+	public TemporaryRowHolderImpl
 	(
 		Activation				activation, 
 		Properties 				properties, 
+		ResultDescription		resultDescription,
 		boolean                 isUniqueStream
 	) 
 	{
-		this(activation, properties, 1, isUniqueStream,
+		this(activation, properties, resultDescription, 1, isUniqueStream,
 			 false);
 	}
 
@@ -141,14 +147,17 @@ class TemporaryRowHolderImpl implements 
 	 * @param activation the activation
 	 * @param properties the properties of the original table.  Used
 	 *		to help the store use optimal page size, etc.
+	 * @param resultDescription the result description.  Relevant for the getResultDescription
+	 * 		call on the result set returned by getResultSet.  May be null
 	 * @param overflowToConglomThreshold on an attempt to insert
 	 * 		this number of rows, the rows will be put
  	 *		into a temporary conglomerate.
 	 */
-	TemporaryRowHolderImpl
+	public TemporaryRowHolderImpl
 	(
 		Activation			 	activation, 
 		Properties				properties,
+		ResultDescription		resultDescription,
 		int 					overflowToConglomThreshold,
 		boolean                 isUniqueStream,
 		boolean					isVirtualMemHeap
@@ -167,6 +176,7 @@ class TemporaryRowHolderImpl implements 
 
 		this.activation = activation;
 		this.properties = properties;
+		this.resultDescription = resultDescription;
 		this.isUniqueStream = isUniqueStream;
 		this.isVirtualMemHeap = isVirtualMemHeap;
 		rowArray = new ExecRow[overflowToConglomThreshold];
@@ -470,12 +480,12 @@ class TemporaryRowHolderImpl implements 
 		if(isUniqueStream)
 		{
 			return new TemporaryRowHolderResultSet(tc, rowArray,
-												   isVirtualMemHeap,
+												   resultDescription, isVirtualMemHeap,
 												   true, positionIndexConglomId, this);
 		}
 		else
 		{
-			return new TemporaryRowHolderResultSet(tc, rowArray, isVirtualMemHeap, this);
+			return new TemporaryRowHolderResultSet(tc, rowArray, resultDescription, isVirtualMemHeap, this);
 
 		}
 	}

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TemporaryRowHolderResultSet.java Wed Jul 14 03:21:33 2010
@@ -58,6 +58,7 @@ class TemporaryRowHolderResultSet implem
 	private boolean 				isOpen;
 	private boolean 				finished;
 	private ExecRow					currentRow;
+	private ResultDescription		resultDescription;
 	private boolean                 isAppendable = false;
 	private long                    positionIndexConglomId;
 	private boolean 				isVirtualMemHeap;
@@ -73,17 +74,19 @@ class TemporaryRowHolderResultSet implem
 	 *
 	 * @param tc the xact controller
 	 * @param rowArray the row array
+	 * @param resultDescription value returned by getResultDescription()
 	 */
-	TemporaryRowHolderResultSet
+	public TemporaryRowHolderResultSet
 	(
 		TransactionController		tc,
 		ExecRow[]					rowArray,
+		ResultDescription			resultDescription,
 		boolean						isVirtualMemHeap,
 		TemporaryRowHolderImpl		holder
    	)
 	{
 
-		this(tc, rowArray, isVirtualMemHeap, false, 0, holder);
+		this(tc, rowArray, resultDescription, isVirtualMemHeap, false, 0, holder);
 
 
 	}
@@ -93,14 +96,16 @@ class TemporaryRowHolderResultSet implem
 	 *
 	 * @param tc the xact controller
 	 * @param rowArray the row array
+	 * @param resultDescription value returned by getResultDescription()
 	 * @param isAppendable true,if we can insert rows after this result is created
 	 * @param positionIndexConglomId conglomId of the index which has order rows
 	 *                               are inserted and their row location 
 	 */
-	TemporaryRowHolderResultSet
+	public TemporaryRowHolderResultSet
 	(
 		TransactionController		tc,
 		ExecRow[]					rowArray,
+		ResultDescription			resultDescription,
 		boolean						isVirtualMemHeap,
 		boolean                     isAppendable,
 		long                        positionIndexConglomId,
@@ -109,6 +114,7 @@ class TemporaryRowHolderResultSet implem
 	{
 		this.tc = tc;
 		this.rowArray = rowArray;
+		this.resultDescription = resultDescription;
 		this.numRowsOut = 0;
 		isOpen = false;
 		finished = false;
@@ -178,14 +184,15 @@ class TemporaryRowHolderResultSet implem
 	 *
 	 * @exception StandardException on error
 	 */
-	static TemporaryRowHolderResultSet getNewRSOnCurrentRow
+	public static TemporaryRowHolderResultSet getNewRSOnCurrentRow
 	(
 		Activation				activation,
 		CursorResultSet 		rs
 	) throws StandardException
 	{
 		TemporaryRowHolderImpl singleRow =
-			new TemporaryRowHolderImpl(activation, null);
+			new TemporaryRowHolderImpl(activation, null,
+									   rs.getResultDescription());
 		singleRow.insert(rs.getCurrentRow());
 		return (TemporaryRowHolderResultSet) singleRow.getResultSet();
 	}
@@ -594,6 +601,20 @@ class TemporaryRowHolderResultSet implem
 	public int modifiedRowCount() { return 0;};
 
 	/**
+	 * Returns a ResultDescription object, which describes the results
+	 * of the statement this ResultSet is in. This will *not* be a
+	 * description of this particular ResultSet, if this is not the
+	 * outermost ResultSet.
+	 *
+	 * @return	A ResultDescription describing the results of the
+	 *		statement.
+	 */
+	public ResultDescription	getResultDescription()
+	{
+		return resultDescription;
+	}
+
+	/**
 	 * Tells the system that there will be calls to getNextRow().
 	 *
 	 * @exception StandardException		Thrown on failure

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TriggerEventActivator.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TriggerEventActivator.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TriggerEventActivator.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TriggerEventActivator.java Wed Jul 14 03:21:33 2010
@@ -21,26 +21,34 @@
 
 package org.apache.derby.impl.sql.execute;
 
-import java.util.Vector;
-
-import org.apache.derby.catalog.UUID;
-import org.apache.derby.iapi.error.StandardException;
-import org.apache.derby.iapi.jdbc.ConnectionContext;
 import org.apache.derby.iapi.services.sanity.SanityManager;
-import org.apache.derby.iapi.sql.Activation;
-import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
-import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor;
+import org.apache.derby.iapi.error.StandardException;
+
 import org.apache.derby.iapi.sql.execute.CursorResultSet;
 import org.apache.derby.iapi.sql.execute.NoPutResultSet;
+import org.apache.derby.iapi.sql.execute.ExecRow; 
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor;
+
+import org.apache.derby.iapi.sql.Activation;
+
 import org.apache.derby.iapi.store.access.TransactionController;
+import org.apache.derby.impl.sql.execute.AutoincrementCounter;
+import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.jdbc.ConnectionContext;
+import org.apache.derby.catalog.UUID;
+
+import java.util.Vector;
+import java.sql.SQLException;
 
 /**
  * Responsible for firing a trigger or set of triggers
  * based on an event.
  */
-class TriggerEventActivator
+public class TriggerEventActivator
 {
 	private LanguageConnectionContext		lcc; 
+	private TransactionController 			tc; 
 	private TriggerInfo 					triggerInfo; 
 	private InternalTriggerExecutionContext	tec;
 	private	GenericTriggerExecutor[][]		executors;
@@ -64,7 +72,7 @@ class TriggerEventActivator
 	 *
 	 * @exception StandardException on error
 	 */
-	TriggerEventActivator
+	public TriggerEventActivator
 	(
 		LanguageConnectionContext	lcc, 
 		TransactionController 		tc, 
@@ -84,6 +92,7 @@ class TriggerEventActivator
 		tableName = triggerInfo.triggerArray[0].getTableDescriptor().getQualifiedName();
 	
 		this.lcc = lcc;
+		this.tc = tc;
 		this.activation = activation;
 		this.tableId = tableId;
 		this.dmlType = dmlType;
@@ -218,7 +227,7 @@ class TriggerEventActivator
 	 *
  	 * @exception StandardException on error
 	 */
-	void notifyEvent
+	public void notifyEvent
 	(
 		TriggerEvent 		event,
 		CursorResultSet		brs,
@@ -281,7 +290,7 @@ class TriggerEventActivator
 	 *
 	 * @exception StandardException on unexpected error
 	 */
-	void cleanup() throws StandardException
+	public void cleanup() throws StandardException
 	{
 		if (tec != null)
 		{

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TriggerInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TriggerInfo.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TriggerInfo.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/TriggerInfo.java Wed Jul 14 03:21:33 2010
@@ -129,6 +129,21 @@ public final class TriggerInfo implement
 		}
 	}
 
+	/*
+	 * private constructor for TriggerInfo
+	 */
+	private TriggerInfo
+	(
+		TriggerDescriptor[]		triggers,
+		int[]					changedColsIds,
+		String[]				changedColsNames
+	) 
+	{
+		this.columnIds = changedColsIds;
+		this.columnNames = changedColsNames;
+		this.triggerArray = triggers;
+	}
+
 	/**
 	 * Do we have a trigger or triggers that meet
 	 * the criteria

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UnionResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UnionResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UnionResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UnionResultSet.java Wed Jul 14 03:21:33 2010
@@ -90,6 +90,15 @@ class UnionResultSet extends NoPutResult
 	//
 
 	/**
+     * Returns the description of the first source.
+     * Assumes the compiler ensured both sources
+     * had the same description.
+	 */
+	public ResultDescription getResultDescription() {
+	    return source1.getResultDescription();
+	}
+
+	/**
      * open the first source.
  	 *	@exception StandardException thrown on failure
      */

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UpdateResultSet.java Wed Jul 14 03:21:33 2010
@@ -34,6 +34,7 @@ import org.apache.derby.iapi.services.sa
 import org.apache.derby.iapi.sql.Activation;
 import org.apache.derby.iapi.sql.ResultDescription;
 import org.apache.derby.iapi.sql.ResultSet;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
 import org.apache.derby.iapi.sql.execute.ConstantAction;
 import org.apache.derby.iapi.sql.execute.CursorResultSet;
 import org.apache.derby.iapi.sql.execute.ExecRow;
@@ -61,6 +62,7 @@ class UpdateResultSet extends DMLWriteRe
 	private ExecRow 					deferredSparseRow;
 	UpdateConstantAction		constants;
 	
+    private ResultDescription 		resultDescription;
 	private NoPutResultSet			source;
 	NoPutResultSet			savedSource;
 	private RowChanger				rowChanger;
@@ -92,11 +94,20 @@ class UpdateResultSet extends DMLWriteRe
 	private ExecRow					deferredTempRow;
 	private ExecRow					deferredBaseRow;
 	private ExecRow					oldDeletedRow;
+	private ResultDescription		triggerResultDescription;
 
 	int lockMode;
 	boolean deferred;
 	boolean beforeUpdateCopyRequired = false;
 
+	/**
+     * Returns the description of the updated rows.
+     * REVISIT: Do we want this to return NULL instead?
+	 */
+	public ResultDescription getResultDescription()
+	{
+	    return resultDescription;
+	}
 
     /*
      * class interface
@@ -180,9 +191,8 @@ class UpdateResultSet extends DMLWriteRe
 		heapConglom = constants.conglomId;
 
 		baseRowReadList = constants.getBaseRowReadList();
-        ResultDescription resultDescription;
 		if(passedInRsd ==null)
-			resultDescription = activation.getResultDescription();
+			resultDescription = source.getResultDescription();
 		else
 			resultDescription = passedInRsd;
 		/*
@@ -370,6 +380,9 @@ class UpdateResultSet extends DMLWriteRe
 			{
 				deferredTempRow = RowUtil.getEmptyValueRow(numberOfBaseColumns+1, lcc);
 				oldDeletedRow = RowUtil.getEmptyValueRow(numberOfBaseColumns, lcc);
+				triggerResultDescription = (resultDescription != null) ?
+									resultDescription.truncateColumns(numberOfBaseColumns+1) :
+									null;
 			}
 
 			Properties properties = new Properties();
@@ -378,10 +391,12 @@ class UpdateResultSet extends DMLWriteRe
 			rowChanger.getHeapConglomerateController().getInternalTablePropertySet(properties);
 			if(beforeUpdateCopyRequired){
 				deletedRowHolder =
-					new TemporaryRowHolderImpl(activation, properties);
+					new TemporaryRowHolderImpl(activation, properties,
+											   triggerResultDescription);
 			}
 			insertedRowHolder =
-				new TemporaryRowHolderImpl(activation, properties);
+				new TemporaryRowHolderImpl(activation, properties,
+										   triggerResultDescription);
 
 			rowChanger.setRowHolder(insertedRowHolder);
 		}
@@ -729,7 +744,7 @@ class UpdateResultSet extends DMLWriteRe
 						// in-memory heap grows), hopefully we never spill temp table to disk.
 
 						tableScan.futureForUpdateRows = new TemporaryRowHolderImpl
-							(activation, null, 100, false, true);
+							(activation, null, null, 100, false, true);
 					}
 
 					rlRow.setColumn(1, rowLoc);

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UpdateVTIResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UpdateVTIResultSet.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UpdateVTIResultSet.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/UpdateVTIResultSet.java Wed Jul 14 03:21:33 2010
@@ -96,7 +96,8 @@ class UpdateVTIResultSet extends DMLVTIR
 			** If deferred we save a copy of the entire row.
 			*/
 			rowHolder =
-				new TemporaryRowHolderImpl(activation, properties);
+				new TemporaryRowHolderImpl(activation, properties,
+										   resultDescription);
 		}
 
         try

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/WriteCursorConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/WriteCursorConstantAction.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/WriteCursorConstantAction.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/WriteCursorConstantAction.java Wed Jul 14 03:21:33 2010
@@ -63,14 +63,12 @@ abstract	class WriteCursorConstantAction
 	**
 	**	This class implements Formatable. But it is NOT used
  	**	across either major or minor releases.  It is only
-	** 	written persistently in stored prepared statements.
-    *   SO, IT IS OK TO CHANGE ITS read/writeExternal.
+	** 	written persistently in stored prepared statements, 
+	**	not in the replication stage.  SO, IT IS OK TO CHANGE
+	**	ITS read/writeExternal.
 	**
 	********************************************************/
 
-    /**
-     * Heap conglomerate identifier.
-     */
 	long						conglomId;
 	StaticCompiledOpenConglomInfo heapSCOCI;
 	IndexRowGenerator[] 		irgs;

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java?rev=963933&r1=963932&r2=963933&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java (original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/TriggerTest.java Wed Jul 14 03:21:33 2010
@@ -1418,6 +1418,41 @@ public class TriggerTest extends BaseJDB
         s.executeUpdate("DROP TABLE APP.LOG");
         s.executeUpdate("DROP TABLE APP.NAMES");
     }
-    
-    
+
+    /**
+     * Regression test case for DERBY-4610, where a DELETE statement failed
+     * because a trigger used the wrong meta-data and mixed up the data types.
+     */
+    public void testDerby4610WrongDataType() throws SQLException {
+        Statement s = createStatement();
+        s.execute("create table testtable " +
+                  "(id integer, name varchar(20), primary key(id))");
+        s.execute("create table testchild (" +
+                  "id integer constraint fk_id " +
+                  "references testtable on delete cascade, " +
+                  "ordernum int, primary key(id))");
+        s.execute("create procedure testproc (str varchar(20)) " +
+                  "PARAMETER STYLE JAVA LANGUAGE JAVA EXTERNAL NAME '" +
+                  getClass().getName() + ".derby4610proc'");
+        s.execute("create trigger testtabletrigger after delete on testtable " +
+                  "referencing old as old " +
+                  "for each row mode db2sql call testproc(char(old.id))");
+        s.execute("create trigger testchildtrigger after delete on testchild " +
+                  "referencing old as old " +
+                  "for each row mode db2sql call testproc(char(old.ordernum))");
+        s.execute("insert into testtable values (1, 'test1')");
+        s.execute("insert into testchild values (1, 10)");
+
+        // Used to fail with ERROR XCL12: An attempt was made to put a data
+        // value of type 'java.lang.String' into a data value of type 'INTEGER'.
+        assertUpdateCount(s, 1, "delete from testtable where id = 1");
+    }
+
+    /**
+     * Procedure that does nothing. Called as a stored procedure in the
+     * regression test case for DERBY-4610.
+     */
+    public static void derby4610proc(String str) {
+        // do nothing
+    }
 }