Search in sources :

Example 11 with DBResultSet

use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.

the class BulkCopyColumnMappingTest method validateValuesRepetativeCM.

/**
 * validate if same values are in both source and destination table taking into account 1 extra column in destination which should be a copy of
 * first column of source.
 *
 * @param con
 * @param sourceTable
 * @param destinationTable
 * @throws SQLException
 */
private void validateValuesRepetativeCM(DBConnection con, DBTable sourceTable, DBTable destinationTable) throws SQLException {
    try (DBStatement srcStmt = con.createStatement();
        DBStatement dstStmt = con.createStatement();
        DBResultSet srcResultSet = srcStmt.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + ";");
        DBResultSet dstResultSet = dstStmt.executeQuery("SELECT * FROM " + destinationTable.getEscapedTableName() + ";")) {
        ResultSetMetaData sourceMeta = ((ResultSet) srcResultSet.product()).getMetaData();
        int totalColumns = sourceMeta.getColumnCount();
        // verify data from sourceType and resultSet
        while (srcResultSet.next() && dstResultSet.next()) {
            for (int i = 1; i <= totalColumns; i++) {
                // TODO: check row and column count in both the tables
                Object srcValue, dstValue;
                srcValue = srcResultSet.getObject(i);
                dstValue = dstResultSet.getObject(i);
                ComparisonUtil.compareExpectedAndActual(sourceMeta.getColumnType(i), srcValue, dstValue);
                // compare value of first column of source with extra column in destination
                if (1 == i) {
                    Object srcValueFirstCol = srcResultSet.getObject(i);
                    Object dstValLastCol = dstResultSet.getObject(totalColumns + 1);
                    ComparisonUtil.compareExpectedAndActual(sourceMeta.getColumnType(i), srcValueFirstCol, dstValLastCol);
                }
            }
        }
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) ResultSet(java.sql.ResultSet) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet)

Example 12 with DBResultSet

use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.

the class bvtTest method testStmtSserverCursorForwardOnly.

/**
 * Create a statement TYPE_SS_SEVER_CURSOR_FORWARD_ONLY, CONCUR_READ_ONLY, executeQuery verify cursor by using next and verify data
 *
 * @throws SQLException
 */
@Test
public void testStmtSserverCursorForwardOnly() throws SQLException {
    DBResultSetTypes rsType = DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_READ_ONLY;
    String query = "SELECT * FROM " + table1.getEscapedTableName();
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement(rsType.resultsetCursor, rsType.resultSetConcurrency);
        DBResultSet rs = stmt.executeQuery(query)) {
        // Verify resultset behavior
        rs.next();
        rs.verify(table1);
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) DBResultSetTypes(com.microsoft.sqlserver.testframework.DBResultSetTypes) Test(org.junit.jupiter.api.Test)

Example 13 with DBResultSet

use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.

the class bvtTest method testStmtScrollInsensitiveReadOnly.

/**
 * Create a statement, ResultSet.SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, executeQuery verify cursor by using next, afterlast and previous
 * and verify data
 *
 * @throws SQLException
 * @throws ClassNotFoundException
 */
@Test
public void testStmtScrollInsensitiveReadOnly() throws SQLException, ClassNotFoundException {
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_INSENSITIVE_CONCUR_READ_ONLY);
        DBResultSet rs = stmt.selectAll(table1)) {
        rs.next();
        rs.verifyCurrentRow(table1);
        rs.afterLast();
        rs.previous();
        rs.verifyCurrentRow(table1);
        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 14 with DBResultSet

use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.

the class bvtTest method testStmtScrollSensitiveUpdatable.

/**
 * Create a statement ResultSet.SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, executeQuery verify cursor by using next and previous and verify
 * data
 *
 * @throws SQLException
 */
@Test
public void testStmtScrollSensitiveUpdatable() throws SQLException {
    String query = "SELECT * FROM " + table1.getEscapedTableName();
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_UPDATABLE);
        DBResultSet rs = stmt.executeQuery(query)) {
        // Verify resultset behavior
        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 15 with DBResultSet

use of com.microsoft.sqlserver.testframework.DBResultSet in project mssql-jdbc by Microsoft.

the class bvtTest method testStmtForwardOnlyUpdateable.

/**
 * Create a statement ResultSet.Type_forward_only, ResultSet.CONCUR_UPDATABLE, executeQuery verify cursor by using next and previous and verify
 * data
 *
 * @throws SQLException
 */
@Test
public void testStmtForwardOnlyUpdateable() throws SQLException {
    String query = "SELECT * FROM " + table1.getEscapedTableName();
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_UPDATABLE);
        DBResultSet rs = stmt.executeQuery(query)) {
        rs.next();
        // Verify resultset behavior
        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);
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) SQLException(java.sql.SQLException) 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