Search in sources :

Example 1 with DBStatement

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

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

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

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

the class bvtTest method testTwoResultsetsDifferentStmt.

/**
 * Verify two concurrent resultsets from same connection, separate statements
 *
 * @throws SQLException
 */
@Test
public void testTwoResultsetsDifferentStmt() throws SQLException {
    String query = "SELECT * FROM " + table1.getEscapedTableName();
    String query2 = "SELECT * FROM " + table2.getEscapedTableName();
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt1 = conn.createStatement();
        DBStatement stmt2 = conn.createStatement()) {
        DBResultSet rs1 = stmt1.executeQuery(query);
        DBResultSet rs2 = stmt2.executeQuery(query2);
        // Interleave resultset calls
        rs1.next();
        rs1.verifyCurrentRow(table1);
        rs2.next();
        rs2.verifyCurrentRow(table2);
        rs1.next();
        rs1.verifyCurrentRow(table1);
        rs1.verify(table1);
        rs1.close();
        rs2.next();
        rs2.verify(table2);
        rs2.close();
    }
}
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 5 with DBStatement

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

the class bvtTest method terminate.

/**
 * drops tables
 *
 * @throws SQLException
 */
@AfterAll
public static void terminate() throws SQLException {
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement()) {
        stmt.execute("if object_id('" + table1.getEscapedTableName() + "','U') is not null" + " drop table " + table1.getEscapedTableName());
        stmt.execute("if object_id('" + table2.getEscapedTableName() + "','U') is not null" + " drop table " + table2.getEscapedTableName());
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) AfterAll(org.junit.jupiter.api.AfterAll)

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