use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.
the class SelectVariables method execute.
public static void execute(ServerConnection c, String sql) {
String subSql = sql.substring(sql.indexOf("SELECT") + 6);
List<String> splitVar = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(subSql);
splitVar = convert(splitVar);
int fieldCount = splitVar.size();
ResultSetHeaderPacket header = PacketUtil.getHeader(fieldCount);
FieldPacket[] fields = new FieldPacket[fieldCount];
int i = 0;
byte packetId = 0;
header.setPacketId(++packetId);
for (String s : splitVar) {
fields[i] = PacketUtil.getField(s, Fields.FIELD_TYPE_VAR_STRING);
fields[i++].setPacketId(++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);
}
EOFPacket eof = new EOFPacket();
eof.setPacketId(++packetId);
// write eof
buffer = eof.write(buffer, c, true);
// write rows
// byte packetId = eof.packetId;
RowDataPacket row = new RowDataPacket(fieldCount);
for (String s : splitVar) {
String value = VARIABLES.get(s) == null ? "" : VARIABLES.get(s);
row.add(value.getBytes());
}
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
// write lastEof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.
the class Explain2Handler method showError.
private static void showError(String stmt, ServerConnection c, String msg) {
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);
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(stmt, c.getCharset().getResults()));
row.add(StringUtil.encode(msg, 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);
}
Aggregations