use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.
the class ExplainHandler method handle.
public static void handle(String stmt, ServerConnection c, int offset) {
stmt = stmt.substring(offset).trim();
RouteResultset rrs = getRouteResultset(c, stmt);
if (rrs == null) {
return;
}
ByteBuffer buffer = c.allocate();
// write header
ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT);
byte packetId = header.packetId;
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
field.packetId = ++packetId;
buffer = field.write(buffer, c, true);
}
// write eof
EOFPacket eof = new EOFPacket();
eof.packetId = ++packetId;
buffer = eof.write(buffer, c, true);
// write rows
RouteResultsetNode[] rrsn = rrs.getNodes();
for (RouteResultsetNode node : rrsn) {
RowDataPacket row = getRow(node, c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.
the class MysqlInformationSchemaHandler method doWrite.
/**
* 写入数据包
* @param field_count
* @param fields
* @param c
*/
private static void doWrite(int field_count, FieldPacket[] fields, ServerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
ResultSetHeaderPacket header = PacketUtil.getHeader(field_count);
byte packetId = header.packetId;
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
field.packetId = ++packetId;
buffer = field.write(buffer, c, true);
}
// write eof
EOFPacket eof = new EOFPacket();
eof.packetId = ++packetId;
buffer = eof.write(buffer, c, true);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.
the class MysqlProcHandler method handle.
public static void handle(String stmt, ServerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT);
byte packetId = header.packetId;
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
field.packetId = ++packetId;
buffer = field.write(buffer, c, true);
}
// write eof
EOFPacket eof = new EOFPacket();
eof.packetId = ++packetId;
buffer = eof.write(buffer, c, true);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.
the class InformationSchemaProfiling method response.
/**
* response method.
* @param c
*/
public static void response(ServerConnection c) {
int i = 0;
byte packetId = 0;
header.packetId = ++packetId;
fields[i] = PacketUtil.getField("State", Fields.FIELD_TYPE_VAR_STRING);
fields[i].packetId = ++packetId;
fields[i + 1] = PacketUtil.getField("Duration", Fields.FIELD_TYPE_DECIMAL);
fields[i + 1].packetId = ++packetId;
fields[i + 2] = PacketUtil.getField("Percentage", Fields.FIELD_TYPE_DECIMAL);
fields[i + 2].packetId = ++packetId;
eof.packetId = ++packetId;
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = eof.write(buffer, c, true);
// write rows
packetId = eof.packetId;
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.
the class SelectConnnectID method response.
public static void response(ServerConnection c) {
if (MycatServer.getInstance().isOnline()) {
ByteBuffer buffer = c.allocate();
buffer = header.write(buffer, c, true);
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
buffer = eof.write(buffer, c, true);
byte packetId = eof.packetId;
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(getConnectID(c));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
c.write(buffer);
} else {
error.write(c);
}
}
Aggregations