Search in sources :

Example 1 with DBConnection

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

the class BulkCopyAllTypes method setupVariation.

private void setupVariation() throws SQLException {
    try (DBConnection dbConnection = new DBConnection(connectionString);
        DBStatement dbStmt = dbConnection.createStatement()) {
        tableSrc = new DBTable(true);
        tableDest = tableSrc.cloneSchema();
        dbStmt.createTable(tableSrc);
        dbStmt.createTable(tableDest);
        dbStmt.populateTable(tableSrc);
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBTable(com.microsoft.sqlserver.testframework.DBTable) DBStatement(com.microsoft.sqlserver.testframework.DBStatement)

Example 2 with DBConnection

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

the class BulkCopyAllTypes method testBulkCopyResultSet.

private void testBulkCopyResultSet(boolean setSelectMethod, Integer resultSetType, Integer resultSetConcurrency) throws SQLException {
    setupVariation();
    try (Connection connnection = DriverManager.getConnection(connectionString + (setSelectMethod ? ";selectMethod=cursor;" : ""));
        Statement statement = (null != resultSetType || null != resultSetConcurrency) ? connnection.createStatement(resultSetType, resultSetConcurrency) : connnection.createStatement()) {
        ResultSet rs = statement.executeQuery("select * from " + tableSrc.getEscapedTableName());
        SQLServerBulkCopy bcOperation = new SQLServerBulkCopy(connection);
        bcOperation.setDestinationTableName(tableDest.getEscapedTableName());
        bcOperation.writeToServer(rs);
        bcOperation.close();
        ComparisonUtil.compareSrcTableAndDestTableIgnoreRowOrder(new DBConnection(connectionString), tableSrc, tableDest);
    }
    terminateVariation();
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) DBConnection(com.microsoft.sqlserver.testframework.DBConnection) ResultSet(java.sql.ResultSet) SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)

Example 3 with DBConnection

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

the class BulkCopyColumnMappingTest method setUpConnection.

/**
 * Create connection, statement and generate path of resource file
 */
@BeforeAll
static void setUpConnection() {
    con = new DBConnection(connectionString);
    stmt = con.createStatement();
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with DBConnection

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

the class BulkCopyISQLServerBulkRecordTest method testISQLServerBulkRecord.

@Test
void testISQLServerBulkRecord() throws SQLException {
    try (DBConnection con = new DBConnection(connectionString);
        DBStatement stmt = con.createStatement()) {
        DBTable dstTable = new DBTable(true);
        stmt.createTable(dstTable);
        BulkData Bdata = new BulkData(dstTable);
        BulkCopyTestWrapper bulkWrapper = new BulkCopyTestWrapper(connectionString);
        bulkWrapper.setUsingConnection((0 == ThreadLocalRandom.current().nextInt(2)) ? true : false);
        BulkCopyTestUtil.performBulkCopy(bulkWrapper, Bdata, dstTable);
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBTable(com.microsoft.sqlserver.testframework.DBTable) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 5 with DBConnection

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

the class DateAndTimeTypeTest method testSetup.

@BeforeEach
public void testSetup() throws TestAbortedException, Exception {
    try (DBConnection dbc = new DBConnection(connectionString)) {
        assumeTrue(9 <= dbc.getServerVersion(), "Aborting test case as SQL Server version does not support TIME");
    }
    // To get TIME & setTime working on Servers >= 2008, we must add 'sendTimeAsDatetime=false'
    // by default to the connection. See issue https://github.com/Microsoft/mssql-jdbc/issues/559
    connection = DriverManager.getConnection(connectionString + ";sendTimeAsDatetime=false");
    stmt = (SQLServerStatement) connection.createStatement();
    Utils.dropTableIfExists("dateandtime", stmt);
    String sql1 = "create table dateandtime (id integer not null, my_date date, my_time time, my_timestamp datetime2 constraint pk_esimple primary key (id))";
    stmt.execute(sql1);
    // add one sample data
    String sPrepStmt = "insert into dateandtime (id, my_date, my_time, my_timestamp) values (?, ?, ?, ?)";
    pstmt = connection.prepareStatement(sPrepStmt);
    pstmt.setInt(1, 42);
    pstmt.setDate(2, DATE_TO_TEST);
    pstmt.setTime(3, TIME_TO_TEST);
    pstmt.setTimestamp(4, TIMESTAMP_TO_TEST);
    pstmt.execute();
    pstmt.close();
    createTVPs("dateTVP", "date");
    createTVPs("timeTVP", "time");
    createTVPs("timestampTVP", "datetime2");
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DBConnection (com.microsoft.sqlserver.testframework.DBConnection)38 DBStatement (com.microsoft.sqlserver.testframework.DBStatement)25 Test (org.junit.jupiter.api.Test)16 DBResultSet (com.microsoft.sqlserver.testframework.DBResultSet)14 SQLException (java.sql.SQLException)8 DBTable (com.microsoft.sqlserver.testframework.DBTable)6 BeforeAll (org.junit.jupiter.api.BeforeAll)6 Connection (java.sql.Connection)5 Statement (java.sql.Statement)5 ResultSet (java.sql.ResultSet)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 SQLServerBulkCopy (com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)3 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)3 SQLServerCallableStatement (com.microsoft.sqlserver.jdbc.SQLServerCallableStatement)2 SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)2 SQLServerStatement (com.microsoft.sqlserver.jdbc.SQLServerStatement)2 DBColumn (com.microsoft.sqlserver.testframework.DBColumn)2 DBPreparedStatement (com.microsoft.sqlserver.testframework.DBPreparedStatement)2 DisplayName (org.junit.jupiter.api.DisplayName)2 SQLServerColumnEncryptionJavaKeyStoreProvider (com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionJavaKeyStoreProvider)1