o aA@s6ddlmZedddgZeddZGdddZd S) ) namedtuple TableInfonametype FieldInfozSname type_code display_size internal_size precision scale null_ok default collationc@seZdZdZiZddZddZddZd$d d Zd d Z ddZ ddZ d%ddZ ddZ ddZd&ddZddZddZd d!Zd"d#ZdS)'BaseDatabaseIntrospectionz5Encapsulate backend-specific introspection utilities.cCs ||_dSN) connection)selfr r G/usr/lib/python3/dist-packages/django/db/backends/base/introspection.py__init__s z"BaseDatabaseIntrospection.__init__cCs |j|S)a Hook for a database backend to use the cursor description to match a Django field type to a database column. For Oracle, the column data_type on its own is insufficient to distinguish between a FloatField and IntegerField, for example. )data_types_reverse)r data_type descriptionr r r get_field_types z(BaseDatabaseIntrospection.get_field_typecCs|S)z Apply a conversion to the identifier for the purposes of comparison. The default identifier converter is for case sensitive comparison. r )r rr r r identifier_convertersz.BaseDatabaseIntrospection.identifier_converterNFcsPfdd}|dur$j }||WdS1swY||S)a  Return a list of names of all tables that exist in the database. Sort the returned table list by Python's default sorting. Do NOT use the database's ORDER BY here to avoid subtle differences in sorting order between databases. cstfdd|DS)Nc3s$|] }s |jdkr|jVqdS)tN)rr).0ti include_viewsr r /s zKBaseDatabaseIntrospection.table_names..get_names..)sortedget_table_list)cursorrr r r get_names.sz8BaseDatabaseIntrospection.table_names..get_namesN)r r)r rrrr rr table_names's   z%BaseDatabaseIntrospection.table_namescCtd)z Return an unsorted list of TableInfo named tuples of all tables and views that exist in the database. zMsubclasses of BaseDatabaseIntrospection may require a get_table_list() methodNotImplementedError)r rr r r r6sz(BaseDatabaseIntrospection.get_table_listcCr)zi Return a description of the table with the DB-API cursor.description interface. zUsubclasses of BaseDatabaseIntrospection may require a get_table_description() method.r r r table_namer r r get_table_description=sz/BaseDatabaseIntrospection.get_table_descriptioncs0ddlm}ddlmfdd|DS)Nr)apps)routerc3s8|]}|jjD] }|jjr |Vq qdSr)get_migratable_modelsr alias_meta can_migrate)r app_configmodelr&r r r rJs  zBBaseDatabaseIntrospection.get_migratable_models..) django.appsr% django.dbr&get_app_configs)r r%r r-r r'Gs   z/BaseDatabaseIntrospection.get_migratable_modelsTcsxt}D]}|jjsq||jj|dd|jjDqt|}|r:tj |dfdd|D}|S)z Return a list of all table names that have associated Django models and are in INSTALLED_APPS. If only_existing is True, include only the tables in the database. css$|] }|jjjjr|VqdSr) remote_fieldthroughr)managed m2m_db_table)rfr r r r]s  z?BaseDatabaseIntrospection.django_table_names..rcsg|] }|vr|qSr )r)rrexisting_tablesr r r ds z@BaseDatabaseIntrospection.django_table_names..) setr'r)r3adddb_tableupdatelocal_many_to_manylistr)r only_existingrtablesr,r r6r django_table_namesQs    z,BaseDatabaseIntrospection.django_table_namescs(ttjfddDS)ze Return a set of all models represented by the provided list of table names. cs"h|] }|jjvr|qSr )rr)r;)rmr r@r r qs z=BaseDatabaseIntrospection.installed_models..)r9maprr'rCr rCr installed_modelsks z*BaseDatabaseIntrospection.installed_modelsc Csg}|jJ}|D]<}|jjsq |jjrq ||||jj|jj |jj D]}|j j jj rG|||}||pE|ddgq*q Wd|S1sTwY|S)zi Return a list of information about all DB sequences for all models in all apps. N)tablecolumn)r rr'r)r3swappedextend get_sequencesr; local_fieldsr=r1r2 auto_createdr4)r sequence_listrr,r5sequencer r r rNvs&       z'BaseDatabaseIntrospection.sequence_listr cCr)z Return a list of introspected sequences for table_name. Each sequence is a dict: {'table': , 'column': }. An optional 'name' key can be added if the backend supports named sequences. zLsubclasses of BaseDatabaseIntrospection may require a get_sequences() methodr )r rr# table_fieldsr r r rKz'BaseDatabaseIntrospection.get_sequencescCr)z Return a dictionary of {field_name: (field_name_other_table, other_table)} representing all relationships to the given table. zMsubclasses of BaseDatabaseIntrospection may require a get_relations() method.r r"r r r get_relationssz'BaseDatabaseIntrospection.get_relationscCr)z Backends can override this to return a list of: (column_name, referenced_table_name, referenced_column_name) for all key columns in given table. zNsubclasses of BaseDatabaseIntrospection may require a get_key_columns() methodr r"r r r get_key_columnsrQz)BaseDatabaseIntrospection.get_key_columnscCs2|||D]}|dr|ddSqdS)zP Return the name of the primary key column for the given table. primary_keycolumnsrN)get_constraintsvalues)r rr# constraintr r r get_primary_key_columns z0BaseDatabaseIntrospection.get_primary_key_columncCr)a_ Retrieve any constraints or keys (unique, pk, fk, check, index) across one or more columns. Return a dict mapping constraint names to their attributes, where attributes is a dict with keys: * columns: List of columns this covers * primary_key: True if primary key, False otherwise * unique: True if this is a unique constraint, False otherwise * foreign_key: (table, column) of target, or None * check: True if check constraint, False otherwise * index: True if index, False otherwise. * orders: The order (ASC/DESC) defined for the columns of indexes * type: The type of the index (btree, hash, etc.) Some backends may return special constraint names that don't exist if they don't name constraints of a certain type (e.g. SQLite) zNsubclasses of BaseDatabaseIntrospection may require a get_constraints() methodr r"r r r rVsz)BaseDatabaseIntrospection.get_constraints)NF)FT)r )__name__ __module__ __qualname____doc__rr rrrrr$r'rArFrNrKrRrSrYrVr r r r rs$     rN) collectionsrrrrr r r r s