@Test public void testIllegalCursors() { checkFails( "select ^cursor^(select * from emps) from emps", "CURSOR expression encountered in illegal context"); checkFails( "call p(^cursor^(select * from emps))", "CURSOR expression encountered in illegal context"); checkFails( "select f(^cursor^(select * from emps)) from emps", "CURSOR expression encountered in illegal context"); }
@Test public void testIllegalCursors() { checkFails( "select ^cursor^(select * from emps) from emps", "CURSOR expression encountered in illegal context"); checkFails( "call p(^cursor^(select * from emps))", "CURSOR expression encountered in illegal context"); checkFails( "select f(^cursor^(select * from emps)) from emps", "CURSOR expression encountered in illegal context"); }
@Test public void testSelectFromBareExplicitTableFails() { // FIXME should fail at "emp" checkFails( "select * from ^table^ emp", "(?s).*Encountered \"table emp\" at .*"); checkFails( "select * from (^table^ (select empno from emp))", "(?s)Encountered \"table \\(\".*"); }
@Test public void testCaseExpressionFails() { // Missing 'END' checkFails( "select case col1 when 1 then 'one' ^from^ t", "(?s).*from.*"); // Wrong 'WHEN' checkFails( "select case col1 ^when1^ then 'one' end from t", "(?s).*when1.*"); }
@Test public void testCaseExpressionFails() { // Missing 'END' checkFails( "select case col1 when 1 then 'one' ^from^ t", "(?s).*from.*"); // Wrong 'WHEN' checkFails( "select case col1 ^when1^ then 'one' end from t", "(?s).*when1.*"); }
/** * In modern SQL, a query can occur almost everywhere that an expression * can. This test tests the few exceptions. */ @Test public void testQueryInIllegalContext() { checkFails( "select 0, multiset[^(^select * from emp), 2] from dept", "Query expression encountered in illegal context"); checkFails( "select 0, multiset[1, ^(^select * from emp), 2, 3] from dept", "Query expression encountered in illegal context"); }
@Test public void testBangEqualIsBad() { // Quoth www.ocelot.ca: // "Other relators besides '=' are what you'd expect if // you've used any programming language: > and >= and < and <=. The // only potential point of confusion is that the operator for 'not // equals' is <> as in BASIC. There are many texts which will tell // you that != is SQL's not-equals operator; those texts are false; // it's one of those unstampoutable urban myths." checkFails( "'abc'^!^=123", "Lexical error at line 1, column 6\\. Encountered: \"!\" \\(33\\), after : \"\""); }
@Test public void testBitStringNotImplemented() { // Bit-string is longer part of the SQL standard. We do not support it. checkFails( "select B^'1011'^ || 'foobar' from (values (true))", "(?s).*Encountered \"\\\\'1011\\\\'\" at line 1, column 9.*"); }
@Test public void testSelectList4() { checkFails( "select ^from^ emp", "(?s).*Encountered \"from\" at line .*"); }
@Test public void testUnionOfNonQueryFails() { checkFails( "select 1 from emp union ^2^ + 5", "Non-query expression encountered in illegal context"); }
@Test public void testEmptyValues() { checkFails( "select * from (values^(^))", "(?s).*Encountered \"\\( \\)\" at .*"); }
@Test public void testInvalidToken() { // Causes problems to the test infrastructure because the token mgr // throws a java.lang.Error. The usual case is that the parser throws // an exception. checkFails( "values (a^#^b)", "Lexical error at line 1, column 10\\. Encountered: \"#\" \\(35\\), after : \"\""); }
@Test public void testBangEqualIsBad() { // Quoth www.ocelot.ca: // "Other relators besides '=' are what you'd expect if // you've used any programming language: > and >= and < and <=. The // only potential point of confusion is that the operator for 'not // equals' is <> as in BASIC. There are many texts which will tell // you that != is SQL's not-equals operator; those texts are false; // it's one of those unstampoutable urban myths." checkFails( "'abc'^!^=123", "Lexical error at line 1, column 6\\. Encountered: \"!\" \\(33\\), after : \"\""); }
@Test public void testHavingBeforeGroupFails() { checkFails( "select deptno from emp having count(*) > 5 and deptno < 4 ^group^ by deptno, emp", "(?s).*Encountered \"group\" at .*"); }
@Test public void testWithFails() { checkFails("with femaleEmps as ^select^ * from emps where gender = 'F'\n" + "select deptno from femaleEmps", "(?s)Encountered \"select\" at .*"); }
@Test public void testInnerOuterJoinFails() { checkFails( "select * from a ^inner^ outer join b", "(?s).*Encountered \"inner outer\" at line 1, column 17.*"); }
@Test public void testParseNumberFails() { checkFails( "SELECT 0.5e1^.1^ from t", "(?s).*Encountered .*\\.1.* at line 1.*"); }
@Test public void testSelectList4() { checkFails( "select ^from^ emp", "(?s).*Encountered \"from\" at line .*"); }
@Test public void testTabStop() { check( "SELECT *\n\tFROM mytable", "SELECT *\n" + "FROM `MYTABLE`"); // make sure that the tab stops do not affect the placement of the // error tokens checkFails( "SELECT *\tFROM mytable\t\tWHERE x ^=^ = y AND b = 1", "(?s).*Encountered \"= =\" at line 1, column 32\\..*"); }
@Test public void testJoinUsing() { check( "select * from a join b using (x)", "SELECT *\n" + "FROM `A`\n" + "INNER JOIN `B` USING (`X`)"); checkFails( "select * from a join b using (^)^ where c = d", "(?s).*Encountered \"[)]\" at line 1, column 31.*"); }