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   úc/var/www/html/premium_crap/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r¢z
| 
| j¡\}}W n	 ty•   Y nw | d| ¡ | |¡ |s³t| jd| jƒ}td|j ƒ‚d |¡}| j| jkrÀd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     +