@@ -11731,4 +11731,63 @@ public <M extends Message> M preProcess(M queryPacket) {
11731
11731
return super.preProcess(queryPacket);
11732
11732
}
11733
11733
}
11734
+
11735
+ @Test
11736
+ public void testBlobWithSJIS() throws Exception {
11737
+ createTable("testBlobWithSJIS", "(a SERIAL, b BLOB)");
11738
+
11739
+ Properties props = new Properties();
11740
+ props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
11741
+ props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
11742
+
11743
+ String sqlMode = getMysqlVariable("sql_mode");
11744
+ sqlMode = removeSqlMode("ANSI_QUOTES", sqlMode);
11745
+ sqlMode = removeSqlMode("NO_BACKSLASH_ESCAPES", sqlMode);
11746
+ if (sqlMode.length() > 0) {
11747
+ sqlMode += ",";
11748
+ }
11749
+
11750
+ byte[] data1 = new byte[20];
11751
+ data1[0] = -21;
11752
+ data1[1] = '\'';
11753
+ data1[2] = '"';
11754
+ data1[3] = '\b';
11755
+ data1[4] = '\n';
11756
+ data1[5] = '\r';
11757
+ data1[6] = '\t';
11758
+ data1[7] = 26; // \Z ASCII 26 (Control+Z)
11759
+ data1[8] = '\\';
11760
+ data1[9] = '%'; // \% A % character; see note following the table
11761
+ data1[10] = '_'; // \_ A _ character; see note following the table
11762
+ data1[11] = 39; // \'
11763
+
11764
+ for (boolean useSSPS : new boolean[] { false, true }) {
11765
+ for (String mode : new String[] { "", "ANSI_QUOTES", "NO_BACKSLASH_ESCAPES", "ANSI_QUOTES,NO_BACKSLASH_ESCAPES" }) {
11766
+ for (String enc : new String[] { "SJIS", "UTF-8" }) {
11767
+ props.setProperty(PropertyKey.characterEncoding.getKeyName(), enc);
11768
+ props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), "" + useSSPS);
11769
+ props.setProperty(PropertyKey.sessionVariables.getKeyName(), "sql_mode='" + sqlMode + mode + "'");
11770
+
11771
+ Connection con = getConnectionWithProps(props);
11772
+ Statement st = con.createStatement();
11773
+
11774
+ st.executeUpdate("truncate table testBlobWithSJIS");
11775
+
11776
+ PreparedStatement ps1 = con.prepareStatement("INSERT INTO testBlobWithSJIS (b) VALUES(?)");
11777
+ Blob blob = con.createBlob();
11778
+ blob.setBytes(1, data1);
11779
+ ps1.setBlob(1, blob);
11780
+ ps1.executeUpdate();
11781
+
11782
+ this.rs = st.executeQuery("SELECT b FROM testBlobWithSJIS");
11783
+ assertTrue(this.rs.next());
11784
+ byte[] data2 = this.rs.getBytes(1);
11785
+ assertTrue(Arrays.equals(data1, data2));
11786
+ assertFalse(this.rs.next());
11787
+
11788
+ con.close();
11789
+ }
11790
+ }
11791
+ }
11792
+ }
11734
11793
}
0 commit comments