db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r329320 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/DerbyNet/ testing/org/apache/derbyTesting/functionT...
Date Fri, 28 Oct 2005 22:13:14 GMT
Author: djd
Date: Fri Oct 28 15:13:05 2005
New Revision: 329320

URL: http://svn.apache.org/viewcvs?rev=329320&view=rev
Log:
DERBY-660 Disable  RETURNS NULL ON NULL INPUT for a procedure. Attempt to provide a
better error message than MISSING ELEMENT when a procedure clause is missing.

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/DerbyNet/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/procedure.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=329320&r1=329319&r2=329320&view=diff
==============================================================================
--- 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 Fri Oct
28 15:13:05 2005
@@ -155,8 +155,16 @@
 public class SQLParser
 {
 	private static final String[] SAVEPOINT_CLAUSE_NAMES = {"UNIQUE", "ON ROLLBACK RETAIN LOCKS",
"ON ROLLBACK RETAIN CURSORS"};
-	private static final String[] PROCEDURE_CLAUSE_NAMES =
+	private static final String[] ROUTINE_CLAUSE_NAMES =
 		{null, "SPECIFIC", "RESULT SET", "LANGUAGE", "EXTERNAL NAME", "PARAMETER STYLE", "SQL",
"ON NULL INPUT"};
+	/**
+	   Clauses required for Java routines. Numbers correspond
+	   to offsets in ROUTINE_CLAUSE_NAMES.
+	   3 - "LANGUAGE"
+	   4 - "EXTERNAL NAME"
+	   5 - "PARAMETER STYLE"
+	*/
+	private static final int[] JAVA_ROUTINE_CLAUSES = {3,4,5};
 	private static final String[] TEMPORARY_TABLE_CLAUSE_NAMES = {"NOT LOGGED", "ON COMMIT",
"ON ROLLBACK"};
 	/* The default length of a char or bit if the length is omitted */
 	private static final int	DEFAULT_STRING_COLUMN_LENGTH = 1;
@@ -1560,6 +1568,27 @@
                                                 ReuseFactory.getInteger( intervalType),
                                                 getContextManager());
     }
+    
+    /**
+        Check to see if the required claues have been added
+        to a procedure or function defintion.
+        
+        @param required int array of require clauses
+        @param the array of declared clauses.
+    */
+    void checkRequiredRoutineClause(int[] required, Object[] clauses)
+        throws StandardException
+    {
+        for (int i = 0; i < required.length; i++)
+        {
+            int re = required[i];
+            if (clauses[re] == null)
+            {
+                throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR,
+				 ROUTINE_CLAUSE_NAMES[re]);
+		    }
+		}
+    }
 }
 
 PARSER_END(SQLParser)
@@ -9016,9 +9045,7 @@
 		procedureElements[0] = procedureParameterList()
 		( routineElement(true, procedureElements) ) +
 		{
-			// some of the procedure elements are mandatory
-		    if ((procedureElements[3] == null) || (procedureElements[4] == null) || (procedureElements[5]
== null))
-				throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR, "MISSING ELEMENT");
+		    checkRequiredRoutineClause(JAVA_ROUTINE_CLAUSES, procedureElements);
 
 			return getCreateAliasNode(
 							procedureName,
@@ -9063,8 +9090,7 @@
 			clauseValue = ReuseFactory.getShort(RoutineAliasInfo.MODIFIES_SQL_DATA); clausePosition
= 6;
 		}
 
-	|   clauseValue = calledOnNullInput() {  clausePosition = 7; }
-
+	|   clauseValue = calledOnNullInput(isProcedure) { clausePosition = 7; }
 	)
 
 	{
@@ -9072,7 +9098,7 @@
 			// check for repeated clause
 			if (routineElements[clausePosition] != null) {
 
-				String which = PROCEDURE_CLAUSE_NAMES[clausePosition];
+				String which = ROUTINE_CLAUSE_NAMES[clausePosition];
 				throw StandardException.newException(SQLState.LANG_DB2_MULTIPLE_ELEMENTS, which);
 			}
 				
@@ -9081,14 +9107,20 @@
 	}
 }
 
