Search in sources :

Example 6 with SQLServerResultSet

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

the class CallableStatementTest method testInputProcedure2.

private void testInputProcedure2(String sql) throws SQLException {
    try (SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) Util.getCallableStmt(con, sql, stmtColEncSetting)) {
        callableStatement.setString(1, charValues[1]);
        callableStatement.setUniqueIdentifier(2, charValues[6]);
        callableStatement.setString(3, charValues[2]);
        callableStatement.setNString(4, charValues[3]);
        callableStatement.setNString(5, charValues[4]);
        callableStatement.setNString(6, charValues[5]);
        callableStatement.setString(7, charValues[7]);
        callableStatement.setNString(8, charValues[8]);
        try (SQLServerResultSet rs = (SQLServerResultSet) callableStatement.executeQuery()) {
            rs.next();
            assertEquals(rs.getString(1).trim(), charValues[1], "Test for input parameter fails.\n");
            assertEquals(rs.getUniqueIdentifier(2), charValues[6].toUpperCase(), "Test for input parameter fails.\n");
            assertEquals(rs.getString(3).trim(), charValues[2], "Test for input parameter fails.\n");
            assertEquals(rs.getString(4).trim(), charValues[3], "Test for input parameter fails.\n");
            assertEquals(rs.getString(5).trim(), charValues[4], "Test for input parameter fails.\n");
            assertEquals(rs.getString(6).trim(), charValues[5], "Test for input parameter fails.\n");
            assertEquals(rs.getString(7).trim(), charValues[7], "Test for input parameter fails.\n");
            assertEquals(rs.getString(8).trim(), charValues[8], "Test for input parameter fails.\n");
        }
    } catch (Exception e) {
        fail(e.toString());
    }
}
Also used : SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) SQLException(java.sql.SQLException)

Example 7 with SQLServerResultSet

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

the class SQLServerSpatialDatatypeTest method testCheckGeogMetaData.

@Test
public void testCheckGeogMetaData() throws SQLException {
    beforeEachSetup();
    pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + geogTableName + " (c1) VALUES (?)");
    ParameterMetaData paramMetaData = pstmt.getParameterMetaData();
    Geography g = Geography.STGeomFromText("POINT (1 2 3 4)", 4326);
    pstmt.setGeography(1, g);
    pstmt.execute();
    int sqlType = paramMetaData.getParameterType(1);
    String sqlTypeName = paramMetaData.getParameterTypeName(1);
    assertEquals(sqlType, -158);
    assertEquals(sqlTypeName, "geography");
    SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("select * from " + geogTableName);
    ResultSetMetaData rsmd = rs.getMetaData();
    assertEquals(rsmd.getColumnType(1), -158);
}
Also used : Geography(com.microsoft.sqlserver.jdbc.Geography) ResultSetMetaData(java.sql.ResultSetMetaData) SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) ParameterMetaData(java.sql.ParameterMetaData) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 8 with SQLServerResultSet

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

the class DatabaseMetaDataForeignKeyTest method testGetCrossReference.

/**
 * test getCrossReference() methods
 *
 * @throws SQLException
 * @throws SQLTimeoutException
 */
@Test
public void testGetCrossReference() throws SQLException {
    String fkTable = table1;
    String[] tableNames = { table2, table3, table4, table5 };
    int[][] values = { // expected UPDATE_RULE, expected DELETE_RULE
    { 4, 3 }, { 2, 0 }, { 0, 2 }, { 3, 4 } };
    SQLServerDatabaseMetaData dmd = (SQLServerDatabaseMetaData) connection.getMetaData();
    for (int i = 0; i < tableNames.length; i++) {
        String pkTable = tableNames[i];
        SQLServerResultSet rs1 = (SQLServerResultSet) dmd.getCrossReference(null, null, pkTable, null, null, fkTable);
        rs1.next();
        assertEquals(values[i][0], rs1.getInt("UPDATE_RULE"));
        assertEquals(values[i][1], rs1.getInt("DELETE_RULE"));
        SQLServerResultSet rs2 = (SQLServerResultSet) dmd.getCrossReference(catalog, schema, pkTable, catalog, schema, fkTable);
        rs2.next();
        assertEquals(values[i][0], rs2.getInt("UPDATE_RULE"));
        assertEquals(values[i][1], rs2.getInt("DELETE_RULE"));
        SQLServerResultSet rs3 = (SQLServerResultSet) dmd.getCrossReference(catalog, "", pkTable, catalog, "", fkTable);
        rs3.next();
        assertEquals(values[i][0], rs3.getInt("UPDATE_RULE"));
        assertEquals(values[i][1], rs3.getInt("DELETE_RULE"));
        try {
            dmd.getCrossReference("", schema, pkTable, "", schema, fkTable);
            fail("Exception is not thrown.");
        } catch (SQLException e) {
            assertEquals(EXPECTED_ERROR_MESSAGE2, e.getMessage());
        }
    }
}
Also used : SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) SQLServerDatabaseMetaData(com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData) SQLException(java.sql.SQLException) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 9 with SQLServerResultSet

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

