Author: shawkins
Date: 2009-02-25 16:59:42 -0500 (Wed, 25 Feb 2009)
New Revision: 503
Removed:
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidateCriteriaVisitor.java
trunk/engine/src/test/java/com/metamatrix/query/validator/TestCriteriaValidator.java
Modified:
trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
Log:
TEIID-384 removing ValidateCriteriaVisitor. Allowing the validator to enforce type based
restrictions.
Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java 2009-02-25
20:18:40 UTC (rev 502)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java 2009-02-25
21:59:42 UTC (rev 503)
@@ -101,7 +101,6 @@
import com.metamatrix.query.util.ContextProperties;
import com.metamatrix.query.util.TypeRetrievalUtil;
import com.metamatrix.query.validator.AbstractValidationVisitor;
-import com.metamatrix.query.validator.ValidateCriteriaVisitor;
import com.metamatrix.query.validator.ValidationVisitor;
import com.metamatrix.query.validator.Validator;
import com.metamatrix.query.validator.ValidatorFailure;
@@ -357,10 +356,6 @@
AbstractValidationVisitor visitor = new ValidationVisitor();
validateWithVisitor(visitor, metadata, command, false);
- // Create criteria validation visitor
- visitor = new ValidateCriteriaVisitor();
- validateWithVisitor(visitor, metadata, command, true);
-
if (validateVisibility) {
// Create model visibility validation visitor
visitor = new ModelVisibilityValidationVisitor(this.vdbService, this.vdbName,
this.vdbVersion);
Deleted:
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidateCriteriaVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidateCriteriaVisitor.java 2009-02-25
20:18:40 UTC (rev 502)
+++
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidateCriteriaVisitor.java 2009-02-25
21:59:42 UTC (rev 503)
@@ -1,196 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.validator;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.api.exception.query.QueryMetadataException;
-import com.metamatrix.query.QueryPlugin;
-import com.metamatrix.query.metadata.SupportConstants;
-import com.metamatrix.query.sql.lang.AbstractCompareCriteria;
-import com.metamatrix.query.sql.lang.BetweenCriteria;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.Criteria;
-import com.metamatrix.query.sql.lang.DependentSetCriteria;
-import com.metamatrix.query.sql.lang.IsNullCriteria;
-import com.metamatrix.query.sql.lang.MatchCriteria;
-import com.metamatrix.query.sql.lang.Query;
-import com.metamatrix.query.sql.lang.SetCriteria;
-import com.metamatrix.query.sql.lang.SubqueryCompareCriteria;
-import com.metamatrix.query.sql.lang.SubquerySetCriteria;
-import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.GroupSymbol;
-import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
-import com.metamatrix.query.util.ErrorMessageKeys;
-
-/**
- * Validates that the elements of various criteria are allowed (by metadata)
- * to be used in the criteria in the way that they are being used.
- */
-public class ValidateCriteriaVisitor extends AbstractValidationVisitor {
-
- // State during validation
- private boolean isXML = false; // only used for Query commands
-
- public ValidateCriteriaVisitor() {
- super();
- }
-
- public void reset() {
- super.reset();
- this.isXML = false;
- }
-
- // ############### Visitor methods for language objects ##################
-
- public void visit(Query obj) {
- if(isXMLCommand(obj)) {
- this.isXML = true;
- }
- }
-
- public void visit(BetweenCriteria obj) {
- checkUncomparableType(obj.getExpression());
- validateCompareElements(obj);
- }
-
- public void visit(CompareCriteria obj) {
- validateCompareCriteria(obj);
- }
-
- private void validateCompareCriteria(AbstractCompareCriteria obj) {
- checkUncomparableTypes(obj.getLeftExpression(), obj.getRightExpression());
- validateCompareElements(obj);
- }
-
- public void visit(IsNullCriteria obj) {
- validateCompareElements(obj);
- }
-
- public void visit(MatchCriteria obj) {
- validateLikeElements(obj);
- }
-
- public void visit(SetCriteria obj) {
- checkUncomparableType(obj.getExpression());
- validateCompareElements(obj);
- }
-
- public void visit(SubquerySetCriteria obj) {
- checkUncomparableType(obj.getExpression());
- validateCompareElements(obj);
- }
-
- public void visit(DependentSetCriteria obj) {
- checkUncomparableType(obj.getExpression());
- validateCompareElements(obj);
- }
-
- public void visit(SubqueryCompareCriteria obj) {
- validateCompareCriteria(obj);
- }
-
- protected void validateCompareElements(Criteria obj) {
- if(isXML) {
- return;
- }
-
- Collection elements = ElementCollectorVisitor.getElements(obj, true);
- Collection badCompareVars =
validateElementsSupport(filterPhysicalElements(elements),
SupportConstants.Element.SEARCHABLE_COMPARE );
-
- if(badCompareVars != null) {
-
handleValidationError(QueryPlugin.Util.getString("ValidateCriteriaVistitor.element_not_comparable",
badCompareVars), badCompareVars); //$NON-NLS-1$
- }
- }
-
- private void checkUncomparableType(Expression expression) {
- if(ValidationVisitor.isNonComparable(expression)) {
-
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0027,
expression), expression);
- }
- }
-
- private void checkUncomparableTypes(Expression leftExpr, Expression rightExpr) {
- List uncomparableExpr = null;
- if(ValidationVisitor.isNonComparable(leftExpr)) {
- uncomparableExpr = new ArrayList();
- uncomparableExpr.add(leftExpr);
- }
- if(ValidationVisitor.isNonComparable(rightExpr)) {
- if(uncomparableExpr == null) {
- uncomparableExpr = new ArrayList();
- }
- uncomparableExpr.add(rightExpr);
- }
-
- if(uncomparableExpr != null) {
-
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0027,
uncomparableExpr), uncomparableExpr);
- }
- }
-
- protected void validateLikeElements(MatchCriteria obj) {
- if(isXML) {
- return;
- }
-
- Collection badLikeVars = validateElementsSupport(
-
filterPhysicalElements(ElementCollectorVisitor.getElements(obj.getLeftExpression(),
true)),
- SupportConstants.Element.SEARCHABLE_LIKE );
-
- if(badLikeVars != null) {
-
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0028,
badLikeVars), badLikeVars);
- }
- }
-
- /**
- * Filter out physical elements as criteria restrictions on physical elements
- * are stating the capabilities of the source, not access restrictions.
- * @param elements Collection of ElementSymbol
- * @return Collection of ElementSymbol with physical elements filtered out
- */
- private Collection filterPhysicalElements(Collection allElements) {
- List filtered = new ArrayList();
-
- try {
- Iterator iter = allElements.iterator();
- while(iter.hasNext()) {
- ElementSymbol elem = (ElementSymbol) iter.next();
- GroupSymbol group = elem.getGroupSymbol();
- if(getMetadata().isVirtualGroup(group.getMetadataID())) {
- filtered.add(elem);
- }
- }
- } catch(QueryMetadataException e) {
- handleException(e);
- } catch(MetaMatrixComponentException e) {
- handleException(e);
- }
-
- return filtered;
- }
-
-}
Modified:
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-02-25
20:18:40 UTC (rev 502)
+++
trunk/engine/src/main/java/com/metamatrix/query/validator/ValidationVisitor.java 2009-02-25
21:59:42 UTC (rev 503)
@@ -231,6 +231,9 @@
}
public void visit(SubquerySetCriteria obj) {
+ if (isNonComparable(obj.getExpression())) {
+ handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0027),obj);
+ }
this.validateRowLimitFunctionNotInInvalidCriteria(obj);
Collection projSymbols = obj.getCommand().getProjectedSymbols();
@@ -957,6 +960,9 @@
* @since 4.3
*/
public void visit(BetweenCriteria obj) {
+ if (isNonComparable(obj.getExpression())) {
+
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0027),obj);
+ }
this.validateRowLimitFunctionNotInInvalidCriteria(obj);
}
@@ -989,6 +995,9 @@
* @since 4.3
*/
public void visit(SetCriteria obj) {
+ if (isNonComparable(obj.getExpression())) {
+
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0027),obj);
+ }
this.validateRowLimitFunctionNotInInvalidCriteria(obj);
}
@@ -997,6 +1006,9 @@
* @since 4.3
*/
public void visit(SubqueryCompareCriteria obj) {
+ if (isNonComparable(obj.getLeftExpression())) {
+
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0027),obj);
+ }
this.validateRowLimitFunctionNotInInvalidCriteria(obj);
}
@@ -1043,5 +1055,12 @@
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.drop_of_nontemptable",
drop.getTable()), drop); //$NON-NLS-1$
}
}
+
+ @Override
+ public void visit(CompareCriteria obj) {
+ if (isNonComparable(obj.getLeftExpression())) {
+
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0027),obj);
+ }
+ }
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java 2009-02-25
20:18:40 UTC (rev 502)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/Validator.java 2009-02-25
21:59:42 UTC (rev 503)
@@ -44,10 +44,6 @@
throws MetaMatrixComponentException {
ValidatorReport report1 = Validator.validate(object, metadata, new
ValidationVisitor(), false);
- if (validateCriteria) {
- ValidatorReport report2 = Validator.validate(object, metadata, new
ValidateCriteriaVisitor(), true);
- report1.addItems(report2.getItems());
- }
return report1;
}
Deleted:
trunk/engine/src/test/java/com/metamatrix/query/validator/TestCriteriaValidator.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/validator/TestCriteriaValidator.java 2009-02-25
20:18:40 UTC (rev 502)
+++
trunk/engine/src/test/java/com/metamatrix/query/validator/TestCriteriaValidator.java 2009-02-25
21:59:42 UTC (rev 503)
@@ -1,48 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.query.validator;
-
-import junit.framework.TestCase;
-
-public class TestCriteriaValidator extends TestCase {
-
- public TestCriteriaValidator(String name) {
- super(name);
- }
-
- public void testClobEquals() {
- TestValidator.helpValidate("SELECT * FROM test.group where e4 =
'1'", new String[] {"e4", "'1'"},
TestValidator.exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- /**
- * Should not fail since the update changing set is not really criteria
- */
- public void testUpdateWithClob() {
- TestValidator.helpValidate("update test.group set e4 = ?", new String[]
{}, TestValidator.exampleMetadata2()); //$NON-NLS-1$
- }
-
- public void testBlobLessThan() {
- TestValidator.helpValidate("SELECT * FROM test.group where e3 < ?",
new String[] {"e3", "?"}, TestValidator.exampleMetadata2());
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
-}
Modified: trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-02-25
20:18:40 UTC (rev 502)
+++
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-02-25
21:59:42 UTC (rev 503)
@@ -54,16 +54,8 @@
import com.metamatrix.query.resolver.QueryResolver;
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.lang.Command;
-import com.metamatrix.query.sql.lang.CompareCriteria;
-import com.metamatrix.query.sql.lang.From;
-import com.metamatrix.query.sql.lang.Query;
import com.metamatrix.query.sql.lang.SPParameter;
-import com.metamatrix.query.sql.lang.Select;
-import com.metamatrix.query.sql.symbol.Constant;
import com.metamatrix.query.sql.symbol.ElementSymbol;
-import com.metamatrix.query.sql.symbol.Expression;
-import com.metamatrix.query.sql.symbol.ExpressionSymbol;
-import com.metamatrix.query.sql.symbol.Function;
import com.metamatrix.query.sql.symbol.GroupSymbol;
import com.metamatrix.query.sql.visitor.SQLStringVisitor;
import com.metamatrix.query.unittest.FakeMetadataFacade;
@@ -362,14 +354,12 @@
try {
ValidatorReport report = Validator.validate(command, metadata);
//System.out.println("\nReport = \n" + report);
- ValidatorReport report2 = Validator.validate(command, metadata, new
ValidateCriteriaVisitor(), true);
ValidatorReport report3 = Validator.validate(command, metadata, new
ValueValidationVisitor(), true);
// Get invalid objects from report
Collection actualObjs = new ArrayList();
report.collectInvalidObjects(actualObjs);
- report2.collectInvalidObjects(actualObjs);
report3.collectInvalidObjects(actualObjs);
// Compare expected and actual objects
@@ -382,7 +372,7 @@
}
if(expectedStrings.size() == 0 && actualStrings.size() > 0) {
- fail("Expected no failures but got some: " +
report.getFailureMessage() + ", " + report2.getFailureMessage() + ", "
+ report3.getFailureMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ fail("Expected no failures but got some: " +
report.getFailureMessage() + ", " + report3.getFailureMessage()); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
} else if(actualStrings.size() == 0 && expectedStrings.size() > 0)
{
fail("Expected some failures but got none for sql = " +
command); //$NON-NLS-1$
} else {
@@ -454,47 +444,31 @@
}
public void testValidateCompare1() {
- helpValidate("SELECT e2 FROM vTest.vMap WHERE e2 = 'a'", new
String[] {"e2"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpValidate("SELECT e2 FROM vTest.vMap WHERE e2 = 'a'", new
String[] {}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
- public void testValidateCompare2() {
- helpValidate("SELECT e2 FROM vTest.vMap WHERE e2 IS NULL", new String[]
{"e2"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testValidateCompare3() {
- helpValidate("SELECT e2 FROM vTest.vMap WHERE e2 IN ('a')", new
String[] {"e2"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
public void testValidateCompare4() {
- helpValidate("SELECT e3 FROM vTest.vMap WHERE e3 LIKE 'a'", new
String[] {"e3"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpValidate("SELECT e3 FROM vTest.vMap WHERE e3 LIKE 'a'", new
String[] {}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
- public void testValidateCompare5() {
- helpValidate("SELECT e2 FROM vTest.vMap WHERE e2 BETWEEN 1000 AND
2000", new String[] {"e2"}, exampleMetadata()); //$NON-NLS-1$
//$NON-NLS-2$
- }
-
public void testValidateCompare6() {
helpValidate("SELECT e0 FROM vTest.vMap WHERE e0 BETWEEN 1000 AND
2000", new String[] {}, exampleMetadata()); //$NON-NLS-1$
}
- public void testValidateCompareInHaving1() {
- helpValidate("SELECT e2 FROM vTest.vMap GROUP BY e2 HAVING e2 =
'a'", new String[] {"e2"}, exampleMetadata()); //$NON-NLS-1$
//$NON-NLS-2$
- }
-
public void testValidateCompareInHaving2() {
- helpValidate("SELECT e2 FROM vTest.vMap GROUP BY e2 HAVING e2 IS NULL",
new String[] {"e2"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpValidate("SELECT e2 FROM vTest.vMap GROUP BY e2 HAVING e2 IS NULL",
new String[] {}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testValidateCompareInHaving3() {
- helpValidate("SELECT e2 FROM vTest.vMap GROUP BY e2 HAVING e2 IN
('a')", new String[] {"e2"}, exampleMetadata()); //$NON-NLS-1$
//$NON-NLS-2$
+ helpValidate("SELECT e2 FROM vTest.vMap GROUP BY e2 HAVING e2 IN
('a')", new String[] {}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testValidateCompareInHaving4() {
- helpValidate("SELECT e3 FROM vTest.vMap GROUP BY e3 HAVING e3 LIKE
'a'", new String[] {"e3"}, exampleMetadata()); //$NON-NLS-1$
//$NON-NLS-2$
+ helpValidate("SELECT e3 FROM vTest.vMap GROUP BY e3 HAVING e3 LIKE
'a'", new String[] {}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testValidateCompareInHaving5() {
- helpValidate("SELECT e2 FROM vTest.vMap GROUP BY e2 HAVING e2 BETWEEN 1000
AND 2000", new String[] {"e2"}, exampleMetadata()); //$NON-NLS-1$
//$NON-NLS-2$
+ helpValidate("SELECT e2 FROM vTest.vMap GROUP BY e2 HAVING e2 BETWEEN 1000
AND 2000", new String[] {}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testInvalidAggregate1() {
@@ -1048,11 +1022,11 @@
}
public void testValidateSubquery1() {
- helpValidate("SELECT e2 FROM (SELECT e2 FROM vTest.vMap WHERE e2 =
'a') AS x", new String[] {"e2"}, exampleMetadata()); //$NON-NLS-1$
//$NON-NLS-2$
+ helpValidate("SELECT e2 FROM (SELECT e2 FROM vTest.vMap WHERE e2 =
'a') AS x", new String[] {}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testValidateSubquery2() {
- helpValidate("SELECT e2 FROM (SELECT e3 FROM vTest.vMap) AS x, vTest.vMap
WHERE e2 = 'a'", new String[] {"e2"}, exampleMetadata());
//$NON-NLS-1$ //$NON-NLS-2$
+ helpValidate("SELECT e2 FROM (SELECT e3 FROM vTest.vMap) AS x, vTest.vMap
WHERE e2 = 'a'", new String[] {}, exampleMetadata()); //$NON-NLS-1$
//$NON-NLS-2$
}
public void testValidateSubquery3() {
@@ -1064,11 +1038,11 @@
}
public void testValidateExistsSubquery() {
- helpValidate("SELECT e2 FROM test.group2 WHERE EXISTS (SELECT e2 FROM
vTest.vMap WHERE e2 = 'a')", new String[] {"e2"},
exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpValidate("SELECT e2 FROM test.group2 WHERE EXISTS (SELECT e2 FROM
vTest.vMap WHERE e2 = 'a')", new String[] {}, exampleMetadata());
//$NON-NLS-1$ //$NON-NLS-2$
}
public void testValidateScalarSubquery() {
- helpValidate("SELECT e2, (SELECT e1 FROM vTest.vMap WHERE e2 = '3')
FROM test.group2", new String[] {"e1", "e2"}, exampleMetadata());
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ helpValidate("SELECT e2, (SELECT e1 FROM vTest.vMap WHERE e2 = '3')
FROM test.group2", new String[] {"e1"}, exampleMetadata()); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
}
public void testValidateAnyCompareSubquery() {
@@ -1662,71 +1636,8 @@
public void testValidateObjectInComparison() throws Exception {
String sql = "SELECT IntKey FROM BQT1.SmallA WHERE ObjectValue = 5";
//$NON-NLS-1$
- FakeMetadataFacade metadata = FakeMetadataFactory.exampleBQTCached();
- String[] expectedStringArray = new String[] { "ObjectValue",
"'xyz'"}; //$NON-NLS-1$ //$NON-NLS-2$
-
- // Parse and modify to add object literal - this is a hack to set up this test
- // which would really be done using a prepared statement in the server (with
setObject()).
- Query command = (Query) QueryParser.getQueryParser().parseCommand(sql);
- CompareCriteria crit = (CompareCriteria) command.getCriteria();
- crit.setRightExpression(new Constant("xyz", Object.class));
//$NON-NLS-1$
-
- // Resolve
- QueryResolver.resolveCommand(command, metadata);
-
- // Validate
- ValidatorReport report = Validator.validate(command, metadata, new
ValidateCriteriaVisitor(), true);
- Collection actualObjs = new ArrayList();
- report.collectInvalidObjects(actualObjs);
-
- // Compare expected and actual objects
- Set expectedStrings = new HashSet(Arrays.asList(expectedStringArray));
- Set actualStrings = new HashSet();
- Iterator objIter = actualObjs.iterator();
- while(objIter.hasNext()) {
- LanguageObject obj = (LanguageObject) objIter.next();
- actualStrings.add(SQLStringVisitor.getSQLString(obj));
- }
-
- if(expectedStrings.size() == 0 && actualStrings.size() > 0) {
- fail("Expected no failures but got some: " +
report.getFailureMessage()); //$NON-NLS-1$
- } else if(actualStrings.size() == 0 && expectedStrings.size() > 0) {
- fail("Expected some failures but got none for sql = " + command);
//$NON-NLS-1$
- } else {
- assertEquals("Expected and actual sets of strings are not the same:
", expectedStrings, actualStrings); //$NON-NLS-1$
- }
}
- public void testValidateObjectInFunction() throws Exception {
- FakeMetadataFacade metadata = FakeMetadataFactory.exampleBQTCached();
-
- Query query = new Query();
- Select select = new Select();
- select.addSymbol(new ExpressionSymbol("e1", new
Constant("x"))); //$NON-NLS-1$//$NON-NLS-2$
- query.setSelect(select);
-
- GroupSymbol group = new GroupSymbol("BQT1.SmallA"); //$NON-NLS-1$
- group.setMetadataID(metadata.getGroupID(group.getName()));
- From from = new From();
- from.addGroup(group);
- query.setFrom(from);
-
- CompareCriteria crit = new CompareCriteria();
- ElementSymbol elem = new ElementSymbol("BQT1.SmallA.ObjectValue");
//$NON-NLS-1$
- elem.setMetadataID(metadata.getElementID(elem.getName()));
- elem.setType(Object.class);
- elem.setGroupSymbol(group);
- Function f = new Function("fake", new Expression[] { elem });
//$NON-NLS-1$
- f.setType(Integer.class);
- crit.setLeftExpression(f);
- crit.setRightExpression(new Constant(new Integer(5)));
- query.setCriteria(crit);
-
- // Validate
- ValidatorReport report = Validator.validate(query, metadata, new
ValidateCriteriaVisitor(), true);
- assertEquals(0, report.getItems().size());
- }
-
public void testValidateAssignmentWithFunctionOnParameter_InServer() throws
Exception{
String sql = "EXEC pm1.vsp36(5)"; //$NON-NLS-1$
QueryMetadataInterface metadata = FakeMetadataFactory.example1Cached();
@@ -1829,7 +1740,7 @@
QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
// Validate
- helpValidate(sql, new String[] {"BQT1.SmallA.ObjectValue",
"BQT2.SmallB.ObjectValue"}, metadata); //$NON-NLS-1$ //$NON-NLS-2$
+ helpValidate(sql, new String[] {"BQT1.SmallA.ObjectValue =
BQT2.SmallB.ObjectValue"}, metadata); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testDefect16772() throws Exception{
@@ -2091,5 +2002,36 @@
Command command = helpResolve(procedure, metadata);
helpRunValidator(command, new String[] {"variables"}, metadata);
//$NON-NLS-1$
}
+
+ public void testClobEquals() {
+ TestValidator.helpValidate("SELECT * FROM test.group where e4 =
'1'", new String[] {"e4 = '1'"},
TestValidator.exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ /**
+ * Should not fail since the update changing set is not really criteria
+ */
+ public void testUpdateWithClob() {
+ TestValidator.helpValidate("update test.group set e4 = ?", new String[]
{}, TestValidator.exampleMetadata2()); //$NON-NLS-1$
+ }
+ public void testBlobLessThan() {
+ TestValidator.helpValidate("SELECT * FROM test.group where e3 < ?",
new String[] {"e3 < ?"}, TestValidator.exampleMetadata2()); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ public void testValidateCompare2() {
+ helpValidate("SELECT e2 FROM test.group WHERE e4 IS NULL", new String[]
{}, exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testValidateCompare3() {
+ helpValidate("SELECT e2 FROM test.group WHERE e4 IN ('a')", new
String[] {"e4 IN ('a')"}, exampleMetadata2()); //$NON-NLS-1$
//$NON-NLS-2$
+ }
+
+ public void testValidateCompare5() {
+ helpValidate("SELECT e2 FROM test.group WHERE e4 BETWEEN '1' AND
'2'", new String[] {"e4 BETWEEN '1' AND '2'"},
exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testValidateCompareInHaving1() {
+ helpValidate("SELECT e1 FROM test.group GROUP BY e1 HAVING convert(e1, clob)
= 'a'", new String[] {"convert(e1, clob) = 'a'"},
exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
}