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);
}
}
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);
}
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());
}
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());
}
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);
}
Aggregations