db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r1772493 - in /db/derby/code/branches/10.13: ./ java/engine/org/apache/derby/impl/sql/compile/ java/testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Sat, 03 Dec 2016 22:28:31 GMT
Author: bpendleton
Date: Sat Dec  3 22:28:31 2016
New Revision: 1772493

URL: http://svn.apache.org/viewvc?rev=1772493&view=rev
Log:
DERBY-6918: Problem with schema name containing a period

Merged: svn merge -r 1772427:1772428 https://svn.apache.org/repos/asf/db/derby/code/trunk

No merge conflicts; no additional changes.

Modified:
    db/derby/code/branches/10.13/   (props changed)
    db/derby/code/branches/10.13/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
    db/derby/code/branches/10.13/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
    db/derby/code/branches/10.13/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForeignKeysDeferrableTest.java

Propchange: db/derby/code/branches/10.13/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Dec  3 22:28:31 2016
@@ -1,4 +1,4 @@
 /db/derby/code/branches/10.7:1061570,1061578,1082235
 /db/derby/code/branches/10.8:1177474,1234973,1464951
 /db/derby/code/branches/10.9:1373148
-/db/derby/code/trunk:1063809,1763024
+/db/derby/code/trunk:1063809,1763024,1772428

Modified: db/derby/code/branches/10.13/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.13/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java?rev=1772493&r1=1772492&r2=1772493&view=diff
==============================================================================
--- db/derby/code/branches/10.13/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
(original)
+++ db/derby/code/branches/10.13/java/engine/org/apache/derby/impl/sql/compile/DMLModStatementNode.java
Sat Dec  3 22:28:31 2016
@@ -95,6 +95,7 @@ abstract class DMLModStatementNode exten
 	private ValueNode		checkConstraints;
 
 	/* Info required to perform referential actions */
+	protected String[] fkSchemaNames; // referencing schema names.
 	protected String[] fkTableNames; // referencing table names.
 	protected int[] fkRefActions;    //type of referential actions 
 	protected ColumnDescriptorList[]  fkColDescriptors;
@@ -908,6 +909,7 @@ abstract class DMLModStatementNode exten
         int[]                               raRules;
         boolean[]                           deferrable;
         UUID[]                              fkIds;
+		ArrayList<String>              refSchemaNames = new ArrayList<String>(1);
 		ArrayList<String>              refTableNames = new ArrayList<String>(1);
 		ArrayList<Long>               refIndexConglomNum = new ArrayList<Long>(1);
 		ArrayList<Integer>            refActions = new ArrayList<Integer>(1);
