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 bp...@apache.org on 2006/10/15 02:29:31 UTC

svn commit: r464078 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/org/apache/derbyTesting/functionTests/...

Author: bpendleton
Date: Sat Oct 14 17:29:29 2006
New Revision: 464078

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

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

The lookahead in the grammar of my previous patches did not work for some
parameter types. I have reworked the lookahead to use syntactic lookahead
similar to that used elsewhere in the grammar. I have included an additional
test that would have failed with the previous patch. I have run the
lang/functions.sql and lang/procedure.java using the various frameworks
without error.

Modified:
    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/procedure.out
    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/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=464078&r1=464077&r2=464078
==============================================================================
--- 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 17:29:29 2006
@@ -759,13 +759,29 @@
 	 * Determine whether the next sequence of tokens represents one of
 	 * the common (built-in) datatypes.
 	 *
+	 * @param checkFollowingToken true if additonal token for NATIONAL
+	 *        or LONG should be checked
 	 * @return	TRUE iff the next set of tokens names a common datatype
 	 */
 	boolean commonDatatypeName(boolean checkFollowingToken)
 	{
+	    return commonDatatypeName(1, checkFollowingToken);
+	}
+
+	/**
+	 * Determine whether a sequence of tokens represents one of
+	 * the common (built-in) datatypes.
+	 *
+	 * @param checkFollowingToken true if additonal token for NATIONAL
+	 *        or LONG should be checked
+	 * @param start starting token index of the sequence
+	 * @return	TRUE iff the next set of tokens names a common datatype
+	 */
+	boolean commonDatatypeName(int start, boolean checkFollowingToken)
+	{
 		boolean retval = false;
 
-		switch (getToken(1).kind)
+		switch (getToken(start).kind)
 		{
 		  case CHARACTER:
 		  case CHAR:
@@ -798,7 +814,7 @@
 		  case LONG:
 			if (checkFollowingToken == true)
 			{
-				switch (getToken(2).kind)
+				switch (getToken(start+1).kind)
 				{
 				  case VARCHAR:
 				  case NVARCHAR:
@@ -819,7 +835,7 @@
 		  case NATIONAL:
 			if (checkFollowingToken == true)
 			{
-				switch (getToken(2).kind)
+				switch (getToken(start+1).kind)
 				{
 				  case CHAR:
 				  case CHARACTER:
@@ -9838,10 +9854,11 @@
 }
 {
 	inout = inoutParameter()
-    // 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) ]
+	
+	// Lookahead needed because token could satisfy identifier and dataTypeDDL
+	[   LOOKAHEAD( { commonDatatypeName(2, false) })
+	    parameterName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true)
+	]
 	typeDescriptor = dataTypeDDL() 
 	{
 		list[0].addElement(parameterName);
@@ -9932,10 +9949,10 @@
 	Integer				inout;
 }
 {
-    // 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) ]
+	// Lookahead needed because token could satisfy identifier and dataTypeDDL
+	[   LOOKAHEAD( { commonDatatypeName(2, false) })
+	    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/procedure.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out?view=diff&rev=464078&r1=464077&r2=464078
==============================================================================
--- 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 17:29:29 2006
@@ -1014,6 +1014,7 @@
 testNoParameterNames
 noname(int,String) called
 noname(int,String) called
+noname(Timestamp,String) called
 MultipleRSAutoCommit: PASS. 
 MultipleRSNoCommit: PASS. 
 JIRA-491 Successful.

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=464078&r1=464077&r2=464078
==============================================================================
--- 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 17:29:29 2006
@@ -110,6 +110,9 @@
         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");
+        s.execute("CREATE PROCEDURE NONAME(TIMESTAMP, IN P2 VARCHAR(10)) LANGUAGE JAVA PARAMETER STYLE JAVA EXTERNAL NAME 'org.apache.derbyTesting.functionTests.util.ProcedureTest.noname2'");
+        s.execute("{call noname(current_timestamp, 'foo')}");
+        s.execute("DROP PROCEDURE NONAME");
     }
     
 	public static void testNegative(Connection conn) throws SQLException {

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=464078&r1=464077&r2=464078
==============================================================================
--- 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 17:29:29 2006
@@ -781,5 +781,9 @@
     public static void noname(int p1, String p2) {
         System.out.println("noname(int,String) called");
     }
+    
+    public static void noname2(Timestamp p1, String p2) {
+        System.out.println("noname(Timestamp,String) called");
+    }
 }