Skip to content

Commit 1b333c0

Browse files
author
Divang Sharma
committed
Added one more state - NOT_SET for QUOTED_IDENTIFIER and CONCAT_NULL_YIELDS_NULL flag
1 parent cf9ea3a commit 1b333c0

File tree

2 files changed

+52
-33
lines changed

2 files changed

+52
-33
lines changed

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

+46-30
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ public String toString() {
299299
/** flag indicating whether prelogin TLS handshake is required */
300300
private boolean isTDS8 = false;
301301

302+
/** flag to indicating whether QUOTED_IDENTIFIER is ON/OFF */
303+
private OnOffOption isQuotedIdentifierOn = OnOffOption.NOT_SET;
304+
305+
/** flag to indicating whether CONCAT_NULL_YIELDS_NULL is ON/OFF */
306+
private OnOffOption isConcatNullYieldsNullOn = OnOffOption.NOT_SET;
307+
302308
/** encrypted truststore password */
303309
byte[] encryptedTrustStorePassword = null;
304310

@@ -1813,6 +1819,20 @@ final void setMaxFieldSize(int limit) throws SQLServerException {
18131819
}
18141820
}
18151821

1822+
private void setCustomFlags() {
1823+
try{
1824+
if (OnOffOption.OFF.equals(isQuotedIdentifierOn)) {
1825+
connectionCommand("SET QUOTED_IDENTIFIER OFF", "quotedIdentifier");
1826+
}
1827+
1828+
if (OnOffOption.OFF.equals(isConcatNullYieldsNullOn)) {
1829+
connectionCommand("SET CONCAT_NULL_YIELDS_NULL OFF", "concatNullYieldsNull");
1830+
}
1831+
} catch(SQLServerException e) {
1832+
loggerExternal.log(Level.WARNING, "Error setting QUOTED_IDENTIFIER and CONCAT_NULL_YIELDS_NULL properties", e);
1833+
}
1834+
}
1835+
18161836
/**
18171837
* This function is used both to init the values on creation of connection and resetting the values after the
18181838
* connection is released to the pool for reuse.
@@ -1828,36 +1848,7 @@ final void initResettableValues() {
18281848
sqlWarnings = null;
18291849
sCatalog = originalCatalog;
18301850
databaseMetaData = null;
1831-
1832-
try{
1833-
// check QUOTED_IDENTIFIER property
1834-
String quotedIdentifierProperty = SQLServerDriverStringProperty.QUOTED_IDENTIFIER.toString();
1835-
String quotedIdentifierValue = activeConnectionProperties.getProperty(quotedIdentifierProperty);
1836-
if (null == quotedIdentifierValue) {
1837-
quotedIdentifierValue = SQLServerDriverStringProperty.QUOTED_IDENTIFIER.getDefaultValue();
1838-
activeConnectionProperties.setProperty(quotedIdentifierProperty, quotedIdentifierValue);
1839-
}
1840-
1841-
String quotedIdentifierOption = OnOffOption.valueOfString(quotedIdentifierValue).toString();
1842-
if (quotedIdentifierOption.compareToIgnoreCase(OnOffOption.OFF.toString()) == 0) {
1843-
connectionCommand("SET QUOTED_IDENTIFIER OFF", "quotedIdentifier");
1844-
}
1845-
1846-
// check CONCAT_NULL_YIELDS_NULL property
1847-
String concatNullYieldsNullProperty = SQLServerDriverStringProperty.CONCAT_NULL_YIELDS_NULL.toString();
1848-
String concatNullYieldsNullValue = activeConnectionProperties.getProperty(concatNullYieldsNullProperty);
1849-
if (null == concatNullYieldsNullValue) {
1850-
concatNullYieldsNullValue = SQLServerDriverStringProperty.CONCAT_NULL_YIELDS_NULL.getDefaultValue();
1851-
activeConnectionProperties.setProperty(concatNullYieldsNullProperty, concatNullYieldsNullValue);
1852-
}
1853-
String concatNullYieldsNullOption = OnOffOption.valueOfString(concatNullYieldsNullValue).toString();
1854-
if (concatNullYieldsNullOption.compareToIgnoreCase(OnOffOption.OFF.toString()) == 0) {
1855-
connectionCommand("SET CONCAT_NULL_YIELDS_NULL OFF", "concatNullYieldsNull");
1856-
1857-
}
1858-
} catch(SQLServerException e) {
1859-
loggerExternal.log(Level.WARNING, "Error setting QUOTED_IDENTIFIER and CONCAT_NULL_YIELDS_NULL properties", e);
1860-
}
1851+
setCustomFlags();
18611852
}
18621853

18631854
/** Limit for the maximum number of rows returned from queries on this connection */
@@ -3557,6 +3548,31 @@ else if (0 == requestedPacketSize)
35573548

