
    h                         S r SSKJr  SSKJrJrJr  SSKJr  / SQr	 " S S\5      r
 " S S	\5      r " S
 S\5      r " S S\5      rg)zR
Query subclasses which provide extra functionality beyond simple data retrieval.
    )
FieldError)CURSORGET_ITERATOR_CHUNK_SIZE
NO_RESULTS)Query)DeleteQueryUpdateQueryInsertQueryAggregateQueryc                   (    \ rS rSrSrSrS rS rSrg)r      zA DELETE SQL query.SQLDeleteCompilerc                     XR                   U   0U l         X l        U R                  U5      R                  [        5      nU(       a  U   UR
                  sS S S 5        $ g! , (       d  f       g= f)Nr   )	alias_mapwhereget_compilerexecute_sqlr   rowcount)selftabler   usingcursors        Q/var/www/html/env/lib/python3.13/site-packages/django/db/models/sql/subqueries.pydo_queryDeleteQuery.do_query   sW    !67
""5)55f=  s   	A  
A.c                 Z   SnU R                  5       R                  n[        S[        U5      [        5       Hp  nU R                  5         U R                  UR                   S3XU[        -    5        X0R                  U R                  5       R                  U R                  US9-  nMr     U$ )z
Set up and execute delete queries for all the objects in pk_list.

More than one physical query may be executed if there are a
lot of values in pk_list.
r   __in)r   )get_metapkrangelenr   clear_where
add_filterattnamer   db_tabler   )r   pk_listr   num_deletedfieldoffsets         r   delete_batchDeleteQuery.delete_batch   s     ""As7|-DEFOO==/&*A!AB ==(($**E )  K F     )r   r   N)	__name__
__module____qualname____firstlineno____doc__compilerr   r*   __static_attributes__ r,   r   r   r      s    "Hr,   r   c                   `   ^  \ rS rSrSrSrU 4S jrS rU 4S jrS r	S r
S	 rS
 rS rSrU =r$ )r	   0   zAn UPDATE SQL query.SQLUpdateCompilerc                 F   > [         TU ]  " U0 UD6  U R                  5         g N)super__init___setup_query)r   argskwargs	__class__s      r   r;   UpdateQuery.__init__5   s!    $)&)r,   c                 .    / U l         SU l        0 U l        g)z
Run on initialization and at the end of chaining. Any attributes that
would normally be set in __init__() should go here instead.
N)valuesrelated_idsrelated_updates)r   s    r   r<   UpdateQuery._setup_query9   s    
 !r,   c                 b   > [         TU ]  5       nU R                  R                  5       Ul        U$ r9   )r:   clonerD   copy)r   objr?   s     r   rG   UpdateQuery.cloneB   s*    gmo"22779
r,   c                    U R                  U5        [        S[        U5      [        5       HR  nU R	                  5         U R                  SXU[        -    5        U R                  U5      R                  [        5        MT     g )Nr   pk__in)	add_update_valuesr    r!   r   r"   r#   r   r   r   )r   r&   rB   r   r)   s        r   update_batchUpdateQuery.update_batchG   sl    v&As7|-DEFOO'64K+KL e$00< Fr,   c                 R   / nUR                  5        GH   u  p4U R                  5       R                  U5      nUR                  =(       a    UR                  (       + (       + =(       d    UR                  (       + nUR
                  R                  R                  nU(       a"  UR                  (       a  UR                  (       a  [        SU-  5      eXpR                  5       R                  La  U R                  XuU5        M  UR                  XWU45        GM     U R                  U5      $ )z
Convert a dictionary of field name to value mappings into an update
query. This is the entry point for the public update() method on
querysets.
zMCannot update model field %r (only non-relations and foreign keys permitted).)itemsr   	get_fieldauto_createdconcretemodel_metaconcrete_modelis_relationmany_to_manyr   add_related_updateappendadd_update_fields)r   rB   
values_seqnamevalr(   directrU   s           r   rM   UpdateQuery.add_update_valuesP   s     
IDMMO--d3E''>,>?Uu~~CU  KK%%44Ee//E4F4F /167  MMO:::''c:uS12 ( %%j11r,   c                     U HX  u  p#nUR                   (       a  M  [        US5      (       a  UR                  U SSS9nU R                  R	                  X#U45        MZ     g)z
Append a sequence of (field, model, value) triples to the internal list
that will be used to generate the UPDATE query. Might be more usefully
called add_update_targets() to hint at the extra information here.
resolve_expressionFT)allow_joinsfor_saveN)	generatedhasattrrc   rB   r[   )r   r]   r(   rU   r_   s        r   r\   UpdateQuery.add_update_fieldsh   sY     ",E#s011,,Tut,TKKc23 ",r,   c                 `    U R                   R                  U/ 5      R                  USU45        g)z
Add (name, value) to an update query for an ancestor model.

Update are coalesced so that only one update query per ancestor is run.
N)rD   
setdefaultr[   )r   rU   r(   values       r   rZ   UpdateQuery.add_related_updatew   s,     	''r2995$:NOr,   c                    U R                   (       d  / $ / nU R                   R                  5        HS  u  p#[        U5      nX4l        U R                  b  UR                  SU R                  U   5        UR                  U5        MU     U$ )z
Return a list of query objects: one for each update required to an
ancestor model. Each query will have the same filtering conditions as
the current query but will only update a single table.
rL   )rD   rQ   r	   rB   rC   r#   r[   )r   resultrU   rB   querys        r   get_related_updatesUpdateQuery.get_related_updates   s{     ##I!11779ME&E!L+  4+;+;E+BCMM%  : r,   )rC   rD   rB   )r-   r.   r/   r0   r1   r2   r;   r<   rG   rN   rM   r\   rZ   rp   r3   __classcell__r?   s   @r   r	   r	   0   s9    "H"
=204P r,   r	   c                   B   ^  \ rS rSrSrSSSS.U 4S jjrSS jrSrU =r$ )	r
      SQLInsertCompilerN)on_conflictupdate_fieldsunique_fieldsc                   > [         TU ]  " U0 UD6  / U l        / U l        Xl        U=(       d    / U l        U=(       d    / U l        g r9   )r:   r;   fieldsobjsrw   rx   ry   )r   rw   rx   ry   r=   r>   r?   s         r   r;   InsertQuery.__init__   sE     	$)&)	&*0b*0br,   c                 (    Xl         X l        X0l        g r9   )r{   r|   raw)r   r{   r|   r   s       r   insert_valuesInsertQuery.insert_values   s    	r,   )r{   r|   rw   r   ry   rx   )F)	r-   r.   r/   r0   r2   r;   r   r3   rr   rs   s   @r   r
   r
      s%    "H "&T1 1 r,   r
   c                   0   ^  \ rS rSrSrSrU 4S jrSrU =r$ )r      zi
Take another query as a parameter to the FROM clause and only select the
elements in the provided list.
SQLAggregateCompilerc                 0   > X l         [        TU ]	  U5        g r9   )inner_queryr:   r;   )r   rU   r   r?   s      r   r;   AggregateQuery.__init__   s    &r,   )r   )	r-   r.   r/   r0   r1   r2   r;   r3   rr   rs   s   @r   r   r      s    
 &H   r,   r   N)r1   django.core.exceptionsr   django.db.models.sql.constantsr   r   r   django.db.models.sql.queryr   __all__r   r	   r
   r   r4   r,   r   <module>r      sQ    . V V ,
I!% !H^% ^B% &
 U 
 r,   