Search in sources :

Example 86 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat_plus by coderczp.

the class MysqlInformationSchemaHandler method queryEngines.

/**
 * @param c
 * @param charset
 */
private static void queryEngines(ServerConnection c, String charset) {
    int field_count = 6;
    FieldPacket[] fields = new FieldPacket[field_count];
    fields[0] = PacketUtil.getField("ENGINE", Fields.FIELD_TYPE_VAR_STRING);
    fields[1] = PacketUtil.getField("SUPPORT", Fields.FIELD_TYPE_VAR_STRING);
    fields[2] = PacketUtil.getField("COMMENT", Fields.FIELD_TYPE_VAR_STRING);
    fields[3] = PacketUtil.getField("TRANSITIONS", Fields.FIELD_TYPE_VAR_STRING);
    fields[4] = PacketUtil.getField("XA", Fields.FIELD_TYPE_VAR_STRING);
    fields[5] = PacketUtil.getField("SAVEPOINTS", Fields.FIELD_TYPE_VAR_STRING);
    RowDataPacket[] rows = new RowDataPacket[1];
    RowDataPacket row = new RowDataPacket(field_count);
    row.add(StringUtil.encode("InnoDB", charset));
    row.add(StringUtil.encode("default ", charset));
    row.add(StringUtil.encode("Supports transactions, row-level locking, and foreign keys ", charset));
    row.add(StringUtil.encode("YES ", charset));
    row.add(StringUtil.encode("YES ", charset));
    row.add(StringUtil.encode("YES", charset));
    rows[0] = row;
    Result rs = new Result();
    rs.fields = fields;
    rs.rows = rows;
    doWrite(rs, c);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 87 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat_plus by coderczp.

the class MysqlInformationSchemaHandler method doWrite.

private static void doWrite(Result rs, ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    ResultSetHeaderPacket header = PacketUtil.getHeader(rs.fields.length);
    byte packetId = header.packetId;
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : rs.fields) {
        field.packetId = ++packetId;
        buffer = field.write(buffer, c, true);
    }
    // write eof
    EOFPacket eof = new EOFPacket();
    eof.packetId = ++packetId;
    buffer = eof.write(buffer, c, true);
    // write rows
    for (RowDataPacket row : rs.rows) {
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : ResultSetHeaderPacket(io.mycat.net.mysql.ResultSetHeaderPacket) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 88 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat_plus by coderczp.

the class MysqlInformationSchemaHandler method querySchema.

/**
 * @param c
 * @param charset
 */
private static void querySchema(ServerConnection c, String charset) {
    int field_count = 5;
    FieldPacket[] fields = new FieldPacket[field_count];
    fields[0] = PacketUtil.getField("CATALOG_NAME", Fields.FIELD_TYPE_VAR_STRING);
    fields[1] = PacketUtil.getField("SCHEMA_NAME", Fields.FIELD_TYPE_VAR_STRING);
    fields[2] = PacketUtil.getField("DEFAULT_CHARACTER_SET_NAME", Fields.FIELD_TYPE_VAR_STRING);
    fields[3] = PacketUtil.getField("DEFAULT_COLLATION_NAME", Fields.FIELD_TYPE_VAR_STRING);
    fields[4] = PacketUtil.getField("SQL_PATH", Fields.FIELD_TYPE_VAR_STRING);
    Map<String, SchemaConfig> schemas = MycatServer.getInstance().getConfig().getSchemas();
    RowDataPacket[] rows = new RowDataPacket[schemas.size()];
    int i = 0;
    for (Entry<String, SchemaConfig> sc : schemas.entrySet()) {
        RowDataPacket row = new RowDataPacket(field_count);
        row.add(StringUtil.encode("def", charset));
        row.add(StringUtil.encode("utf-8", charset));
        row.add(StringUtil.encode(sc.getKey(), charset));
        row.add(StringUtil.encode("utf8_general_ci", charset));
        row.add(StringUtil.encode("", charset));
        rows[i++] = row;
    }
    Result rs = new Result();
    rs.fields = fields;
    rs.rows = rows;
    doWrite(rs, c);
}
Also used : SchemaConfig(io.mycat.config.model.SchemaConfig) RowDataPacket(io.mycat.net.mysql.RowDataPacket) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 89 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat_plus by coderczp.

the class MysqlInformationSchemaHandler method queryCharacterSets.

/**
 * @param c
 * @param charset
 */
private static void queryCharacterSets(ServerConnection c, String charset) {
    int field_count = 4;
    FieldPacket[] fields = new FieldPacket[field_count];
    fields[0] = PacketUtil.getField("CHARACTER_SET_NAME", Fields.FIELD_TYPE_VAR_STRING);
    fields[1] = PacketUtil.getField("DEFAULT_COLLATE_NAME", Fields.FIELD_TYPE_VAR_STRING);
    fields[2] = PacketUtil.getField("DESCRIPTION", Fields.FIELD_TYPE_VAR_STRING);
    fields[3] = PacketUtil.getField("MAXLEN", Fields.FIELD_TYPE_LONG);
    RowDataPacket[] rows = new RowDataPacket[1];
    RowDataPacket row = new RowDataPacket(field_count);
    row.add(StringUtil.encode("big5", charset));
    row.add(StringUtil.encode("big5_chinese_ci", charset));
    row.add(StringUtil.encode("Big5 Traditional Chinese", charset));
    row.add(LongUtil.toBytes(2));
    rows[0] = row;
    Result rs = new Result();
    rs.fields = fields;
    rs.rows = rows;
    doWrite(rs, c);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 90 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat_plus by coderczp.

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.packetId;
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        field.packetId = ++packetId;
        buffer = field.write(buffer, c, true);
    }
    // write eof
    EOFPacket eof = new EOFPacket();
    eof.packetId = ++packetId;
    buffer = eof.write(buffer, c, true);
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(stmt, c.getCharset()));
    row.add(StringUtil.encode(msg, c.getCharset()));
    row.packetId = ++packetId;
    buffer = row.write(buffer, c, true);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : ResultSetHeaderPacket(io.mycat.net.mysql.ResultSetHeaderPacket) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Aggregations

FieldPacket (io.mycat.net.mysql.FieldPacket)173 ByteBuffer (java.nio.ByteBuffer)151 EOFPacket (io.mycat.net.mysql.EOFPacket)146 RowDataPacket (io.mycat.net.mysql.RowDataPacket)143 ResultSetHeaderPacket (io.mycat.net.mysql.ResultSetHeaderPacket)18 NIOProcessor (io.mycat.net.NIOProcessor)14 UserStat (io.mycat.statistic.stat.UserStat)12 Map (java.util.Map)12 SchemaConfig (io.mycat.config.model.SchemaConfig)9 ServerConnection (io.mycat.server.ServerConnection)8 ArrayList (java.util.ArrayList)8 MycatConfig (io.mycat.config.MycatConfig)6 FrontendConnection (io.mycat.net.FrontendConnection)6 HashMap (java.util.HashMap)6 BackendConnection (io.mycat.backend.BackendConnection)4 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)4 UserConfig (io.mycat.config.model.UserConfig)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 List (java.util.List)4 TreeSet (java.util.TreeSet)3