Search in sources :

Example 16 with ColumnDefPacket

use of io.mycat.beans.mysql.packet.ColumnDefPacket in project Mycat2 by MyCATApache.

the class NewVertxConnectionImpl method toColumnMetaData.

public static MycatRowMetaData toColumnMetaData(List<ColumnDefinition> event) {
    boolean isMysql = event.get(0) instanceof ColumnDefinition;
    if (isMysql) {
        List<ColumnDefinition> columnDefinitions = event;
        List<ColumnDefPacket> columnDefPackets = new ArrayList<>(event.size());
        for (ColumnDefinition columnDefinition : columnDefinitions) {
            final String catalog = columnDefinition.catalog();
            final String schema = columnDefinition.schema();
            final String table = columnDefinition.table();
            final String orgTable = columnDefinition.orgTable();
            final String name = columnDefinition.name();
            final String orgName = columnDefinition.orgName();
            final int characterSet = columnDefinition.characterSet();
            final long columnLength = columnDefinition.columnLength();
            final DataType type = columnDefinition.type();
            final int flags = columnDefinition.flags();
            byte decimals = columnDefinition.decimals();
            if (decimals == 31) {
                decimals = 0;
            }
            ColumnDefPacketImpl mySQLFieldInfo = new ColumnDefPacketImpl();
            mySQLFieldInfo.setColumnCatalog(catalog.getBytes());
            mySQLFieldInfo.setColumnSchema(schema.getBytes());
            mySQLFieldInfo.setColumnTable(table.getBytes());
            mySQLFieldInfo.setColumnOrgTable(orgTable.getBytes());
            mySQLFieldInfo.setColumnName(name.getBytes());
            mySQLFieldInfo.setColumnOrgName(orgName.getBytes());
            mySQLFieldInfo.setColumnCharsetSet(characterSet);
            mySQLFieldInfo.setColumnLength((int) columnLength);
            mySQLFieldInfo.setColumnType(type.id);
            mySQLFieldInfo.setColumnFlags(flags);
            mySQLFieldInfo.setColumnDecimals(decimals);
            columnDefPackets.add(mySQLFieldInfo);
        }
        return new MycatMySQLRowMetaData(columnDefPackets);
    } else {
        ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
        for (ColumnDefinition columnDescriptor : event) {
            resultSetBuilder.addColumnInfo(columnDescriptor.name(), columnDescriptor.jdbcType());
        }
        RowBaseIterator build = resultSetBuilder.build();
        return build.getMetaData();
    }
}
Also used : ResultSetBuilder(io.mycat.beans.mycat.ResultSetBuilder) MycatMySQLRowMetaData(io.mycat.beans.mycat.MycatMySQLRowMetaData) ColumnDefinition(io.vertx.mysqlclient.impl.protocol.ColumnDefinition) ColumnDefPacketImpl(io.mycat.beans.mysql.packet.ColumnDefPacketImpl) ColumnDefPacket(io.mycat.beans.mysql.packet.ColumnDefPacket) DataType(io.vertx.mysqlclient.impl.datatype.DataType) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) RowBaseIterator(io.mycat.api.collector.RowBaseIterator)

Aggregations

ColumnDefPacket (io.mycat.beans.mysql.packet.ColumnDefPacket)16 MySQLResultSet (io.mycat.prototypeserver.mysql.MySQLResultSet)6 ColumnDefPacketImpl (io.mycat.beans.mysql.packet.ColumnDefPacketImpl)3 DataType (io.vertx.mysqlclient.impl.datatype.DataType)3 ArrayList (java.util.ArrayList)3 MycatException (io.mycat.MycatException)2 ColumnDefinition (io.vertx.mysqlclient.impl.protocol.ColumnDefinition)2 Function (java.util.function.Function)2 NotNull (org.jetbrains.annotations.NotNull)2 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)1 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)1 SQLCreateDatabaseStatement (com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement)1 SQLShowCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLShowCreateTableStatement)1 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