use of com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData in project mssql-jdbc by Microsoft.
the class DatabaseMetaDataTest method testGetFunctionsWithWrongParams.
/**
* TODO: Check JDBC Specs: Can we have any tables/functions without category?
*
* Testing {@link SQLServerDatabaseMetaData#getFunctions(String, String, String)} with sending wrong category.
* @throws SQLException
*/
@Test
public void testGetFunctionsWithWrongParams() throws SQLException {
try {
DatabaseMetaData databaseMetaData = connection.getMetaData();
databaseMetaData.getFunctions("", null, "xp_%");
assertTrue(false, "As we are not supplying schema it should fail.");
} catch (Exception ae) {
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData in project mssql-jdbc by Microsoft.
the class DatabaseMetaDataTest method testDBSchema.
/**
* Testing of {@link SQLServerDatabaseMetaData#getSchemas()}
* @throws SQLException
*/
@Test
public void testDBSchema() throws SQLException {
DatabaseMetaData databaseMetaData = connection.getMetaData();
ResultSet rs = databaseMetaData.getSchemas();
while (rs.next()) {
assertTrue(!StringUtils.isEmpty(rs.getString(1)), "Schema Name should not be Empty");
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData in project mssql-jdbc by Microsoft.
the class DatabaseMetaDataForeignKeyTest method testGetImportedKeys.
/**
* test getImportedKeys() methods
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testGetImportedKeys() throws SQLException {
SQLServerDatabaseMetaData dmd = (SQLServerDatabaseMetaData) connection.getMetaData();
SQLServerResultSet rs1 = (SQLServerResultSet) dmd.getImportedKeys(null, null, table1);
validateGetImportedKeysResults(rs1);
SQLServerResultSet rs2 = (SQLServerResultSet) dmd.getImportedKeys(catalog, schema, table1);
validateGetImportedKeysResults(rs2);
SQLServerResultSet rs3 = (SQLServerResultSet) dmd.getImportedKeys(catalog, "", table1);
validateGetImportedKeysResults(rs3);
try {
dmd.getImportedKeys("", schema, table1);
fail("Exception is not thrown.");
} catch (SQLException e) {
assertTrue(e.getMessage().startsWith(EXPECTED_ERROR_MESSAGE));
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData in project mssql-jdbc by Microsoft.
the class DatabaseMetaDataTest method testGetFunctions.
/**
* Test {@link SQLServerDatabaseMetaData#getFunctions(String, String, String)}
* @throws SQLException
*/
@Test
public void testGetFunctions() throws SQLException {
DatabaseMetaData databaseMetaData = connection.getMetaData();
ResultSet rs = databaseMetaData.getFunctions(null, null, "xp_%");
while (rs.next()) {
assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_CAT")), "FUNCTION_CAT should not be NULL");
assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_SCHEM")), "FUNCTION_SCHEM should not be NULL");
assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_NAME")), "FUNCTION_NAME should not be NULL");
assertTrue(!StringUtils.isEmpty(rs.getString("NUM_INPUT_PARAMS")), "NUM_INPUT_PARAMS should not be NULL");
assertTrue(!StringUtils.isEmpty(rs.getString("NUM_OUTPUT_PARAMS")), "NUM_OUTPUT_PARAMS should not be NULL");
assertTrue(!StringUtils.isEmpty(rs.getString("NUM_RESULT_SETS")), "NUM_RESULT_SETS should not be NULL");
assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_TYPE")), "FUNCTION_TYPE should not be NULL");
}
rs.close();
}
use of com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData in project mssql-jdbc by Microsoft.
the class DatabaseMetaDataForeignKeyTest method testGetCrossReference.
/**
* test getCrossReference() methods
*
* @throws SQLException
* @throws SQLTimeoutException
*/
@Test
public void testGetCrossReference() throws SQLException {
String fkTable = table1;
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.getCrossReference(null, null, pkTable, null, null, fkTable);
rs1.next();
assertEquals(values[i][0], rs1.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs1.getInt("DELETE_RULE"));
SQLServerResultSet rs2 = (SQLServerResultSet) dmd.getCrossReference(catalog, schema, pkTable, catalog, schema, fkTable);
rs2.next();
assertEquals(values[i][0], rs2.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs2.getInt("DELETE_RULE"));
SQLServerResultSet rs3 = (SQLServerResultSet) dmd.getCrossReference(catalog, "", pkTable, catalog, "", fkTable);
rs3.next();
assertEquals(values[i][0], rs3.getInt("UPDATE_RULE"));
assertEquals(values[i][1], rs3.getInt("DELETE_RULE"));
try {
dmd.getCrossReference("", schema, pkTable, "", schema, fkTable);
fail("Exception is not thrown.");
} catch (SQLException e) {
assertEquals(EXPECTED_ERROR_MESSAGE2, e.getMessage());
}
}
}
Aggregations