Result metadata for DBAPI cursors.
| 154 | |
| 155 | |
| 156 | class CursorResultMetaData(ResultMetaData): |
| 157 | """Result metadata for DBAPI cursors.""" |
| 158 | |
| 159 | __slots__ = ( |
| 160 | "_keymap", |
| 161 | "_processors", |
| 162 | "_keys", |
| 163 | "_keymap_by_result_column_idx", |
| 164 | "_tuplefilter", |
| 165 | "_translated_indexes", |
| 166 | "_safe_for_cache", |
| 167 | "_unpickled", |
| 168 | "_key_to_index", |
| 169 | # don't need _create_unique_filters here for now. Can be added |
| 170 | # if a need arises. |
| 171 | ) |
| 172 | |
| 173 | _keymap: _CursorKeyMapType |
| 174 | _processors: _ProcessorsType |
| 175 | _keymap_by_result_column_idx: Optional[Dict[int, _KeyMapRecType]] |
| 176 | _unpickled: bool |
| 177 | _safe_for_cache: bool |
| 178 | _translated_indexes: Optional[List[int]] |
| 179 | |
| 180 | returns_rows: ClassVar[bool] = True |
| 181 | |
| 182 | def _has_key(self, key: Any) -> bool: |
| 183 | return key in self._keymap |
| 184 | |
| 185 | def _for_freeze(self) -> ResultMetaData: |
| 186 | ambiguous = { |
| 187 | rec[MD_LOOKUP_KEY] |
| 188 | for rec in self._keymap.values() |
| 189 | if rec[MD_INDEX] is None |
| 190 | } |
| 191 | return SimpleResultMetaData( |
| 192 | self._keys, |
| 193 | extra=[self._keymap[key][MD_OBJECTS] for key in self._keys], |
| 194 | _ambiguous_keys=frozenset(ambiguous) if ambiguous else None, |
| 195 | ) |
| 196 | |
| 197 | def _make_new_metadata( |
| 198 | self, |
| 199 | *, |
| 200 | unpickled: bool, |
| 201 | processors: _ProcessorsType, |
| 202 | keys: Sequence[str], |
| 203 | keymap: _KeyMapType, |
| 204 | tuplefilter: Optional[_TupleGetterType], |
| 205 | translated_indexes: Optional[List[int]], |
| 206 | safe_for_cache: bool, |
| 207 | keymap_by_result_column_idx: Any, |
| 208 | ) -> Self: |
| 209 | new_obj = self.__class__.__new__(self.__class__) |
| 210 | new_obj._unpickled = unpickled |
| 211 | new_obj._processors = processors |
| 212 | new_obj._keys = keys |
| 213 | new_obj._keymap = keymap |