use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.
the class PacketUtil method getHeader.
public static ResultSetHeaderPacket getHeader(int fieldCount) {
ResultSetHeaderPacket packet = new ResultSetHeaderPacket();
packet.setPacketId(1);
packet.setFieldCount(fieldCount);
return packet;
}
use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.
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.getPacketId();
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : FIELDS) {
field.setPacketId(++packetId);
buffer = field.write(buffer, c, true);
}
// write eof
EOFPacket eof = new EOFPacket();
eof.setPacketId(++packetId);
buffer = eof.write(buffer, c, true);
if (!rrs.isNeedOptimizer()) {
// write rows
for (RouteResultsetNode node : rrs.getNodes()) {
RowDataPacket row = getRow(node, c.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
} else {
List<String[]> results = getComplexQueryResult(rrs, c);
for (String[] result : results) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(result[0], c.getCharset().getResults()));
row.add(StringUtil.encode(result[1], c.getCharset().getResults()));
row.add(StringUtil.encode(result[2].replaceAll("[\\t\\n\\r]", " "), c.getCharset().getResults()));
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.
the class MysqlInformationSchemaHandler method doWrite.
/**
* @param fieldCount
* @param fields
* @param c
*/
public static void doWrite(int fieldCount, FieldPacket[] fields, ServerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
ResultSetHeaderPacket header = PacketUtil.getHeader(fieldCount);
byte packetId = header.getPacketId();
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
field.setPacketId(++packetId);
buffer = field.write(buffer, c, true);
}
// write eof
EOFPacket eof = new EOFPacket();
eof.setPacketId(++packetId);
buffer = eof.write(buffer, c, true);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.
the class ShowTables method writeFullTablesHeader.
public static PackageBufINf writeFullTablesHeader(ByteBuffer buffer, ServerConnection c, String cSchema, List<FieldPacket> fieldPackets) {
int fieldCount = 2;
ResultSetHeaderPacket header = PacketUtil.getHeader(fieldCount);
FieldPacket[] fields = new FieldPacket[fieldCount];
int i = 0;
byte packetId = 0;
header.setPacketId(++packetId);
fields[i] = PacketUtil.getField("Tables in " + cSchema, Fields.FIELD_TYPE_VAR_STRING);
fields[i].setPacketId(++packetId);
fieldPackets.add(fields[i]);
fields[i + 1] = PacketUtil.getField("Table_type ", Fields.FIELD_TYPE_VAR_STRING);
fields[i + 1].setPacketId(++packetId);
fieldPackets.add(fields[i + 1]);
EOFPacket eof = new EOFPacket();
eof.setPacketId(++packetId);
// write header
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
eof.write(buffer, c, true);
PackageBufINf packBuffInfo = new PackageBufINf();
packBuffInfo.setBuffer(buffer);
packBuffInfo.setPacketId(packetId);
return packBuffInfo;
}
use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.
the class ShowTables method writeTablesHeaderAndRows.
public static PackageBufINf writeTablesHeaderAndRows(ByteBuffer buffer, ServerConnection c, Map<String, String> tableMap, String cSchema) {
int fieldCount = 1;
ResultSetHeaderPacket header = PacketUtil.getHeader(fieldCount);
FieldPacket[] fields = new FieldPacket[fieldCount];
int i = 0;
byte packetId = 0;
header.setPacketId(++packetId);
fields[i] = PacketUtil.getField("Tables in " + cSchema, Fields.FIELD_TYPE_VAR_STRING);
fields[i].setPacketId(++packetId);
EOFPacket eof = new EOFPacket();
eof.setPacketId(++packetId);
// write header
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
// write eof
eof.write(buffer, c, true);
for (String name : tableMap.keySet()) {
RowDataPacket row = new RowDataPacket(fieldCount);
row.add(StringUtil.encode(name.toLowerCase(), c.getCharset().getResults()));
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
PackageBufINf packBuffInfo = new PackageBufINf();
packBuffInfo.setBuffer(buffer);
packBuffInfo.setPacketId(packetId);
return packBuffInfo;
}
Aggregations