Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 15578 invoked from network); 16 Nov 2007 13:52:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Nov 2007 13:52:21 -0000 Received: (qmail 36773 invoked by uid 500); 16 Nov 2007 13:52:09 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 36751 invoked by uid 500); 16 Nov 2007 13:52:08 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 36740 invoked by uid 99); 16 Nov 2007 13:52:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Nov 2007 05:52:08 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Nov 2007 13:52:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5EFF61A9832; Fri, 16 Nov 2007 05:52:00 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r595662 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java Date: Fri, 16 Nov 2007 13:51:57 -0000 To: derby-commits@db.apache.org From: dag@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071116135200.5EFF61A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dag Date: Fri Nov 16 05:51:56 2007 New Revision: 595662 URL: http://svn.apache.org/viewvc?rev=595662&view=rev Log: DERBY-1749 Implement Bracketed SQL comments (/*...*/ comments) Patch Derby-1749-4.diff implements SQL feature T352 and adds a test. Thanks to James F. Adams for help with the change and for providing the test. I added some extra test cases. Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java (with props) 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/tests/lang/_Suite.java 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=595662&r1=595661&r2=595662&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 Fri Nov 16 05:51:56 2007 @@ -1696,6 +1696,8 @@ t.beginOffset = input_stream.getBeginOffset(); t.endOffset = input_stream.getEndOffset(); } + + int commentNestingDepth = 0; } SKIP : @@ -1708,7 +1710,24 @@ SKIP : { /* comments */ - "--" : IN_COMMENT + "--" : IN_COMMENT + | "/*" { commentNestingDepth = 1; } : IN_BRACKETED_COMMENT +} + + SKIP : +{ + "/*" { commentNestingDepth++; } +} + + SKIP : +{ + "*/" + { commentNestingDepth--; SwitchTo(commentNestingDepth == 0 ? DEFAULT : IN_BRACKETED_COMMENT); } +} + + SKIP : +{ + < ~[] > } SKIP : Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java?rev=595662&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java Fri Nov 16 05:51:56 2007 @@ -0,0 +1,141 @@ +/* + + Derby - Class org.apache.derbyTesting.functionTests.tests.lang.CreateTableFromQueryTest + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License +*/ +package org.apache.derbyTesting.functionTests.tests.lang; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.derbyTesting.junit.BaseJDBCTestCase; +import org.apache.derbyTesting.junit.CleanDatabaseTestSetup; +import org.apache.derbyTesting.junit.JDBC; +import org.apache.derbyTesting.junit.TestConfiguration; + +/** + * Test for comments. + */ +public final class CommentTest extends BaseJDBCTestCase { + private Statement stmt; + + /** + * Public constructor required for running test as standalone JUnit. + */ + public CommentTest(String name) + { + super(name); + } + + /** + * Create a suite of tests. + */ + public static Test suite() + { + return TestConfiguration.embeddedSuite(CommentTest.class); + } + + /** + * Some simple tests of bracketed comments. + */ + public void testBracketedComments() throws Exception + { + JDBC.assertFullResultSet( + stmt.executeQuery("/* a comment */ VALUES 1"), + new String [][] {{"1"}}); + + JDBC.assertFullResultSet( + stmt.executeQuery("VALUES 1 /* a comment */"), + new String [][] {{"1"}}); + + JDBC.assertFullResultSet( + stmt.executeQuery("VALUES /* a comment */ 1"), + new String [][] {{"1"}}); + + JDBC.assertFullResultSet( + stmt.executeQuery("VALUES /* a comment \n with newline */ 1"), + new String [][] {{"1"}}); + + JDBC.assertFullResultSet( + stmt.executeQuery("VALUES /* SELECT * from FOO */ 1"), + new String [][] {{"1"}}); + + JDBC.assertFullResultSet( + stmt.executeQuery("VALUES /* a comment /* nested comment */ */ 1"), + new String [][] {{"1"}}); + + JDBC.assertFullResultSet( + stmt.executeQuery( + "VALUES /*/* XXX /*/*/* deeply nested comment */*/*/YYY*/*/ 1"), + new String [][] {{"1"}}); + + // mix with eol-comments + JDBC.assertFullResultSet( + stmt.executeQuery( + "VALUES 1 --/*/* XXX /*/*/* deeply nested comment */*/*/YYY*/*/ 1"), + new String [][] {{"1"}}); + + JDBC.assertFullResultSet( + stmt.executeQuery( + "VALUES 1 --/*/* XXX /*/*/* deeply nested comment */*/*/YYY*/*/ 1--/*"), + new String [][] {{"1"}}); + + JDBC.assertFullResultSet( + stmt.executeQuery("VALUES /* a comment --\n with newline */ 1"), + new String [][] {{"1"}}); + + JDBC.assertFullResultSet( + stmt.executeQuery("VALUES /* a comment -- */ 1"), + new String [][] {{"1"}}); + + JDBC.assertFullResultSet( + stmt.executeQuery("VALUES /* a comment \n-- */ 1"), + new String [][] {{"1"}}); + + // mix with string quotes + JDBC.assertFullResultSet( + stmt.executeQuery("VALUES '/* a comment \n-- */'"), + new String [][] {{"/* a comment \n-- */"}}); + } + + /** + * Set the fixture up. + */ + protected void setUp() throws SQLException + { + getConnection().setAutoCommit(false); + stmt = createStatement(); + } + + /** + * Tear-down the fixture. + */ + protected void tearDown() throws Exception + { + stmt.close(); + super.tearDown(); + } +} Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CommentTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=595662&r1=595661&r2=595662&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java Fri Nov 16 05:51:56 2007 @@ -121,6 +121,7 @@ suite.addTest(Bug5054Test.suite()); suite.addTest(Bug4356Test.suite()); suite.addTest(SynonymTest.suite()); + suite.addTest(CommentTest.suite()); // Add the XML tests, which exist as a separate suite // so that users can "run all XML tests" easily.