use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.
the class BulkCopyCSVTest method validateValuesFromCSV.
/**
* validate value in csv and in destination table as string
*
* @param destinationTable
*/
static void validateValuesFromCSV(DBTable destinationTable, String inputFile) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath + inputFile), encoding))) {
if (inputFile.equalsIgnoreCase("BulkCopyCSVTestInput.csv"))
// skip first line as it is header
br.readLine();
try (DBResultSet dstResultSet = stmt.executeQuery("SELECT * FROM " + destinationTable.getEscapedTableName() + ";")) {
ResultSetMetaData destMeta = ((ResultSet) dstResultSet.product()).getMetaData();
int totalColumns = destMeta.getColumnCount();
while (dstResultSet.next()) {
String[] srcValues = br.readLine().split(delimiter);
if ((0 == srcValues.length) && (srcValues.length != totalColumns)) {
srcValues = new String[totalColumns];
Arrays.fill(srcValues, null);
}
for (int i = 1; i <= totalColumns; i++) {
String srcValue = srcValues[i - 1];
String dstValue = dstResultSet.getString(i);
srcValue = (null != srcValue) ? srcValue.trim() : srcValue;
dstValue = (null != dstValue) ? dstValue.trim() : dstValue;
// get the value from csv as string and compare them
ComparisonUtil.compareExpectedAndActual(java.sql.Types.VARCHAR, srcValue, dstValue);
}
}
}
} catch (Exception e) {
fail("CSV validation failed with " + e.getMessage());
}
}
use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.
the class bvtTest method testTwoResultsetsDifferentStmt.
/**
* Verify two concurrent resultsets from same connection, separate statements
*
* @throws SQLException
*/
@Test
public void testTwoResultsetsDifferentStmt() throws SQLException {
String query = "SELECT * FROM " + table1.getEscapedTableName();
String query2 = "SELECT * FROM " + table2.getEscapedTableName();
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt1 = conn.createStatement();
DBStatement stmt2 = conn.createStatement()) {
DBResultSet rs1 = stmt1.executeQuery(query);
DBResultSet rs2 = stmt2.executeQuery(query2);
// Interleave resultset calls
rs1.next();
rs1.verifyCurrentRow(table1);
rs2.next();
rs2.verifyCurrentRow(table2);
rs1.next();
rs1.verifyCurrentRow(table1);
rs1.verify(table1);
rs1.close();
rs2.next();
rs2.verify(table2);
rs2.close();
}
}
use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.
the class bvtTest method testCreatepreparedStatement.
/**
* Create a preparedStatement, call close
*
* @throws SQLException
*/
@Test
public void testCreatepreparedStatement() throws SQLException {
String colName = table1.getColumnName(7);
String value = table1.getRowData(7, 0).toString();
String query = "SELECT * from " + table1.getEscapedTableName() + " where [" + colName + "] = ? ";
try (DBConnection conn = new DBConnection(connectionString);
DBPreparedStatement pstmt = conn.prepareStatement(query)) {
pstmt.setObject(1, new BigDecimal(value));
DBResultSet rs = pstmt.executeQuery();
rs.verify(table1);
rs.close();
}
}
use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.
the class bvtTest method testStmtScrollSensitiveReadOnly.
/**
* Create a statement ResultSet.SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY, executeQuery verify cursor by using next and absolute and verify
* data
*
* @throws SQLException
*/
@Test
public void testStmtScrollSensitiveReadOnly() throws SQLException {
String query = "SELECT * FROM " + table1.getEscapedTableName();
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_READ_ONLY);
DBResultSet rs = stmt.executeQuery(query)) {
rs.next();
rs.next();
rs.verifyCurrentRow(table1);
rs.absolute(3);
rs.verifyCurrentRow(table1);
rs.absolute(1);
rs.verify(table1);
}
}
use of com.microsoft.sqlserver.testframework.DBResultSet 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);
}
}
Aggregations