
    gO                          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e	      Z
 G d d	      Z G d
 d      Z G d d      Zy)z]
Useful auxiliary data structures for query construction. Not useful outside
the SQL domain.
    N)FullResultSet)INNERLOUTER)RemovedInDjango60Warningc                       e Zd ZdZd Zy)	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                      || _         || _        y N)levelnames_with_path)self	names_pospath_with_namess      {/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/db/models/sql/datastructures.py__init__zMultiJoin.__init__   s    
.    N)__name__
__module____qualname____doc__r    r   r   r   r      s    /r   r   c                       e Zd Zy)EmptyN)r   r   r   r   r   r   r   r      s    r   r   c                   N    e Zd ZdZ	 ddZd Zd Zed        Zd Z	d Z
d	 Zd
 Zy)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                 X   || _         || _        || _        || _        t	        |d      r7|j                         | _        t        d | j                  D              | _        n6t        j                  dt               d | _        |j                         | _        || _        || _        || _        y )Nget_joining_fieldsc              3   R   K   | ]  \  }}|j                   |j                   f ! y wr
   )column).0	lhs_field	rhs_fields      r   	<genexpr>z Join.__init__.<locals>.<genexpr>F   s.      #,<(Iy !!9#3#34,<s   %'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/   r0   r1   s           r   r   zJoin.__init__1   s     %(&" :34)<<>D" #,0,<,<# DN
 MM0(
  $D';;=DN$ !2r   c                    g }g }|j                   }|j                  j                  }| j                  xs | j                  }|D ]  \  }}	t        |t              r; || j                        d ||      }
 || j                        d ||	      }ng|j                  j                  | j                  || j                  |	      \  }}	|j                  |      \  }}||z  }
|j                  |	      \  }}||z  }|j                  |
 d|         | j                  j                  | j                  | j                        }|r9|j                  |      \  }}|j                  d|z         |j                  |       | j                  rD	 |j                  | j                        \  }}|j                  d|z         |j                  |       |s9t#        | j                  d| j                        }t%        d|j&                  z        dj)                  |      }| j                  | j*                  k(  rdnd| j                  z  }| j,                  d	 || j*                        |d
|d}||fS # t         $ r Y w xY w)z
        Generate the full
           LEFT OUTER JOIN sometable ON sometable.somecol = othertable.othercol, params
        clause for this join.
        .z = z(%s)fieldzaJoin generated an empty ON clause. %s did not yield either joining columns or extra restrictions.z AND   %s z ON ())quote_name_unless_aliasops
quote_namer)   r+   
isinstancestrr%   r&   prepare_join_on_clausecompileappendr/   get_extra_restrictionextendr1   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sqls                          r   as_sqlzJoin.as_sqlX   sl    --nn'' &&8$..#HC#s# ,.d.?.?+@#c( K+-d.>.>+?S J%>>@@%%sD,<,<cS '/&6&6s&;# '* 4&.&6&6s&;# '* 4""m_C#GH $$ __::d//

 &.&6&6z&B#I|""6I#56MM,'!!,*2*:*:4;Q;Q*R'	<  &&v	'9:l+$T__gtON9;I;S;ST   _5""doo5BEDDTDT<T 	 NNt	
 F{- ! s   I/ /	I;:I;c           	      n   |j                  | j                  | j                        }|j                  | j                  | j                        }| j                  | j                  j	                  |      }nd }| j                  | j                  ||| j                  | j                  | j                  |      S )N)r1   )
getr%   r&   r1   relabeled_clonerE   r$   r'   r/   r0   )r   
change_mapnew_parent_aliasnew_table_aliasr1   s        r   r_   zJoin.relabeled_clone   s    %>>$*;*;T=N=NO$..)9)94;K;KL!!- $ 6 6 F Fz R $~~OONNOOMM/  
 	
r   c                 t    | j                   | j                  | j                  | j                  | j                  fS r
   )rE   r$   r%   r/   r1   r   s    r   identityzJoin.identity   s5     NNOOOO""
 	
r   c                 `    t        |t              st        S | j                  |j                  k(  S r
   )r<   r   NotImplementedre   r   others     r   __eq__zJoin.__eq__   s%    %&!!}}..r   c                 ,    t        | j                        S r
   hashre   rd   s    r   __hash__zJoin.__hash__       DMM""r   c                 >    | j                  i       }t        |_        |S r
   )r_   r   r'   r   news     r   demotezJoin.demote   s    ""2&
r   c                 >    | j                  i       }t        |_        |S r
   )r_   r   r'   rq   s     r   promotezJoin.promote   s    ""2&
r   r
   )r   r   r   r   r   r\   r_   propertyre   rj   rn   rs   ru   r   r   r   r   r      sF    4 %3N@D
" 
 
/
#
r   r   c                   J    e Zd ZdZdZdZdZd Zd Zd Z	e
d        Zd Zd Zy)		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                      || _         || _        y r
   )r$   r&   )r   r$   aliass      r   r   zBaseTable.__init__   s    $ r   c                     | j                   | j                  k(  rdnd| j                   z  }|j                  | j                        }||z   g fS )Nr5   r6   )r&   r$   r9   )r   rG   rH   rZ   base_sqls        r   r\   zBaseTable.as_sql   sN    ""doo5BEDDTDT<T 	 33DOOD)#R''r   c                     | j                  | j                  |j                  | j                  | j                              S r
   )rE   r$   r^   r&   )r   r`   s     r   r_   zBaseTable.relabeled_clone   s3    ~~OOZ^^D,<,<d>N>NO
 	
r   c                 H    | j                   | j                  | j                  fS r
   )rE   r$   r&   rd   s    r   re   zBaseTable.identity   s    ~~t0@0@@@r   c                 `    t        |t              st        S | j                  |j                  k(  S r
   )r<   rx   rg   re   rh   s     r   rj   zBaseTable.__eq__   s%    %+!!}}..r   c                 ,    t        | j                        S r
   rl   rd   s    r   rn   zBaseTable.__hash__   ro   r   )r   r   r   r   r'   r%   r1   r   r\   r_   rv   re   rj   rn   r   r   r   rx   rx      sH     IL!(

 A A/
#r   rx   )r   r,   django.core.exceptionsr   django.db.models.sql.constantsr   r   django.utils.deprecationr   	Exceptionr   r   r   rx   r   r   r   <module>r      sE   
  0 8 =
/	 
/	 	g gT&# &#r   