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

fix a bug when the value of queryTimeout is bigger than the max value of integer #78

Merged
merged 1 commit into from
Dec 13, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ final ApplicationIntent getApplicationIntent()
final String getSelectMethod() { return selectMethod; }
private String responseBuffering;
final String getResponseBuffering() { return responseBuffering; }
private int queryTimeoutSeconds ;
final int getQueryTimeoutSeconds() { return queryTimeoutSeconds; }

private boolean sendTimeAsDatetime = SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.getDefaultValue();

Expand Down Expand Up @@ -1457,6 +1459,34 @@ else if (0 == requestedPacketSize)
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
}

sPropKey = SQLServerDriverIntProperty.QUERY_TIMEOUT.toString();
int defaultQueryTimeout = SQLServerDriverIntProperty.QUERY_TIMEOUT.getDefaultValue();
queryTimeoutSeconds = defaultQueryTimeout; //Wait forever
if (activeConnectionProperties.getProperty(sPropKey) != null &&
activeConnectionProperties.getProperty(sPropKey).length() > 0)
{
try
{
int n = (new Integer(activeConnectionProperties.getProperty(sPropKey))).intValue();
if (n>=defaultTimeOut){
queryTimeoutSeconds = n;
}
else
{
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidQueryTimeout"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in case of wrong querytimeout we should fallback to some valid querytimeout by logging error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be consistent with our current implementation of LoginTimeout and LockTimeout. In both case of LoginTimeoutand and LockTimeout, we throw exceptions.

SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
}
catch (NumberFormatException e)
{
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidQueryTimeout"));
Object[] msgArgs = {activeConnectionProperties.getProperty(sPropKey)};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}
}

FailoverInfo fo =null;
String databaseNameProperty = SQLServerDriverStringProperty.DATABASE_NAME.toString();
String serverNameProperty = SQLServerDriverStringProperty.SERVER_NAME.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ protected Object[][] getContents()
{"R_sendTimeAsDateTimeForAE", "Use sendTimeAsDateTime=false with Always Encrypted."},
{"R_invalidServerCursorForTVP" , "Use different Connection for source ResultSet and prepared query, if selectMethod is set to cursor for Table-Valued Parameter."},
{"R_TVPnotWorkWithSetObjectResultSet" , "setObject() with ResultSet is not supported for Table-Valued Parameter. Please use setStructured()"},
{"R_invalidQueryTimeout", "The queryTimeout {0} is not valid."},
};
}

Original file line number Diff line number Diff line change
Expand Up @@ -627,15 +627,10 @@ else if (ResultSet.TYPE_SCROLL_SENSITIVE == nType)

// add query timeout to statement
private void setDefaultQueryTimeout() {

String sPropValue = this.connection.activeConnectionProperties.getProperty(SQLServerDriverIntProperty.QUERY_TIMEOUT.toString());

if (null != sPropValue && sPropValue.length() > 0) {
int queryTimeoutSeconds = Integer.parseInt(sPropValue);
if (queryTimeoutSeconds > 0) {
this.queryTimeout = queryTimeoutSeconds;
}
}
int queryTimeoutSeconds = this.connection.getQueryTimeoutSeconds();
if (queryTimeoutSeconds > 0) {
this.queryTimeout = queryTimeoutSeconds;
}
}

final java.util.logging.Logger getStatementLogger()
Expand Down