db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r463982 - in /db/derby/code/trunk/java: engine/org/apache/derby/catalog/types/ engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNet/ te...
Date Sat, 14 Oct 2006 17:00:55 GMT
Author: bpendleton
Date: Sat Oct 14 10:00:54 2006
New Revision: 463982

URL: http://svn.apache.org/viewvc?view=rev&rev=463982
Log:
DERBY-183: Allow unnamed parameters in CREATE FUNCTION

This patch was contributed by James F. Adams (derby@xemaps.com)

The patch does the following:

1) Modifies java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    a) Initializes parameterName to "" in procedureParameterDefinition
       and functionParameterDefinition
    b) Makes parameterName optional in procedureParameterDefinition
       and functionParameterDefinition

2) Modifies java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
   to ignore function and procedure parameter names equal to "" when
   checking for duplicate parameter names. 

Tests have been added to lang/functions.sql and lang/procedure.java. 

The parameter name is made optional by surrounding its production with [].

This changes the grammar from:

parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true)
  typeDescriptor = dataTypeDDL()

to:

        [ parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true) ]
        typeDescriptor = dataTypeDDL()

This results in a choice conflict because certain tokens satisfy both
identifier() and dataTypeDDL(). An additional token of lookahead resolves
this conflict. This results in:

        [ LOOKAHEAD(2) parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true) ]
        typeDescriptor = dataTypeDDL()

Expressing this in an alternate form such as:

        (
                parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true)
                typeDescriptor = dataTypeDDL()
        ) | typeDescriptor = dataTypeDDL()

still results in a choice conflict so I opted for the more compact form.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RoutineAliasInfo.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/jdk16/procedure.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/procedure.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/procedure.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk16/procedure.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/procedure.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/functions.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/functions.sql
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RoutineAliasInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RoutineAliasInfo.java?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RoutineAliasInfo.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/types/RoutineAliasInfo.java Sat
Oct 14 10:00:54 2006
@@ -34,7 +34,7 @@
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
 /**
- * Describe a r (procedure or function) alias.
+ * Describe a routine (procedure or function) alias.
  *
  * @see AliasInfo
  */
@@ -55,6 +55,11 @@
 	private int parameterCount;
 
 	private TypeDescriptor[]	parameterTypes;
+        /**
+         * Name of each parameter. As of DERBY 10.3, parameter names
+         * are optional. If the parameter is unnamed, parameterNames[i]
+         * is a string of length 0
+         */
 	private String[]			parameterNames;
 	/**
 		IN, OUT, INOUT
@@ -171,6 +176,12 @@
 	public int[] getParameterModes() {
 		return parameterModes;
 	}
+        /**
+         * Returns an array containing the names of the parameters.
+         * As of DERBY 10.3, parameter names are optional (see DERBY-183
+         * for more information). If the i-th parameter was unnamed,
+         * parameterNames[i] will contain a string of length 0.
+         */
 	public String[] getParameterNames() {
 		return parameterNames;
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/CreateAliasNode.java
Sat Oct 14 10:00:54 2006
@@ -168,7 +168,7 @@
 						System.arraycopy(names, 0, dupNameCheck, 0, paramCount);
 						java.util.Arrays.sort(dupNameCheck);
 						for (int dnc = 1; dnc < dupNameCheck.length; dnc++) {
-							if (dupNameCheck[dnc].equals(dupNameCheck[dnc - 1]))
+							if (! dupNameCheck[dnc].equals("") && dupNameCheck[dnc].equals(dupNameCheck[dnc
- 1]))
 								throw StandardException.newException(SQLState.LANG_DB2_DUPLICATE_NAMES, dupNameCheck[dnc],
getFullName());
 						}
 					}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Sat Oct
