Skip to content

Commit

Permalink
fix bug for prepared Statement With Blob
Browse files Browse the repository at this point in the history
compatible c-api and python.connector
  • Loading branch information
Ken.li authored and Ken.li committed Mar 30, 2020
1 parent 92abb49 commit b688a25
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
16 changes: 15 additions & 1 deletion src/main/java/io/mycat/backend/mysql/BindValueUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package io.mycat.backend.mysql;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import io.mycat.config.Fields;
Expand Down Expand Up @@ -79,7 +81,19 @@ public static final void read(MySQLMessage mm, BindValue bv, String charset) thr
}
break;
case Fields.FIELD_TYPE_BLOB:
bv.isLongData = true;
byte[] vv = mm.readBytesWithLength();
if (vv == null) {
bv.isNull = true;
} else {
//vv.length >= 0
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
out.write(vv);
} catch (IOException e) {
throw new IllegalArgumentException("bindValue error,unsupported type:" + bv.type);
}
bv.value = out;
}
break;
default:
throw new IllegalArgumentException("bindValue error,unsupported type:" + bv.type);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/mycat/backend/mysql/PreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public int getParametersNumber() {
public int[] getParametersType() {
return parametersType;
}

public boolean hasLongData(long paramId) {
return longDataMap.containsKey(paramId);
}

public ByteArrayOutputStream getLongData(long paramId) {
return longDataMap.get(paramId);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/io/mycat/net/mysql/ExecutePacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ public void read(byte[] data, String charset) throws UnsupportedEncodingExceptio
if ((nullBitMap[i / 8] & (1 << (i & 7))) != 0) {
bv.isNull = true;
} else {
BindValueUtil.read(mm, bv, charset);
if(bv.isLongData) {
bv.value = pstmt.getLongData(i);
}
if (!pstmt.hasLongData(i)) {
BindValueUtil.read(mm, bv, charset);
} else {
bv.value = pstmt.getLongData(i);
}
}
values[i] = bv;
}
Expand Down

0 comments on commit b688a25

Please sign in to comment.