[ 
https://issues.apache.org/jira/browse/CALCITE-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16350417#comment-16350417
 ] 

ASF GitHub Bot commented on CALCITE-508:
----------------------------------------

Github user asolimando commented on a diff in the pull request:

    https://github.com/apache/calcite-avatica/pull/23#discussion_r165661423
  
    --- Diff: 
core/src/test/java/org/apache/calcite/avatica/AvaticaResultSetThrowsSqlExceptionTest.java
 ---
    @@ -75,11 +90,118 @@ public void testUpdateNull() throws SQLException {
         final TestDriver driver = new TestDriver();
         try (Connection connection = driver.connect("jdbc:test", properties);
              ResultSet resultSet =
    -             connection.createStatement().executeQuery("SELECT * FROM 
TABLE")) {
    +                 connection.createStatement().executeQuery("SELECT * FROM 
TABLE")) {
           thrown.expect(SQLFeatureNotSupportedException.class);
           resultSet.updateNull(1);
         }
       }
    -}
     
    +  @Test
    +  public void testCommonCursorStates() throws SQLException {
    +    final ResultSet resultSet = getResultSet();
    +
    +    // right after statement execution, result set is before first row
    +    assert resultSet.isBeforeFirst();
    +
    +    // retrieve each row until the last one
    +    while (!resultSet.isAfterLast()) {
    +      assert resultSet.next() != resultSet.isAfterLast();
    +    }
    +
    +    // result set is not closed yet, despite fully consumed
    +    assert !resultSet.isClosed();
    +
    +    resultSet.close();
    +
    +    // result set is now closed
    +    assert resultSet.isClosed();
    +
    +    // once closed, next should fail
    +    thrown.expect(SQLException.class);
    +    resultSet.next();
    +  }
    +
    +  /**
    +   * Auxiliary method for testing column access.
    +   * @param resultSet the result set
    +   * @param index the index of the column to be accessed
    +   * @param shouldThrow true iff the column access should throw an 
exception
    +   * @return true iff the method invocation succeeded
    +   * @throws SQLException in case of database error
    +   */
    +  private boolean getColumn(final ResultSet resultSet,
    +                            final int index,
    +                            final boolean shouldThrow) throws SQLException 
{
    +    try {
    +      switch (index) {
    +      case 1:
    +        resultSet.getBoolean(index);   // BOOLEAN
    +        break;
    +      case 2:
    +        resultSet.getByte(index);      // TINYINT
    +        break;
    +      case 3:
    +        resultSet.getShort(index);     // SMALLINT
    +        break;
    +      case 4:
    +        resultSet.getInt(index);       // INTEGER
    +        break;
    +      case 5:
    +        resultSet.getLong(index);      // BIGINT
    +        break;
    +      case 6:
    +        resultSet.getFloat(index);     // REAL
    +        break;
    +      case 7:
    +        resultSet.getDouble(index);    // FLOAT
    +        break;
    +      case 8:
    +        resultSet.getString(index);    // VARCHAR
    +        break;
    +      case 9:
    +        resultSet.getDate(index);      // DATE
    +        break;
    +      case 10:
    +        resultSet.getTime(index);      // TIME
    +        break;
    +      case 11:
    +        resultSet.getTimestamp(index); // TIMESTAMP
    +        break;
    +      default:
    +        resultSet.getObject(index);
    +      }
    +    } catch (SQLException e) {
    +      if (!shouldThrow) {
    --- End diff --
    
    I totally agree with you, but if I am not wrong the official documentation 
for JDBC SQL states and error codes can only be purchased from ANSI and XOpen, 
and this is not an option for me. 
    
    Open documentation is available from different vendors, but they often map 
error codes differently from the standard and among them. 
    
    I would be happy to raise (and consequently test) specific error codes if 
you can suggest a source where I can freely access them.


> Reading from ResultSet before calling next() should throw SQLException not 
> NoSuchElementException
> -------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-508
>                 URL: https://issues.apache.org/jira/browse/CALCITE-508
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Julian Hyde
>            Assignee: Julian Hyde
>            Priority: Major
>              Labels: newbie
>
> Reading from ResultSet before calling next() should throw SQLException not 
> NoSuchElementException.
> Each of the Cursor.Accessor.getXxx methods should convert runtime exceptions 
> to SQLException.
> JdbcTest.testExtract currently demonstrates this problem; it passes if there 
> is a NoSuchElementException, but should look for a SQLException.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to