blob column insert exception: Unknown exception: INSERT INTO column size mismatch value size
Bug Report
Which version of ShardingSphere did you use?
4.0.0.M1
Which project did you use? Sharding-JDBC or Sharding-Proxy?
sharding-proxy
Expected behavior
images table has no shards.
The images table structure is as follows:
CREATE TABLE `images` (
`id` int(11) DEFAULT NULL,
`image` blob
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
java code is as follows:
@Test
public void blobInsertTest() throws Exception {
Class.forName("com.mysql.jdbc.Driver");
String sql = "INSERT INTO images(id,image) values(?,?)";
Connection conn = DriverManager.getConnection(url, username, password);
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1,2);
InputStream in = new FileInputStream("f:\\1122.jpg");
ps.setBlob(2, in);
int count = ps.executeUpdate();
System.out.println(count);
}
Run the code normally by connecting mysql.
Running code by connecting sharding-proxy reports the error as follows:
java.sql.SQLException: Unknown exception: INSERT INTO column size mismatch value size.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2535)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1911)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2145)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2081)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2066)
at com.zhongan.dmds.sharding_sphere.ShardingProxyTest.blobInsertTest(ShardingProxyTest.java:105)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
"SELECT blob column do not have the same problem", @guowdxp said.
query blob column no problem。
query java code as follows:
/**
* blob字段查询测试
* @param args
* @throws Exception
*/
@Test
public void blobQueryTest() throws Exception {
Class.forName("com.mysql.jdbc.Driver");
String sql = "select id,image from images";
Connection conn = DriverManager.getConnection(url, username, password);
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery(sql);
if(rs.next()) {
Integer id = rs.getInt("id");
Blob image = rs.getBlob("image");
System.out.println(id);
InputStream in = image.getBinaryStream();
OutputStream out = new FileOutputStream("f://3.jpg");
byte[] buffer = new byte[1024*1024];
int len = 0;
int i=0;
while((len = in.read(buffer)) != -1){
out.write(buffer, 0, len);
i++;
}
out.close();
in.close();
}
rs.close();
ps.close();
conn.close();
}
@guowdxp , thanks for your report. This issue will be fixed in 4.0.0.
Duplicate with #1567. Will be fixed together.
Duplicate with #1567. Will be fixed together.
Not the same problem.