Search in sources :

Example 6 with DBTable

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

the class BulkCopyTestSetUp method setUpSourceTable.

/**
 * Create source table needed for testing bulk copy
 * @throws SQLException
 */
@BeforeAll
static void setUpSourceTable() throws SQLException {
    try (DBConnection con = new DBConnection(connectionString);
        DBStatement stmt = con.createStatement();
        DBPreparedStatement pstmt = new DBPreparedStatement(con)) {
        sourceTable = new DBTable(true);
        stmt.createTable(sourceTable);
        pstmt.populateTable(sourceTable);
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBPreparedStatement(com.microsoft.sqlserver.testframework.DBPreparedStatement) DBTable(com.microsoft.sqlserver.testframework.DBTable) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 7 with DBTable

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

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

the class BulkCopyColumnMappingTest method testRepetativeCM.

@Test
@DisplayName("BulkCopy:test repetative column mapping")
void testRepetativeCM() {
    // create source table
    DBTable sourceTable1 = new DBTable(true);
    stmt.createTable(sourceTable1);
    stmt.populateTable(sourceTable1);
    // create destication table with same shcema as source
    DBTable destTable = sourceTable1.cloneSchema();
    // add 1 column to destination which will be duplicate of first source column
    SqlType sqlType = sourceTable1.getSqlType(0);
    destTable.addColumn(sqlType);
    stmt.createTable(destTable);
    // set up bulkCopy with explicit column mapping
    BulkCopyTestWrapper bulkWrapper = new BulkCopyTestWrapper(connectionString);
    bulkWrapper.setUsingConnection((0 == ThreadLocalRandom.current().nextInt(2)) ? true : false);
    for (int i = 1; i <= sourceTable1.totalColumns(); i++) {
        int select = i % 4;
        switch(select) {
            case 0:
                bulkWrapper.setColumnMapping(i, i);
                break;
            case 1:
                bulkWrapper.setColumnMapping(i, destTable.getColumnName(i - 1));
                break;
            case 2:
                bulkWrapper.setColumnMapping(sourceTable1.getColumnName(i - 1), destTable.getColumnName(i - 1));
                break;
            case 3:
                bulkWrapper.setColumnMapping(sourceTable1.getColumnName(i - 1), i);
                break;
        }
    }
    // add column mapping for duplicate column in destination
    bulkWrapper.setColumnMapping(1, 24);
    // perform bulkCopy without validating results or dropping destination table
    BulkCopyTestUtil.performBulkCopy(bulkWrapper, sourceTable1, destTable, false, false, false);
    try {
        validateValuesRepetativeCM(con, sourceTable1, destTable);
    } catch (SQLException e) {
        fail("failed to validate values in " + sourceTable1.getTableName() + " and " + destTable.getTableName() + "\n" + e.getMessage());
    }
    dropTable(sourceTable1.getEscapedTableName());
    dropTable(destTable.getEscapedTableName());
}
Also used : DBTable(com.microsoft.sqlserver.testframework.DBTable) SQLException(java.sql.SQLException) SqlType(com.microsoft.sqlserver.testframework.sqlType.SqlType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with DBTable

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

the class BulkCopyColumnMappingTest method testUnicodeCM.

@Test
@DisplayName("BulkCopy:test unicode column mapping")
void testUnicodeCM() {
    // create source unicode table
    DBTable sourceTableUnicode = new DBTable(true, true);
    stmt.createTable(sourceTableUnicode);
    // create destication unicode table with same schema as source
    DBTable destTableUnicode = sourceTableUnicode.cloneSchema();
    stmt.createTable(destTableUnicode);
    // set up bulkCopy with explicit column mapping
    BulkCopyTestWrapper bulkWrapper = new BulkCopyTestWrapper(connectionString);
    bulkWrapper.setUsingConnection((0 == ThreadLocalRandom.current().nextInt(2)) ? true : false);
    for (int i = 1; i <= destTableUnicode.totalColumns(); i++) {
        int select = i % 4;
        switch(select) {
            case 0:
                bulkWrapper.setColumnMapping(i, i);
                break;
            case 1:
                bulkWrapper.setColumnMapping(i, destTableUnicode.getColumnName(i - 1));
                break;
            case 2:
                bulkWrapper.setColumnMapping(sourceTableUnicode.getColumnName(i - 1), destTableUnicode.getColumnName(i - 1));
                break;
            case 3:
                bulkWrapper.setColumnMapping(sourceTableUnicode.getColumnName(i - 1), i);
                break;
        }
    }
    BulkCopyTestUtil.performBulkCopy(bulkWrapper, sourceTableUnicode, destTableUnicode);
    dropTable(sourceTableUnicode.getEscapedTableName());
}
Also used : DBTable(com.microsoft.sqlserver.testframework.DBTable) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 10 with DBTable

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

the class BulkCopyColumnMappingTest method testImplicitMismatchCM.

@Test
@DisplayName("BulkCopy:test implicit mismatched column mapping")
void testImplicitMismatchCM() {
    // create non unicode dest table with different schema from source table
    DBTable destTable = new DBTable(true, false, true);
    stmt.createTable(destTable);
    // set up bulkCopy with explicit column mapping
    BulkCopyTestWrapper bulkWrapper = new BulkCopyTestWrapper(connectionString);
    bulkWrapper.setUsingConnection((0 == ThreadLocalRandom.current().nextInt(2)) ? true : false);
    for (int i = 1; i <= destTable.totalColumns(); i++) {
        int select = i % 4;
        switch(select) {
            case 0:
                bulkWrapper.setColumnMapping(i, i);
                break;
            case 1:
                bulkWrapper.setColumnMapping(i, destTable.getColumnName(i - 1));
                break;
            case 2:
                bulkWrapper.setColumnMapping(sourceTable.getColumnName(i - 1), destTable.getColumnName(i - 1));
                break;
            case 3:
                bulkWrapper.setColumnMapping(sourceTable.getColumnName(i - 1), i);
                break;
        }
    }
    BulkCopyTestUtil.performBulkCopy(bulkWrapper, sourceTable, destTable, true, true);
}
Also used : DBTable(com.microsoft.sqlserver.testframework.DBTable) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

DBTable (com.microsoft.sqlserver.testframework.DBTable)13 Test (org.junit.jupiter.api.Test)7 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)6 DBStatement (com.microsoft.sqlserver.testframework.DBStatement)6 DisplayName (org.junit.jupiter.api.DisplayName)6 SqlType (com.microsoft.sqlserver.testframework.sqlType.SqlType)3 SQLException (java.sql.SQLException)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 SQLServerBulkCopy (com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)1 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)1 DBPreparedStatement (com.microsoft.sqlserver.testframework.DBPreparedStatement)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1