class documentation

class CursorResultMetaData(ResultMetaData):

Known subclasses: sqlalchemy.engine.cursor.LegacyCursorResultMetaData

View In Hierarchy

Result metadata for DBAPI cursors.
Class Method ​_create​_description​_match​_map when matching cursor.description to a set of names that are present in a Compiled object, as is the case with TextualSelect, get all the names we expect might match those in cursor.description.
Method __getstate__ Undocumented
Method __init__ Undocumented
Method __setstate__ Undocumented
Method ​_adapt​_to​_context No summary
Method ​_colnames​_from​_description Extract column names and data types from a cursor.description.
Method ​_for​_freeze Undocumented
Method ​_has​_key Undocumented
Method ​_index​_for​_key Undocumented
Method ​_indexes​_for​_keys Undocumented
Method ​_key​_fallback Undocumented
Method ​_merge​_cols​_by​_name Undocumented
Method ​_merge​_cols​_by​_none Undocumented
Method ​_merge​_cursor​_description Merge a cursor.description with compiled result column information.
Method ​_merge​_textual​_cols​_by​_position Undocumented
Method ​_metadata​_for​_keys Undocumented
Method ​_raise​_for​_ambiguous​_column​_name Undocumented
Method ​_reduce Undocumented
Class Variable __slots__ Undocumented
Class Variable returns​_rows Undocumented
Instance Variable ​_keymap Undocumented
Instance Variable ​_keymap​_by​_result​_column​_idx Undocumented
Instance Variable ​_keys Undocumented
Instance Variable ​_processors Undocumented
Instance Variable ​_safe​_for​_cache Undocumented
Instance Variable ​_translated​_indexes Undocumented
Instance Variable ​_tuplefilter Undocumented
Instance Variable case​_sensitive Undocumented

Inherited from ResultMetaData:

Method ​_getter Undocumented
Method ​_raise​_for​_nonint Undocumented
Method ​_row​_as​_tuple​_getter Undocumented
Method ​_warn​_for​_nonint Undocumented
Class Variable ​_unique​_filters Undocumented
Property keys Undocumented
@classmethod
def _create_description_match_map(cls, result_columns, case_sensitive=True, loose_column_name_matching=False):
when matching cursor.description to a set of names that are present in a Compiled object, as is the case with TextualSelect, get all the names we expect might match those in cursor.description.
def __getstate__(self):

Undocumented

def __init__(self, parent, cursor_description):

Undocumented

def __setstate__(self, state):

Undocumented

def _adapt_to_context(self, context):
When using a cached Compiled construct that has a _result_map, for a new statement that used the cached Compiled, we need to ensure the keymap has the Column objects from our new statement as keys. So here we rewrite keymap with new entries for the new columns as matched to those of the cached statement.
def _colnames_from_description(self, context, cursor_description):

Extract column names and data types from a cursor.description.

Applies unicode decoding, column translation, "normalization", and case sensitivity rules to the names based on the dialect.

def _for_freeze(self):
def _index_for_key(self, key, raiseerr=True):
def _indexes_for_keys(self, keys):

Undocumented

def _key_fallback(self, key, err, raiseerr=True):
def _merge_cols_by_name(self, context, cursor_description, result_columns, loose_column_name_matching):

Undocumented

def _merge_cols_by_none(self, context, cursor_description):

Undocumented

def _merge_cursor_description(self, context, cursor_description, result_columns, num_ctx_cols, cols_are_ordered, textual_ordered, loose_column_name_matching):

Merge a cursor.description with compiled result column information.

There are at least four separate strategies used here, selected depending on the type of SQL construct used to start with.

The most common case is that of the compiled SQL expression construct, which generated the column names present in the raw SQL string and which has the identical number of columns as were reported by cursor.description. In this case, we assume a 1-1 positional mapping between the entries in cursor.description and the compiled object. This is also the most performant case as we disregard extracting / decoding the column names present in cursor.description since we already have the desired name we generated in the compiled SQL construct.

The next common case is that of the completely raw string SQL, such as passed to connection.execute(). In this case we have no compiled construct to work with, so we extract and decode the names from cursor.description and index those as the primary result row target keys.

The remaining fairly common case is that of the textual SQL that includes at least partial column information; this is when we use a _expression.TextualSelect construct. This construct may have unordered or ordered column information. In the ordered case, we merge the cursor.description and the compiled construct's information positionally, and warn if there are additional description names present, however we still decode the names in cursor.description as we don't have a guarantee that the names in the columns match on these. In the unordered case, we match names in cursor.description to that of the compiled construct based on name matching. In both of these cases, the cursor.description names and the column expression objects and names are indexed as result row target keys.

The final case is much less common, where we have a compiled non-textual SQL expression construct, but the number of columns in cursor.description doesn't match what's in the compiled construct. We make the guess here that there might be textual column expressions in the compiled construct that themselves include a comma in them causing them to split. We do the same name-matching as with textual non-ordered columns.

The name-matched system of merging is the same as that used by SQLAlchemy for all cases up through te 0.9 series. Positional matching for compiled SQL expressions was introduced in 1.0 as a major performance feature, and positional matching for textual _expression.TextualSelect objects in 1.1. As name matching is no longer a common case, it was acceptable to factor it into smaller generator- oriented methods that are easier to understand, but incur slightly more performance overhead.

def _merge_textual_cols_by_position(self, context, cursor_description, result_columns):

Undocumented

def _metadata_for_keys(self, keys):
def _raise_for_ambiguous_column_name(self, rec):

Undocumented

def _reduce(self, keys):
returns_rows: bool =

Undocumented

_keymap =

Undocumented

_keymap_by_result_column_idx =

Undocumented

_keys =

Undocumented

_processors =

Undocumented

_safe_for_cache: bool =

Undocumented

_translated_indexes =
_tuplefilter =
case_sensitive =

Undocumented