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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations