db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1429197 [1/3] - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/...
Date Sat, 05 Jan 2013 03:13:35 GMT
Author: dag
Date: Sat Jan  5 03:13:35 2013
New Revision: 1429197

URL: http://svn.apache.org/viewvc?rev=1429197&view=rev
Log:
DERBY-5945 Inappropriate error message when calling a procedure as a function (as if it had
a return value) 

Committed patch "DERBY-5945". It adds new usage checks for a procedure
called as a function and vice versa, two new eror messages,
LANG_PROC_USED_AS_FUNCTION (42Y03.S.3) and LANG_FUNCTION_USED_AS_PROC
(42Y03.S.4) as well as new test cases to LangProcedureTest.

The patch also does some cleanup of LangProcedureTest and activates to
be run as a standard part of the regressions in the lang suite.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outparams.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangProcedureTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java?rev=1429197&r1=1429196&r2=1429197&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StaticMethodCallNode.java
Sat Jan  5 03:13:35 2013
@@ -231,18 +231,65 @@ public class StaticMethodCallNode extend
                 return this;
             }
 
-			if (ad == null && noSchema && !forCallStatement)
-			{
-				// Resolve to a built-in SYSFUN function but only
-				// if this is a function call and the call
-				// was not qualified. E.g. COS(angle). The
-				// SYSFUN functions are not in SYSALIASES but
-				// an in-memory table, set up in DataDictioanryImpl.
-				sd = getSchemaDescriptor("SYSFUN", true);
-				
-				resolveRoutine(fromList, subqueryList, aggregateVector, sd);
-			}
-	
+            SchemaDescriptor savedSd = sd;
+
+            if (ad == null && noSchema && !forCallStatement)
+            {
+                // Resolve to a built-in SYSFUN function but only
+                // if this is a function call and the call
+                // was not qualified. E.g. COS(angle). The
+                // SYSFUN functions are not in SYSALIASES but
+                // an in-memory table, set up in DataDictioanryImpl.
+                sd = getSchemaDescriptor("SYSFUN", true);
+
+                resolveRoutine(fromList, subqueryList, aggregateVector, sd);
+            }
+
+            if (ad == null) {
+                // DERBY-2927. Check if a procedure is being used as a
+                // function, or vice versa.
+                sd = savedSd;
+
+                if (!forCallStatement) {
+                    // Procedure as function. We have JDBC escape syntax which
+                    // may entice users to try that:
+                    //      "{? = CALL <proc>}"
+                    //
+                    // but we don't currently support it (it's not std SQL
+                    // either). By resolving it as a procedure we can give a
+                    // better error message.
+                    //
+                    // Note that with the above escape syntax one *can* CALL a
+                    // function, though:
+                    //      "{? = CALL <func>}"
+                    //
+                    // but such cases have already been resolved above.
+
+                    forCallStatement = true; // temporarily: resolve
+                                             // as procedure
+                    resolveRoutine(fromList, subqueryList, aggregateVector, sd);
+                    forCallStatement = false; // restore it
+
+                    if (ad != null) {
+                        throw StandardException.newException
+                            (SQLState.LANG_PROC_USED_AS_FUNCTION,
+                             procedureName);
+                    }
+                } else {
+                    // Maybe a function is being CALLed ?
+                    forCallStatement = false; // temporarily: resolve
+                                              // as function
+                    resolveRoutine(fromList, subqueryList, aggregateVector, sd);
+                    forCallStatement = true; // restore it
+
+                    if (ad != null) {
+                        throw StandardException.newException
+                            (SQLState.LANG_FUNCTION_USED_AS_PROC,
+                             procedureName);
+                    }
+                }
+            }
+
 			/* Throw exception if no routine found */
 			if (ad == null)
 			{

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1429197&r1=1429196&r2=1429197&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Sat Jan  5 03:13:35
2013
@@ -2278,6 +2278,18 @@ Guide.
             </msg>
 
             <msg>
+                <name>42Y03.S.3</name>
+                <text>'{0}' is a procedure but it is being used as a function.</text>
+                <arg>statement</arg>
+            </msg>
+
+            <msg>
+                <name>42Y03.S.4</name>
+                <text>'{0}' is a function but it is being called as a procedure.</text>
+                <arg>statement</arg>
+            </msg>
+
+            <msg>
                 <name>42Y04</name>
                 <text>Cannot create a procedure or function with EXTERNAL NAME '{0}'
because it is not a list separated by periods. The expected format is &lt;full java path&gt;.&lt;method
name&gt;.</text>
                 <arg>name</arg>

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1429197&r1=1429196&r2=1429197&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Sat Jan  5 03:13:35 2013
@@ -942,6 +942,8 @@ public interface SQLState {
 	String LANG_NO_SUCH_METHOD_ALIAS                                   = "42Y03.S.0";
 	String LANG_NO_SUCH_PROCEDURE                                      = "42Y03.S.1";
 	String LANG_NO_SUCH_FUNCTION                                       = "42Y03.S.2";
+    String LANG_PROC_USED_AS_FUNCTION                                  = "42Y03.S.3";
+    String LANG_FUNCTION_USED_AS_PROC                                  = "42Y03.S.4";
 	String LANG_INVALID_FULL_STATIC_METHOD_NAME                        = "42Y04";
 	String LANG_NO_SUCH_FOREIGN_KEY                                    = "42Y05";
 	//String LANG_METHOD_ALIAS_NOT_FOUND                                 = "42Y06";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outparams.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outparams.out?rev=1429197&r1=1429196&r2=1429197&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outparams.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outparams.out
Sat Jan  5 03:13:35 2013
@@ -7,7 +7,7 @@ Expected exception java.sql.SQLException
 Expected exception java.sql.SQLException: Return output parameters cannot be set.
 Expected exception java.sql.SQLException: Return output parameters cannot be set.
 Expected exception on setString() on a return output param: java.sql.SQLException: Return
output parameters cannot be set.
-Expected exception on prepare of '? = call returnsNothing()': java.sql.SQLException: 'RETURNSNOTHING'
is not recognized as a function or procedure.
+Expected exception on prepare of '? = call returnsNothing()': java.sql.SQLException: 'RETURNSNOTHING'
is a procedure but it is being used as a function.
 ==============================================
 TESTING NULLS
 ==============================================



Mime
View raw message