Search in sources :

Example 36 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

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, true);
    // 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, true);
        }
        EOFPacket eof = new EOFPacket();
        eof.packetId = ++packetId;
        buffer = eof.write(buffer, c, true);
    }
    // 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, true);
        }
        EOFPacket eof = new EOFPacket();
        eof.packetId = ++packetId;
        buffer = eof.write(buffer, c, true);
    }
    // send buffer
    c.write(buffer);
}
Also used : EOFPacket(io.mycat.net.mysql.EOFPacket) PreparedOkPacket(io.mycat.net.mysql.PreparedOkPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 37 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

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 FIELD_COUNT = splitVar.size();
    ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT);
    FieldPacket[] fields = new FieldPacket[FIELD_COUNT];
    int i = 0;
    byte packetId = 0;
    header.packetId = ++packetId;
    for (int i1 = 0, splitVarSize = splitVar.size(); i1 < splitVarSize; i1++) {
        String s = splitVar.get(i1);
        fields[i] = PacketUtil.getField(s, Fields.FIELD_TYPE_VAR_STRING);
        fields[i++].packetId = ++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.packetId = ++packetId;
    // write eof
    buffer = eof.write(buffer, c, true);
    // write rows
    //byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    for (int i1 = 0, splitVarSize = splitVar.size(); i1 < splitVarSize; i1++) {
        String s = splitVar.get(i1);
        String value = variables.get(s) == null ? "" : variables.get(s);
        row.add(value.getBytes());
    }
    row.packetId = ++packetId;
    buffer = row.write(buffer, c, true);
    // write lastEof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : ResultSetHeaderPacket(io.mycat.net.mysql.ResultSetHeaderPacket) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) FieldPacket(io.mycat.net.mysql.FieldPacket) ByteBuffer(java.nio.ByteBuffer)

Example 38 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

the class SessionIncrement method response.

public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = header.write(buffer, c, true);
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    buffer = eof.write(buffer, c, true);
    byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(LongUtil.toBytes(1));
    row.packetId = ++packetId;
    buffer = row.write(buffer, c, true);
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    c.write(buffer);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 39 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

the class SessionIsolation method response.

public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = header.write(buffer, c, true);
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    buffer = eof.write(buffer, c, true);
    byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode("REPEATABLE-READ", c.getCharset()));
    row.packetId = ++packetId;
    buffer = row.write(buffer, c, true);
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    c.write(buffer);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 40 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.

the class JDBCConnection method getNewFieldPacket.

private FieldPacket getNewFieldPacket(String charset, String fieldName) {
    FieldPacket fieldPacket = new FieldPacket();
    fieldPacket.orgName = StringUtil.encode(fieldName, charset);
    fieldPacket.name = StringUtil.encode(fieldName, charset);
    fieldPacket.length = 20;
    fieldPacket.flags = 0;
    fieldPacket.decimals = 0;
    int javaType = 12;
    fieldPacket.type = (byte) (MysqlDefs.javaTypeMysql(javaType) & 0xff);
    return fieldPacket;
}
Also used : FieldPacket(io.mycat.net.mysql.FieldPacket)

Aggregations

FieldPacket (io.mycat.net.mysql.FieldPacket)84 ByteBuffer (java.nio.ByteBuffer)75 EOFPacket (io.mycat.net.mysql.EOFPacket)74 RowDataPacket (io.mycat.net.mysql.RowDataPacket)69 ResultSetHeaderPacket (io.mycat.net.mysql.ResultSetHeaderPacket)9 NIOProcessor (io.mycat.net.NIOProcessor)7 UserStat (io.mycat.statistic.stat.UserStat)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 SchemaConfig (io.mycat.config.model.SchemaConfig)4 MycatConfig (io.mycat.config.MycatConfig)3 FrontendConnection (io.mycat.net.FrontendConnection)3 BackendConnection (io.mycat.backend.BackendConnection)2 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)2 UserConfig (io.mycat.config.model.UserConfig)2 ServerConnection (io.mycat.server.ServerConnection)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2