Search in sources :

Example 1 with DBResultSet

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());
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ResultSet(java.sql.ResultSet) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) FileInputStream(java.io.FileInputStream) SQLException(java.sql.SQLException)

Example 2 with DBResultSet

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();
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) Test(org.junit.jupiter.api.Test)

Example 3 with DBResultSet

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();
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBPreparedStatement(com.microsoft.sqlserver.testframework.DBPreparedStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 4 with DBResultSet

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);
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) Test(org.junit.jupiter.api.Test)

Example 5 with DBResultSet

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);
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) Test(org.junit.jupiter.api.Test)

Aggregations

DBResultSet (com.microsoft.sqlserver.testframework.DBResultSet)18 DBStatement (com.microsoft.sqlserver.testframework.DBStatement)15 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)13 Test (org.junit.jupiter.api.Test)11 SQLException (java.sql.SQLException)6 ResultSet (java.sql.ResultSet)4 ResultSetMetaData (java.sql.ResultSetMetaData)4 SQLServerBulkCopy (com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)1 SQLServerResultSetMetaData (com.microsoft.sqlserver.jdbc.SQLServerResultSetMetaData)1 ColumnMap (com.microsoft.sqlserver.jdbc.bulkCopy.BulkCopyTestWrapper.ColumnMap)1 DBColumn (com.microsoft.sqlserver.testframework.DBColumn)1 DBPreparedStatement (com.microsoft.sqlserver.testframework.DBPreparedStatement)1 DBResultSetTypes (com.microsoft.sqlserver.testframework.DBResultSetTypes)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 BigDecimal (java.math.BigDecimal)1