use of com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData in project mssql-jdbc by Microsoft.
the class DatabaseMetaDataForeignKeyTest method testGetExportedKeys.
/**
* test getExportedKeys() methods
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testGetExportedKeys() throws SQLException {
String[] tableNames = { table2, table3, table4, table5 };
int[][] values = { // expected UPDATE_RULE, expected DELETE_RULE
{ 4, 3 }, { 2, 0 }, { 0, 2 }, { 3, 4 } };
SQLServerDatabaseMetaData dmd = (SQLServerDatabaseMetaData) connection.getMetaData();
for (int i = 0; i < tableNames.length; i++) {
String pkTable = tableNames[i];
SQLServerResultSet rs1 = (SQLServerResultSet) dmd.getExportedKeys(null, null, pkTable);
rs1.next();
assertEquals(values[i][0], rs1.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs1.getInt("DELETE_RULE"));
SQLServerResultSet rs2 = (SQLServerResultSet) dmd.getExportedKeys(catalog, schema, pkTable);
rs2.next();
assertEquals(values[i][0], rs2.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs2.getInt("DELETE_RULE"));
SQLServerResultSet rs3 = (SQLServerResultSet) dmd.getExportedKeys(catalog, "", pkTable);
rs3.next();
assertEquals(values[i][0], rs3.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs3.getInt("DELETE_RULE"));
try {
dmd.getExportedKeys("", schema, pkTable);
fail("Exception is not thrown.");
} catch (SQLException e) {
assertTrue(e.getMessage().startsWith(EXPECTED_ERROR_MESSAGE));
}
}
}
Aggregations