
    `?ii                         d Z ddlmZ ddlmZmZmZ ddlmZ g dZ	 G d de      Z
 G d d	e      Z G d
 de      Z G d de      Zy)zR
Query subclasses which provide extra functionality beyond simple data
retrieval.
    )
FieldError)GET_ITERATOR_CHUNK_SIZE
NO_RESULTS	ROW_COUNT)Query)DeleteQueryUpdateQueryInsertQueryAggregateQueryc                        e Zd ZdZdZd Zd Zy)r   zA DELETE SQL query.SQLDeleteCompilerc                     || j                   |   i| _         || _        | j                  |      j                  t              S N)	alias_mapwhereget_compilerexecute_sqlr   )selftabler   usings       q/home/cursorai/projects/django-cronjob-utils/venv/lib/python3.12/site-packages/django/db/models/sql/subqueries.pydo_queryzDeleteQuery.do_query   s:    !67
  '33I>>    c                 `   d}| j                         j                  }t        dt        |      t              D ]t  }| j                          | j                  |j                   d|||t        z           || j                  | j                         j                  | j                  |      z  }v |S )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_batchzDeleteQuery.delete_batch   s     ""As7|-DEFOO==/&*A!AB 4==(($**E )  K F r   N)__name__
__module____qualname____doc__compilerr   r(    r   r   r   r      s    "H?
r   r   c                   T     e Zd ZdZdZ fdZd Z fdZd Zd Z	d Z
d	 Zd
 Z xZS )r	   zAn UPDATE SQL query.SQLUpdateCompilerc                 D    t        |   |i | | j                          y r   )super__init___setup_query)r   argskwargs	__class__s      r   r3   zUpdateQuery.__init__6   s!    $)&)r   c                 .    g | _         d| _        i | _        y)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   r4   zUpdateQuery._setup_query:   s    
 !r   c                 b    t         |          }| j                  j                         |_        |S r   )r2   cloner;   copy)r   objr7   s     r   r=   zUpdateQuery.cloneC   s*    gmo"22779
r   c                    | j                  |       t        dt        |      t              D ]R  }| j	                          | j                  d|||t        z           | j                  |      j                  t               T y )Nr   pk__in)	add_update_valuesr   r   r   r    r!   r   r   r   )r   r$   r9   r   r'   s        r   update_batchzUpdateQuery.update_batchH   sn    v&As7|-DEFOO'&64K+KL e$00< Fr   c                    g }|j                         D ]  \  }}| j                         j                  |      }|j                  j                  j
                  }|j                  dk(  r!|j                  j                  rt        d      |j                  st        d|z        || j                         j
                  ur| j                  |||       |j                  |||f        | j                  |      S )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.
        r   z:Composite primary key fields must be updated individually.zBCannot update model field %r (only concrete fields are permitted).)itemsr   	get_fieldmodel_metaconcrete_modelnameis_composite_pkr   concreteadd_related_updateappendadd_update_fields)r   r9   
values_seqrJ   valr&   rG   s          r   rB   zUpdateQuery.add_update_valuesQ   s     
ID#MMO--d3EKK%%44EzzT!ekk&A&A P  >> X  DMMO:::''uc:ueS12 (  %%j11r   c                     |D ]Q  \  }}}|j                   rt        |d      r|j                  | dd      }| j                  j	                  |||f       S y)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hasattrrS   r9   rN   )r   rP   r&   rG   rQ   s        r   rO   zUpdateQuery.add_update_fieldsj   s\     ",E5#s01 ,,Tut,TKKuc23 ",r   c                 `    | j                   j                  |g       j                  |d|f       y)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)r;   
setdefaultrN   )r   rG   r&   values       r   rM   zUpdateQuery.add_related_updatez   s,     	''r2995$:NOr   c                    | j                   sg S g }| j                   j                         D ]S  \  }}t        |      }||_        | j                  |j                  d| j                  |          |j                  |       U |S )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.
        rA   )r;   rE   r	   r9   r:   r!   rN   )r   resultrG   r9   querys        r   get_related_updateszUpdateQuery.get_related_updates   s     ##I!11779ME6&E!EL+  4+;+;E+BCMM%  : r   )r)   r*   r+   r,   r-   r3   r4   r=   rC   rB   rO   rM   r^   __classcell__r7   s   @r   r	   r	   1   s4    "H"
=224 Pr   r	   c                   4     e Zd ZdZdddd fd
ZddZ xZS )r
   SQLInsertCompilerN)on_conflictupdate_fieldsunique_fieldsc                z    t        |   |i | g | _        g | _        || _        |xs g | _        |xs g | _        y r   )r2   r3   fieldsobjsrc   rd   re   )r   rc   rd   re   r5   r6   r7   s         r   r3   zInsertQuery.__init__   sG     	$)&)	&*0b*0br   c                 .    || _         || _        || _        y r   )rg   rh   raw)r   rg   rh   rj   s       r   insert_valueszInsertQuery.insert_values   s    	r   )F)r)   r*   r+   r-   r3   rk   r_   r`   s   @r   r
   r
      s    "H "&T1r   r
   c                   &     e Zd ZdZdZ fdZ xZS )r   zu
    Take another query as a parameter to the FROM clause and only select the
    elements in the provided list.
    SQLAggregateCompilerc                 2    || _         t        | 	  |       y r   )inner_queryr2   r3   )r   rG   ro   r7   s      r   r3   zAggregateQuery.__init__   s    &r   )r)   r*   r+   r,   r-   r3   r_   r`   s   @r   r   r      s    
 &H   r   r   N)r,   django.core.exceptionsr   django.db.models.sql.constantsr   r   r   django.db.models.sql.queryr   __all__r   r	   r
   r   r.   r   r   <module>rt      sW   
 . 
 -
I% @`% `F% &
 U 
 r   