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

Check for JSON feature extension #2553

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@
static final byte TDS_FEATURE_EXT_AZURESQLDNSCACHING = 0x0B;
static final byte TDS_FEATURE_EXT_SESSIONRECOVERY = 0x01;

// JSON support
static final byte TDS_FEATURE_EXT_JSONSUPPORT = 0x0D;
static final byte JSONSUPPORT_NOT_SUPPORTED = 0x00;
static final byte MAX_JSONSUPPORT_VERSION = 0x01;

static final int TDS_TVP = 0xF3;
static final int TVP_ROW = 0x01;
static final int TVP_NULL_TOKEN = 0xFFFF;
Expand Down Expand Up @@ -237,6 +242,9 @@
return "TDS_FEATURE_EXT_AZURESQLDNSCACHING (0x0B)";
case TDS_FEATURE_EXT_SESSIONRECOVERY:
return "TDS_FEATURE_EXT_SESSIONRECOVERY (0x01)";
case TDS_FEATURE_EXT_JSONSUPPORT:
return "TDS_FEATURE_EXT_JSONSUPPORT (0x0D)";

Check warning on line 246 in src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java#L246

Added line #L246 was not covered by tests

default:
return "unknown token (0x" + Integer.toHexString(tdsTokenType).toUpperCase() + ")";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,16 @@
return serverSupportedDataClassificationVersion;
}

/** whether server supports JSON */
private boolean serverSupportsJSON = false;

/** server supported JSON version */
private byte serverSupportedJSONVersion = TDS.JSONSUPPORT_NOT_SUPPORTED;

boolean getServerSupportsJSON() {
return serverSupportsJSON;

Check warning on line 1031 in src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java#L1031

Added line #L1031 was not covered by tests
}

/** Boolean that indicates whether LOB objects created by this connection should be loaded into memory */
private boolean delayLoadingLobs = SQLServerDriverBooleanProperty.DELAY_LOADING_LOBS.getDefaultValue();

Expand Down Expand Up @@ -5340,6 +5350,17 @@
return len;
}

int writeJSONSupportFeatureRequest(boolean write, /* if false just calculates the length */
TDSWriter tdsWriter) throws SQLServerException {
int len = 6; // 1byte = featureID, 4bytes = featureData length, 1 bytes = Version
if (write) {
tdsWriter.writeByte(TDS.TDS_FEATURE_EXT_JSONSUPPORT);
tdsWriter.writeInt(1);
tdsWriter.writeByte(TDS.MAX_JSONSUPPORT_VERSION);
}
return len;
}

int writeIdleConnectionResiliencyRequest(boolean write, TDSWriter tdsWriter) throws SQLServerException {
SessionStateTable ssTable = sessionRecovery.getSessionStateTable();
int len = 1;
Expand Down Expand Up @@ -6469,6 +6490,24 @@
sessionRecovery.setConnectionRecoveryPossible(true);
break;
}

Check warning on line 6493 in src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java#L6493

Added line #L6493 was not covered by tests
case TDS.TDS_FEATURE_EXT_JSONSUPPORT: {
if (connectionlogger.isLoggable(Level.FINER)) {
connectionlogger.fine(toString() + " Received feature extension acknowledgement for JSON Support.");
}

Check warning on line 6498 in src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java#L6498

Added line #L6498 was not covered by tests
if (1 != data.length) {
throw new SQLServerException(SQLServerException.getErrString("R_unknownJSONSupportValue"), null);
}

serverSupportedJSONVersion = data[0];
if (0 == serverSupportedJSONVersion || serverSupportedJSONVersion > TDS.MAX_JSONSUPPORT_VERSION) {
throw new SQLServerException(SQLServerException.getErrString("R_InvalidJSONVersionNumber"), null);
}

Check warning on line 6506 in src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java#L6506

Added line #L6506 was not covered by tests
serverSupportsJSON = true;
break;
}

default: {
// Unknown feature ack
throw new SQLServerException(SQLServerException.getErrString("R_UnknownFeatureAck"), null);
Expand Down Expand Up @@ -6768,6 +6807,9 @@

len = len + writeDNSCacheFeatureRequest(false, tdsWriter);

// request JSON support
len += writeJSONSupportFeatureRequest(false, tdsWriter);

len = len + 1; // add 1 to length because of FeatureEx terminator

// Idle Connection Resiliency is requested
Expand Down Expand Up @@ -6964,6 +7006,7 @@
writeDataClassificationFeatureRequest(true, tdsWriter);
writeUTF8SupportFeatureRequest(true, tdsWriter);
writeDNSCacheFeatureRequest(true, tdsWriter);
writeJSONSupportFeatureRequest(true, tdsWriter);

// Idle Connection Resiliency is requested
if (connectRetryCount > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ protected Object[][] getContents() {
{"R_StreamingDataTypeAE", "Data of length greater than {0} is not supported in encrypted {1} column."},
{"R_AE_NotSupportedByServer", "SQL Server in use does not support column encryption."},
{"R_InvalidAEVersionNumber", "Received invalid version number \"{0}\" for Always Encrypted."}, // From server
{"R_InvalidJSONVersionNumber", "Received invalid version number \"{0}\" for JSON."},
{"R_NullEncryptedColumnEncryptionKey", "Internal error. Encrypted column encryption key cannot be null."},
{"R_EmptyEncryptedColumnEncryptionKey", "Internal error. Empty encrypted column encryption key specified."},
{"R_InvalidMasterKeyDetails", "Invalid master key details specified."},
Expand Down Expand Up @@ -470,6 +471,7 @@ protected Object[][] getContents() {
{"R_InvalidDataClsVersionNumber", "Invalid version number {0} for Data Classification."}, // From Server
{"R_unknownUTF8SupportValue", "Unknown value for UTF8 support."},
{"R_unknownAzureSQLDNSCachingValue", "Unknown value for Azure SQL DNS Caching."},
{"R_unknownJSONSupportValue", "Unknown value for JSON support."},
{"R_illegalWKT", "Illegal Well-Known text. Please make sure Well-Known text is valid."},
{"R_illegalTypeForGeometry", "{0} is not supported for Geometry."},
{"R_illegalWKTposition", "Illegal character in Well-Known text at position {0}."},
Expand Down
Loading