@Test public void testInvalidSelectStar() throws Exception { SQLParser parser = new SQLParser(new StringReader("select *,k from t where k in ( 1,2 )")); try { parser.parseStatement(); fail(); } catch (SQLException e) { assertEquals(SQLExceptionCode.MISMATCHED_TOKEN.getErrorCode(), e.getErrorCode()); } }
@Test public void testParsingStatementWithMissingToken() throws Exception { try { SQLParser parser = new SQLParser(new StringReader("select a b\n" + "where e = d\n")); parser.parseStatement(); fail("Should have caught exception."); } catch (SQLException e) { assertEquals(SQLExceptionCode.MISMATCHED_TOKEN.getErrorCode(), e.getErrorCode()); } }
@Test public void testInvalidTrailingCommaOnCreateTable() throws Exception { SQLParser parser = new SQLParser(new StringReader("create table foo (c1 varchar primary key, c2 varchar,)")); try { parser.parseStatement(); fail(); } catch (SQLException e) { assertEquals(SQLExceptionCode.MISMATCHED_TOKEN.getErrorCode(), e.getErrorCode()); } }
@Test public void testNegative1() throws Exception { SQLParser parser = new SQLParser( new StringReader( "select /*gatherSlowStats*/ count(1) core.search_name_lookup ind\n" + "where (ind.name = 'X')\n" + "and rownum <= 2000\n" + "and (ind.organization_id = '000000000000000')\n" + "and (ind.key_prefix = '00T')\n" + "and (ind.name_type = 't')")); try { parser.parseStatement(); fail(); } catch (SQLException e) { assertEquals(SQLExceptionCode.MISMATCHED_TOKEN.getErrorCode(), e.getErrorCode()); } }