o
    ×ŸŽi�  ã                   @   s^   d Z ddlmZ ddlmZ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.
é    )ÚFullResultSet)ÚINNERÚLOUTERc                   @   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)ÚlevelZnames_with_path)ÚselfZ	names_posZpath_with_names© r
   úmC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\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                   @   s`   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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   s8   || _ || _|| _|| _| ¡ | _|| _|| _|| _d S r   )	Ú
table_nameÚparent_aliasÚtable_aliasÚ	join_typeZget_joining_columnsÚ	join_colsÚ
join_fieldÚnullableÚfiltered_relation)r	   r   r   r   r   r   r   r   r
   r
   r   r   -   s   

zJoin.__init__c              	   C   s8  g }g }|j }|jj}| jD ]\}}| d|| jƒ||ƒ|| jƒ||ƒf ¡ q| j | j| j¡}	|	rF| 	|	¡\}
}| d|
 ¡ | 
|¡ | jriz
| 	| j¡\}
}W n	 ty\   Y nw | d|
 ¡ | 
|¡ |szt| 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.%s = %s.%sz(%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)N)Úquote_name_unless_aliasÚopsZ
quote_namer   Úappendr   r   r   Zget_extra_restrictionÚcompileÚextendr   r   ÚgetattrÚ
ValueErrorÚ	__class__Újoinr   r   )r	   ÚcompilerÚ
connectionZjoin_conditionsÚparamsÚqnZqn2Zlhs_colZrhs_colZ
extra_condZ	extra_sqlZextra_paramsZdeclared_fieldZon_clause_sqlÚ	alias_strZsqlr
   r
   r   Úas_sqlG   s\   üÿÿÿ
ÿ
ÿÿ
ÿüzJoin.as_sqlc              	      sr   ˆ   | j| j¡}ˆ   | j| j¡}| jd ur'| j ¡ }‡ fdd„| jjD ƒ|_nd }| j| j||| j| j	| j
|d�S )Nc                    s   g | ]}ˆ   ||¡‘qS r
   )Úget)Ú.0Úp©Ú
change_mapr
   r   Ú
<listcomp>‡   s    ÿz(Join.relabeled_clone.<locals>.<listcomp>)r   )r-   r   r   r   ÚcloneÚpathr%   r   r   r   r   )r	   r1   Znew_parent_aliasZnew_table_aliasr   r
   r0   r   Úrelabeled_clone‚   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   )Ú
isinstancer   ÚNotImplementedr7   ©r	   Úotherr
   r
   r   Ú__eq__    ó   
zJoin.__eq__c                 C   ó
   t | jƒS r   ©Úhashr7   r6   r
   r
   r   Ú__hash__¥   ó   
zJoin.__hash__c                 C   s   | j d d… |j d d… kS )Néÿÿÿÿ©r7   r;   r
   r
   r   Úequals¨   s   zJoin.equalsc                 C   ó   |   i ¡}t|_|S r   )r5   r   r   ©r	   Únewr
   r
   r   Údemote¬   ó   
zJoin.demotec                 C   rG   r   )r5   r   r   rH   r
   r
   r   Úpromote±   rK   zJoin.promoter   )r   r   r   r   r   r,   r5   Úpropertyr7   r=   rB   rF   rJ   rL   r
   r
   r
   r   r      s    
ø;
	r   c                   @   sX   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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(   r+   Zbase_sqlr
   r
   r   r,   Ç   s   ÿzBaseTable.as_sqlc                 C   s   |   | j| | j| j¡¡S r   )r%   r   r-   r   )r	   r1   r
   r
   r   r5   Î   s   ÿzBaseTable.relabeled_clonec                 C   s   | j | j| jfS r   )r%   r   r   r6   r
   r
   r   r7   Ó   s   zBaseTable.identityc                 C   r8   r   )r9   rN   r:   r7   r;   r
   r
   r   r=   ×   r>   zBaseTable.__eq__c                 C   r?   r   r@   r6   r
   r
   r   rB   Ü   rC   zBaseTable.__hash__c                 C   s   | j |j kS r   rE   r;   r
   r
   r   rF   ß   s   zBaseTable.equals)r   r   r   r   r   r   r   r   r,   r5   rM   r7   r=   rB   rF   r
   r
   r
   r   rN   ·   s    
rN   N)r   Zdjango.core.exceptionsr   Zdjango.db.models.sql.constantsr   r   Ú	Exceptionr   r   r   rN   r
   r
   r
   r   Ú<module>   s     