Skip to content

Commit

Permalink
0005711: When connecting to Azure, set platform version to SQL Server
Browse files Browse the repository at this point in the history
2016
  • Loading branch information
Philip Marzullo committed Feb 27, 2023
1 parent 975430f commit b9f9879
Showing 1 changed file with 15 additions and 10 deletions.
Expand Up @@ -314,8 +314,11 @@ protected void determineDatabaseNameVersionSubprotocol(DataSource dataSource, Co
}
}
if (nameVersion.getProtocol().equalsIgnoreCase(MsSql2016DatabasePlatform.JDBC_SUBPROTOCOL)) {
if (isMSSQLAzureManagedInstance(connection)) {
int engineEdition = getMsSqlEngineEdition(connection);
if (isMSSQLAzureManagedInstance(engineEdition)) {
nameVersion.setName(DatabaseNamesConstants.MSSQLAZURE);
} else if (engineEdition >= 5) {
nameVersion.setName(DatabaseNamesConstants.MSSQL2016);
}
}
if (nameVersion.getProtocol().equalsIgnoreCase(SqlAnywhereDatabasePlatform.JDBC_SUBPROTOCOL_SHORT) && nameVersion.getVersion() >= 12) {
Expand Down Expand Up @@ -372,19 +375,21 @@ private boolean isFirebirdDialect1(Connection connection) {
return isDialect1;
}

private boolean isMSSQLAzureManagedInstance(Connection connection) {
boolean isManagedInstance = false;
try (Statement s = connection.createStatement()) {
private boolean isMSSQLAzureManagedInstance(int engineEdition) {
return engineEdition == 8;
}

private int getMsSqlEngineEdition(Connection connection) {
int engineEdition = -1;
try (Statement s = connection.createStatement()) {
ResultSet rs = s.executeQuery("SELECT CAST(SERVERPROPERTY('EngineEdition') AS INT)");
if (rs.next()) {
if (rs.getInt(1) == 8) {
isManagedInstance = true;
}
engineEdition = rs.getInt(1);
}
} catch (Exception e) {
log.info("Azure Managed Instance of SQLServer not detected.");
} catch (SQLException e) {
log.info("Unable to get Sql Server Engine Edition");
}
return isManagedInstance;
return engineEdition;
}

private boolean isOracle122Compatible(Connection connection) {
Expand Down

0 comments on commit b9f9879

Please sign in to comment.