db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sure...@apache.org
Subject svn commit: r516145 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/load/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/tests/tools/
Date Thu, 08 Mar 2007 18:55:10 GMT
Author: suresht
Date: Thu Mar  8 10:55:08 2007
New Revision: 516145

URL: http://svn.apache.org/viewvc?view=rev&rev=516145
Log:
DERBY-378 (partial)
This patch checks for invalid hex strings in the import file 
while performing import into a table with CHAR FOR BIT DATA, 
VARCHAR FOR BIT DATA,  LONG VARCHAR FOR BIT DATA data types.
Import will throw an exception if it  detects any invalid hex 
strings during import. 

Tests:
Added a new junit test case to ImportExportBinaryDataTest.java 
to test for the invalid hex strings in the import file. 


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportAbstract.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportBinaryDataTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportAbstract.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportAbstract.java?view=diff&rev=516145&r1=516144&r2=516145
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportAbstract.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ImportAbstract.java Thu Mar
 8 10:55:08 2007
@@ -27,6 +27,10 @@
 import org.apache.derby.vti.VTITemplate;
 import java.util.ArrayList;
 import org.apache.derby.iapi.util.StringUtil;
+import org.apache.derby.iapi.error.PublicAPI;
+import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.error.StandardException;
+
 
 /**
  * 
@@ -196,8 +200,18 @@
         // if hex data is null, then column value is SQL NULL
         wasNull = (hexData == null);
         byte[] data = null;
-        if (hexData != null) 
+        if (hexData != null) {
             data = StringUtil.fromHexString(hexData, 0, hexData.length());
+            // fromHexString() returns null if the hex string is invalid one.
+            // It is invalid if the data string length is not multiple of 2 
+            // or the data string contains non-hex characters. 
+            if (data == null) {
+                throw PublicAPI.wrapStandardException(
+                      StandardException.newException(
+                      SQLState.IMPORTFILE_HAS_INVALID_HEXSTRING, 
+                      hexData));
+            }
+        }
         return data;
 	}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?view=diff&rev=516145&r1=516144&r2=516145
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Thu Mar  8 10:55:08
2007
@@ -3846,6 +3846,12 @@
                 <arg>tableName</arg>
             </msg>
 
+            <msg>
+                <name>XIE0N.S</name>
+                <text>An invalid hexadecimal string '{0}' detected in the import file.</text>
+                <arg>hexString</arg>
+            </msg>
+
         </family>
 
 

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?view=diff&rev=516145&r1=516144&r2=516145
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Thu Mar  8 10:55:08 2007
@@ -1700,5 +1700,6 @@
 	String DELIMITERS_ARE_NOT_MUTUALLY_EXCLUSIVE                   ="XIE0J.S";
 	String PERIOD_AS_CHAR_DELIMITER_NOT_ALLOWED                    ="XIE0K.S";
 	String TABLE_NOT_FOUND                                         ="XIE0M.S";
+	String IMPORTFILE_HAS_INVALID_HEXSTRING                        ="XIE0N.S";
 }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportBinaryDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportBinaryDataTest.java?view=diff&rev=516145&r1=516144&r2=516145
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportBinaryDataTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportBinaryDataTest.java
Thu Mar  8 10:55:08 2007
@@ -77,6 +77,11 @@
                               "C_BD CHAR(4) FOR BIT DATA," + 
                               "C_VBD VARCHAR(10) FOR BIT DATA, " +
                               "C_LVBD LONG VARCHAR FOR BIT DATA)");
+                    // Create a table that holds some invalid hex strings. 
+                    s.execute("CREATE TABLE hex_tab(id int," +
+                              "C1 varchar(20)," + 
+                              "C2 varchar(20)," +
+                              "C3 varchar(20))");
                 }
             };
     }
@@ -212,6 +217,70 @@
         }
     }
 
+
+    /* 
+     * Tests import procedures with invalid hex strings in 
+     * the import file. 
+     */
+    public void testImportWitgInvalidHexStrings() 
+        throws SQLException   
+    {
+        Statement s = createStatement();
+        // Insert row with correctly formed hex strings.  
+        s.executeUpdate("insert into hex_tab " + 
+                        "values(1, 'A121', '3122A1F20B', 'B1C201DA')");
+
+        // Insert row with an invalid hex string, because 
+        // it's length is not a multiple of 2 (B1C201A) , 
+        s.executeUpdate("insert into hex_tab " + 
+                        "values(2, 'A121', '3122A1F20B', 'B1C201A')");
+
+        // Insert row with an invalid hex string that contains 
+        // a non-hex character (3122A1F20Z). 
+        s.executeUpdate("insert into hex_tab " + 
+                        "values(3, '', '3122A1F20Z', 'B1C201DA')");
+
+        // Insert row with an invalid hex string that contains 
+        // a delimiter character (A1\"21). 
+        s.executeUpdate("insert into hex_tab " + 
+                        "values(3, 'A1\"21', '3122A1F20Z', 'B1C201DA')");
+        s.close();
+
+        // export the invalid hex strings from the table to a file. 
+        doExportTable("APP", "HEX_TAB", fileName, null, null , null);
+
+
+        // attempt to import the invalid hex string data into a table 
+        // with binary columns. It should fail.
+ 
+        try {
+            // import should fail because of invalied hex string length
+            doImportTable("APP", "BIN_TAB_IMP", fileName, null, null, null, 0);
+            fail("import did not fail on data with invalid hex string");
+        } catch (SQLException e) {
+             assertSQLState(JDBC.vmSupportsJDBC4() ? "38000": "XIE0N", e);
+        }
+
+        try {
+            // import should fail because hex string contains invalid 
+            // hex chatacters.
+            doImportData(null, "BIN_TAB_IMP", "ID, C_VBD", "1,3",
+                         fileName, null, null, null, 1);
+            fail("import did not fail on data with invalid hex strings");
+        } catch (SQLException e) {
+            assertSQLState(JDBC.vmSupportsJDBC4() ? "38000": "XIE0N", e);
+        }
+        
+        try {
+            // import should fail because hex string contains invalid 
+            // hex chatacters.
+            doImportData(null, "BIN_TAB_IMP", "ID, C_VBD", "1,2",
+                         fileName, null, null, null, 1);
+            fail("import did not fail on data with invalid hex strings");
+        } catch (SQLException e) {
+            assertSQLState(JDBC.vmSupportsJDBC4() ? "38000": "XIE0N", e);
+        }
+    }
 
 
     /* 



Mime
View raw message