35583549
state = State.OPENED;
35593550

3551+
// check QUOTED_IDENTIFIER property
3552+
String quotedIdentifierProperty = SQLServerDriverStringProperty.QUOTED_IDENTIFIER.toString();
3553+
String quotedIdentifierValue = activeConnectionProperties.getProperty(quotedIdentifierProperty);
3554+
if (null == quotedIdentifierValue) {
3555+
quotedIdentifierValue = SQLServerDriverStringProperty.QUOTED_IDENTIFIER.getDefaultValue();
3556+
activeConnectionProperties.setProperty(quotedIdentifierProperty, quotedIdentifierValue);
3557+
}
3558+
3559+
isQuotedIdentifierOn = OnOffOption.valueOfString(quotedIdentifierValue);
3560+
if (!isQuotedIdentifierOn.equals(OnOffOption.NOT_SET)) {
3561+
connectionCommand("SET QUOTED_IDENTIFIER " + isQuotedIdentifierOn, "quotedIdentifier");
3562+
}
3563+
3564+
// check CONCAT_NULL_YIELDS_NULL property
3565+
String concatNullYieldsNullProperty = SQLServerDriverStringProperty.CONCAT_NULL_YIELDS_NULL.toString();
3566+
String concatNullYieldsNullValue = activeConnectionProperties.getProperty(concatNullYieldsNullProperty);
3567+
if (null == concatNullYieldsNullValue) {
3568+
concatNullYieldsNullValue = SQLServerDriverStringProperty.CONCAT_NULL_YIELDS_NULL.getDefaultValue();
3569+
activeConnectionProperties.setProperty(concatNullYieldsNullProperty, concatNullYieldsNullValue);
3570+
}
3571+
isConcatNullYieldsNullOn = OnOffOption.valueOfString(concatNullYieldsNullValue);
3572+
if (!isConcatNullYieldsNullOn.equals(OnOffOption.NOT_SET)) {
3573+
connectionCommand("SET CONCAT_NULL_YIELDS_NULL " + isConcatNullYieldsNullOn, "concatNullYieldsNull");
3574+
}
3575+
35603576
// Socket timeout is bounded by loginTimeout during the login phase.
35613577
// Reset socket timeout back to the original value.
35623578
tdsChannel.resetTcpSocketTimeout();

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ enum SQLServerDriverStringProperty {
613613
ACCESS_TOKEN_CALLBACK_CLASS("accessTokenCallbackClass", ""),
614614
RETRY_EXEC("retryExec", ""),
615615
RETRY_CONN("retryConn", ""),
616-
QUOTED_IDENTIFIER("quotedIdentifier", OnOffOption.OFF.toString()),
617-
CONCAT_NULL_YIELDS_NULL("concatNullYieldsNull", OnOffOption.OFF.toString());
616+
QUOTED_IDENTIFIER("quotedIdentifier", OnOffOption.NOT_SET.toString()),
617+
CONCAT_NULL_YIELDS_NULL("concatNullYieldsNull", OnOffOption.NOT_SET.toString());
618618

619619
private final String name;
620620
private final String defaultValue;
@@ -732,7 +732,8 @@ public String toString() {
732732

733733
enum OnOffOption {
734734
ON("ON"),
735-
OFF("OFF");
735+
OFF("OFF"),
736+
NOT_SET("NOT_SET");
736737

737738
private final String option;
738739

@@ -752,6 +753,8 @@ static OnOffOption valueOfString(String value) throws SQLServerException {
752753
option = OnOffOption.ON;
753754
} else if (value.toLowerCase(Locale.US).equalsIgnoreCase(OnOffOption.OFF.toString())) {
754755
option = OnOffOption.OFF;
756+
} else if (value.toLowerCase(Locale.US).equalsIgnoreCase(OnOffOption.NOT_SET.toString())) {
757+
option = OnOffOption.NOT_SET;
755758
} else {
756759
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting"));
757760
Object[] msgArgs = {"OnOffOption", value};

0 commit comments

Comments
 (0)