use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.
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);
}
use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.
the class ShowCache method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = eof.write(buffer, c, true);
// write rows
byte packetId = eof.packetId;
CacheService cacheService = MycatServer.getInstance().getCacheService();
for (Map.Entry<String, CachePool> entry : cacheService.getAllCachePools().entrySet()) {
String cacheName = entry.getKey();
CachePool cachePool = entry.getValue();
if (cachePool instanceof LayerCachePool) {
for (Map.Entry<String, CacheStatic> staticsEntry : ((LayerCachePool) cachePool).getAllCacheStatic().entrySet()) {
RowDataPacket row = getRow(cacheName + '.' + staticsEntry.getKey(), staticsEntry.getValue(), c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
} else {
RowDataPacket row = getRow(cacheName, cachePool.getCacheStatic(), 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);
// write buffer
c.write(buffer);
}
use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.
the class ShowMyCATCluster method response.
public static void response(ServerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c, true);
// write field
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = eof.write(buffer, c, true);
// write rows
byte packetId = eof.packetId;
for (RowDataPacket row : getRows(c)) {
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
// 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-Server by MyCATApache.
the class ShowMyCatStatus method response.
public static void response(ServerConnection c) {
if (MycatServer.getInstance().isOnline()) {
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);
buffer = status.write(buffer, c, true);
buffer = lastEof.write(buffer, c, true);
c.write(buffer);
} else {
error.write(c);
}
}
use of io.mycat.net.mysql.FieldPacket in project Mycat-Server by MyCATApache.
the class ShowTables method response.
/**
* response method.
* @param c
*/
public static void response(ServerConnection c, String stmt, int type) {
String showSchemal = SchemaUtil.parseShowTableSchema(stmt);
String cSchema = showSchemal == null ? c.getSchema() : showSchemal;
SchemaConfig schema = MycatServer.getInstance().getConfig().getSchemas().get(cSchema);
if (schema != null) {
//不分库的schema,show tables从后端 mysql中查
String node = schema.getDataNode();
if (!Strings.isNullOrEmpty(node)) {
c.execute(stmt, ServerParse.SHOW);
return;
}
} else {
c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
return;
}
//分库的schema,直接从SchemaConfig中获取所有表名
Map<String, String> parm = buildFields(c, stmt);
java.util.Set<String> tableSet = getTableSet(c, parm);
int i = 0;
byte packetId = 0;
header.packetId = ++packetId;
fields[i] = PacketUtil.getField("Tables in " + parm.get(SCHEMA_KEY), Fields.FIELD_TYPE_VAR_STRING);
fields[i++].packetId = ++packetId;
eof.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);
}
// write eof
buffer = eof.write(buffer, c, true);
// write rows
packetId = eof.packetId;
for (String name : tableSet) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(name.toLowerCase(), 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