Execute a statement + params on the given cursor. Adds appropriate logging and exception handling. This method is used by DefaultDialect for special-case executions, such as for sequences and column defaults. The path of statement execution in the majority of cases
(
self,
cursor: DBAPICursor,
statement: str,
parameters: _DBAPISingleExecuteParams,
context: Optional[ExecutionContext] = None,
)
| 2171 | return result |
| 2172 | |
| 2173 | def _cursor_execute( |
| 2174 | self, |
| 2175 | cursor: DBAPICursor, |
| 2176 | statement: str, |
| 2177 | parameters: _DBAPISingleExecuteParams, |
| 2178 | context: Optional[ExecutionContext] = None, |
| 2179 | ) -> None: |
| 2180 | """Execute a statement + params on the given cursor. |
| 2181 | |
| 2182 | Adds appropriate logging and exception handling. |
| 2183 | |
| 2184 | This method is used by DefaultDialect for special-case |
| 2185 | executions, such as for sequences and column defaults. |
| 2186 | The path of statement execution in the majority of cases |
| 2187 | terminates at _execute_context(). |
| 2188 | |
| 2189 | """ |
| 2190 | if self._has_events or self.engine._has_events: |
| 2191 | for fn in self.dispatch.before_cursor_execute: |
| 2192 | statement, parameters = fn( |
| 2193 | self, cursor, statement, parameters, context, False |
| 2194 | ) |
| 2195 | |
| 2196 | if self._echo: |
| 2197 | self._log_info(statement) |
| 2198 | self._log_info("[raw sql] %r", parameters) |
| 2199 | try: |
| 2200 | for fn in ( |
| 2201 | () |
| 2202 | if not self.dialect._has_events |
| 2203 | else self.dialect.dispatch.do_execute |
| 2204 | ): |
| 2205 | if fn(cursor, statement, parameters, context): |
| 2206 | break |
| 2207 | else: |
| 2208 | self.dialect.do_execute(cursor, statement, parameters, context) |
| 2209 | except BaseException as e: |
| 2210 | self._handle_dbapi_exception( |
| 2211 | e, statement, parameters, cursor, context |
| 2212 | ) |
| 2213 | |
| 2214 | if self._has_events or self.engine._has_events: |
| 2215 | self.dispatch.after_cursor_execute( |
| 2216 | self, cursor, statement, parameters, context, False |
| 2217 | ) |
| 2218 | |
| 2219 | def _safe_close_cursor(self, cursor: DBAPICursor) -> None: |
| 2220 | """Close the given cursor, catching exceptions |