You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2010/05/14 11:00:34 UTC
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
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;
/**
<p>
@@ -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;
/**
* <p>
@@ -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