|
25 | 25 | UPDATE_ENDPOINT_HEADER, |
26 | 26 | UPDATE_PARAMETERS_HEADER, |
27 | 27 | CursorState, |
| 28 | + ParameterStyle, |
28 | 29 | ) |
29 | 30 | from firebolt.common.cursor.base_cursor import ( |
30 | 31 | BaseCursor, |
@@ -216,27 +217,65 @@ async def _do_execute( |
216 | 217 | ) -> None: |
217 | 218 | await self._close_rowset_and_reset() |
218 | 219 | self._row_set = StreamingAsyncRowSet() if streaming else InMemoryAsyncRowSet() |
219 | | - queries: List[Union[SetParameter, str]] = ( |
220 | | - [raw_query] |
221 | | - if skip_parsing |
222 | | - else self._formatter.split_format_sql(raw_query, parameters) |
223 | | - ) |
224 | | - timeout_controller = TimeoutController(timeout) |
| 220 | + # Import paramstyle from module level |
| 221 | + from firebolt.async_db import paramstyle |
225 | 222 |
|
226 | | - if len(queries) > 1 and async_execution: |
227 | | - raise FireboltError( |
228 | | - "Server side async does not support multi-statement queries" |
229 | | - ) |
230 | 223 | try: |
231 | | - for query in queries: |
232 | | - await self._execute_single_query( |
233 | | - query, timeout_controller, async_execution, streaming |
| 224 | + parameter_style = ParameterStyle(paramstyle) |
| 225 | + except ValueError: |
| 226 | + raise ProgrammingError(f"Unsupported paramstyle: {paramstyle}") |
| 227 | + try: |
| 228 | + if parameter_style == ParameterStyle.FB_NUMERIC: |
| 229 | + await self._execute_fb_numeric( |
| 230 | + raw_query, parameters, timeout, async_execution, streaming |
234 | 231 | ) |
| 232 | + else: |
| 233 | + queries: List[Union[SetParameter, str]] = ( |
| 234 | + [raw_query] |
| 235 | + if skip_parsing |
| 236 | + else self._formatter.split_format_sql(raw_query, parameters) |
| 237 | + ) |
| 238 | + timeout_controller = TimeoutController(timeout) |
| 239 | + if len(queries) > 1 and async_execution: |
| 240 | + raise FireboltError( |
| 241 | + "Server side async does not support multi-statement queries" |
| 242 | + ) |
| 243 | + for query in queries: |
| 244 | + await self._execute_single_query( |
| 245 | + query, timeout_controller, async_execution, streaming |
| 246 | + ) |
235 | 247 | self._state = CursorState.DONE |
236 | 248 | except Exception: |
237 | 249 | self._state = CursorState.ERROR |
238 | 250 | raise |
239 | 251 |
|
| 252 | + async def _execute_fb_numeric( |
| 253 | + self, |
| 254 | + query: str, |
| 255 | + parameters: Sequence[Sequence[ParameterType]], |
| 256 | + timeout: Optional[float], |
| 257 | + async_execution: bool, |
| 258 | + streaming: bool, |
| 259 | + ) -> None: |
| 260 | + Cursor._log_query(query) |
| 261 | + timeout_controller = TimeoutController(timeout) |
| 262 | + timeout_controller.raise_if_timeout() |
| 263 | + query_params = self._build_fb_numeric_query_params( |
| 264 | + parameters, streaming, async_execution |
| 265 | + ) |
| 266 | + resp = await self._api_request( |
| 267 | + query, |
| 268 | + query_params, |
| 269 | + timeout=timeout_controller.remaining(), |
| 270 | + ) |
| 271 | + await self._raise_if_error(resp) |
| 272 | + if async_execution: |
| 273 | + await resp.aread() |
| 274 | + self._parse_async_response(resp) |
| 275 | + else: |
| 276 | + await self._parse_response_headers(resp.headers) |
| 277 | + await self._append_row_set_from_response(resp) |
| 278 | + |
240 | 279 | async def _execute_single_query( |
241 | 280 | self, |
242 | 281 | query: Union[SetParameter, str], |
|
0 commit comments