use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.
the class bvtTest method testStmtSSScrollDynamicOptimisticCC.
/**
* Create a statement TYPE_SS_SCROLL_DYNAMIC, CONCUR_SS_OPTIMISTIC_CC, executeQuery verify cursor by using next and previous and verify data
*
* @throws SQLException
*/
@Test
public void testStmtSSScrollDynamicOptimisticCC() throws SQLException {
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_DYNAMIC_CONCUR_OPTIMISTIC);
DBResultSet rs = stmt.selectAll(table1)) {
// Verify resultset behavior
rs.next();
rs.afterLast();
rs.previous();
rs.verify(table1);
}
}
use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.
the class bvtTest method testConnectionIsClosed.
/**
* Verify isClosed()
*
* @throws SQLException
*/
@Test
public void testConnectionIsClosed() throws SQLException {
try (DBConnection conn = new DBConnection(connectionString)) {
assertTrue(!conn.isClosed(), "BVT connection should not be closed");
conn.close();
assertTrue(conn.isClosed(), "BVT connection should not be open");
}
}
use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.
the class bvtTest method testTwoResultsetsSameStmt.
/**
* Verify two concurrent resultsets from same connection, same statement
*
* @throws SQLException
*/
@Test
public void testTwoResultsetsSameStmt() throws SQLException {
String query = "SELECT * FROM " + table1.getEscapedTableName();
String query2 = "SELECT * FROM " + table2.getEscapedTableName();
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement()) {
DBResultSet rs1 = stmt.executeQuery(query);
DBResultSet rs2 = stmt.executeQuery(query2);
// Interleave resultset calls. rs is expected to be closed
try {
rs1.next();
} catch (SQLException e) {
assertEquals(e.toString(), "com.microsoft.sqlserver.jdbc.SQLServerException: The result set is closed.");
}
rs2.next();
rs2.verifyCurrentRow(table2);
try {
rs1.next();
} catch (SQLException e) {
assertEquals(e.toString(), "com.microsoft.sqlserver.jdbc.SQLServerException: The result set is closed.");
}
rs1.close();
rs2.next();
rs2.verify(table2);
rs2.close();
}
}
use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.
the class bvtTest method testDriverNameAndDriverVersion.
/**
* Verify Driver Name and Version from MetaData
*
* @throws SQLException
*/
@Test
public void testDriverNameAndDriverVersion() throws SQLException {
try (DBConnection conn = new DBConnection(connectionString)) {
DatabaseMetaData metaData = conn.getMetaData();
Pattern p = Pattern.compile(driverNamePattern);
Matcher m = p.matcher(metaData.getDriverName());
assertTrue(m.find(), "Driver name is not a correct format! ");
String[] parts = metaData.getDriverVersion().split("\\.");
if (parts.length != 4)
assertTrue(true, "Driver version number should be four parts! ");
}
}
use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.
the class BulkCopyTestUtil method performBulkCopy.
/**
* perform bulk copy using source and destination tables
*
* @param wrapper
* @param sourceTable
* @param destTable
* @param validateResult
*/
static void performBulkCopy(BulkCopyTestWrapper wrapper, DBTable sourceTable, DBTable destinationTable, boolean validateResult) {
try (DBConnection con = new DBConnection(wrapper.getConnectionString());
DBStatement stmt = con.createStatement();
DBResultSet srcResultSet = stmt.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + ";");
SQLServerBulkCopy bulkCopy = wrapper.isUsingConnection() ? new SQLServerBulkCopy((Connection) con.product()) : new SQLServerBulkCopy(wrapper.getConnectionString())) {
if (wrapper.isUsingBulkCopyOptions()) {
bulkCopy.setBulkCopyOptions(wrapper.getBulkOptions());
}
bulkCopy.setDestinationTableName(destinationTable.getEscapedTableName());
if (wrapper.isUsingColumnMapping()) {
for (int i = 0; i < wrapper.cm.size(); i++) {
ColumnMap currentMap = wrapper.cm.get(i);
if (currentMap.sourceIsInt && currentMap.destIsInt) {
bulkCopy.addColumnMapping(currentMap.srcInt, currentMap.destInt);
} else if (currentMap.sourceIsInt && (!currentMap.destIsInt)) {
bulkCopy.addColumnMapping(currentMap.srcInt, currentMap.destString);
} else if ((!currentMap.sourceIsInt) && currentMap.destIsInt) {
bulkCopy.addColumnMapping(currentMap.srcString, currentMap.destInt);
} else if ((!currentMap.sourceIsInt) && (!currentMap.destIsInt)) {
bulkCopy.addColumnMapping(currentMap.srcString, currentMap.destString);
}
}
}
bulkCopy.writeToServer((ResultSet) srcResultSet.product());
if (validateResult) {
validateValues(con, sourceTable, destinationTable);
}
} catch (SQLException ex) {
fail(ex.getMessage());
}
}
Aggregations