14 10:00:54 2006
@@ -9833,12 +9833,15 @@
 procedureParameterDefinition(Vector[] list) throws StandardException :
 {
 	DataTypeDescriptor	typeDescriptor;
-	String				parameterName;
+	String				parameterName = "";
 	Integer				inout;
 }
 {
 	inout = inoutParameter()
-	parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true) 
+    // Two tokens of LOOKAHEAD are necessary because certain tokens can be both
+    // an identifier() and a dataTypeDDL().  The extra token of lookahead resolves
+    // this choice conflict. 
+	[ LOOKAHEAD(2) parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true) ]
 	typeDescriptor = dataTypeDDL() 
 	{
 		list[0].addElement(parameterName);
@@ -9925,11 +9928,14 @@
 functionParameterDefinition(Vector[] list) throws StandardException :
 {
 	DataTypeDescriptor	typeDescriptor;
-	String				parameterName;
+	String				parameterName = "";
 	Integer				inout;
 }
 {
-	parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true) 
+    // Two tokens of LOOKAHEAD are necessary because certain tokens can be both
+    // an identifier() and a dataTypeDDL().  The extra token of lookahead resolves
+    // this choice conflict. 
+	[ LOOKAHEAD(2) parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true) ]
 	typeDescriptor = dataTypeDDL() 
 	{
 		list[0].addElement(parameterName);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/jdk16/procedure.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/jdk16/procedure.out?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/jdk16/procedure.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/jdk16/procedure.out
Sat Oct 14 10:00:54 2006
@@ -935,6 +935,7 @@
 CALL LITT.TY_DECIMAL ('12.34', ?) (42821) Columns of type 'DECIMAL' cannot hold values of
type 'CHAR'. 
 CALL LITT.TY_CHAR ('12.34', ?)=>12.34     <
 CALL LITT.TY_VARCHAR ('12.34', ?)=>12.34<
+testNoParameterNames
 JIRA-491 Successful.
 JIRA-492 successful -- no hang!
 testImplicitClose(): PASSED

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/procedure.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/procedure.out?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/procedure.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/procedure.out
Sat Oct 14 10:00:54 2006
@@ -935,6 +935,7 @@
 CALL LITT.TY_DECIMAL ('12.34', ?) (42821) Columns of type 'DECIMAL' cannot hold values of
type 'CHAR'. 
 CALL LITT.TY_CHAR ('12.34', ?)=>12.34     <
 CALL LITT.TY_VARCHAR ('12.34', ?)=>12.34<
+testNoParameterNames
 JIRA-491 Successful.
 JIRA-492 successful -- no hang!
 testImplicitClose(): PASSED

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/procedure.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/procedure.out?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/procedure.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk14/procedure.out
Sat Oct 14 10:00:54 2006
@@ -935,6 +935,7 @@
 CALL LITT.TY_DECIMAL ('12.34', ?) (42821) Columns of type 'DECIMAL' cannot hold values of
type 'CHAR'. 
 CALL LITT.TY_CHAR ('12.34', ?)=>12.34     <
 CALL LITT.TY_VARCHAR ('12.34', ?)=>12.34<
+testNoParameterNames
 MultipleRSAutoCommit: PASS. 
 MultipleRSNoCommit: PASS. 
 JIRA-491 Successful.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk16/procedure.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk16/procedure.out?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk16/procedure.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/jdk16/procedure.out
Sat Oct 14 10:00:54 2006
@@ -935,6 +935,7 @@
 CALL LITT.TY_DECIMAL ('12.34', ?) (42821) Columns of type 'DECIMAL' cannot hold values of
type 'CHAR'. 
 CALL LITT.TY_CHAR ('12.34', ?)=>12.34     <
 CALL LITT.TY_VARCHAR ('12.34', ?)=>12.34<
+testNoParameterNames
 MultipleRSAutoCommit: PASS. 
 MultipleRSNoCommit: PASS. 
 JIRA-491 Successful.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/procedure.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/procedure.out?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/procedure.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/procedure.out
Sat Oct 14 10:00:54 2006
@@ -935,6 +935,7 @@
 CALL LITT.TY_DECIMAL ('12.34', ?) (42821) Columns of type 'DECIMAL' cannot hold values of
type 'CHAR'. 
 CALL LITT.TY_CHAR ('12.34', ?)=>12.34     <
 CALL LITT.TY_VARCHAR ('12.34', ?)=>12.34<
+testNoParameterNames
 MultipleRSAutoCommit: PASS. 
 MultipleRSNoCommit: PASS. 
 JIRA-491 Successful.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/functions.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/functions.out?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/functions.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/functions.out
Sat Oct 14 10:00:54 2006
@@ -482,6 +482,23 @@
 0 rows inserted/updated/deleted
 ij> DROP TABLE SV_TAB;
 0 rows inserted/updated/deleted
+ij> -- function definition without parameter names are valid
+CREATE FUNCTION NONAME1(INT, INT) RETURNS INT EXTERNAL NAME 'java.lang.Math.max' LANGUAGE
JAVA PARAMETER STYLE JAVA;
+0 rows inserted/updated/deleted
+ij> CREATE FUNCTION NONAME2(P1 INT, INT) RETURNS INT EXTERNAL NAME 'java.lang.Math.max'
LANGUAGE JAVA PARAMETER STYLE JAVA;
+0 rows inserted/updated/deleted
+ij> VALUES NONAME1(99, -45);
+1          
+-----------
+99         
+ij> VALUES NONAME2(99, -45);
+1          
+-----------
+99         
+ij> DROP FUNCTION NONAME1;
+0 rows inserted/updated/deleted
+ij> DROP FUNCTION NONAME2;
+0 rows inserted/updated/deleted
 ij> -- check MODIFIES SQL DATA not allowed with FUNCTION
 CREATE FUNCTION COUNT_ROWS(P1 VARCHAR(128), P2 VARCHAR(128)) RETURNS INT
 MODIFIES SQL DATA

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out
Sat Oct 14 10:00:54 2006
@@ -1011,6 +1011,9 @@
 CALL LITT.TY_DECIMAL ('12.34', ?) (42821) Columns of type 'DECIMAL' cannot hold values of
type 'CHAR'. 
 CALL LITT.TY_CHAR ('12.34', ?)=>12.34     <
 CALL LITT.TY_VARCHAR ('12.34', ?)=>12.34<
+testNoParameterNames
+noname(int,String) called
+noname(int,String) called
 MultipleRSAutoCommit: PASS. 
 MultipleRSNoCommit: PASS. 
 JIRA-491 Successful.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/functions.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/functions.sql?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/functions.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/functions.sql
Sat Oct 14 10:00:54 2006
@@ -193,6 +193,16 @@
 
 DROP TABLE SV_TAB;
 
+-- function definition without parameter names are valid
+CREATE FUNCTION NONAME1(INT, INT) RETURNS INT EXTERNAL NAME 'java.lang.Math.max' LANGUAGE
JAVA PARAMETER STYLE JAVA;
+CREATE FUNCTION NONAME2(P1 INT, INT) RETURNS INT EXTERNAL NAME 'java.lang.Math.max' LANGUAGE
JAVA PARAMETER STYLE JAVA;
+
+VALUES NONAME1(99, -45);
+VALUES NONAME2(99, -45);
+
+DROP FUNCTION NONAME1;
+DROP FUNCTION NONAME2;
+
 -- check MODIFIES SQL DATA not allowed with FUNCTION
 CREATE FUNCTION COUNT_ROWS(P1 VARCHAR(128), P2 VARCHAR(128)) RETURNS INT
 MODIFIES SQL DATA

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java
Sat Oct 14 10:00:54 2006
@@ -87,6 +87,8 @@
 			testSQLControl(conn);
 			testLiterals(conn);
             
+            testNoParameterNames(conn);
+            
             multipleRSTests(conn);
                         jira_491_492(conn);
             testImplicitClose(conn);
@@ -98,6 +100,18 @@
 		
 	}
 
