|
1 | 1 | package com.databricks.jdbc.core; |
2 | 2 |
|
| 3 | +import static com.databricks.jdbc.core.DatabricksResultSet.AFFECTED_ROWS_COUNT; |
3 | 4 | import static org.junit.jupiter.api.Assertions.*; |
4 | 5 | import static org.mockito.Mockito.mock; |
5 | 6 | import static org.mockito.Mockito.when; |
@@ -718,4 +719,69 @@ void testVolumeOperationInputStream() throws Exception { |
718 | 719 | resultSet.setVolumeOperationEntityStream(mockEntity); |
719 | 720 | assertNotNull(resultSet.getVolumeOperationInputStream()); |
720 | 721 | } |
| 722 | + |
| 723 | + @Test |
| 724 | + void testGetUpdateCountForMetadataStatement() throws SQLException { |
| 725 | + DatabricksResultSet resultSet = getResultSet(StatementState.SUCCEEDED, null); |
| 726 | + assertEquals(0, resultSet.getUpdateCount()); |
| 727 | + } |
| 728 | + |
| 729 | + @Test |
| 730 | + void testGetUpdateCountForQueryStatement() throws SQLException { |
| 731 | + DatabricksResultSet resultSet = |
| 732 | + new DatabricksResultSet( |
| 733 | + new StatementStatus().setState(StatementState.SUCCEEDED), |
| 734 | + "test-statementID", |
| 735 | + StatementType.QUERY, |
| 736 | + null, |
| 737 | + mockedExecutionResult, |
| 738 | + mockedResultSetMetadata); |
| 739 | + |
| 740 | + assertEquals(0, resultSet.getUpdateCount()); |
| 741 | + } |
| 742 | + |
| 743 | + @Test |
| 744 | + void testGetUpdateCountForUpdateStatement() throws SQLException { |
| 745 | + when(mockedResultSetMetadata.getColumnType(1)).thenReturn(Types.BIGINT); |
| 746 | + when(mockedResultSetMetadata.getColumnNameIndex(AFFECTED_ROWS_COUNT)).thenReturn(1); |
| 747 | + when(mockedExecutionResult.next()).thenReturn(true).thenReturn(false); |
| 748 | + when(mockedExecutionResult.getObject(0)).thenReturn(5L); |
| 749 | + |
| 750 | + DatabricksResultSet resultSet = |
| 751 | + new DatabricksResultSet( |
| 752 | + new StatementStatus().setState(StatementState.SUCCEEDED), |
| 753 | + "test-statementID", |
| 754 | + StatementType.UPDATE, |
| 755 | + null, |
| 756 | + mockedExecutionResult, |
| 757 | + mockedResultSetMetadata); |
| 758 | + |
| 759 | + assertEquals(5L, resultSet.getUpdateCount()); |
| 760 | + } |
| 761 | + |
| 762 | + @Test |
| 763 | + void testGetUpdateCountForUpdateStatementMultipleRows() throws SQLException { |
| 764 | + when(mockedResultSetMetadata.getColumnType(1)).thenReturn(Types.BIGINT); |
| 765 | + when(mockedResultSetMetadata.getColumnNameIndex("num_affected_rows")).thenReturn(1); |
| 766 | + when(mockedExecutionResult.next()).thenReturn(true).thenReturn(true).thenReturn(false); |
| 767 | + when(mockedExecutionResult.getObject(0)).thenReturn(3L).thenReturn(2L); |
| 768 | + |
| 769 | + DatabricksResultSet resultSet = |
| 770 | + new DatabricksResultSet( |
| 771 | + new StatementStatus().setState(StatementState.SUCCEEDED), |
| 772 | + "test-statementID", |
| 773 | + StatementType.UPDATE, |
| 774 | + null, |
| 775 | + mockedExecutionResult, |
| 776 | + mockedResultSetMetadata); |
| 777 | + |
| 778 | + assertEquals(5L, resultSet.getUpdateCount()); |
| 779 | + } |
| 780 | + |
| 781 | + @Test |
| 782 | + void testGetUpdateCountForClosedResultSet() throws SQLException { |
| 783 | + DatabricksResultSet resultSet = getResultSet(StatementState.SUCCEEDED, null); |
| 784 | + resultSet.close(); |
| 785 | + assertThrows(DatabricksSQLException.class, resultSet::getUpdateCount); |
| 786 | + } |
721 | 787 | } |
0 commit comments