use of io.vertx.mysqlclient.impl.protocol.ColumnDefinition in project vertx-sql-client by eclipse-vertx.
the class CommandCodec method decodeColumnDefinitionPacketPayload.
ColumnDefinition decodeColumnDefinitionPacketPayload(ByteBuf payload) {
String catalog = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
String schema = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
String table = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
String orgTable = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
String name = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
String orgName = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
long lengthOfFixedLengthFields = BufferUtils.readLengthEncodedInteger(payload);
int characterSet = payload.readUnsignedShortLE();
long columnLength = payload.readUnsignedIntLE();
DataType type = DataType.valueOf(payload.readUnsignedByte());
int flags = payload.readUnsignedShortLE();
byte decimals = payload.readByte();
return new ColumnDefinition(catalog, schema, table, orgTable, name, orgName, characterSet, columnLength, type, flags, decimals);
}
use of io.vertx.mysqlclient.impl.protocol.ColumnDefinition in project vertx-sql-client by eclipse-vertx.
the class QueryCommandBaseCodec method handleResultsetColumnDefinitions.
protected void handleResultsetColumnDefinitions(ByteBuf payload) {
ColumnDefinition def = decodeColumnDefinitionPacketPayload(payload);
columnDefinitions[currentColumn++] = def;
if (currentColumn == columnDefinitions.length) {
// all column definitions have been decoded, switch to column definitions decoding completed state
if (isDeprecatingEofFlagEnabled()) {
// we enabled the DEPRECATED_EOF flag and don't need to accept an EOF_Packet
handleResultsetColumnDefinitionsDecodingCompleted();
} else {
// we need to decode an EOF_Packet before handling rows, to be compatible with MySQL version below 5.7.5
commandHandlerState = CommandHandlerState.COLUMN_DEFINITIONS_DECODING_COMPLETED;
}
}
}
use of io.vertx.mysqlclient.impl.protocol.ColumnDefinition in project vertx-sql-client by eclipse-vertx.
the class RowResultDecoder method decodeRow.
@Override
protected Row decodeRow(int len, ByteBuf in) {
Row row = new MySQLRowImpl(rowDesc);
if (rowDesc.dataFormat() == DataFormat.BINARY) {
// BINARY row decoding
// 0x00 packet header
// null_bitmap
int nullBitmapLength = (len + 7 + 2) >> 3;
int nullBitmapIdx = 1 + in.readerIndex();
in.skipBytes(1 + nullBitmapLength);
// values
for (int c = 0; c < len; c++) {
int val = c + 2;
int bytePos = val >> 3;
int bitPos = val & 7;
byte mask = (byte) (1 << bitPos);
byte nullByte = (byte) (in.getByte(nullBitmapIdx + bytePos) & mask);
Object decoded = null;
if (nullByte == 0) {
// non-null
ColumnDefinition columnDef = rowDesc.columnDefinitions()[c];
DataType dataType = columnDef.type();
int collationId = rowDesc.columnDefinitions()[c].characterSet();
int columnDefinitionFlags = columnDef.flags();
decoded = DataTypeCodec.decodeBinary(dataType, collationId, columnDefinitionFlags, in);
}
row.addValue(decoded);
}
} else {
// TEXT row decoding
for (int c = 0; c < len; c++) {
Object decoded = null;
if (in.getUnsignedByte(in.readerIndex()) == NULL) {
in.skipBytes(1);
} else {
DataType dataType = rowDesc.columnDefinitions()[c].type();
int columnDefinitionFlags = rowDesc.columnDefinitions()[c].flags();
int collationId = rowDesc.columnDefinitions()[c].characterSet();
decoded = DataTypeCodec.decodeText(dataType, collationId, columnDefinitionFlags, in);
}
row.addValue(decoded);
}
}
return row;
}
use of io.vertx.mysqlclient.impl.protocol.ColumnDefinition 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.vertx.mysqlclient.impl.protocol.ColumnDefinition in project Mycat2 by MyCATApache.
the class MycatVertxRowResultDecoder method decodeRow.
@Override
protected Row decodeRow(int len, ByteBuf in) {
Row row = new MySQLRowImpl(rowDesc);
if (rowDesc.dataFormat() == DataFormat.BINARY) {
// BINARY row decoding
// 0x00 packet header
// null_bitmap
int nullBitmapLength = (len + 7 + 2) >> 3;
int nullBitmapIdx = 1 + in.readerIndex();
in.skipBytes(1 + nullBitmapLength);
// values
for (int c = 0; c < len; c++) {
int val = c + 2;
int bytePos = val >> 3;
int bitPos = val & 7;
byte mask = (byte) (1 << bitPos);
byte nullByte = (byte) (in.getByte(nullBitmapIdx + bytePos) & mask);
Object decoded = null;
if (nullByte == 0) {
// non-null
ColumnDefinition columnDef = rowDesc.columnDefinitions()[c];
DataType dataType = columnDef.type();
int collationId = rowDesc.columnDefinitions()[c].characterSet();
int columnDefinitionFlags = columnDef.flags();
decoded = DataTypeCodec.decodeBinary(dataType, collationId, columnDefinitionFlags, in);
}
row.addValue(decoded);
}
} else {
// TEXT row decoding
for (int c = 0; c < len; c++) {
Object decoded = null;
if (in.getUnsignedByte(in.readerIndex()) == NULL) {
in.skipBytes(1);
} else {
DataType dataType = rowDesc.columnDefinitions()[c].type();
int columnDefinitionFlags = rowDesc.columnDefinitions()[c].flags();
int collationId = rowDesc.columnDefinitions()[c].characterSet();
decoded = DataTypeCodec.decodeText(dataType, collationId, columnDefinitionFlags, in);
}
row.addValue(decoded);
}
}
return row;
}
Aggregations