Search in sources :

Example 1 with PreparedOkPacket

use of com.alibaba.cobar.net.mysql.PreparedOkPacket in project cobar by alibaba.

the class PreparedStmtResponse method response.

public static void response(PreparedStatement pstmt, FrontendConnection c) {
    byte packetId = 0;
    // write preparedOk packet
    PreparedOkPacket preparedOk = new PreparedOkPacket();
    preparedOk.packetId = ++packetId;
    preparedOk.statementId = pstmt.getId();
    preparedOk.columnsNumber = pstmt.getColumnsNumber();
    preparedOk.parametersNumber = pstmt.getParametersNumber();
    ByteBuffer buffer = preparedOk.write(c.allocate(), c);
    // write parameter field packet
    int parametersNumber = preparedOk.parametersNumber;
    if (parametersNumber > 0) {
        for (int i = 0; i < parametersNumber; i++) {
            FieldPacket field = new FieldPacket();
            field.packetId = ++packetId;
            buffer = field.write(buffer, c);
        }
        EOFPacket eof = new EOFPacket();
        eof.packetId = ++packetId;
        buffer = eof.write(buffer, c);
    }
    // write column field packet
    int columnsNumber = preparedOk.columnsNumber;
    if (columnsNumber > 0) {
        for (int i = 0; i < columnsNumber; i++) {
            FieldPacket field = new FieldPacket();
            field.packetId = ++packetId;
            buffer = field.write(buffer, c);
        }
        EOFPacket eof = new EOFPacket();
        eof.packetId = ++packetId;
        buffer = eof.write(buffer, c);
    }
    // send buffer
    c.write(buffer);
}
Also used : EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) PreparedOkPacket(com.alibaba.cobar.net.mysql.PreparedOkPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Aggregations

EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)1 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)1 PreparedOkPacket (com.alibaba.cobar.net.mysql.PreparedOkPacket)1 ByteBuffer (java.nio.ByteBuffer)1