Search in sources :

Example 6 with ResultSetHeaderPacket

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);
}
Also used : ResultSetHeaderPacket(com.actiontech.dble.net.mysql.ResultSetHeaderPacket) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) ByteBuffer(java.nio.ByteBuffer)

Example 7 with ResultSetHeaderPacket

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);
}
Also used : ResultSetHeaderPacket(com.actiontech.dble.net.mysql.ResultSetHeaderPacket) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Aggregations

ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)7 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)6 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)6 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)4 ByteBuffer (java.nio.ByteBuffer)4 PackageBufINf (com.actiontech.dble.manager.handler.PackageBufINf)2 RouteResultset (com.actiontech.dble.route.RouteResultset)1 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)1