Author: kahatlen Date: Tue Sep 8 08:34:40 2009 New Revision: 812387 URL: http://svn.apache.org/viewvc?rev=812387&view=rev Log: DERBY-4369: Give a more useful error message when join specification is missing Made the join specification optional in the grammar. This makes the parser go further before failing because of a missing ON clause, and existing code that emits a more useful error message can be reached. Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/innerjoin.out db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outerjoin.out Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=812387&r1=812386&r2=812387&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Tue Sep 8 08:34:40 2009 @@ -9202,19 +9202,12 @@ TableOperatorNode ton = null; Object[] onOrUsingClause = null; ResultColumnList usingClause = null; - ValueNode onClause; + ValueNode onClause = null; } { - /* RESOLVE - If we ever support NATURAL JOIN then we will need to break up - * this rule. Right now the joinSpecification() is non-optional. This - * allows us to build the Join tree from left to right. With NATURAL JOINS - * there is no joinSpecification() and we would want to build the tree from - * right to left. - */ - //[ ] [ joinType = joinType() ] rightRSN = tableReferenceTypes(nestedInParens) - onOrUsingClause = joinSpecification(leftRSN, rightRSN) + [ onOrUsingClause = joinSpecification(leftRSN, rightRSN) ] { /* If NATURAL OR UNION is specified, then no joinSpecification() * is required, otherwise it is required. @@ -9226,8 +9219,11 @@ */ /* Figure out whether an ON or USING clause was used */ - onClause = (ValueNode) onOrUsingClause[ON_CLAUSE]; - usingClause = (ResultColumnList) onOrUsingClause[USING_CLAUSE]; + if (onOrUsingClause != null) + { + onClause = (ValueNode) onOrUsingClause[ON_CLAUSE]; + usingClause = (ResultColumnList) onOrUsingClause[USING_CLAUSE]; + } if (onClause == null && usingClause == null) { Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out?rev=812387&r1=812386&r2=812387&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out Tue Sep 8 08:34:40 2009 @@ -1192,28 +1192,16 @@ ij> -- CROSS JOIN not supported in both Cloudscape and DB2 mode and that is why rather than getting feature not implemented, we will get syntax error -- (1) CROSS JOIN should be disabled in FROM clause of SELECT statement SELECT * FROM t1 CROSS JOIN t2; -ERROR 42X01: Syntax error: Encountered "" at line 3, column 30. -Issue the 'help' command for general information on IJ command syntax. -Any unrecognized commands are treated as potential SQL commands and executed directly. -Consult your DBMS server reference documentation for details of the SQL syntax supported by your server. +ERROR 42Y11: A join specification is required with the 'INNER JOIN' clause. ij> -- (2) USING should be disabled in INNER JOIN of SELECT statement SELECT * FROM t1 INNER JOIN t2 USING (col1); -ERROR 42X01: Syntax error: Encountered "USING" at line 2, column 32. -Issue the 'help' command for general information on IJ command syntax. -Any unrecognized commands are treated as potential SQL commands and executed directly. -Consult your DBMS server reference documentation for details of the SQL syntax supported by your server. +ERROR 42Y11: A join specification is required with the 'INNER JOIN' clause. ij> -- (3) USING should be disabled in INNER JOIN of SELECT statement SELECT * FROM t1 LEFT OUTER JOIN t2 USING (col1); -ERROR 42X01: Syntax error: Encountered "USING" at line 2, column 37. -Issue the 'help' command for general information on IJ command syntax. -Any unrecognized commands are treated as potential SQL commands and executed directly. -Consult your DBMS server reference documentation for details of the SQL syntax supported by your server. +ERROR 42Y11: A join specification is required with the 'LEFT OUTER JOIN' clause. ij> -- (4) USING should be disabled in INNER JOIN of SELECT statement SELECT * FROM t1 RIGHT OUTER JOIN t2 USING (col1); -ERROR 42X01: Syntax error: Encountered "USING" at line 2, column 38. -Issue the 'help' command for general information on IJ command syntax. -Any unrecognized commands are treated as potential SQL commands and executed directly. -Consult your DBMS server reference documentation for details of the SQL syntax supported by your server. +ERROR 42Y11: A join specification is required with the 'RIGHT OUTER JOIN' clause. ij> -- (5) TRUE and FALSE constants should be disabled in WHERE clause of SELECT statement SELECT * FROM t1 INNER JOIN t2 ON t1.col1 = t2.col1 WHERE true; ERROR 42X01: Syntax error: true. Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/innerjoin.out URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/innerjoin.out?rev=812387&r1=812386&r2=812387&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/innerjoin.out (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/innerjoin.out Tue Sep 8 08:34:40 2009 @@ -40,21 +40,12 @@ -- no join clause select * from t1 join t2; -ERROR 42X01: Syntax error: Encountered "" at line 4, column 24. -Issue the 'help' command for general information on IJ command syntax. -Any unrecognized commands are treated as potential SQL commands and executed directly. -Consult your DBMS server reference documentation for details of the SQL syntax supported by your server. +ERROR 42Y11: A join specification is required with the 'INNER JOIN' clause. ij> select * from t1 inner join t2; -ERROR 42X01: Syntax error: Encountered "" at line 1, column 30. -Issue the 'help' command for general information on IJ command syntax. -Any unrecognized commands are treated as potential SQL commands and executed directly. -Consult your DBMS server reference documentation for details of the SQL syntax supported by your server. +ERROR 42Y11: A join specification is required with the 'INNER JOIN' clause. ij> -- empty column list select * from t1 join t2 using (); -ERROR 42X01: Syntax error: Encountered "using" at line 2, column 26. -Issue the 'help' command for general information on IJ command syntax. -Any unrecognized commands are treated as potential SQL commands and executed directly. -Consult your DBMS server reference documentation for details of the SQL syntax supported by your server. +ERROR 42Y11: A join specification is required with the 'INNER JOIN' clause. ij> -- non-boolean join clause select * from t1 join t2 on 1; ERROR 42Y12: The ON clause of a JOIN is a 'INTEGER' expression. It must be a BOOLEAN expression. Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outerjoin.out URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outerjoin.out?rev=812387&r1=812386&r2=812387&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outerjoin.out (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/outerjoin.out Tue Sep 8 08:34:40 2009 @@ -62,15 +62,9 @@ Consult your DBMS server reference documentation for details of the SQL syntax supported by your server. ij> -- no join clause select * from t1 left outer join t2; -ERROR 42X01: Syntax error: Encountered "" at line 2, column 35. -Issue the 'help' command for general information on IJ command syntax. -Any unrecognized commands are treated as potential SQL commands and executed directly. -Consult your DBMS server reference documentation for details of the SQL syntax supported by your server. +ERROR 42Y11: A join specification is required with the 'LEFT OUTER JOIN' clause. ij> select * from t1 right outer join t2; -ERROR 42X01: Syntax error: Encountered "" at line 1, column 36. -Issue the 'help' command for general information on IJ command syntax. -Any unrecognized commands are treated as potential SQL commands and executed directly. -Consult your DBMS server reference documentation for details of the SQL syntax supported by your server. +ERROR 42Y11: A join specification is required with the 'RIGHT OUTER JOIN' clause. ij> -- positive tests select t1.c1 from t1 left outer join t2 on t1.c1 = t2.c1; C1