db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1035238 - in /db/derby/code/trunk/java: testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java tools/org/apache/derby/impl/tools/planexporter/CreateXMLFile.java
Date Mon, 15 Nov 2010 12:03:33 GMT
Author: kahatlen
Date: Mon Nov 15 12:03:33 2010
New Revision: 1035238

URL: http://svn.apache.org/viewvc?rev=1035238&view=rev
Log:
DERBY-4902: Encoding problem in output from plan exporter

Make sure the encoding in the header of the generated XML file matches
the actual encoding used in the file.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/CreateXMLFile.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java?rev=1035238&r1=1035237&r2=1035238&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XplainStatisticsTest.java
Mon Nov 15 12:03:33 2010
@@ -2422,6 +2422,34 @@ public class XplainStatisticsTest extend
     }
 
     /**
+     * Test that queries that contain non-ASCII characters are not garbled
+     * by the plan exporter tool. Regression test case for DERBY-4902.
+     */
+    public void testPlanExporterEncoding() throws Exception {
+        String table = "D4902_BL\u00C5B\u00C6R";
+        String queryText = "SELECT * FROM " + table;
+
+        Statement s = createStatement();
+        s.execute("CREATE TABLE " + table + "(X INT)");
+
+        enableXplainStyle(s);
+        JDBC.assertEmpty(s.executeQuery(queryText));
+        disableXplainStyle(s);
+
+        ResultSet rs = s.executeQuery(
+                "SELECT STMT_ID, STMT_TEXT FROM XPLTEST.SYSXPLAIN_STATEMENTS");
+        assertTrue(rs.next());
+        String stmtId = rs.getString(1);
+        assertEquals(queryText, rs.getString(2));
+        assertFalse(rs.next());
+        rs.close();
+
+        if (XML.classpathMeetsXMLReqs()) {
+            assertEquals(queryText, readStatement(stmtId));
+        }
+    }
+
+    /**
      * Abstract class for a thread executing a database action (i.e. a query).
      */
     private static abstract class AbstractMTThread

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/CreateXMLFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/CreateXMLFile.java?rev=1035238&r1=1035237&r2=1035238&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/CreateXMLFile.java
(original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/planexporter/CreateXMLFile.java
Mon Nov 15 12:03:33 2010
@@ -21,14 +21,14 @@
 
 package org.apache.derby.impl.tools.planexporter;
 
-import java.io.BufferedOutputStream;
-import java.io.DataOutputStream;
+import java.io.BufferedWriter;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
-import org.apache.derby.impl.tools.planexporter.AccessDatabase;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * This class is to create the final xml file, that will be used
@@ -57,7 +57,7 @@ public class CreateXMLFile {
             TreeNode[] data, final String file_name, String xsl_sheet_name)
     throws IOException {
 
-        String defaultXML = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
+        String defaultXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
         String embedXSL="";
         if(xsl_sheet_name != null)
             embedXSL ="<?xml-stylesheet type=\"text/xsl\" href=\""
@@ -68,31 +68,44 @@ public class CreateXMLFile {
         String childTagStart = "<details>\n";
         String childTagEnd = "</details>\n";
 
-        DataOutputStream dos;
-		try {
-			dos = new DataOutputStream(
-                    new BufferedOutputStream(
-                            (OutputStream)AccessController.doPrivileged
-                            (new java.security.PrivilegedExceptionAction(){
-                                public Object run() throws IOException{
-                                    return new FileOutputStream(file_name);
-                                }
-                            })));
-
-        dos.write(defaultXML.getBytes());
-        dos.write(embedXSL.getBytes());
-        dos.write(comment.getBytes());
-        dos.write(parentTagStart.getBytes());
-        dos.write((access.indent(0)+stmt).getBytes());
-        dos.write((access.indent(0)+time).getBytes());
-        dos.write((access.indent(0)+access.stmtID()).getBytes());
-        dos.write((access.indent(0)+childTagStart).getBytes());
-        dos.write(access.getXmlString().getBytes());
-        dos.write((access.indent(0)+childTagEnd).getBytes());
-        dos.write(parentTagEnd.getBytes());
-        dos.close();
-		} catch (PrivilegedActionException pae) {
-			throw (IOException)pae.getCause(); 
-		}
+        FileOutputStream fos;
+        try {
+            fos = (FileOutputStream) AccessController.doPrivileged(
+                    new PrivilegedExceptionAction() {
+                        public Object run() throws IOException {
+                            return new FileOutputStream(file_name);
+                        }
+                    });
+        } catch (PrivilegedActionException pae) {
+            throw (IOException) pae.getCause();
+        }
+
+        Writer out = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"));
+
+        out.write(defaultXML);
+
+        out.write(embedXSL);
+        out.write(comment);
+        out.write(parentTagStart);
+
+        out.write(access.indent(0));
+        out.write(stmt);
+
+        out.write(access.indent(0));
+        out.write(time);
+
+        out.write(access.indent(0));
+        out.write(access.stmtID());
+
+        out.write(access.indent(0));
+        out.write(childTagStart);
+
+        out.write(access.getXmlString());
+
+        out.write(access.indent(0));
+        out.write(childTagEnd);
+
+        out.write(parentTagEnd);
+        out.close();
     }
 }



Mime
View raw message