@Test public void testExistsPredicateCriteria(){ Query q2 = exampleExists(false); helpTest("SELECT e1 FROM m.g2 WHERE Exists (SELECT e1 FROM m.g1)", //$NON-NLS-1$ "SELECT e1 FROM m.g2 WHERE EXISTS (SELECT e1 FROM m.g1)", //$NON-NLS-1$ q2); } static Query exampleExists(boolean semiJoin) {
@Test public void testSubquerySetCriteria0() { //test wrap up command with subquerySetCriteria Query outer = exampleIn(false); helpTest("SELECT a FROM db.g WHERE b IN (SELECT a FROM db.g WHERE a2 = 5)", //$NON-NLS-1$ "SELECT a FROM db.g WHERE b IN (SELECT a FROM db.g WHERE a2 = 5)", //$NON-NLS-1$ outer); }
/** SELECT a FROM db.g WHERE b = aString order by c desc*/ @Test public void testOrderByDesc(){ ArrayList<ElementSymbol> elements = new ArrayList<ElementSymbol>(); elements.add(new ElementSymbol("c")); //$NON-NLS-1$ ArrayList<Boolean> orderTypes = new ArrayList<Boolean>(); orderTypes.add(Boolean.FALSE); OrderBy orderBy = new OrderBy(elements, orderTypes); Query query = getOrderByQuery(orderBy); helpTest("SELECT a FROM db.g WHERE b = aString ORDER BY c desc", //$NON-NLS-1$ "SELECT a FROM db.g WHERE b = aString ORDER BY c DESC", //$NON-NLS-1$ query); } private Query getOrderByQuery(OrderBy orderBy) {
@Test public void testCommandStatement() throws Exception { Query query = sampleQuery(); Command sqlCmd = query; CommandStatement cmdStmt = new CommandStatement(sqlCmd); helpStmtTest("SELECT a1 FROM g WHERE a2 = 5;", "SELECT a1 FROM g WHERE a2 = 5;", //$NON-NLS-1$ //$NON-NLS-2$ cmdStmt); }
/** * Should only work for string literals, not with the keyword */ @Test public void testIncompleteTimestampDateLiteral() { helpException("DATE '2000-01-01 00:00'"); }
@Test public void testDropTable() { Drop drop = new Drop(); drop.setTable(new GroupSymbol("tempTable")); //$NON-NLS-1$ helpTest("DROP table tempTable", "DROP TABLE tempTable", drop); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testBreakStatement() throws Exception { Statement breakStmt = new BranchingStatement(); helpStmtTest("break;", "BREAK;", breakStmt); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testArrayParsing() throws Exception { TestParser.helpTestExpression("()", "()", new Array(new ArrayList<Expression>())); TestParser.helpTestExpression("(,)", "()", new Array(new ArrayList<Expression>())); TestParser.helpTestExpression("(1,)", "(1,)", new Array(Arrays.asList((Expression)new Constant(1)))); TestParser.helpTestExpression("(1,2)", "(1, 2)", new Array(Arrays.asList((Expression)new Constant(1), (Expression)new Constant(2)))); TestParser.helpTestExpression("(1,2,)", "(1, 2)", new Array(Arrays.asList((Expression)new Constant(1), (Expression)new Constant(2)))); }
@Test public void testCompoundNonJoinCriteriaInFromUWithIN() { Collection<Expression> values = new ArrayList<Expression>(); values.add(new Constant(new Integer(0))); values.add(new Constant(new Integer(1))); PredicateCriteria crit = new SetCriteria(new ElementSymbol("e2"), values); //$NON-NLS-1$ helpTestCompoundNonJoinCriteria("e2 IN (0, 1)", crit); //$NON-NLS-1$ }
/** SELECT a from db.g where (((b = x) and (a = 1000))) */ @Test public void testCompoundCompare4(){ helpTestCompoundCompare("SELECT a from db.g where (((b = x) and (a = 1000)))"); //$NON-NLS-1$ }
@Test public void testBlock() throws Exception { ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$ String type = new String("short"); //$NON-NLS-1$ DeclareStatement declStmt = new DeclareStatement(a, type); Statement stmt = declStmt; Block block = new Block(stmt); helpBlockTest("BEGIN DECLARE short a; END", "BEGIN"+"\n"+"DECLARE short a;"+"\n"+"END", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ block); }
/** SELECT * FROM g1 inner join g2 */ @Test public void testInvalidInnerJoin() { helpException("SELECT * FROM g1 inner join g2"); //$NON-NLS-1$ }
@Test public void testVariablesInExec(){ StoredProcedure storedQuery = new StoredProcedure(); storedQuery.setProcedureName("proc1"); //$NON-NLS-1$ SPParameter parameter = new SPParameter(1, new ElementSymbol("param1")); //$NON-NLS-1$ parameter.setParameterType(ParameterInfo.IN); storedQuery.setParameter(parameter); helpTest("Exec proc1(param1)", "EXEC proc1(param1)", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$ helpTest("execute proc1(param1)", "EXEC proc1(param1)", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testContinueStatement() throws Exception { BranchingStatement contStmt = new BranchingStatement(BranchingMode.CONTINUE); helpStmtTest("continue;", "CONTINUE;", contStmt); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testXmlElement() throws Exception { XMLElement f = new XMLElement("table", Arrays.asList((Expression)new Constant("x"))); helpTestExpression("xmlelement(name \"table\", 'x')", "XMLELEMENT(NAME \"table\", 'x')", f); }
@Test public void testDeclareStatementWithAssignment1() throws Exception { ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$ String type = new String("string"); //$NON-NLS-1$ DeclareStatement stmt = new DeclareStatement(a, type, new ScalarSubquery(sampleQuery())); helpStmtTest("DECLARE string a = SELECT a1 FROM g WHERE a2 = 5;","DECLARE string a = (SELECT a1 FROM g WHERE a2 = 5);", stmt); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testCompoundNonJoinCriteriaInFromWithComparisonCriteria() { CompareCriteria c2 = new CompareCriteria(new ElementSymbol("e2"), CompareCriteria.EQ, new Constant(new Integer(1))); //$NON-NLS-1$ helpTestCompoundNonJoinCriteria("e2 = 1", c2); //$NON-NLS-1$ }
/** SELECT a from db.g where (b = x and a = 1000) */ @Test public void testCompoundCompare2(){ helpTestCompoundCompare("SELECT a from db.g where (b = x and a = 1000)"); //$NON-NLS-1$ }
/** SELECT a FROM m.g GROUP BY a, b AS x */ @Test public void testFailAliasInHaving() { helpException("SELECT a FROM m.g GROUP BY a, b AS x"); //$NON-NLS-1$ }
/** SELECT a FROM db.g WHERE b = aString order by c,d*/ @Test public void testOrderBys(){ ArrayList<ElementSymbol> elements = new ArrayList<ElementSymbol>(); elements.add(new ElementSymbol("c")); //$NON-NLS-1$ elements.add(new ElementSymbol("d")); //$NON-NLS-1$ OrderBy orderBy = new OrderBy(elements); Query query = getOrderByQuery(orderBy); helpTest("SELECT a FROM db.g WHERE b = aString ORDER BY c,d", //$NON-NLS-1$ "SELECT a FROM db.g WHERE b = aString ORDER BY c, d", //$NON-NLS-1$ query); }