Search in sources :

Example 16 with DBStatement

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

the class bvtTest method testStmtScrollInsensitiveReadOnly.

/**
 * Create a statement, ResultSet.SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, executeQuery verify cursor by using next, afterlast and previous
 * and verify data
 *
 * @throws SQLException
 * @throws ClassNotFoundException
 */
@Test
public void testStmtScrollInsensitiveReadOnly() throws SQLException, ClassNotFoundException {
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_INSENSITIVE_CONCUR_READ_ONLY);
        DBResultSet rs = stmt.selectAll(table1)) {
        rs.next();
        rs.verifyCurrentRow(table1);
        rs.afterLast();
        rs.previous();
        rs.verifyCurrentRow(table1);
        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)

Example 17 with DBStatement

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

the class bvtTest method testStmtScrollSensitiveUpdatable.

/**
 * Create a statement ResultSet.SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, executeQuery verify cursor by using next and previous and verify
 * data
 *
 * @throws SQLException
 */
@Test
public void testStmtScrollSensitiveUpdatable() throws SQLException {
    String query = "SELECT * FROM " + table1.getEscapedTableName();
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_UPDATABLE);
        DBResultSet rs = stmt.executeQuery(query)) {
        // Verify resultset behavior
        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)

Example 18 with DBStatement

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

the class bvtTest method testStmtForwardOnlyUpdateable.

/**
 * Create a statement ResultSet.Type_forward_only, ResultSet.CONCUR_UPDATABLE, executeQuery verify cursor by using next and previous and verify
 * data
 *
 * @throws SQLException
 */
@Test
public void testStmtForwardOnlyUpdateable() throws SQLException {
    String query = "SELECT * FROM " + table1.getEscapedTableName();
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_UPDATABLE);
        DBResultSet rs = stmt.executeQuery(query)) {
        rs.next();
        // Verify resultset behavior
        rs.next();
        rs.verifyCurrentRow(table1);
        rs.next();
        rs.verifyCurrentRow(table1);
        try {
            rs.previous();
            assertTrue(false, "Previous should have thrown an exception");
        } catch (SQLException ex) {
        // expected exception
        }
        rs.verify(table1);
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) SQLException(java.sql.SQLException) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) Test(org.junit.jupiter.api.Test)

Example 19 with DBStatement

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

the class bvtTest method testResultSetAndCloseStmt.

/**
 * Verify resultset closed after statement is closed
 *
 * @throws SQLException
 */
@Test
public void testResultSetAndCloseStmt() throws SQLException {
    String query = "SELECT * FROM " + table1.getEscapedTableName();
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement();
        DBResultSet rs = stmt.executeQuery(query)) {
        // this should close the resultSet
        stmt.close();
        try {
            rs.next();
        } catch (SQLException e) {
            assertEquals(e.toString(), "com.microsoft.sqlserver.jdbc.SQLServerException: The result set is closed.");
        }
        assertTrue(true, "Previous one should have thrown exception!");
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) SQLException(java.sql.SQLException) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) Test(org.junit.jupiter.api.Test)

Example 20 with DBStatement

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

the class bvtTest method testStmtForwardOnlyReadOnly.

/**
 * Create a statement ResultSet.Type_forward_only, ResultSet.CONCUR_READ_ONLY, executeQuery verify cursor by using next and previous and verify
 * data
 *
 * @throws SQLException
 * @throws ClassNotFoundException
 */
@Test
public void testStmtForwardOnlyReadOnly() throws SQLException, ClassNotFoundException {
    String query = "SELECT * FROM " + table1.getEscapedTableName();
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_READ_ONLY);
        DBResultSet rs = stmt.executeQuery(query)) {
        rs.next();
        rs.verifyCurrentRow(table1);
        rs.next();
        rs.verifyCurrentRow(table1);
        try {
            rs.previous();
            assertTrue(false, "Previous should have thrown an exception");
        } catch (SQLException ex) {
        // expected exception
        }
        rs.verify(table1);
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) SQLException(java.sql.SQLException) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) Test(org.junit.jupiter.api.Test)

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