Author: shawkins
Date: 2009-12-09 17:48:20 -0500 (Wed, 09 Dec 2009)
New Revision: 1631
Modified:
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java
trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
Log:
TEIID-898 adding more information to the invalid named param message. also adding a check
for duplicate params.
Modified:
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java 2009-12-09
21:41:41 UTC (rev 1630)
+++
trunk/engine/src/main/java/com/metamatrix/query/resolver/command/ExecResolver.java 2009-12-09
22:48:20 UTC (rev 1631)
@@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -118,9 +119,10 @@
while(oldParamIter.hasNext()) {
SPParameter param = (SPParameter) oldParamIter.next();
if(param.getExpression() != null) {
-
if (namedParameters) {
- inputExpressions.put(param.getName().toUpperCase(),
param.getExpression());
+ if (inputExpressions.put(param.getName().toUpperCase(),
param.getExpression()) != null) {
+ throw new
QueryResolverException(QueryPlugin.Util.getString("ExecResolver.duplicate_named_params",
param.getName().toUpperCase())); //$NON-NLS-1$
+ }
} else {
inputExpressions.put(new Integer(param.getIndex()),
param.getExpression());
}
@@ -159,6 +161,7 @@
// input parameters
paramIter = clonedMetadataParams.iterator();
int exprIndex = 1;
+ HashSet<String> expected = new HashSet<String>();
while(paramIter.hasNext()) {
SPParameter param = (SPParameter) paramIter.next();
if(param.getParameterType() == ParameterInfo.IN || param.getParameterType()
== ParameterInfo.INOUT) {
@@ -172,7 +175,8 @@
if (expr == null) {
expr = ResolverUtil.getDefault(param.getParameterSymbol(),
metadata);
param.setUsingDefault(true);
- }
+ expected.add(nameKey);
+ }
param.setExpression(expr);
} else {
Expression expr = (Expression)inputExpressions.remove(new
Integer(exprIndex));
@@ -184,7 +188,7 @@
// Check for leftovers, i.e. params entered by user w/ wrong/unknown names
if (namedParameters && !inputExpressions.isEmpty()) {
- throw new
QueryResolverException(QueryPlugin.Util.getString("ExecResolver.invalid_named_params",
inputExpressions.keySet())); //$NON-NLS-1$
+ throw new
QueryResolverException(QueryPlugin.Util.getString("ExecResolver.invalid_named_params",
inputExpressions.keySet(), expected)); //$NON-NLS-1$
}
// Create temporary metadata that defines a group based on either the stored
proc
Modified: trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties 2009-12-09
21:41:41 UTC (rev 1630)
+++ trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties 2009-12-09
22:48:20 UTC (rev 1631)
@@ -845,7 +845,8 @@
FunctionMethods.cant_execute_relate=The relate function may only be used in XML queries.
FunctionMethods.cant_execute_relateSource=The relateSource function may only be used in
XML relationship models and queries.
FunctionMethods.cant_execute_relateTarget=The relateTarget function may only be used in
XML relationship models and queries.
-ExecResolver.invalid_named_params=Invalid param name(s): {0}
+ExecResolver.invalid_named_params=Invalid param name(s): {0}. Name(s) of params without
explicit values: {1}
+ExecResolver.duplicate_named_params=Duplicate named param ''{0}''
ResolverUtil.required_param=Required parameter ''{0}'' has no value was
set or is an invalid parameter.
ResolverUtil.duplicateName=Cannot create group ''{0}'' with multiple
columns named ''{1}''
ResolverUtil.error_converting_value_type=Exception converting value {0} of type {1} to
expected type {2}
Modified: trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-12-09
21:41:41 UTC (rev 1630)
+++ trunk/engine/src/test/java/com/metamatrix/query/resolver/TestResolver.java 2009-12-09
22:48:20 UTC (rev 1631)
@@ -1055,6 +1055,10 @@
Object[] expectedParameterExpressions = new Object[] {new
Constant("xyz")};//$NON-NLS-1$
helpResolveExec("EXEC pm1.sq2(\"in\" = 'xyz')",
expectedParameterExpressions);//$NON-NLS-1$
}
+
+ @Test public void testExecNamedParamDup() {
+ helpResolveException("EXEC pm1.sq2(\"in\" = 'xyz',
\"in\" = 'xyz1')");//$NON-NLS-1$
+ }
/** Should get exception because param name is wrong. */
@Test public void testExecWrongParamName() {
Show replies by date