(
self, col: _ET, _include_singleton_constants: bool = False
)
| 1152 | |
| 1153 | @util.preload_module("sqlalchemy.sql.functions") |
| 1154 | def replace( |
| 1155 | self, col: _ET, _include_singleton_constants: bool = False |
| 1156 | ) -> Optional[_ET]: |
| 1157 | functions = util.preloaded.sql_functions |
| 1158 | |
| 1159 | # TODO: cython candidate |
| 1160 | |
| 1161 | if self.include_fn and not self.include_fn(col): # type: ignore |
| 1162 | return None |
| 1163 | elif self.exclude_fn and self.exclude_fn(col): # type: ignore |
| 1164 | return None |
| 1165 | |
| 1166 | if isinstance(col, FromClause) and not isinstance( |
| 1167 | col, functions.FunctionElement |
| 1168 | ): |
| 1169 | if self.selectable.is_derived_from(col): |
| 1170 | if self.adapt_from_selectables: |
| 1171 | for adp in self.adapt_from_selectables: |
| 1172 | if adp.is_derived_from(col): |
| 1173 | break |
| 1174 | else: |
| 1175 | return None |
| 1176 | return self.selectable # type: ignore |
| 1177 | elif isinstance(col, Alias) and isinstance( |
| 1178 | col.element, TableClause |
| 1179 | ): |
| 1180 | # we are a SELECT statement and not derived from an alias of a |
| 1181 | # table (which nonetheless may be a table our SELECT derives |
| 1182 | # from), so return the alias to prevent further traversal |
| 1183 | # or |
| 1184 | # we are an alias of a table and we are not derived from an |
| 1185 | # alias of a table (which nonetheless may be the same table |
| 1186 | # as ours) so, same thing |
| 1187 | return col |
| 1188 | else: |
| 1189 | # other cases where we are a selectable and the element |
| 1190 | # is another join or selectable that contains a table which our |
| 1191 | # selectable derives from, that we want to process |
| 1192 | return None |
| 1193 | |
| 1194 | elif not isinstance(col, ColumnElement): |
| 1195 | return None |
| 1196 | elif not _include_singleton_constants and col._is_singleton_constant: |
| 1197 | # dont swap out NULL, TRUE, FALSE for a label name |
| 1198 | # in a SQL statement that's being rewritten, |
| 1199 | # leave them as the constant. This is first noted in #6259, |
| 1200 | # however the logic to check this moved here as of #7154 so that |
| 1201 | # it is made specific to SQL rewriting and not all column |
| 1202 | # correspondence |
| 1203 | |
| 1204 | return None |
| 1205 | |
| 1206 | if "adapt_column" in col._annotations: |
| 1207 | col = col._annotations["adapt_column"] |
| 1208 | |
| 1209 | if TYPE_CHECKING: |
| 1210 | assert isinstance(col, KeyedColumnElement) |
| 1211 |
no test coverage detected