Search in sources :

Example 6 with DBConnection

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

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

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

Example 9 with DBConnection

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

the class bvtTest method testCreatepreparedStatement.

/**
 * Create a preparedStatement, call close
 *
 * @throws SQLException
 */
@Test
public void testCreatepreparedStatement() throws SQLException {
    String colName = table1.getColumnName(7);
    String value = table1.getRowData(7, 0).toString();
    String query = "SELECT * from " + table1.getEscapedTableName() + " where [" + colName + "] = ? ";
    try (DBConnection conn = new DBConnection(connectionString);
        DBPreparedStatement pstmt = conn.prepareStatement(query)) {
        pstmt.setObject(1, new BigDecimal(value));
        DBResultSet rs = pstmt.executeQuery();
        rs.verify(table1);
        rs.close();
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBPreparedStatement(com.microsoft.sqlserver.testframework.DBPreparedStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 10 with DBConnection

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

the class bvtTest method testStmtScrollSensitiveReadOnly.

/**
 * Create a statement ResultSet.SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY, executeQuery verify cursor by using next and absolute and verify
 * data
 *
 * @throws SQLException
 */
@Test
public void testStmtScrollSensitiveReadOnly() throws SQLException {
    String query = "SELECT * FROM " + table1.getEscapedTableName();
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_READ_ONLY);
        DBResultSet rs = stmt.executeQuery(query)) {
        rs.next();
        rs.next();
        rs.verifyCurrentRow(table1);
        rs.absolute(3);
        rs.verifyCurrentRow(table1);
        rs.absolute(1);
        rs.verify(table1);
    }
}
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)

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