
    h                         d Z ddlm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)Q)CURSORGET_ITERATOR_CHUNK_SIZE
NO_RESULTS)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              }|r|5  |j
                  cd d d        S y# 1 sw Y   yxY w)Nr   )	alias_mapwhereget_compilerexecute_sqlr   rowcount)selftabler   usingcursors        b/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/django/db/models/sql/subqueries.pydo_queryzDeleteQuery.do_query   sa    !67
""5)55f= '' ''s   AA&c                 ~   d}| j                         j                  }t        dt        |      t              D ]  }| j                         | _        | j                  t        di |j                  dz   |||t        z    i       || j                  | j                         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   where_classr   add_qr   attnamer   db_table)r   pk_listr   num_deletedfieldoffsets         r   delete_batchzDeleteQuery.delete_batch   s     ""As7|-DE 	\F))+DJJJq ^==6)76&CZ:Z+[\^ _4==)A)A4::UZ=[[K		\
     N)__name__
__module____qualname____doc__compilerr   r*   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 N)super__init___setup_query)r   argskwargs	__class__s      r   r6   zUpdateQuery.__init__4   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   r7   zUpdateQuery._setup_query8   s    
 !r+   c                 b    t         |          }| j                  j                         |_        |S r4   )r5   cloner>   copy)r   objr:   s     r   r@   zUpdateQuery.cloneA   s*    gmo"22779
r+   c           	          | j                  |       t        dt        |      t              D ]`  }| j	                         | _        | j                  t        |||t        z                 | j                  |      j                  t               b y )Nr   )pk__in)add_update_valuesr    r!   r   r"   r   r#   r   r   r   r   )r   r&   r<   r   r)   s        r   update_batchzUpdateQuery.update_batchF   st    v&As7|-DE 	=F))+DJJJq9P0P QRSe$00<	=r+   c                    g }|j                         D ]  \  }}| j                         j                  |      }|j                  xr |j                    xs |j                   }|j
                  j                  j                  }|r|j                  r|j                  r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.
        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(   directrL   s           r   rE   zUpdateQuery.add_update_valuesM   s     
 	3ID#MMO--d3E,,CU^^1CDZENNHZFKK%%44Ee//E4F4F /167  DMMO:::''uc:ueS12	3 %%j11r+   c                     |D ]D  \  }}}t        |d      r|j                  | dd      }| j                  j                  |||f       F 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)hasattrrY   r<   rR   )r   rT   r(   rL   rV   s        r   rS   zUpdateQuery.add_update_fieldsc   sU     ", 	4E5#s01,,Tut,TKKuc23		4r+   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>   
setdefaultrR   )r   rL   r(   values       r   rQ   zUpdateQuery.add_related_updateo   s,     	''r2995$:NOr+   c                    | j                   sg S g }| j                   j                         D ]Q  \  }}t        |      }||_        | j                  |j                  d| j                  f       |j                  |       S |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.
        rD   )r>   rH   r
   r<   r=   
add_filterrR   )r   resultrL   r<   querys        r   get_related_updateszUpdateQuery.get_related_updatesw   s     ##I!11779 	!ME6&E!EL+  (D,<,<!=>MM% 	! r+   )r,   r-   r.   r/   r0   r6   r7   r@   rF   rE   rS   rQ   rd   __classcell__r:   s   @r   r
   r
   /   s4    "H"
=2,
4Pr+   r
   c                   0     e Zd ZdZdd fd
ZddZ xZS )r   SQLInsertCompilerF)ignore_conflictsc                N    t        |   |i | g | _        g | _        || _        y r4   )r5   r6   fieldsobjsri   )r   ri   r8   r9   r:   s       r   r6   zInsertQuery.__init__   s+    $)&)	 0r+   c                 .    || _         || _        || _        y r4   )rk   rl   raw)r   rk   rl   rn   s       r   insert_valueszInsertQuery.insert_values   s    	r+   )F)r,   r-   r.   r0   r6   ro   re   rf   s   @r   r   r      s    "H/4 1r+   r   c                       e Zd ZdZdZd Zy)r   zu
    Take another query as a parameter to the FROM clause and only select the
    elements in the provided list.
    SQLAggregateCompilerc                 n    d|_         |j                  |      j                  d      \  | _         | _        y )NT)with_col_aliases)subqueryr   as_sql
sub_params)r   rc   r   s      r   add_subqueryzAggregateQuery.add_subquery   s1    ).););E)B)I)I[_)I)`&tr+   N)r,   r-   r.   r/   r0   rw   r   r+   r   r   r      s    
 &Har+   r   N)r/   django.core.exceptionsr   django.db.models.query_utilsr   django.db.models.sql.constantsr   r   r   django.db.models.sql.queryr   __all__r	   r
   r   r   r   r+   r   <module>r}      s\    . *  -
I% @W% Wt% 
aU 
ar+   