Search in sources :

Example 11 with DBStatement

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

the class BulkCopyTestUtil method validateValues.

/**
 * validate if same values are in both source and destination table
 *
 * @param con
 * @param sourceTable
 * @param destinationTable
 * @throws SQLException
 */
static void validateValues(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 destMeta = ((ResultSet) dstResultSet.product()).getMetaData();
        int totalColumns = destMeta.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(destMeta.getColumnType(i), srcValue, dstValue);
            }
        }
    }
}
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 DBStatement

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

the class TVPAllTypes method setupVariation.

private void setupVariation() throws SQLException {
    conn = DriverManager.getConnection(connectionString);
    stmt = conn.createStatement();
    Utils.dropProcedureIfExists(procedureName, stmt);
    dropTVPS(tvpName);
    DBConnection dbConnection = new DBConnection(connectionString);
    DBStatement dbStmt = dbConnection.createStatement();
    tableSrc = new DBTable(true);
    tableDest = tableSrc.cloneSchema();
    dbStmt.createTable(tableSrc);
    dbStmt.createTable(tableDest);
    createTVPS(tvpName, tableSrc.getDefinitionOfColumns());
    createPreocedure(procedureName, tableDest.getEscapedTableName());
    dbStmt.populateTable(tableSrc);
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBTable(com.microsoft.sqlserver.testframework.DBTable) DBStatement(com.microsoft.sqlserver.testframework.DBStatement)

Example 13 with DBStatement

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

the class lobsTest method testMultipleClose.

/**
 * Tests stream closures
 *
 * @param streamClass
 * @throws Exception
 */
private void testMultipleClose(Class streamClass) throws Exception {
    DBConnection conn = new DBConnection(connectionString);
    String[] types = { "varchar(max)", "nvarchar(max)", "varbinary(max)" };
    try {
        table = this.createTable(table, types, true);
        DBStatement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
        String query = "select * from " + table.getEscapedTableName();
        DBResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            for (int i = 0; i < 3; i++) {
                DBColumn col = table.getColumns().get(i);
                if (!col.getSqlType().canConvert(streamClass, DBCoercion.GET, new DBConnection(connectionString)))
                    continue;
                Object stream = rs.getXXX(i + 1, streamClass);
                if (stream == null) {
                    assertEquals(stream, rs.getObject(i + 1), "Stream is null when data is not");
                } else {
                    // close the stream twice
                    if (streamClass == DBCharacterStream.class) {
                        ((Reader) stream).close();
                        ((Reader) stream).close();
                    } else {
                        ((InputStream) stream).close();
                        ((InputStream) stream).close();
                    }
                }
            }
        }
    } finally {
        if (null != table)
            this.dropTables(table);
        if (null != null)
            conn.close();
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) DBColumn(com.microsoft.sqlserver.testframework.DBColumn) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet)

Example 14 with DBStatement

use of com.microsoft.sqlserver.testframework.DBStatement 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 15 with DBStatement

use of com.microsoft.sqlserver.testframework.DBStatement 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)

Aggregations

DBStatement (com.microsoft.sqlserver.testframework.DBStatement)24 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)21 DBResultSet (com.microsoft.sqlserver.testframework.DBResultSet)15 Test (org.junit.jupiter.api.Test)12 DBTable (com.microsoft.sqlserver.testframework.DBTable)6 SQLException (java.sql.SQLException)6 ResultSet (java.sql.ResultSet)3 ResultSetMetaData (java.sql.ResultSetMetaData)3 SQLServerBulkCopy (com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)2 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 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 SqlType (com.microsoft.sqlserver.testframework.sqlType.SqlType)1 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 Connection (java.sql.Connection)1