[Fix](Prepared Statment) use fixed charset to init StringLiteral (#37084)
picked from #36860
This commit is contained in:
@ -40,6 +40,7 @@ import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
|
||||
public class StringLiteral extends LiteralExpr {
|
||||
@ -346,7 +347,9 @@ public class StringLiteral extends LiteralExpr {
|
||||
}
|
||||
byte[] bytes = new byte[strLen];
|
||||
data.get(bytes);
|
||||
value = new String(bytes);
|
||||
// ATTN: use fixed StandardCharsets.UTF_8 to avoid unexpected charset in
|
||||
// different environment
|
||||
value = new String(bytes, StandardCharsets.UTF_8);
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("parsed value '{}'", value);
|
||||
}
|
||||
|
||||
@ -45,6 +45,7 @@ import com.google.common.collect.ImmutableList;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
@ -582,7 +583,9 @@ public abstract class Literal extends Expression implements LeafExpression, Comp
|
||||
strLen = Math.min(strLen, data.remaining());
|
||||
byte[] bytes = new byte[strLen];
|
||||
data.get(bytes);
|
||||
return new StringLiteral(new String(bytes));
|
||||
// ATTN: use fixed StandardCharsets.UTF_8 to avoid unexpected charset in
|
||||
// different environment
|
||||
return new StringLiteral(new String(bytes, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private static Literal handleVarcharLiteral(ByteBuffer data) {
|
||||
@ -590,6 +593,8 @@ public abstract class Literal extends Expression implements LeafExpression, Comp
|
||||
strLen = Math.min(strLen, data.remaining());
|
||||
byte[] bytes = new byte[strLen];
|
||||
data.get(bytes);
|
||||
return new VarcharLiteral(new String(bytes));
|
||||
// ATTN: use fixed StandardCharsets.UTF_8 to avoid unexpected charset in
|
||||
// different environment
|
||||
return new VarcharLiteral(new String(bytes, StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,7 +213,9 @@ public class MysqlConnectProcessor extends ConnectProcessor {
|
||||
// process COM_EXECUTE, parse binary row data
|
||||
// https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_execute.html
|
||||
private void handleExecute() {
|
||||
// debugPacket();
|
||||
if (LOG.isDebugEnabled()) {
|
||||
debugPacket();
|
||||
}
|
||||
packetBuf = packetBuf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
// parse stmt_id, flags, params
|
||||
int stmtId = packetBuf.getInt();
|
||||
|
||||
Reference in New Issue
Block a user