db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r430381 - in /db/derby/code/branches/10.1/java: engine/org/apache/derby/impl/sql/execute/InsertResultSet.java testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
Date Thu, 10 Aug 2006 13:43:21 GMT
Author: kmarsden
Date: Thu Aug 10 06:43:20 2006
New Revision: 430381

URL: http://svn.apache.org/viewvc?rev=430381&view=rev
Log:
DERBY-353 It is desirable to have IDENTITY_VAL_LOCAL() function return last recent user specified
value or system generated value for BY DEFAULT identity columns.

Merged from trunk 267331, contributed by V.Narayanan

DERBY-1554 IDENTITY_VAL_LOCAL() returned value is modified incorrectly by a multi-row INSERT
statement.

Merged from trunk 429425, contributed by Yip Ng




Modified:
    db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java?rev=430381&r1=430380&r2=430381&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/InsertResultSet.java
Thu Aug 10 06:43:20 2006
@@ -178,7 +178,6 @@
 	private	TriggerInfo				triggerInfo;
 	private RISetChecker 			fkChecker;
 	private TriggerEventActivator	triggerActivator;
-
 	/**
 	 * keeps track of autoincrement values that are generated by 
 	 * getSetAutoincrementValues.
@@ -371,8 +370,9 @@
 
 		// Is this a bulkInsert or regular insert?
 		String insertMode = constants.getProperty("insertMode");
-		
-		RowLocation[] rla;
+
+                RowLocation[] rla;
+
 		if ((rla = constants.getAutoincRowLocation()) != null)
 		{
 			aiCache = 
@@ -719,7 +719,7 @@
 		throws StandardException
 	{
 		long startValue = 0;
-		NumberDataValue dvd;
+                NumberDataValue dvd;
 		int index = columnPosition - 1;	// all our indices are 0 based.
 
 		/* As in DB2, only for single row insert: insert into t1(c1) values (..) do
@@ -855,13 +855,28 @@
 		return isRow;
 	}
 
+    // checks if source result set is a RowResultSet type.
+    private boolean isSingleRowResultSet()
+    {
+        boolean isRow = false;
+        
+        if (sourceResultSet instanceof RowResultSet)
+        	isRow = true;
+        else if (sourceResultSet instanceof NormalizeResultSet)
+            isRow = (((NormalizeResultSet) sourceResultSet).source instanceof RowResultSet);
+        
+        return isRow;
+    }
+	
 	// Do the work for a "normal" insert
 	private void normalInsertCore(LanguageConnectionContext lcc, boolean firstExecute)
 		throws StandardException
 	{
+		boolean setUserIdentity = constants.hasAutoincrement() && isSingleRowResultSet();
 		boolean	firstDeferredRow = true;
 		ExecRow	deferredRowBuffer = null;
-
+                long user_autoinc=0;
+                        
 		/* Get or re-use the row changer.
 		 * NOTE: We need to set ourself as the top result set
 		 * if this is not the 1st execution.  (Done in constructor
@@ -999,16 +1014,40 @@
 			}
 
             rowCount++;
+            
+            if(setUserIdentity )
+            {
+                        dd = lcc.getDataDictionary();
+                        td = dd.getTableDescriptor(constants.targetUUID);
+                       
+                        int maxColumns = td.getMaxColumnID();
+                        int col;
+                        
+                        for(col=1;col<=maxColumns;col++)
+                        {
+                            ColumnDescriptor cd = td.getColumnDescriptor(col);
+                            if(cd.isAutoincrement())
+                            {
+                                break;
+                            }
+                        }
+                        
+                        if(col <= maxColumns)
+                        {
+                            DataValueDescriptor dvd = row.cloneColumn(col);
+                            user_autoinc = dvd.getLong();
+                        }
+             } 
 
 			// No need to do a next on a single row source
-			if (constants.singleRowSource)
-			{
-				row = null;
-			}
-			else
-			{
-				row = getNextRowCore(sourceResultSet);
-			}
+             if (constants.singleRowSource)
+	     {
+			row = null;
+	     }
+	     else
+	     {
+		row = getNextRowCore(sourceResultSet);
+	     }
         }
 
 		/*
@@ -1128,7 +1167,15 @@
 		}
 		if (setIdentity)
 			lcc.setIdentityValue(identityVal);
-    }
+                /*
+                 * find the value of the identity column from the user inserted value
+                 * and do a lcc.setIdentityValue(<user_value>);
+                 */
+                else if(setUserIdentity )
+                {
+                        lcc.setIdentityValue(user_autoinc);
+                } 
+ }
 
 	/*
 	 * Take the input row and return a new compact ExecRow

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql?rev=430381&r1=430380&r2=430381&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/autoincrement.sql
Thu Aug 10 06:43:20 2006
@@ -164,7 +164,7 @@
 					  y int);
 insert into ai_test (y) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
 
--- should see 20.
+-- should see 0.
 values IDENTITY_VAL_LOCAL();
 
 insert into ai_test (y) select y+10 from ai_test;



Mime
View raw message