-Boolean calledOnNullInput() :
+Boolean calledOnNullInput(boolean isProcedure) throws StandardException :
 {
 	Boolean calledOnNull;
 }
 {
 	(
 		<CALLED> { calledOnNull = Boolean.TRUE; }
-		| <RETURNS> <NULL> { calledOnNull = Boolean.FALSE; }
+		| <RETURNS> <NULL> {
+		   if (isProcedure)
+		     throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR,
+		             "RETURNS NULL ON NULL INPUT");
+		   
+		   calledOnNull = Boolean.FALSE;
+		}
 		
 	) <ON> <NULL> <INPUT>
 	{
@@ -9184,10 +9216,8 @@
 		<RETURNS> functionElements[8] = dataTypeCommon() 
 		( routineElement(false, functionElements) ) +
 		{
-			// some of the elements are mandatory
-		    if ((functionElements[3] == null) || (functionElements[4] == null) || (functionElements[5]
== null))
-				throw StandardException.newException(SQLState.LANG_SYNTAX_ERROR, "MISSING ELEMENT");
-
+		    checkRequiredRoutineClause(JAVA_ROUTINE_CLAUSES, functionElements);
+		    
 			return getCreateAliasNode(
 							functionName,
 							(String) functionElements[4],

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/procedure.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/procedure.out?rev=329320&r1=329319&r2=329320&view=diff
==============================================================================
--- 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
Fri Oct 28 15:13:05 2005
@@ -22,19 +22,21 @@
 create procedure missing01()
 EXPECTED SQL Exception: (42X01) Syntax error: Encountered "<EOF>" at line 1, column
28.
 create procedure missing02() language java
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: EXTERNAL NAME.
 create procedure missing03() language java parameter style java
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: EXTERNAL NAME.
 create procedure missing04() language java external name 'foo.bar'
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: PARAMETER STYLE.
 create procedure missing05() parameter style java
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
 create procedure missing06() parameter style java external name 'foo.bar'
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
 create procedure missing07() external name 'goo.bar'
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
 create procedure missing08() dynamic result sets 1
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
+create procedure nullinput2() returns null on null input language java parameter style java
external name 'foo.bar'
+EXPECTED SQL Exception: (42X01) Syntax error: RETURNS NULL ON NULL INPUT.
 create procedure NO_BLOB(IN P1 BLOB(3k)) language java parameter style java external name
'no.blob'
 EXPECTED SQL Exception: (42962) Long column type column or parameter 'P1' not permitted in
declared global temporary tables or procedure definitions. 
 create procedure NO_CLOB(IN P1 CLOB(3k)) language java parameter style java external name
'no.clob'

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/procedure.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/procedure.out?rev=329320&r1=329319&r2=329320&view=diff
==============================================================================
--- 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
Fri Oct 28 15:13:05 2005
@@ -22,19 +22,21 @@
 create procedure missing01()
 EXPECTED SQL Exception: (42X01) Syntax error: Encountered "<EOF>" at line 1, column
28.
 create procedure missing02() language java
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: EXTERNAL NAME.
 create procedure missing03() language java parameter style java
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: EXTERNAL NAME.
 create procedure missing04() language java external name 'foo.bar'
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: PARAMETER STYLE.
 create procedure missing05() parameter style java
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
 create procedure missing06() parameter style java external name 'foo.bar'
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
 create procedure missing07() external name 'goo.bar'
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
 create procedure missing08() dynamic result sets 1
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
+create procedure nullinput2() returns null on null input language java parameter style java
external name 'foo.bar'
+EXPECTED SQL Exception: (42X01) Syntax error: RETURNS NULL ON NULL INPUT.
 create procedure NO_BLOB(IN P1 BLOB(3k)) language java parameter style java external name
'no.blob'
 EXPECTED SQL Exception: (42962) Long column type column or parameter 'P1' not permitted in
declared global temporary tables or procedure definitions. 
 create procedure NO_CLOB(IN P1 CLOB(3k)) language java parameter style java external name
'no.clob'

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/procedure.out?rev=329320&r1=329319&r2=329320&view=diff
==============================================================================
--- 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
Fri Oct 28 15:13:05 2005
@@ -22,19 +22,21 @@
 create procedure missing01()
 EXPECTED SQL Exception: (42X01) Syntax error: Encountered "<EOF>" at line 1, column
28.
 create procedure missing02() language java
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: EXTERNAL NAME.
 create procedure missing03() language java parameter style java
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: EXTERNAL NAME.
 create procedure missing04() language java external name 'foo.bar'
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: PARAMETER STYLE.
 create procedure missing05() parameter style java
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
 create procedure missing06() parameter style java external name 'foo.bar'
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
 create procedure missing07() external name 'goo.bar'
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
 create procedure missing08() dynamic result sets 1
-EXPECTED SQL Exception: (42X01) Syntax error: MISSING ELEMENT.
+EXPECTED SQL Exception: (42X01) Syntax error: LANGUAGE.
+create procedure nullinput2() returns null on null input language java parameter style java
external name 'foo.bar'
+EXPECTED SQL Exception: (42X01) Syntax error: RETURNS NULL ON NULL INPUT.
 create procedure NO_BLOB(IN P1 BLOB(3k)) language java parameter style java external name
'no.blob'
 EXPECTED SQL Exception: (42962) Long column type column or parameter 'P1' not permitted in
declared global temporary tables or procedure definitions. 
 create procedure NO_CLOB(IN P1 CLOB(3k)) language java parameter style java external name
'no.clob'

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/procedure.java?rev=329320&r1=329319&r2=329320&view=diff
==============================================================================
--- 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
Fri Oct 28 15:13:05 2005
@@ -134,6 +134,10 @@
 		statementExceptionExpected(s, "create procedure missing07() external name 'goo.bar'");
 		statementExceptionExpected(s, "create procedure missing08() dynamic result sets 1");
 		//statementExceptionExpected(s, "create procedure missing09() specific name fred");
+		
+		// RETURNS NULL ON NULL INPUT not allowed in procedures.
+		statementExceptionExpected(s, "create procedure nullinput2() returns null on null input
language java parameter style java external name 'foo.bar'");
+		
 
 
 		// no BLOB/CLOB/ long parameters



Mime
View raw message