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,
)
| 2136 | return result |
| 2137 | |
| 2138 | def _cursor_execute( |
| 2139 | self, |
| 2140 | cursor: DBAPICursor, |
| 2141 | statement: str, |
| 2142 | parameters: _DBAPISingleExecuteParams, |
| 2143 | context: Optional[ExecutionContext] = None, |
| 2144 | ) -> None: |
| 2145 | """Execute a statement + params on the given cursor. |
| 2146 | |
| 2147 | Adds appropriate logging and exception handling. |
| 2148 | |
| 2149 | This method is used by DefaultDialect for special-case |
| 2150 | executions, such as for sequences and column defaults. |
| 2151 | The path of statement execution in the majority of cases |
| 2152 | terminates at _execute_context(). |
| 2153 | |
| 2154 | """ |
| 2155 | try: |
| 2156 | if self._has_events or self.engine._has_events: |
| 2157 | for fn in self.dispatch.before_cursor_execute: |
| 2158 | statement, parameters = fn( |
| 2159 | self, cursor, statement, parameters, context, False |
| 2160 | ) |
| 2161 | |
| 2162 | if self._echo: |
| 2163 | self._log_info(statement) |
| 2164 | self._log_info("[raw sql] %r", parameters) |
| 2165 | |
| 2166 | for fn in ( |
| 2167 | () |
| 2168 | if not self.dialect._has_events |
| 2169 | else self.dialect.dispatch.do_execute |
| 2170 | ): |
| 2171 | if fn(cursor, statement, parameters, context): |
| 2172 | break |
| 2173 | else: |
| 2174 | self.dialect.do_execute(cursor, statement, parameters, context) |
| 2175 | |
| 2176 | if self._has_events or self.engine._has_events: |
| 2177 | self.dispatch.after_cursor_execute( |
| 2178 | self, cursor, statement, parameters, context, False |
| 2179 | ) |
| 2180 | except BaseException as e: |
| 2181 | self._handle_dbapi_exception( |
| 2182 | e, statement, parameters, cursor, context |
| 2183 | ) |
| 2184 | |
| 2185 | def _safe_close_cursor(self, cursor: DBAPICursor) -> None: |
| 2186 | """Close the given cursor, catching exceptions |