| 68 | |
| 69 | |
| 70 | class CompiledSQL(SQLMatchRule): |
| 71 | def __init__( |
| 72 | self, statement, params=None, dialect="default", enable_returning=True |
| 73 | ): |
| 74 | self.statement = statement |
| 75 | self.params = params |
| 76 | self.dialect = dialect |
| 77 | self.enable_returning = enable_returning |
| 78 | |
| 79 | def _compare_sql(self, execute_observed, received_statement): |
| 80 | stmt = re.sub(r"[\n\t]", "", self.statement) |
| 81 | return received_statement == stmt |
| 82 | |
| 83 | def _compile_dialect(self, execute_observed): |
| 84 | if self.dialect == "default": |
| 85 | dialect = DefaultDialect() |
| 86 | # this is currently what tests are expecting |
| 87 | # dialect.supports_default_values = True |
| 88 | dialect.supports_default_metavalue = True |
| 89 | |
| 90 | if self.enable_returning: |
| 91 | dialect.insert_returning = dialect.update_returning = ( |
| 92 | dialect.delete_returning |
| 93 | ) = True |
| 94 | dialect.use_insertmanyvalues = True |
| 95 | dialect.supports_multivalues_insert = True |
| 96 | dialect.update_returning_multifrom = True |
| 97 | dialect.delete_returning_multifrom = True |
| 98 | # dialect.favor_returning_over_lastrowid = True |
| 99 | # dialect.insert_null_pk_still_autoincrements = True |
| 100 | |
| 101 | # this is calculated but we need it to be True for this |
| 102 | # to look like all the current RETURNING dialects |
| 103 | assert dialect.insert_executemany_returning |
| 104 | |
| 105 | return dialect |
| 106 | else: |
| 107 | return url.URL.create(self.dialect).get_dialect()() |
| 108 | |
| 109 | def _received_statement(self, execute_observed): |
| 110 | """reconstruct the statement and params in terms |
| 111 | of a target dialect, which for CompiledSQL is just DefaultDialect.""" |
| 112 | |
| 113 | context = execute_observed.context |
| 114 | compare_dialect = self._compile_dialect(execute_observed) |
| 115 | |
| 116 | # received_statement runs a full compile(). we should not need to |
| 117 | # consider extracted_parameters; if we do this indicates some state |
| 118 | # is being sent from a previous cached query, which some misbehaviors |
| 119 | # in the ORM can cause, see #6881 |
| 120 | cache_key = None # execute_observed.context.compiled.cache_key |
| 121 | extracted_parameters = ( |
| 122 | None # execute_observed.context.extracted_parameters |
| 123 | ) |
| 124 | |
| 125 | if "schema_translate_map" in context.execution_options: |
| 126 | map_ = context.execution_options["schema_translate_map"] |
| 127 | else: |
no outgoing calls