use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class ExecutePacket method read.
public void read(byte[] data, String charset) throws UnsupportedEncodingException {
MySQLMessage mm = new MySQLMessage(data);
packetLength = mm.readUB3();
packetId = mm.read();
code = mm.read();
statementId = mm.readUB4();
flags = mm.read();
iterationCount = mm.readUB4();
// 读取NULL指示器数据
int parameterCount = values.length;
if (parameterCount > 0) {
nullBitMap = new byte[(parameterCount + 7) / 8];
for (int i = 0; i < nullBitMap.length; i++) {
nullBitMap[i] = mm.read();
}
// 当newParameterBoundFlag==1时,更新参数类型。
newParameterBoundFlag = mm.read();
}
if (newParameterBoundFlag == (byte) 1) {
for (int i = 0; i < parameterCount; i++) {
pstmt.getParametersType()[i] = mm.readUB2();
}
}
// 设置参数类型和读取参数值
byte[] nullBitMap = this.nullBitMap;
for (int i = 0; i < parameterCount; i++) {
BindValue bv = new BindValue();
bv.type = pstmt.getParametersType()[i];
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);
}
}
values[i] = bv;
}
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class HandshakePacket method read.
public void read(BinaryPacket bin) {
packetLength = bin.packetLength;
packetId = bin.packetId;
MySQLMessage mm = new MySQLMessage(bin.data);
protocolVersion = mm.read();
serverVersion = mm.readBytesWithNull();
threadId = mm.readUB4();
seed = mm.readBytesWithNull();
serverCapabilities = mm.readUB2();
serverCharsetIndex = mm.read();
serverStatus = mm.readUB2();
mm.move(13);
restOfScrambleBuff = mm.readBytesWithNull();
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class FrontendConnection method stmtPrepare.
public void stmtPrepare(byte[] data) {
if (prepareHandler != null) {
// 取得语句
MySQLMessage mm = new MySQLMessage(data);
mm.position(5);
String sql = null;
try {
sql = mm.readString(charset);
} catch (UnsupportedEncodingException e) {
writeErrMessage(ErrorCode.ER_UNKNOWN_CHARACTER_SET, "Unknown charset '" + charset + "'");
return;
}
if (sql == null || sql.length() == 0) {
writeErrMessage(ErrorCode.ER_NOT_ALLOWED_COMMAND, "Empty SQL");
return;
}
// 记录SQL
this.setExecuteSql(sql);
// 执行预处理
prepareHandler.prepare(sql);
} else {
writeErrMessage(ErrorCode.ER_UNKNOWN_COM_ERROR, "Prepare unsupported!");
}
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class MySQLMessageTest method testReadBytesWithNull.
@Test
public void testReadBytesWithNull() {
byte[] bytes = new byte[] { 1, 2, 3, 0, 5 };
MySQLMessage message = new MySQLMessage(bytes);
byte[] ab = message.readBytesWithNull();
Assert.assertEquals(3, ab.length);
Assert.assertEquals(4, message.position());
}
use of io.mycat.backend.mysql.MySQLMessage in project Mycat-Server by MyCATApache.
the class MySQLMessageTest method testReadBytesWithNull3.
@Test
public void testReadBytesWithNull3() {
byte[] bytes = new byte[] {};
MySQLMessage message = new MySQLMessage(bytes);
byte[] ab = message.readBytesWithNull();
Assert.assertEquals(0, ab.length);
Assert.assertEquals(0, message.position());
}
Aggregations