use of com.actiontech.dble.net.mysql.RowDataPacket 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.RowDataPacket in project dble by actiontech.
the class ExplainHandler method getRow.
private static RowDataPacket getRow(RouteResultsetNode node, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(node.getName(), charset));
row.add(StringUtil.encode("BASE SQL", charset));
row.add(StringUtil.encode(node.getStatement().replaceAll("[\\t\\n\\r]", " "), charset));
return row;
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class ShowTables method writeFullTablesRow.
public static PackageBufINf writeFullTablesRow(ByteBuffer buffer, ServerConnection c, Map<String, String> tableMap, byte packetId, Item whereItem, List<Field> sourceFields) {
for (Map.Entry<String, String> entry : tableMap.entrySet()) {
RowDataPacket row = new RowDataPacket(2);
row.add(StringUtil.encode(entry.getKey().toLowerCase(), c.getCharset().getResults()));
row.add(StringUtil.encode(entry.getValue(), c.getCharset().getResults()));
if (whereItem != null) {
HandlerTool.initFields(sourceFields, row.fieldValues);
/* filter by where condition */
if (whereItem.valBool()) {
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
} else {
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
}
PackageBufINf packBuffInfo = new PackageBufINf();
packBuffInfo.setBuffer(buffer);
packBuffInfo.setPacketId(packetId);
return packBuffInfo;
}
use of com.actiontech.dble.net.mysql.RowDataPacket 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;
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class SelectVersionComment method response.
public static void response(FrontendConnection c) {
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
byte packetId = EOF.getPacketId();
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(Versions.VERSION_COMMENT);
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);
}
Aggregations