[
https://issues.apache.org/jira/browse/CALCITE-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16346315#comment-16346315
]
ASF GitHub Bot commented on CALCITE-508:
----------------------------------------
Github user vlsi commented on a diff in the pull request:
https://github.com/apache/calcite-avatica/pull/23#discussion_r164960629
--- 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 --
What bothers me is the test verifies a mere presence of `SQLException`. Is
it possible to test for the exact exception the test expects? E.g.
`getSQLState`, `getErrorCode`,
`
getErrorCode
--
> 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)