Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 91272 invoked from network); 14 May 2010 09:00:56 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 14 May 2010 09:00:56 -0000 Received: (qmail 30065 invoked by uid 500); 14 May 2010 09:00:56 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 29995 invoked by uid 500); 14 May 2010 09:00:56 -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 29988 invoked by uid 99); 14 May 2010 09:00:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 May 2010 09:00:55 +0000 X-ASF-Spam-Status: No, hits=-1526.9 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 May 2010 09:00:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2032523889D7; Fri, 14 May 2010 09:00:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r944159 - in /db/derby/code/branches/10.6: ./ java/engine/org/apache/derby/vti/Restriction.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/RestrictedVTITest.java Date: Fri, 14 May 2010 09:00:34 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100514090034.2032523889D7@eris.apache.org> Author: kahatlen Date: Fri May 14 09:00:33 2010 New Revision: 944159 URL: http://svn.apache.org/viewvc?rev=944159&view=rev Log: DERBY-4654: Restriction.toSQL() doesn't escape special characters Merged fix from trunk (revision 944152). Modified: db/derby/code/branches/10.6/ (props changed) db/derby/code/branches/10.6/java/engine/org/apache/derby/vti/Restriction.java db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RestrictedVTITest.java Propchange: db/derby/code/branches/10.6/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Fri May 14 09:00:33 2010 @@ -1 +1 @@ -/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031 +/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,944152 Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/vti/Restriction.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/vti/Restriction.java?rev=944159&r1=944158&r2=944159&view=diff ============================================================================== --- db/derby/code/branches/10.6/java/engine/org/apache/derby/vti/Restriction.java (original) +++ db/derby/code/branches/10.6/java/engine/org/apache/derby/vti/Restriction.java Fri May 14 09:00:33 2010 @@ -21,7 +21,7 @@ package org.apache.derby.vti; import java.io.Serializable; -import java.sql.SQLException; +import org.apache.derby.iapi.util.IdUtil; /**

@@ -40,9 +40,6 @@ public abstract class Restriction implem */ public abstract String toSQL(); - /** Utility method to double quote a string */ - protected String doubleQuote( String raw ) { return "\"" + raw + "\""; } - /** Utility method to parenthesize an expression */ protected String parenthesize( String raw ) { return "( " + raw + " )"; } @@ -236,7 +233,7 @@ public abstract class Restriction implem { StringBuffer buffer = new StringBuffer(); - buffer.append( doubleQuote( _columnName ) ); + buffer.append( IdUtil.normalToDelimited( _columnName ) ); buffer.append( " " + OPERATOR_SYMBOLS[ _comparisonOperator ] + " " ); if ( _constantOperand != null ) { buffer.append( _constantOperand ); } Modified: db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RestrictedVTITest.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RestrictedVTITest.java?rev=944159&r1=944158&r2=944159&view=diff ============================================================================== --- db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RestrictedVTITest.java (original) +++ db/derby/code/branches/10.6/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RestrictedVTITest.java Fri May 14 09:00:33 2010 @@ -24,13 +24,14 @@ package org.apache.derbyTesting.function import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.Statement; import junit.framework.Test; import junit.framework.TestSuite; -import org.apache.derbyTesting.junit.BaseJDBCTestCase; import org.apache.derbyTesting.junit.TestConfiguration; import org.apache.derbyTesting.junit.CleanDatabaseTestSetup; +import org.apache.derbyTesting.junit.JDBC; /** *

@@ -154,6 +155,21 @@ public class RestrictedVTITest extends "external name 'org.apache.derbyTesting.functionTests.tests.lang.RestrictedVTITest.nullableIntegerList'\n" ); } + if ( !routineExists( conn, "INTEGERLISTSPECIALCOLNAMES" ) ) + { + goodStatement + ( + conn, + "create function integerListSpecialColNames()\n" + + "returns table( \"CoL \"\"1\"\"\" int,\n" + + "\"cOL \"\"2\"\"\" int, col3 int, col4 int )\n" + + "language java\n" + + "parameter style derby_jdbc_result_set\n" + + "no sql\n" + + "external name '" + getClass().getName() + + ".integerListSpecialColNames'\n" + ); + } if ( !tableExists( conn, "T_4357_1" ) ) { goodStatement @@ -708,6 +724,44 @@ public class RestrictedVTITest extends ); } + /** + * Test that {@code Restriction.toSQL()} returns properly quoted column + * names. DERBY-4654. + */ + public void test_10_quotes_in_column_names() throws Exception + { + String[][] expectedRows = new String[][] {{"100", "200", "300", "400"}}; + String expectedRestriction = + "( \"cOL \"\"2\"\"\" < 1000 ) AND ( \"CoL \"\"1\"\"\" > 1 )"; + + // Check that we can execute a query against a restricted VTI with + // double quotes in the column names. + assertPR( + getConnection(), + "select * from table(integerListSpecialColNames()) t " + + "where \"CoL \"\"1\"\"\" > 1 and \"cOL \"\"2\"\"\" < 1000", + expectedRows, + "[CoL \"1\", cOL \"2\", COL3, COL4]", + expectedRestriction); + + // Get the restriction that was pushed down. + Statement stmt = createStatement(); + ResultSet rs = executeQuery(stmt, "values getLastRestriction()"); + assertTrue("empty result", rs.next()); + String restriction = rs.getString(1); + assertEquals(expectedRestriction, restriction); + rs.close(); + + // Verify that the returned restriction has correct syntax so that + // we can put it directly into the WHERE clause of a select query and + // get the same rows as we did above. + rs = executeQuery( + stmt, + "select * from table(integerListSpecialColNames()) t where " + + restriction); + JDBC.assertUnorderedResultSet(rs, expectedRows); + } + /////////////////////////////////////////////////////////////////////////////////// // // SQL ROUTINES @@ -752,7 +806,22 @@ public class RestrictedVTITest extends ); } private static Integer i( int intValue ) { return new Integer( intValue ); } - + + public static IntegerArrayVTI integerListSpecialColNames() + { + return new IntegerArrayVTI + ( + new String[] { "CoL \"1\"", "cOL \"2\"", "COL3", "COL4" }, + new int[][] + { + new int[] { 1, 2, 3, 4 }, + new int[] { 100, 200, 300, 400 }, + new int[] { 1000, 2000, 3000, 4000 }, + new int[] { 10000, 20000, 30000, 40000 }, + } + ); + } + /////////////////////////////////////////////////////////////////////////////////// // // MINIONS