Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify data type codec maintenance #987

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import io.vertx.mssqlclient.impl.protocol.MessageType;
import io.vertx.mssqlclient.impl.protocol.TdsMessage;
import io.vertx.mssqlclient.impl.protocol.client.rpc.ProcId;
import io.vertx.mssqlclient.impl.protocol.datatype.MSSQLDataTypeId;
import io.vertx.mssqlclient.impl.protocol.token.DataPacketStreamTokenType;
import io.vertx.sqlclient.impl.command.CloseStatementCommand;
import io.vertx.sqlclient.impl.command.CommandResponse;

import static io.vertx.mssqlclient.impl.codec.DataType.INTN;

class CloseStatementCommandCodec extends MSSQLCommandCodec<Void, CloseStatementCommand> {

CloseStatementCommandCodec(CloseStatementCommand cmd) {
Expand Down Expand Up @@ -93,7 +94,7 @@ private void sendUnprepareRequest() {
// Option flags
packet.writeShortLE(0x0000);

encodeIntNParameter(packet, ((MSSQLPreparedStatement) cmd.statement()).handle);
INTN.encodeParam(packet, null, false, ((MSSQLPreparedStatement) cmd.statement()).handle);

int packetLen = packet.writerIndex() - packetLenIdx + 2;
packet.setShort(packetLenIdx, packetLen);
Expand All @@ -107,13 +108,4 @@ protected void encodeTransactionDescriptor(ByteBuf payload, long transactionDesc
payload.writeLongLE(transactionDescriptor);
payload.writeIntLE(outstandingRequestCount);
}

private void encodeIntNParameter(ByteBuf payload, Object value) {
payload.writeByte(0x00);
payload.writeByte(0x00);
payload.writeByte(MSSQLDataTypeId.INTNTYPE_ID);
payload.writeByte(4);
payload.writeByte(4);
payload.writeIntLE((Integer) value);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2019 Contributors to the Eclipse Foundation
* Copyright (c) 2011-2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -11,53 +11,33 @@

package io.vertx.mssqlclient.impl.codec;

import io.vertx.mssqlclient.impl.protocol.datatype.MSSQLDataType;
import io.vertx.sqlclient.desc.ColumnDescriptor;

import java.sql.JDBCType;

public final class ColumnData implements ColumnDescriptor {
/*
Protocol reference: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/58880b9f-381c-43b2-bf8b-0727a98c4f4c
*/
private final long usertype;
private final int flags;
private final MSSQLDataType dataType;
private final String colName;

// CryptoMetaData support?
String tableName;
private final String name;
private final DataType dataType;
private final DataType.Metadata metadata;

public ColumnData(long usertype, int flags, MSSQLDataType dataType, String colName) {
this.usertype = usertype;
this.flags = flags;
public ColumnData(String name, DataType dataType, DataType.Metadata metadata) {
this.dataType = dataType;
this.colName = colName;
this.name = name;
this.metadata = metadata;
}

public long usertype() {
return usertype;
}

public int flags() {
return flags;
}

public MSSQLDataType dataType() {
public DataType dataType() {
return dataType;
}

public String colName() {
return colName;
}

public String tableName() {
return tableName;
public DataType.Metadata metadata() {
return metadata;
}

@Override
public String name() {
return colName;
return name;
}

@Override
Expand All @@ -67,22 +47,6 @@ public boolean isArray() {

@Override
public JDBCType jdbcType() {
return dataType.jdbcType();
}

public static final class Flags {
public static final int NULLABLE = 0x0001;
public static final int CASESEN = 0x0002;
public static final int UPDATEABLE = 0x0004;
public static final int IDENTITY = 0x0010;
public static final int COMPUTED = 0x0020;
// 2-BIT RESERVED for ODBC
public static final int FIXED_LEN_CLR_TYPE = 0x0100;
// 1-BIT RESERVED
public static final int SPARSE_COLUMN_SET = 0x0400;
public static final int ENCRYPTED = 0x0800;
public static final int HIDDEN = 0x2000;
public static final int KEY = 0x4000;
public static final int NULLABLE_UNKNOWN = 0x8000;
return dataType.jdbcType(metadata);
}
}
Loading