use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.
the class bvtTest method testResultSetAndCloseStmt.
/**
* Verify resultset closed after statement is closed
*
* @throws SQLException
*/
@Test
public void testResultSetAndCloseStmt() throws SQLException {
String query = "SELECT * FROM " + table1.getEscapedTableName();
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement();
DBResultSet rs = stmt.executeQuery(query)) {
// this should close the resultSet
stmt.close();
try {
rs.next();
} catch (SQLException e) {
assertEquals(e.toString(), "com.microsoft.sqlserver.jdbc.SQLServerException: The result set is closed.");
}
assertTrue(true, "Previous one should have thrown exception!");
}
}
use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.
the class bvtTest method testStmtForwardOnlyReadOnly.
/**
* Create a statement ResultSet.Type_forward_only, ResultSet.CONCUR_READ_ONLY, executeQuery verify cursor by using next and previous and verify
* data
*
* @throws SQLException
* @throws ClassNotFoundException
*/
@Test
public void testStmtForwardOnlyReadOnly() throws SQLException, ClassNotFoundException {
String query = "SELECT * FROM " + table1.getEscapedTableName();
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_READ_ONLY);
DBResultSet rs = stmt.executeQuery(query)) {
rs.next();
rs.verifyCurrentRow(table1);
rs.next();
rs.verifyCurrentRow(table1);
try {
rs.previous();
assertTrue(false, "Previous should have thrown an exception");
} catch (SQLException ex) {
// expected exception
}
rs.verify(table1);
}
}
use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.
the class ComparisonUtil method compareSrcTableAndDestTableIgnoreRowOrder.
/**
* test if source table and destination table are the same
*
* @param con
* @param srcTable
* @param destTable
* @throws SQLException
*/
public static void compareSrcTableAndDestTableIgnoreRowOrder(DBConnection con, DBTable srcTable, DBTable destTable) throws SQLException {
DBResultSet srcResultSetCount = con.createStatement().executeQuery("SELECT COUNT(*) FROM " + srcTable.getEscapedTableName() + ";");
DBResultSet dstResultSetCount = con.createStatement().executeQuery("SELECT COUNT(*) FROM " + destTable.getEscapedTableName() + ";");
srcResultSetCount.next();
dstResultSetCount.next();
int srcRows = srcResultSetCount.getInt(1);
int destRows = dstResultSetCount.getInt(1);
if (srcRows != destRows) {
fail("Souce table and Destination table have different number of rows.");
}
if (srcTable.getColumns().size() != destTable.getColumns().size()) {
fail("Souce table and Destination table have different number of columns.");
}
DBResultSet srcResultSet = con.createStatement().executeQuery("SELECT * FROM " + srcTable.getEscapedTableName() + " ORDER BY [" + srcTable.getColumnName(1) + "], [" + srcTable.getColumnName(2) + "],[" + srcTable.getColumnName(3) + "];");
DBResultSet dstResultSet = con.createStatement().executeQuery("SELECT * FROM " + destTable.getEscapedTableName() + " ORDER BY [" + destTable.getColumnName(1) + "], [" + destTable.getColumnName(2) + "],[" + destTable.getColumnName(3) + "];");
while (srcResultSet.next() && dstResultSet.next()) {
for (int i = 0; i < destTable.getColumns().size(); i++) {
SQLServerResultSetMetaData srcMeta = (SQLServerResultSetMetaData) ((ResultSet) srcResultSet.product()).getMetaData();
SQLServerResultSetMetaData destMeta = (SQLServerResultSetMetaData) ((ResultSet) dstResultSet.product()).getMetaData();
int srcJDBCTypeInt = srcMeta.getColumnType(i + 1);
int destJDBCTypeInt = destMeta.getColumnType(i + 1);
// verify column types
if (srcJDBCTypeInt != destJDBCTypeInt) {
fail("Souce table and Destination table have different number of columns.");
}
Object expectedValue = srcResultSet.getObject(i + 1);
Object actualValue = dstResultSet.getObject(i + 1);
compareExpectedAndActual(destJDBCTypeInt, expectedValue, actualValue);
}
}
}
Aggregations