+    public static void testNoParameterNames(Connection conn) throws SQLException {
+        System.out.println("testNoParameterNames");
+        
+        Statement s = conn.createStatement();
+        s.execute("CREATE PROCEDURE NONAME(IN INT, IN VARCHAR(10)) LANGUAGE JAVA PARAMETER
STYLE JAVA EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.ProcedureTest.noname'");
+        s.execute("{call noname(1, 'foo')}");
+        s.execute("DROP PROCEDURE NONAME");
+        s.execute("CREATE PROCEDURE NONAME(IN INT, IN P2 VARCHAR(10)) LANGUAGE JAVA PARAMETER
STYLE JAVA EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.ProcedureTest.noname'");
+        s.execute("{call noname(1, 'foo')}");
+        s.execute("DROP PROCEDURE NONAME");
+    }
+    
 	public static void testNegative(Connection conn) throws SQLException {
 
 		System.out.println("testNegative");

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java?view=diff&rev=463982&r1=463981&r2=463982
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/ProcedureTest.java
Sat Oct 14 10:00:54 2006
@@ -777,5 +777,9 @@
 		ps.close();
 		conn.close();
 	}
+    
+    public static void noname(int p1, String p2) {
+        System.out.println("noname(int,String) called");
+    }
 }
 



Mime
View raw message