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

Handled failure in getApplicationName() #2571

Merged
merged 7 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -170,7 +170,7 @@ public void setApplicationName(String applicationName) {
@Override
public String getApplicationName() {
return getStringProperty(connectionProps, SQLServerDriverStringProperty.APPLICATION_NAME.toString(),
SQLServerDriverStringProperty.APPLICATION_NAME.getDefaultValue());
SQLServerDriver.constructedAppName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,9 @@ public java.sql.Connection connect(String url, Properties suppliedProperties) th
Properties connectProperties = parseAndMergeProperties(url, suppliedProperties);
if (connectProperties != null) {
result = DriverJDBCVersion.getSQLServerConnection(toString());
connectProperties.setProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString(), SQLServerDriver.constructedAppName);
if (suppliedProperties == null || (suppliedProperties != null && suppliedProperties.getProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString()) == null)) {
connectProperties.setProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString(), SQLServerDriver.constructedAppName);
}
result.connect(connectProperties, null);
}
loggerExternal.exiting(getClassNameLogging(), "connect", result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,24 @@ public void testApplicationName() throws SQLException {
}
}

/**
* test application name by executing select app_name()
*
* @throws SQLException
*/
@Test
public void testApplicationNameUsingApp_Name() throws SQLException {
try (Connection conn = DriverManager.getConnection(connectionString);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT app_name()")) {
if (rs.next()) {
assertEquals(SQLServerDriver.constructedAppName, rs.getString(1));
}
} catch (SQLException e) {
fail(e.getMessage());
}
}

/**
* test application name when system properties are empty
*
Expand Down
Loading