
    Evg                         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dS )zR
Query subclasses which provide extra functionality beyond simple data retrieval.
    )
FieldError)CURSORGET_ITERATOR_CHUNK_SIZE
NO_RESULTS)Query)DeleteQueryUpdateQueryInsertQueryAggregateQueryc                   "    e Zd ZdZdZd Zd ZdS )r   zA DELETE SQL query.SQLDeleteCompilerc                     || j         |         i| _         || _        |                     |                              t                    }|r!|5  |j        cd d d            S # 1 swxY w Y   dS )Nr   )	alias_mapwhereget_compilerexecute_sqlr   rowcount)selftabler   usingcursors        \/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/db/models/sql/subqueries.pydo_queryzDeleteQuery.do_query   s    !67
""5))55f== 	' ' '' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'qs   A!!A%(A%c                 z   d}|                                  j        }t          dt          |          t                    D ]{}|                                  |                     |j         d|||t          z                       ||                     |                                  j	        | j
        |          z  }||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EE 	 	FOO=&&&*A!AAB   4==($*E )   KK     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                 b     t                      j        |i | |                                  d S N)super__init___setup_query)r   argskwargs	__class__s      r   r5   zUpdateQuery.__init__5   s7    $)&)))r)   c                 0    g | _         d| _        i | _        dS )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   r6   zUpdateQuery._setup_query9   s!    
 !r)   c                     t                                                      }| j                                        |_        |S r3   )r4   cloner=   copy)r   objr9   s     r   r?   zUpdateQuery.cloneB   s0    ggmmoo"27799
r)   c                 J   |                      |           t          dt          |          t                    D ]i}|                                  |                     d|||t          z                       |                     |                              t                     jd S )Nr   pk__in)	add_update_valuesr   r   r   r    r!   r   r   r   )r   r$   r;   r   r'   s        r   update_batchzUpdateQuery.update_batchG   s    v&&&As7||-DEE 	= 	=FOO'&64K+K"KL   e$$00<<<<	= 	=r)   c                    g }|                                 D ]\  }}|                                                     |          }|j        o|j          p|j         }|j        j        j        }|r|j        r|j	        rt          d|z            ||                                 j        ur|                     |||           |                    |||f           |                     |          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.
        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   r;   
values_seqnamevalr&   directrK   s           r   rD   zUpdateQuery.add_update_valuesP   s    
 	3 	3ID#MMOO--d33E'>,>?Uu~CU  K%4E e/ E4F  /167   DMMOO:::''uc:::ueS12222%%j111r)   c                     |D ]S\  }}}|j         rt          |d          r|                    | dd          }| j                            |||f           TdS )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hasattrrX   r;   rQ   )r   rS   r&   rK   rU   s        r   rR   zUpdateQuery.add_update_fieldsh   s     ", 	4 	4E5# s011 U,,Tut,TTKuc23333	4 	4r)   c                 h    | j                             |g                               |d|f           dS )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=   
setdefaultrQ   )r   rK   r&   values       r   rP   zUpdateQuery.add_related_updatew   s8     	''r22995$:NOOOOOr)   c                     | j         sg S g }| j                                         D ]X\  }}t          |          }||_        | j        !|                    d| j        |                    |                    |           Y|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.
        NrC   )r=   rG   r	   r;   r<   r!   rQ   )r   resultrK   r;   querys        r   get_related_updateszUpdateQuery.get_related_updates   s     # 	I!17799 	! 	!ME6&&E!EL+  4+;E+BCCCMM%    r)   )r*   r+   r,   r-   r.   r5   r6   r?   rE   rD   rR   rP   rc   __classcell__r9   s   @r   r	   r	   0   s        "H    " " "    
= = =2 2 204 4 4P P 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                     t                      j        |i | g | _        g | _        || _        |pg | _        |pg | _        d S r3   )r4   r5   fieldsobjsrh   ri   rj   )r   rh   ri   rj   r7   r8   r9   s         r   r5   zInsertQuery.__init__   sW     	$)&)))	&*0b*0br)   Fc                 0    || _         || _        || _        d S r3   )rl   rm   raw)r   rl   rm   ro   s       r   insert_valueszInsertQuery.insert_values   s    	r)   )F)r*   r+   r,   r.   r5   rp   rd   re   s   @r   r
   r
      sd        "H "&T1 1 1 1 1 1 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                 X    || _         t                                          |           d S r3   )inner_queryr4   r5   )r   rK   rt   r9   s      r   r5   zAggregateQuery.__init__   s)    &r)   )r*   r+   r,   r-   r.   r5   rd   re   s   @r   r   r      sI         
 &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>ry      s    . - - - - - V V V V V V V V V V , , , , , ,
I
I
I! ! ! ! !% ! ! !H^ ^ ^ ^ ^% ^ ^ ^B    %   &
  
  
  
  
 U 
  
  
  
  
 r)   