o
    {,hO                      @   sr   d Z ddlZddlmZ ddlmZmZ ddlmZ G dd de	Z
G dd	 d	ZG d
d dZG dd dZdS )z]
Useful auxiliary data structures for query construction. Not useful outside
the SQL domain.
    N)FullResultSet)INNERLOUTER)RemovedInDjango60Warningc                   @   s   e Zd ZdZdd ZdS )	MultiJoinz
    Used by join construction code to indicate the point at which a
    multi-valued join was attempted (if the caller wants to treat that
    exceptionally).
    c                 C      || _ || _d S N)levelnames_with_path)self	names_pospath_with_names r   Y/var/www/html/rh/venv/lib/python3.10/site-packages/django/db/models/sql/datastructures.py__init__   s   
zMultiJoin.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   r      s    r   c                   @   s   e Zd ZdS )EmptyN)r   r   r   r   r   r   r   r      s    r   c                   @   sX   e Zd ZdZ	dddZdd Zdd Zed	d
 Zdd Z	dd Z
dd Zdd ZdS )Joina  
    Used by sql.Query and sql.SQLCompiler to generate JOIN clauses into the
    FROM entry. For example, the SQL generated could be
        LEFT OUTER JOIN "sometable" T1
        ON ("othertable"."sometable_id" = "sometable"."id")

    This class is primarily used in Query.alias_map. All entries in alias_map
    must be Join compatible by providing the following attributes and methods:
        - table_name (string)
        - table_alias (possible alias for the table, can be None)
        - join_type (can be None for those entries that aren't joined from
          anything)
        - parent_alias (which table is this join's parent, can be None similarly
          to join_type)
        - as_sql()
        - relabeled_clone()
    Nc                 C   sv   || _ || _|| _|| _t|dr"| | _tdd | jD | _nt	
dt d | _| | _|| _|| _|| _d S )Nget_joining_fieldsc                 s   s     | ]\}}|j |j fV  qd S r   )column).0	lhs_field	rhs_fieldr   r   r   	<genexpr>F   s
    

z Join.__init__.<locals>.<genexpr>zaThe usage of get_joining_columns() in Join is deprecated. Implement get_joining_fields() instead.)
table_nameparent_aliastable_alias	join_typehasattrr   join_fieldstuple	join_colswarningswarnr   get_joining_columns
join_fieldnullablefiltered_relation)r   r   r   r   r    r(   r)   r*   r   r   r   r   1   s$   



zJoin.__init__c                 C   s  g }g }|j }|jj}| jp| j}|D ]M\}}	t|tr3d|| j||f }
d|| j||	f }n#|j	| j|| j|	\}}	|
|\}}|| }
|
|	\}}|| }||
 d|  q| j| j| j}|r|
|\}}|d|  || | jrz
|
| j\}}W n	 ty   Y nw |d|  || |st| jd| j}td|j d|}| j| jkrdnd| j }d	| j|| j||f }||fS )
z
        Generate the full
           LEFT OUTER JOIN sometable ON sometable.somecol = othertable.othercol, params
        clause for this join.
        z%s.%sz = z(%s)fieldzaJoin generated an empty ON clause. %s did not yield either joining columns or extra restrictions.z AND   %sz%s %s%s ON (%s))quote_name_unless_aliasops
quote_namer"   r$   
isinstancestrr   r   prepare_join_on_clausecompileappendr(   get_extra_restrictionextendr*   r   getattr
ValueError	__class__joinr   r    )r   compiler
connectionjoin_conditionsparamsqnqn2r"   lhsrhslhs_full_namerhs_full_namelhs_sql
lhs_paramsrhs_sql
rhs_params
extra_cond	extra_sqlextra_paramsdeclared_fieldon_clause_sql	alias_strsqlr   r   r   as_sqlX   sb   



zJoin.as_sqlc              	   C   s\   | | j| j}| | j| j}| jd ur| j|}nd }| j| j||| j| j| j	|dS )N)r*   )
getr   r   r*   relabeled_cloner:   r   r    r(   r)   )r   
change_mapnew_parent_aliasnew_table_aliasr*   r   r   r   rS      s   
zJoin.relabeled_clonec                 C   s   | j | j| j| j| jfS r   )r:   r   r   r(   r*   r   r   r   r   identity   s   zJoin.identityc                 C      t |tstS | j|jkS r   )r1   r   NotImplementedrX   r   otherr   r   r   __eq__      
zJoin.__eq__c                 C   
   t | jS r   hashrX   rW   r   r   r   __hash__      
zJoin.__hash__c                 C      |  i }t|_|S r   )rS   r   r    r   newr   r   r   demote      
zJoin.demotec                 C   rd   r   )rS   r   r    re   r   r   r   promote   rh   zJoin.promoter   )r   r   r   r   r   rQ   rS   propertyrX   r]   rb   rg   ri   r   r   r   r   r      s    
'B
	r   c                   @   sP   e Zd ZdZdZdZdZdd Zdd Zdd Z	e
d	d
 Zdd Zdd ZdS )	BaseTablez
    The BaseTable class is used for base table references in FROM clause. For
    example, the SQL "foo" in
        SELECT * FROM "foo" WHERE somecond
    could be generated by this class.
    Nc                 C   r   r   )r   r   )r   r   aliasr   r   r   r      s   
zBaseTable.__init__c                 C   s2   | j | jkrdnd| j  }|| j}|| g fS )Nr,   r-   )r   r   r.   )r   r<   r=   rO   base_sqlr   r   r   rQ      s   zBaseTable.as_sqlc                 C   s   |  | j|| j| jS r   )r:   r   rR   r   )r   rT   r   r   r   rS      s   zBaseTable.relabeled_clonec                 C   s   | j | j| jfS r   )r:   r   r   rW   r   r   r   rX      s   zBaseTable.identityc                 C   rY   r   )r1   rk   rZ   rX   r[   r   r   r   r]      r^   zBaseTable.__eq__c                 C   r_   r   r`   rW   r   r   r   rb      rc   zBaseTable.__hash__)r   r   r   r   r    r   r*   r   rQ   rS   rj   rX   r]   rb   r   r   r   r   rk      s    
rk   )r   r%   django.core.exceptionsr   django.db.models.sql.constantsr   r   django.utils.deprecationr   	Exceptionr   r   r   rk   r   r   r   r   <module>   s     +