the class DatabaseMetaDataForeignKeyTest method testGetExportedKeys.

/**
 * test getExportedKeys() methods
 *
 * @throws SQLException
 * @throws SQLTimeoutException
 */
@Test
public void testGetExportedKeys() throws SQLException {
    String[] tableNames = { table2, table3, table4, table5 };
    int[][] values = { // expected UPDATE_RULE, expected DELETE_RULE
    { 4, 3 }, { 2, 0 }, { 0, 2 }, { 3, 4 } };
    SQLServerDatabaseMetaData dmd = (SQLServerDatabaseMetaData) connection.getMetaData();
    for (int i = 0; i < tableNames.length; i++) {
        String pkTable = tableNames[i];
        SQLServerResultSet rs1 = (SQLServerResultSet) dmd.getExportedKeys(null, null, pkTable);
        rs1.next();
        assertEquals(values[i][0], rs1.getInt("UPDATE_RULE"));
        assertEquals(values[i][1], rs1.getInt("DELETE_RULE"));
        SQLServerResultSet rs2 = (SQLServerResultSet) dmd.getExportedKeys(catalog, schema, pkTable);
        rs2.next();
        assertEquals(values[i][0], rs2.getInt("UPDATE_RULE"));
        assertEquals(values[i][1], rs2.getInt("DELETE_RULE"));
        SQLServerResultSet rs3 = (SQLServerResultSet) dmd.getExportedKeys(catalog, "", pkTable);
        rs3.next();
        assertEquals(values[i][0], rs3.getInt("UPDATE_RULE"));
        assertEquals(values[i][1], rs3.getInt("DELETE_RULE"));
        try {
            dmd.getExportedKeys("", schema, pkTable);
            fail("Exception is not thrown.");
        } catch (SQLException e) {
            assertTrue(e.getMessage().startsWith(EXPECTED_ERROR_MESSAGE));
        }
    }
}
Also used : SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) SQLServerDatabaseMetaData(com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData) SQLException(java.sql.SQLException) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 10 with SQLServerResultSet

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

the class ResultSetWrapper42Test method SQLServerResultSet42Test.

/**
 * Tests creation of SQLServerResultSet42 object
 *
 * @throws SQLException
 */
@Test
public void SQLServerResultSet42Test() throws SQLException {
    String sql = "SELECT SUSER_SNAME()";
    ResultSet rs = null;
    try {
        rs = connection.createStatement().executeQuery(sql);
        if (1.8d <= javaVersion && 4 == major && 2 == minor) {
            assertTrue(rs instanceof SQLServerResultSet42);
        } else {
            assertTrue(rs instanceof SQLServerResultSet);
        }
    } finally {
        if (null != rs) {
            rs.close();
        }
    }
}
Also used : SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) SQLServerResultSet42(com.microsoft.sqlserver.jdbc.SQLServerResultSet42) SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) ResultSet(java.sql.ResultSet) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Aggregations

SQLServerResultSet (com.microsoft.sqlserver.jdbc.SQLServerResultSet)10 SQLException (java.sql.SQLException)6 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)5 Test (org.junit.jupiter.api.Test)5 SQLServerDatabaseMetaData (com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData)3 SQLServerCallableStatement (com.microsoft.sqlserver.jdbc.SQLServerCallableStatement)2 ParameterMetaData (java.sql.ParameterMetaData)2 ResultSetMetaData (java.sql.ResultSetMetaData)2 Geography (com.microsoft.sqlserver.jdbc.Geography)1 Geometry (com.microsoft.sqlserver.jdbc.Geometry)1 SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)1 SQLServerResultSet42 (com.microsoft.sqlserver.jdbc.SQLServerResultSet42)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 BigDecimal (java.math.BigDecimal)1 Date (java.sql.Date)1 ResultSet (java.sql.ResultSet)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1