Search in sources :

Example 1 with ColumnDefPacketImpl

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;
}
Also used : ArrayList(java.util.ArrayList) ColumnDefPacketImpl(io.mycat.beans.mysql.packet.ColumnDefPacketImpl) Field(com.mysql.cj.result.Field) ColumnDefPacket(io.mycat.beans.mysql.packet.ColumnDefPacket) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ColumnDefPacketImpl

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();
}
Also used : ColumnDefPacketImpl(io.mycat.beans.mysql.packet.ColumnDefPacketImpl)

Example 3 with ColumnDefPacketImpl

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;
}
Also used : ReadView(io.mycat.vertx.ReadView) ColumnDefPacketImpl(io.mycat.beans.mysql.packet.ColumnDefPacketImpl)

Example 4 with ColumnDefPacketImpl

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;
}
Also used : DataType(io.vertx.mysqlclient.impl.datatype.DataType) ColumnDefPacketImpl(io.mycat.beans.mysql.packet.ColumnDefPacketImpl) ColumnDefinition(io.vertx.mysqlclient.impl.protocol.ColumnDefinition)

Example 5 with ColumnDefPacketImpl

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;
}
Also used : ColumnDefPacketImpl(io.mycat.beans.mysql.packet.ColumnDefPacketImpl)

Aggregations

ColumnDefPacketImpl (io.mycat.beans.mysql.packet.ColumnDefPacketImpl)11 ColumnDefPacket (io.mycat.beans.mysql.packet.ColumnDefPacket)3 DataType (io.vertx.mysqlclient.impl.datatype.DataType)3 ColumnDefinition (io.vertx.mysqlclient.impl.protocol.ColumnDefinition)3 ReadView (io.mycat.vertx.ReadView)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 Field (com.mysql.cj.result.Field)1 IOExecutor (io.mycat.IOExecutor)1 MetaClusterCurrent (io.mycat.MetaClusterCurrent)1 RowBaseIterator (io.mycat.api.collector.RowBaseIterator)1 JdbcRowMetaData (io.mycat.beans.mycat.JdbcRowMetaData)1 MycatMySQLRowMetaData (io.mycat.beans.mycat.MycatMySQLRowMetaData)1 MycatRelDataType (io.mycat.beans.mycat.MycatRelDataType)1 ResultSetBuilder (io.mycat.beans.mycat.ResultSetBuilder)1 MycatPreparedStatementUtil (io.mycat.calcite.executor.MycatPreparedStatementUtil)1 AbstractMySqlConnectionImpl.adaptType (io.mycat.vertxmycat.AbstractMySqlConnectionImpl.adaptType)1 AbstractMySqlConnectionImpl.toObjects (io.mycat.vertxmycat.AbstractMySqlConnectionImpl.toObjects)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1