use of io.mycat.beans.mysql.packet.ColumnDefPacketImpl in project Mycat2 by MyCATApache.
the class NewMycatConnectionImpl method getJdbcRowMetaData.
@NotNull
private MycatRowMetaData getJdbcRowMetaData(ResultSetMetaData jdbcMetaData) throws SQLException {
MycatRowMetaData mycatRowMetaData;
if (isMySQLDriver || "com.mysql.cj.jdbc.result.ResultSetMetaData".equals(jdbcMetaData.getClass().getCanonicalName())) {
isMySQLDriver = true;
com.mysql.cj.jdbc.result.ResultSetMetaData mysqlJdbcMetaData = (com.mysql.cj.jdbc.result.ResultSetMetaData) jdbcMetaData;
int columnCount = mysqlJdbcMetaData.getColumnCount();
Field[] fields = mysqlJdbcMetaData.getFields();
List<ColumnDefPacket> columnDefPackets = new ArrayList<>(columnCount);
for (int i = 0; i < columnCount; i++) {
ColumnDefPacketImpl columnDefPacket = new ColumnDefPacketImpl();
Field field = fields[i];
columnDefPacket.setColumnSchema(ColumnDefPacketImpl.getBytes(field.getDatabaseName()));
columnDefPacket.setColumnTable(ColumnDefPacketImpl.getBytes(field.getTableName()));
columnDefPacket.setColumnOrgTable(ColumnDefPacketImpl.getBytes(field.getOriginalTableName()));
columnDefPacket.setColumnName(ColumnDefPacketImpl.getBytes(field.getName()));
columnDefPacket.setColumnOrgName(ColumnDefPacketImpl.getBytes(field.getOriginalName()));
columnDefPacket.setColumnCharsetSet((field.getCollationIndex()));
columnDefPacket.setColumnLength((int) field.getLength());
columnDefPacket.setColumnType((int) field.getMysqlTypeId());
columnDefPacket.setColumnFlags((int) field.getFlags());
columnDefPacket.setColumnDecimals((byte) field.getDecimals());
columnDefPackets.add(columnDefPacket);
}
mycatRowMetaData = new MycatMySQLRowMetaData(columnDefPackets);
} else {
mycatRowMetaData = new CopyMycatRowMetaData(new JdbcRowMetaData(jdbcMetaData));
}
return mycatRowMetaData;
}
use of io.mycat.beans.mysql.packet.ColumnDefPacketImpl in project Mycat2 by MyCATApache.
the class ObjectArrayDecoder method addColumn.
@Override
public void addColumn(int index, Buffer buffer) {
ColumnDefPacketImpl columnDefPacket = decodeColumnDefinitionPacketPayload(buffer);
this.columnDefPackets[index] = columnDefPacket;
this.dataTypes[index] = DataType.valueOf(columnDefPacket.getColumnType());
this.signeds[index] = columnDefPacket.isSigned();
}
use of io.mycat.beans.mysql.packet.ColumnDefPacketImpl in project Mycat2 by MyCATApache.
the class ObjectArrayDecoder method decodeColumnDefinitionPacketPayload.
ColumnDefPacketImpl decodeColumnDefinitionPacketPayload(Buffer payload) {
ReadView readView = new ReadView(payload);
byte[] catalog = readView.readLenencStringBytes();
byte[] schema = readView.readLenencStringBytes();
byte[] table = readView.readLenencStringBytes();
byte[] orgTable = readView.readLenencStringBytes();
byte[] name = readView.readLenencStringBytes();
byte[] orgName = readView.readLenencStringBytes();
long lengthOfFixedLengthFields = readView.readLenencInt();
int characterSet = (int) readView.readFixInt(2);
long columnLength = (int) readView.readFixInt(4);
int type = readView.readByte() & 0xff;
int flags = (int) readView.readFixInt(2);
byte decimals = readView.readByte();
ColumnDefPacketImpl columnDefPacket = new ColumnDefPacketImpl();
columnDefPacket.setColumnSchema(schema);
columnDefPacket.setColumnTable(table);
columnDefPacket.setColumnOrgTable(orgTable);
columnDefPacket.setColumnName(name);
columnDefPacket.setColumnOrgName(orgName);
columnDefPacket.setColumnCharsetSet(characterSet);
columnDefPacket.setColumnLength((int) columnLength);
columnDefPacket.setColumnType(type);
columnDefPacket.setColumnFlags(flags);
columnDefPacket.setColumnDecimals(decimals);
return columnDefPacket;
}
use of io.mycat.beans.mysql.packet.ColumnDefPacketImpl in project Mycat2 by MyCATApache.
the class VertxMycatTextCollector method onColumnDef.
@Override
public void onColumnDef(MySQLPacket mySQLPacket, int startPos, int endPos) {
ColumnDefPacketImpl packet = new ColumnDefPacketImpl();
packet.read(mySQLPacket, startPos, endPos);
String catalog = new String(packet.getColumnCatalog());
String schema = new String(packet.getColumnSchema());
String table = new String(packet.getColumnTable());
String orgTable = new String(packet.getColumnOrgTable());
String name = new String(packet.getColumnName());
String orgName = new String(packet.getColumnOrgName());
int characterSet = packet.getColumnCharsetSet();
long columnLength = packet.getColumnLength();
DataType type = DataType.valueOf(packet.getColumnType());
int flags = packet.getColumnFlags();
byte decimals = packet.getColumnDecimals();
ColumnDefinition columnDefinition = new ColumnDefinition(catalog, schema, table, orgTable, name, orgName, characterSet, columnLength, type, flags, decimals);
this.currentColumnDefList[this.columnCount++] = columnDefinition;
}
use of io.mycat.beans.mysql.packet.ColumnDefPacketImpl in project Mycat2 by MyCATApache.
the class TextResultSetHandler method onColumnDef.
// public void request(
// MySQLClientSession mysql, String sql,
// ResultSetCallBack<MySQLClientSession> callBack) {
// this.collector = new ResultSetCollector();
// this.predicate = (i) -> true;
// request(mysql, 3, sql, callBack);
// }
@Override
public void onColumnDef(MySQLPacket mySQLPacket, int startPos, int endPos) {
ColumnDefPacketImpl packet = new ColumnDefPacketImpl();
packet.read(mySQLPacket, startPos, endPos);
int i = this.columnCount++;
this.currentColumnDefList[i] = packet;
}
Aggregations