db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1004197 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/load/ColumnInfo.java testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java
Date Mon, 04 Oct 2010 11:11:07 GMT
Author: kahatlen
Date: Mon Oct  4 11:11:07 2010
New Revision: 1004197

URL: http://svn.apache.org/viewvc?rev=1004197&view=rev
Log:
DERBY-4828: Import fails if column names contain double quotes

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ColumnInfo.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ColumnInfo.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ColumnInfo.java?rev=1004197&r1=1004196&r2=1004197&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ColumnInfo.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ColumnInfo.java Mon Oct  4
11:11:07 2010
@@ -387,11 +387,11 @@ class ColumnInfo {
 				sb.append(", ");
 			else
 				first = false;
-			// column names can be SQL reserved words, so it 
-			// is necessary delimit them using quotes for insert to work correctly. 
-			sb.append("\"");
-			sb.append(insertColumnNames.get(index));
-			sb.append("\"");
+            // Column names can be SQL reserved words, or they can contain
+            // spaces and special characters, so it is necessary delimit them
+            // for insert to work correctly.
+            String name = (String) insertColumnNames.get(index);
+            sb.append(IdUtil.normalToDelimited(name));
 		}
 	
 		//there is no column info available

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java?rev=1004197&r1=1004196&r2=1004197&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java
Mon Oct  4 11:11:07 2010
@@ -241,6 +241,44 @@ public class ImportExportTest extends Ba
     }
 
     /**
+     * Test that we can successfully export from and import to tables that
+     * have columns with special characters in their names (single and double
+     * quotes, spaces, mixed case). Regression test case for DERBY-4828.
+     */
+    public void testQuotesInColumnNames() throws Exception {
+        Statement s = createStatement();
+
+        // Create a source table with column names that contain special
+        // characters.
+        s.execute("create table table_with_funny_cols_src ("
+                // simple column name
+                + "x int, "
+                // column name with single and double quotes, mixed case
+                // and spaces
+                + "\"Let's try this! \"\" :)\" int)");
+        s.execute("insert into table_with_funny_cols_src values (1,2), (3,4)");
+
+        // Export the table to a file.
+        doExport(null, "TABLE_WITH_FUNNY_COLS_SRC", null, null, null);
+
+        // Create an empty destination table with the same schema as the
+        // source table.
+        s.execute("create table table_with_funny_cols_dest as "
+                + "select * from table_with_funny_cols_src with no data");
+
+        // Import into the destination table.
+        doImport("TABLE_WITH_FUNNY_COLS_SRC",
+                 null, "TABLE_WITH_FUNNY_COLS_DEST",
+                 null, null, null, 0);
+
+        // Verify that the rows were successfully imported.
+        JDBC.assertFullResultSet(
+                s.executeQuery(
+                    "select * from table_with_funny_cols_dest order by x"),
+                new String[][] { {"1", "2"}, {"3", "4"} });
+    }
+
+    /**
      * Test that you can't import the wrong type of object into a UDT column.
      */
     public void testCastingProblem() throws Exception



Mime
View raw message