(
&mut self,
name: String,
count: Option<FetchDirection>,
max_rows: ExecuteCount,
fetch_portal_name: Option<String>,
timeout: ExecuteTimeout,
ct
| 1767 | } |
| 1768 | |
| 1769 | async fn fetch( |
| 1770 | &mut self, |
| 1771 | name: String, |
| 1772 | count: Option<FetchDirection>, |
| 1773 | max_rows: ExecuteCount, |
| 1774 | fetch_portal_name: Option<String>, |
| 1775 | timeout: ExecuteTimeout, |
| 1776 | ctx_extra: ExecuteContextGuard, |
| 1777 | ) -> Result<State, io::Error> { |
| 1778 | // Unlike Execute, no count specified in FETCH returns 1 row, and 0 means 0 |
| 1779 | // instead of All. |
| 1780 | let count = count.unwrap_or(FetchDirection::ForwardCount(1)); |
| 1781 | |
| 1782 | // Figure out how many rows we should send back by looking at the various |
| 1783 | // combinations of the execute and fetch. |
| 1784 | // |
| 1785 | // In Postgres, Fetch will cache <count> rows from the target portal and |
| 1786 | // return those as requested (if, say, an Execute message was sent with a |
| 1787 | // max_rows < the Fetch's count). We expect that case to be incredibly rare and |
| 1788 | // so have chosen to not support it until users request it. This eases |
| 1789 | // implementation difficulty since we don't have to be able to "send" rows to |
| 1790 | // a buffer. |
| 1791 | // |
| 1792 | // TODO(mjibson): Test this somehow? Need to divide up the pgtest files in |
| 1793 | // order to have some that are not Postgres compatible. |
| 1794 | let count = match (max_rows, count) { |
| 1795 | (ExecuteCount::Count(max_rows), FetchDirection::ForwardCount(count)) => { |
| 1796 | let count = usize::cast_from(count); |
| 1797 | if max_rows < count { |
| 1798 | let msg = "Execute with max_rows < a FETCH's count is not supported"; |
| 1799 | self.adapter_client.retire_execute( |
| 1800 | ctx_extra, |
| 1801 | StatementEndedExecutionReason::Errored { |
| 1802 | error: msg.to_string(), |
| 1803 | }, |
| 1804 | ); |
| 1805 | return self |
| 1806 | .send_error_and_get_state(ErrorResponse::error( |
| 1807 | SqlState::FEATURE_NOT_SUPPORTED, |
| 1808 | msg, |
| 1809 | )) |
| 1810 | .await; |
| 1811 | } |
| 1812 | ExecuteCount::Count(count) |
| 1813 | } |
| 1814 | (ExecuteCount::Count(_), FetchDirection::ForwardAll) => { |
| 1815 | let msg = "Execute with max_rows of a FETCH ALL is not supported"; |
| 1816 | self.adapter_client.retire_execute( |
| 1817 | ctx_extra, |
| 1818 | StatementEndedExecutionReason::Errored { |
| 1819 | error: msg.to_string(), |
| 1820 | }, |
| 1821 | ); |
| 1822 | return self |
| 1823 | .send_error_and_get_state(ErrorResponse::error( |
| 1824 | SqlState::FEATURE_NOT_SUPPORTED, |
| 1825 | msg, |
| 1826 | )) |
no test coverage detected