use of io.vertx.mysqlclient.impl.datatype.DataType 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.datatype.DataType in project vertx-sql-client by eclipse-vertx.
the class ExtendedBatchQueryCommandCodec method sendBatchStatementExecuteCommand.
private void sendBatchStatementExecuteCommand(MySQLPreparedStatement statement, Tuple params) {
ByteBuf packet = allocateBuffer();
// encode packet header
int packetStartIdx = packet.writerIndex();
// will set payload length later by calculation
packet.writeMediumLE(0);
packet.writeByte(sequenceId);
// encode packet payload
packet.writeByte(CommandType.COM_STMT_EXECUTE);
packet.writeIntLE((int) statement.statementId);
packet.writeByte(CURSOR_TYPE_NO_CURSOR);
// iteration count, always 1
packet.writeIntLE(1);
/*
* Null-bit map and type should always be reconstructed for every batch of parameters here
*/
int numOfParams = statement.bindingTypes().length;
int bitmapLength = (numOfParams + 7) / 8;
byte[] nullBitmap = new byte[bitmapLength];
int pos = packet.writerIndex();
if (numOfParams > 0) {
// write a dummy bitmap first
packet.writeBytes(nullBitmap);
packet.writeByte(1);
for (int i = 0; i < params.size(); i++) {
Object param = params.getValue(i);
DataType dataType = DataTypeCodec.inferDataTypeByEncodingValue(param);
packet.writeByte(dataType.id);
// parameter flag: signed
packet.writeByte(0);
}
for (int i = 0; i < numOfParams; i++) {
Object value = params.getValue(i);
if (value != null) {
DataTypeCodec.encodeBinary(DataTypeCodec.inferDataTypeByEncodingValue(value), value, encoder.encodingCharset, packet);
} else {
nullBitmap[i / 8] |= (1 << (i & 7));
}
}
// padding null-bitmap content
packet.setBytes(pos, nullBitmap);
}
// set payload length
int payloadLength = packet.writerIndex() - packetStartIdx - 4;
packet.setMediumLE(packetStartIdx, payloadLength);
sendPacket(packet, payloadLength);
}
use of io.vertx.mysqlclient.impl.datatype.DataType in project vertx-sql-client by eclipse-vertx.
the class ExtendedQueryCommandCodec method sendStatementExecuteCommand.
private void sendStatementExecuteCommand(MySQLPreparedStatement statement, boolean sendTypesToServer, Tuple params, byte cursorType) {
ByteBuf packet = allocateBuffer();
// encode packet header
int packetStartIdx = packet.writerIndex();
// will set payload length later by calculation
packet.writeMediumLE(0);
packet.writeByte(sequenceId);
// encode packet payload
packet.writeByte(CommandType.COM_STMT_EXECUTE);
packet.writeIntLE((int) statement.statementId);
packet.writeByte(cursorType);
// iteration count, always 1
packet.writeIntLE(1);
int numOfParams = statement.bindingTypes().length;
int bitmapLength = (numOfParams + 7) / 8;
byte[] nullBitmap = new byte[bitmapLength];
int pos = packet.writerIndex();
if (numOfParams > 0) {
// write a dummy bitmap first
packet.writeBytes(nullBitmap);
packet.writeBoolean(sendTypesToServer);
if (sendTypesToServer) {
for (DataType bindingType : statement.bindingTypes()) {
packet.writeByte(bindingType.id);
// parameter flag: signed
packet.writeByte(0);
}
}
for (int i = 0; i < numOfParams; i++) {
Object value = params.getValue(i);
if (value != null) {
DataTypeCodec.encodeBinary(statement.bindingTypes()[i], value, encoder.encodingCharset, packet);
} else {
nullBitmap[i / 8] |= (1 << (i & 7));
}
}
// padding null-bitmap content
packet.setBytes(pos, nullBitmap);
}
// set payload length
int payloadLength = packet.writerIndex() - packetStartIdx - 4;
packet.setMediumLE(packetStartIdx, payloadLength);
sendPacket(packet, payloadLength);
}
use of io.vertx.mysqlclient.impl.datatype.DataType in project vertx-sql-client by eclipse-vertx.
the class MySQLPreparedStatement method bindParameters.
public String bindParameters(Tuple params) {
int numberOfParameters = params.size();
int paramDescLength = paramDesc.paramDefinitions().length;
if (numberOfParameters != paramDescLength) {
return ErrorMessageFactory.buildWhenArgumentsLengthNotMatched(paramDescLength, numberOfParameters);
}
// binding the parameters
boolean reboundParameters = false;
for (int i = 0; i < params.size(); i++) {
Object value = params.getValue(i);
DataType dataType = DataTypeCodec.inferDataTypeByEncodingValue(value);
DataType paramDataType = bindingTypes[i];
if (paramDataType != dataType) {
bindingTypes[i] = dataType;
reboundParameters = true;
}
}
// parameter must be re-bound
sendTypesToServer = reboundParameters;
return null;
}
use of io.vertx.mysqlclient.impl.datatype.DataType 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;
}
Aggregations