@@ -988,7 +990,8 @@ abstract class DMLModStatementNode exten
 					{
 						//find  the referencing  table Name
 						fktd = fkcd.getTableDescriptor();
-						refTableNames.add(fktd.getSchemaName() + "." + fktd.getName());
+						refSchemaNames.add(fktd.getSchemaName());
+						refTableNames.add(fktd.getName());
                         refActions.add(Integer.valueOf(raRules[inner]));
 						//find the referencing column name required for update null.
 						refColumns = fkcd.getReferencedColumns();
@@ -1056,6 +1059,7 @@ abstract class DMLModStatementNode exten
 		if (size > 0)
 		{
 			fkTableNames = new String[size];
+			fkSchemaNames = new String[size];
 			fkRefActions  = new int[size];
 			fkColDescriptors = new ColumnDescriptorList[size];
 			fkIndexConglomNumbers = new long[size];
@@ -1063,6 +1067,7 @@ abstract class DMLModStatementNode exten
 			for (int i = 0; i < size; i++)
 			{
 				fkTableNames[i] = refTableNames.get(i);
+				fkSchemaNames[i] = refSchemaNames.get(i);
 				fkRefActions[i]  = (refActions.get(i)).intValue();
 				fkColDescriptors[i] =
 					refColDescriptors.get(i);

Modified: db/derby/code/branches/10.13/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.13/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java?rev=1772493&r1=1772492&r2=1772493&view=diff
==============================================================================
--- db/derby/code/branches/10.13/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
(original)
+++ db/derby/code/branches/10.13/java/engine/org/apache/derby/impl/sql/compile/DeleteNode.java
Sat Dec  3 22:28:31 2016
@@ -368,7 +368,9 @@ class DeleteNode extends DMLModStatement
 					dependentNodes = new StatementNode[noDependents];
 					for(int i =0 ; i < noDependents ; i ++)
 					{
-						dependentNodes[i] = getDependentTableNode(fkTableNames[i],
+						dependentNodes[i] = getDependentTableNode(
+															  fkSchemaNames[i],
+															  fkTableNames[i],
 															  fkRefActions[i],
 															  fkColDescriptors[i]);
 						dependentNodes[i].bindStatement();
@@ -735,22 +737,19 @@ class DeleteNode extends DMLModStatement
 	 * DML (UPDATE or DELETE) on the dependent tables. 
 	 * Following function returns the DML Node for the dependent table.
 	 */
-	private StatementNode getDependentTableNode(String tableName, int refAction,
+	private StatementNode getDependentTableNode(String schemaName, String tableName, int refAction,
 												ColumnDescriptorList cdl) throws StandardException
 	{
         DMLModStatementNode node = null;
 
-		int index = tableName.indexOf('.');
-		String schemaName = tableName.substring(0 , index);
-		String tName = tableName.substring(index+1);
 		if(refAction == StatementType.RA_CASCADE)
 		{
-			node = getEmptyDeleteNode(schemaName , tName);
+			node = getEmptyDeleteNode(schemaName , tableName);
 		}
 
 		if(refAction == StatementType.RA_SETNULL)
 		{
-			node = getEmptyUpdateNode(schemaName , tName, cdl);
+			node = getEmptyUpdateNode(schemaName , tableName, cdl);
 		}
 
         // The dependent node should be marked as such, and it should inherit

Modified: db/derby/code/branches/10.13/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForeignKeysDeferrableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.13/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForeignKeysDeferrableTest.java?rev=1772493&r1=1772492&r2=1772493&view=diff
==============================================================================
--- db/derby/code/branches/10.13/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForeignKeysDeferrableTest.java
(original)
+++ db/derby/code/branches/10.13/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ForeignKeysDeferrableTest.java
Sat Dec  3 22:28:31 2016
@@ -1350,4 +1350,56 @@ public class ForeignKeysDeferrableTest e
             assertTrue( dsicve.getConstraintName().startsWith( "SQL" ) );
         }
     }
+
+    /* Regression test for DERBY-6918, which is not directly related
+     * to deferrable foreign key constraints. But this was a convenient
+     * and simple place to add the regression test.
+     */
+    public void testDerby6918()
+                throws SQLException
+    {
+        Statement s = createStatement();
+        s.execute("create schema \"1.a\"");
+        s.execute("create table \"1.a\".\"role\" " +
+                   "( \"id\" integer generated always as identity," +
+                   "  \"name\" varchar(255) not null)" );
+
+        s.execute("alter table \"1.a\".\"role\" " +
+                  "  add constraint \"role_pk\" primary key (\"id\")");
+
+        s.execute("create table \"1.a\".\"user\"" +
+                  " ( \"id\" integer generated always as identity," +
+                  "   \"name\" varchar(255) not null)");
+
+        s.execute("alter table \"1.a\".\"user\" " +
+                  "  add constraint \"user_pk\" primary key (\"id\")");
+
+        s.execute("create table \"1.a\".\"user_role\" " +
+                  " ( \"role\" integer not null," +
+                  "   \"user\" integer not null)");
+
+        s.execute("alter table \"1.a\".\"user_role\"" +
+                  " add constraint \"user_role_fk1\" " +
+                  "     foreign key (\"role\") " +
+                  "     references \"1.a\".\"role\" (\"id\")" +
+                  "     on delete cascade");
+
+        s.execute("alter table \"1.a\".\"user_role\"" +
+                  " add constraint \"user_role_fk2\"" +
+                  "     foreign key (\"user\")" +
+                  "     references \"1.a\".\"user\" (\"id\")" +
+                  "     on delete cascade");
+
+        s.execute("alter table \"1.a\".\"user_role\"" +
+                  "  add constraint \"user_role_u1\"" +
+                  "      unique (\"user\", \"role\")");
+
+        s.execute("insert into \"1.a\".\"role\" (\"name\") values ('r1')");
+        s.execute("insert into \"1.a\".\"user\" (\"name\") values ('u1')");
+        s.execute("insert into \"1.a\".\"user_role\" (\"role\",\"user\") values (1,1)");
+
+        s.execute("select * from \"1.a\".\"user\"");
+
+        s.execute("delete from \"1.a\".\"user\"");
+    }
 }



Mime
View raw message