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

Added DatabaseMetaData.getDatabaseCompatabilityLevel #1345

Merged
merged 2 commits into from
Jun 15, 2020
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 @@ -2537,6 +2537,27 @@ public boolean locatorsUpdateCopy() throws SQLException {
checkClosed();
return true;
}

/* -------------- MSSQL-JDBC Extension methods start here --------------- */

ulvii marked this conversation as resolved.
Show resolved Hide resolved
/**
* Returns the database compatibility level setting for the current database. This is useful if the
* database's compatibility level is lower than the engine version. In this case the database will only
* support SQL commands at its compatibility level, and not the wider set of commands accepted by the
* engine.
*
* @return the database compatibility level value (from sys.databases table).
*/
public int getDatabaseCompatibilityLevel() throws SQLException {
checkClosed();
String database = connection.getCatalog();
SQLServerResultSet rs = getResultSetFromInternalQueries(null,
"select name, compatibility_level from sys.databases where name = '" + database + "'");
if (!rs.next()) {
return 0;
}
return rs.getInt("compatibility_level");
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ public void testDriverVersion() throws SQLException, IOException {
}
}

@Test
public void testDatabaseCompatibilityLevel() throws SQLException {
try (Connection conn = getConnection()) {
SQLServerDatabaseMetaData dbmData = (SQLServerDatabaseMetaData) conn.getMetaData();
int compatibilityLevel = dbmData.getDatabaseCompatibilityLevel();
assertTrue(compatibilityLevel > 0);
}
}

/**
* Your password should not be in getURL method.
*
Expand Down