+
    Tjv                       ^ RI t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHtH	t	H
t
 ^ RIHtHt ^ RIHt ^ RIHtHtHtHtHtHt ^ RIHtHt ^ R	IHtHt ^ R
IHt ^ RIH t  ^ RI!H"t"H#t#H$t$H%t%H&t&H't'H(t( ^ RI)H*t*H+t+ ^ RI,H-t- ^ RI.H/t/ ^ RI0H1t1 ^ RI2H3t3  ! R R]4      t4 ! R R4      t5 ! R R]54      t6 ! R R]54      t7 ! R R]54      t8 ! R R]54      t9R t:R# )    N)partial)chain)EmptyResultSet
FieldErrorFullResultSet)DatabaseErrorNotSupportedError)
LOOKUP_SEP)ColPairsFOrderByRawSQLRefValue)	AutoField	composite)CastRandom)Lookup)select_related_descend)CURSORGET_ITERATOR_CHUNK_SIZEMULTI
NO_RESULTS	ORDER_DIR	ROW_COUNTSINGLE)Queryget_order_dir)TransactionManagementError)cached_property)make_hashable)_lazy_re_compilec                   8   a a ] tR t^t oV 3R ltR tRtVtV ;t# )PositionRefc                2   < Wn         \        SV `	  W#4       R # N)ordinalsuper__init__)selfr(   refssource	__class__s   &&&&R/var/www/idalgo/venv/lib/python3.14/site-packages/django/db/models/sql/compiler.pyr*   PositionRef.__init__    s    &    c                0    \        V P                  4      R3# )N )strr(   )r+   compiler
connections   &&&r/   as_sqlPositionRef.as_sql$   s    4<< "$$r1   )r(   )	__name__
__module____qualname____firstlineno__r*   r7   __static_attributes____classdictcell____classcell__r.   __classdict__s   @@r/   r%   r%      s     '% %r1   r%   c                   X  a  ] tR t^(t o ]! R]P                  ]P                  ,          4      tR$R lt	R t
R%R ltR%R ltR tR tR%R	 ltR
 tR tR tR tR tR tR tR tR&R ltR'R ltR tR(R ltR tR tR)R ltR tR t R t!R t"R t#RRR]$3R lt%R  t&]'R]$3R! lt(R" t)R#t*V t+R# )*SQLCompilerz^(.*)\s(?:ASC|DESC).*c                    Wn         W n        W0n        W@n        R R /V n        RV n        RV n        RV n        RV n        R# )*N)	queryr6   usingelide_emptyquote_cacheselectannotation_col_map
klass_info_meta_ordering)r+   rF   r6   rG   rH   s   &&&&&r/   r*   SQLCompiler.__init__/   sE    
$
 ': "&"r1   c           	         R V P                   P                   RV P                  P                  P                   RV P                  : RV P
                  : R2	# )<z model=z connection=z using=>)r.   r;   rF   modelr6   rG   r+   s   &r/   __repr__SQLCompiler.__repr__A   sU    ++, -ZZ%%223 4//,GDJJ>D	
r1   Fc                  a  \         ;QJ d3    V 3R  lS P                  P                   4       F  '       d   K   RM(	  RM$! V 3R  lS P                  P                   4       4      '       d   S P                  P                  4        S P	                  VR7      w  S n        S n        S n        \        S P
                  4      S n	        R# )c              3   d   <"   T F%  pSP                   P                  V,          ^ 8H  x  K'  	  R# 5ir   NrF   alias_refcount).0ar+   s   & r/   	<genexpr>*SQLCompiler.setup_query.<locals>.<genexpr>I   s'     O:NQtzz((+q0:N   -0FTwith_col_aliasesN)
allrF   	alias_mapget_initial_alias
get_selectrJ   rL   rK   len	col_count)r+   ra   s   f&r/   setup_querySQLCompiler.setup_queryH   s    3O$**:N:NO333O$**:N:NOOOJJ((*@D- AP A
=T_d&= T[[)r1   c                   V P                  VR7       V P                  4       pV P                  P                  P	                  V P                  P
                  RJR7      w  V n        V n        V n        V P                  W P                  4      p\        V4      V n        V P                  V P                  V,           V4      pW2V3# )z
Do any necessary class setup immediately prior to producing SQL. This
is for things that can't necessarily be done in __init__ because we
might not have all the pieces in place at that time.
r`   N)must_group_by)rh   get_order_byrF   wheresplit_having_qualifygroup_byhavingqualifyget_extra_selectrJ   boolhas_extra_selectget_group_by)r+   ra   order_byextra_selectro   s   &&   r/   pre_sql_setupSQLCompiler.pre_sql_setupP   s     	*:;$$&04

0@0@0U0U**--T9 1V 1
-
DK ,,X{{C $\ 2$$T[[<%?Jx//r1   c                   V P                   P                  f   . # . p\        4       pV P                   P                  RJd   V P                   P                   F  p\        VR4      '       g   V P                   P	                  V4      p\        V\        4      '       dL   VP                  V9  d9   VP                  VP                  4       VP                  VP                  4       K  K  VP                  V4       K  	  / p\        V^R7       F<  w  pw  rXp	V	'       d   WvV&   W9   d   K  VP                  VP                  4       4       K>  	  V P                  '       g9   V F2  w  pw  rpV'       d   K  VP                  VP                  4       4       K4  	  V P                  '       d   V P                  P                  4       MRpV F  pVP                  V4       K  	  . p\        4       pV P!                  W=4      pV P"                  P$                  P&                  pV F  p V P)                  V4      w  rT'       d#   TP/                  T4      ;pe   \1        T4      RrMTP3                  Y
T4      w  r\5        T4      pT
T3T9  g   Kk  TP                  Y34       TP                  T
T34       K  	  V#   \*        \,        3 d     K  i ; i)z
Return a list of 2-tuples of form (sql, params).

The logic of what exactly the GROUP BY clause contains is hard
to describe in other words than "if it passes the test suite,
then it is correct".
Tr7   startr3   )rF   ro   sethasattrresolve_ref
isinstancer   r,   addappendr-   	enumerateextendget_group_by_colsrM   rp   collapse_group_byr6   featuresallows_group_by_select_indexcompiler   r   getr4   select_formatr"   )r+   rJ   rv   expressionsgroup_by_refsexprselected_expr_positionsr(   _aliassqlparamsis_refhaving_group_byresultseenr   positionparams_hashs   &&&                r/   ru   SQLCompiler.get_group_by`   sp   L ::&I::d* 

++tX..::11$7DdC((yy5%))$))4#**4;;7 6  &&t, , #%)26)C%G%du07- %t5578 *D """/7++sF v&&t'='='?@	 08
 >B[[[$++779b#Dt$ $u,,[J OO$$AA 	%  D"ll40 -!8!<!<T!BBXO!(mRV"00FC'/K[!-sm,#{+,     #M2 s   !J33KKc                   V P                   P                  P                  '       d   V Uu0 uFx  p\        VR 4      '       g   K  VP                  P
                  '       g   K5  V P                   P                  P                  VP                  P                  4      '       g   Kv  VkKz  	  ppV Uu0 uF  q3P                  kK  	  ppV Uu. uF%  pW49   g   W29   g   \        VRR4      V9  g   K#  VNK'  	  ppV# u upi u upi u upi )targetr   N)
r6   r   allows_group_by_selected_pksr~   r   primary_key%allows_group_by_selected_pks_on_modelrR   r   getattr)r+   r   rp   r   pksaliasess   &&&   r/   r   SQLCompiler.collapse_group_by   s     ??##@@@ (
'DD(+  //	 
 00VV)) '  
 /22cdzzcG2 ('D;>4$/w>	 '   '
 3s)   C8C8"<C8#C8/C=	 D.Dc           	     v  a . pRp/ pV P                   P                  '       d   V P                   P                  '       d   Q hV P                   P                  4       pV P                   P                  '       d   V P	                  V4      pMV P                   P                  p. pRpV P                   P
                  f   . R V P                   P                  P                  4        4       OR V 4       OV P                   P                  P                  4       Op\        \        \        V P                   P                  4      \        V P                   P                  4      \        V4      ,           4      4      pM. p\        V P                   P
                  P                  4       4       F  w  p	w  r\        V\        4      '       d   V P                   P                  V,          pM/\        V\         4      '       d   VP#                  V	4       Wk,          p\        V\$        4      '       d   Rp
VP#                  W34       K  	  V'       d   RV P                   P&                  RV/p\        V4       F&  w  pw  rV
'       d   WV
&   VP#                  W34       K(  	  V P                   P(                  '       d$   V P+                  W%4      pWR&   V3R loS! V4       . p^pV Fa  w  pp
 V P-                  V4      w  ppVP/                  V VV4      w  ppV
f   V'       d   RV 2p
V^,          pVP#                  VVV3V
34       Kc  	  WV3#   \0         dB    \3        TR\4        4      pT\4        J d   R	Rpp LdT P-                  \7        T4      4      w  pp L\8         d!    T P-                  \7        R
4      4      w  pp Li ; i)a8  
Return three values:
- a list of 3-tuples of (expression, (sql, params), alias)
- a klass_info structure,
- a dictionary of annotations

The (sql, params) is what the expression will produce, and alias is the
"AS alias" for the column (possibly None).

The klass_info structure contains the following information:
- The base model of the query.
- Which columns for that model are present in the query (by
  position of the select clause).
- related_klass_infos: [f, klass_info] to descent into

The annotations is a dictionary of {'attname': column position} values.
Nc              3   <   "   T F  w  rV\        V!  3x  K  	  R # 5ir'   )r   )r[   r   argss   &  r/   r]   )SQLCompiler.get_select.<locals>.<genexpr>  s"      'F FDM*'Fs   c              3   *   "   T F	  pR V3x  K  	  R # 5ir'   r3   )r[   cols   & r/   r]   r     s     .#4+s   rR   select_fieldsrelated_klass_infosc                    < V R ,           F4  pVR,          '       d   V R,          VR,          ,           VR&   S! V4       K6  	  R# )r   from_parentr   Nr3   )rL   kiget_select_from_parents   & r/   r   6SQLCompiler.get_select.<locals>.get_select_from_parent/  sG    $%:;;B-((&7"_:MM ?+ +2. <r1   empty_result_set_value0Tr   r3   )rF   rJ   default_colsget_select_maskget_default_columnsselectedrw   itemsannotation_selectlistrangerf   r   r   r4   annotationsintr   r   rR   select_relatedget_related_selectionsr   r   r   r   NotImplementedr   r   )r+   ra   rJ   rL   r   select_maskcolsr   r   indexr   
expression
select_idxr   retcol_idxr   r   r   r   r   s   &&                  @r/   re   SQLCompiler.get_select   sJ   $ 
JJ%%%$***A*A*ABBjj002::"""++K8D ::$$D::&'+zz'>'>'D'D'F
 /. --335H !

//0

//03t9<M M.7

8K8K8Q8Q8S.T**j#..!%!7!7
!CJ
C00!((/!%!1Jj(33 E 34 /U !4::#3#3_mTJ/8/B+J+%/E"MM:-. 0C
 ::$$$"&"="=f"R0C,-/ #:. JCC"ll3/V "//c6BV}!1gY1JJc6]E23' !( ++# " N)01>*& *^;"%rC"&,,u5K/L"MKC  8"ll5;7V8s$   !M*N8/N8N8N87N8c           
   #    "   V P                   P                  '       d   V P                   P                  pMV P                   P                  '       g   V P                   P                  pM|V P                   P                  '       d   V P                   P                  pMIV P                   P	                  4       ;p'       d&   VP
                  '       d   VP
                  pWn        M. pV P                   P                  '       d   \        R ,          w  r4M\        R,          w  r4/ pV'       dK   V P                  ;p'       d7   \        V^R7       F%  w  pw  rp	\        WyV4      p
V	'       d   WV	&   WV&   K'  	  V EF  p\        VR4      '       Ed   \        V\        4      '       d   \        WP                   4      p\        V\"        4      '       g   VP%                  4       pV P                   P                  '       g!   VP'                  4       pVP)                  4        VP+                  VP,                  4      pV'       gN   \        VP,                  \.        4      '       d   VP+                  VP,                  P0                  4      ;p'       d   VP2                  f   VP4                  e'   V P6                  P8                  P:                  '       d   VP'                  4       pWn        MQV P                   P<                  '       d6   VP'                  4       p\?        VP@                  VPB                  4      Vn        WRJ3x  EK  VR8X  d   \#        \E        4       4      R3x  EK  \G        W4      w  rVR8H  pVP+                  V4      ;p'       d   \#        VVR7      R3x  EK(  V P                   PH                  P+                  V4      ;p'       d   Tp. pM<VPK                  \L        4      vppV P                   PH                  P+                  V4      pV'       d   V P                   P<                  '       d1   V P                  '       d   V'       d   \O        R	4      h\/        V4      pV'       d&   V F  pV P                   PQ                  VV4      pK!  	  \        V\        4      '       d   \        WP                   4      p\#        WR7      R3x  EKU  R
V9   dJ   VPK                  R
^4      w  pp\#        \S        V PU                  V4      : R
V: 2. 4      VR7      R3x  EK  V P                   PV                  '       d   WP                   PV                  9   d   WP                   PX                  9   dA   \#        \?        V\S        V P                   PV                  V,          !  4      VR7      R3x  EK5  \#        \S        V P                   PV                  V,          !  VR7      R3x  EKk  V P                   P<                  '       d0   V P                  '       d   \#        \/        V4      VR7      R3x  EK  V P[                  VV P                   P	                  4       VR7       Rj  xL
  EK  	  R#  L5i)ASCDESCr{   resolve_expressionN?F
descendingTz;Ordering combined queries by transforms is not implemented..)default_order).rF   extra_order_bydefault_orderingrv   get_metaorderingrM   standard_orderingr   rJ   r   r%   r~   r   r   r   output_fieldr   asccopyreverse_orderingr   r   r   namenulls_first
nulls_lastr6   r    supports_order_by_nulls_modifier
combinatorr   r,   r-   r   r   r   splitr
   NotImplementedErrortry_transformr   quote_name_unless_aliasextrarw   find_ordering_name)r+   r   metar   r   selected_exprsrJ   r(   r   r   pos_exprfield
select_refr   orderr   ref
transformsr   tables   &                   r/   _order_by_pairsSQLCompiler._order_by_pairsQ  s    ::$$$zz00H,,,zz**HZZ   zz**Hjj))++d+}}H"*H::'''(/M1(0M 4;;..-6vQ-G))$5&wt<,45)'/t$	 .H Eu233eU++ (:(:;E!%11!IIKEzz333!JJLE**,+//0@0@A
u//33'5'9'9%:J:J:O:O'PPP
 ))1e6F6F6N11RRR %

+5( ... %

+.z
@Q@Q+R(t333|fh'..&u<JC&J+//44z4 "#-   zz--11#66t6
#&99Z#8 jzz--11#6::(((T[[[!1+  S6D *#zz77dC !+dE**&7&78Dd:EAAe| !YYsA.
s'+'C'CE'JCPRT $.	   zzC::+;+;$;**111VTZZ-=-=c-B%CD'1    

(8(8(= >:V 
 ::(((T[[[ "!C&Z@%GG  $66

++-&3  7    ] \s   AY)2Y)8Y)>Y)0Y)(Y)*Y)>B;Y):AY)=AY)
AY)2Y)?CY)AY)Y)0Y)Y)
Y)(CY)7CY)=Y)AY)Y'Y)c                   . p\        4       pV P                  4        EFJ  w  r4VP                  V P                  RRR7      pV'       Eg   V P                  P                  '       Ed   V P
                  '       Ed{   VP                  pVP                  pV P
                   F  w  rp
Wh8X  g   K  V P                  P                  '       dC   WP                  P                  9   d)   \        V\        4      '       d   WP                  8X  g   Kl  TP                  \        V
'       d   T
MVP                  P                  V4      .4        M	  \!        V P                  P
                  4      ^,           pRV 2p
V P                  P"                   F1  pVP                  '       d   \%        R4      hVP'                  Wz4       K3  	  V P                  P)                  WZ4       VP                  \        W4      .4       V P+                  V4      w  rV P,                  P/                  V4      ^,          p\1        V4      pVV3V9   d   EK#  VP3                  VV34       VP5                  W]W334       EKM  	  V# )z
Return a list of 2-tuples of the form (expr, (sql, params, is_ref)) for
the ORDER BY clause.

The order_by clause can alter the select clause (for example it can add
aliases to clauses that do not yet have one, or it can add totally new
select clauses).
TN)allow_joinsreuse__orderbycolz:ORDER BY term does not match any column in the result set.)r}   r   r   rF   r   rJ   r   has_select_fieldsr   r   r   r   set_source_expressionsr   r   columnrf   combined_queriesr   add_annotationadd_select_colr   ordering_partssearchr"   r   r   )r+   r   r   r   r   resolvedsrcexpr_srcsel_exprr   	col_aliasorder_by_idxqr   r   without_orderingr   s   &                r/   rl   SQLCompiler.get_order_by  s    u 002LD..tzztSW.XH6djj333))??.2kk*H !JJ888 )ZZ-I-I I *8Q 7 7I<V % 77 iSZZ=N=NPSTU  /:& $'tzz'8'8#9A#=L".|n =I!ZZ88 ..."/!2#  ((= 9 JJ--hB33S5H4IJ,,x0KC
  $2299#>qA'/K +.$6HH&45MM86%:;<_ 3` r1   c                f   . pV P                   P                  '       d   V P                   P                  '       gr   V Uu. uF  qD^,          NK  	  ppV FT  w  pw  rxp	V P                  P	                  V4      ^,          p
V	'       d   K5  W3V9  g   K?  VP                  WjV3R34       KV  	  V# u upi    N)rF   distinctdistinct_fieldsr   r   r   )r+   rv   rJ   rw   t
select_sqlr   r   r   r   r  s   &&&        r/   rr   SQLCompiler.get_extra_select  s    ::tzz'A'A'A(./1A$$J//7++sF#'#6#6#=#=c#B1#E v#3"<J"N ''&/I4(PQ 08  0s   B.c                   WP                   9   d   V P                   V,          # WP                  P                  9   d   WP                  P                  9  g`   WP                  P                  9   gF   V P                  P
                  P                  V4      '       d+   WP                  P                  9  d   WP                   V&   V# V P                  P                  P                  V4      pW P                   V&   V# )z
A wrapper around connection.ops.quote_name that doesn't quote aliases
for table names. This avoids problems with some SQL dialects that treat
quoted strings specially (e.g. PostgreSQL).
)
rI   rF   rc   	table_maprw   external_aliasesr   r6   ops
quote_name)r+   r   rs   && r/   r   #SQLCompiler.quote_name_unless_alias'  s     #####D))ZZ)))d**:N:N.Nzz...

++//55

 4 44 &*T"KOO**40!"r1   c                    \        VR V P                  P                  ,           R4      pV'       d   V! W P                  4      w  r4W43# VP                  W P                  4      w  r4W43# )as_N)r   r6   vendorr7   )r+   nodevendor_implr   r   s   &&   r/   r   SQLCompiler.compile=  sZ    dEDOO,B,B$BDI%dOO<KC { ++dOO<KC{r1   c                  a V P                   P                  pV P                  P                   Uu. uF4  pVP	                  V P
                  V P                   V P                  4      NK6  	  ppVP                  '       gR   V FK  pVP                  P                  '       d   \        R 4      hVP                  4       '       g   KB  \        R4      h	  . pRpV F$  p VP                  V P                  V4      4       K&  	  V'       g   \        h\        V4      ^8X  dK   VR8X  dD   V P                  P                  '       d(   RVn        VP                  V P                  V4      4       V P                   P                  P                   V,          p	V'       d   VR8X  d
   V	R,          p	RoV P                  P"                  '       g   VP                  '       d   Ro\%        V3R	 lV 4       !  w  rR
P'                  V	4      P)                  V
4      .p. pV F  pVP+                  V4       K  	  W3# u upi   \         d    TR8X  g   TR8X  d   T'       d   Tp EK  h i ; i)z>LIMIT/OFFSET not allowed in subqueries of compound statements.z:ORDER BY not allowed in subqueries of compound statements.Nunion
differenceFz ALLz{}({})c              3   N   <"   T F  w  rSP                  V4      V3x  K  	  R # 5ir'   )format)r[   r   r   bracess   &  r/   r]   1SQLCompiler.get_combinator_sql.<locals>.<genexpr>r  s!     @%YSv}}S!4(%   "%z {} )r6   r   rF   r   get_compilerrG   rH   %supports_slicing_ordering_in_compound	is_slicedr   rl   r   _get_combinator_part_sqlr   rf   r  set_operatorssubqueryzipr  joinr   )r+   r   rb   r   rF   	compilersr5   partsempty_compilercombinator_sql	sql_parts
args_partsr   r   partr   s   &&&            @r/   get_combinator_sqlSQLCompiler.get_combinator_sqlE  s   ??++ 44
4 tzz4??D<L<LM4 	 
 ===%>>+++'X  ((**'T  & !HT::8DE "   Z1_w!64::;O;O;O */N&LL66~FG,,:::F:(f$Nzz"""x'U'U'UF #@%@!
	 --/44Y?@DMM$ ~c
& "  (Z<-GE%-Ns   :H+ H00 IIIc                   V P                   P                  pV P                  P                  pVeS   VP                  P                  f;   VP                  P	                  4       Vn        VP                  P                  V4       VP                  RR7      w  rEVP                  P                  '       di   VP                  '       g   RP                  V4      pWE3# V P                  P                  '       g   VP                  '       g   RP                  V4      pWE3# V P                  P                  '       d$   VP                  '       d   RP                  V4      pWE3# )NTr`   zSELECT * FROM ({})r  )r6   r   rF   r   clone
set_valuesr7   r    supports_parentheses_in_compoundr  r(  r$  )r+   r5   r   r   part_sql	part_argss   &&    r/   r&  $SQLCompiler._get_combinator_part_sqlz  s   ??++ ::&&HNN$;$;$C%^^113HNNN%%h/&ootoD>>$$$ <<</66x@ "" 

###EEE!==2 "" ZZ   X%S%S%S}}X.H""r1   c                @  aaaaa . pV P                   '       d   VP                  V P                   4       V P                  '       d   VP                  V P                  4       V P                  P	                  4       oR Sn        SP                   P                  V4      Sn         V P                  R R7      ^ ,           UUUu/ uF  w  r#qBVbK
  	  upppo\        SP                  4       4      o\        4       o/ oVVVVV3R lpV! \        V P                  P                  4       4      4       V P                  P                  SP                  4        UUu/ uF  w  r$V\        WB4      bK  	  upp4      V n        . pV P!                  4        Ff  vrsV! VP#                  4       4       TP                  TP                  SP                  4        UUu/ uF  w  r$V\        WB4      bK  	  upp4      4       Kh  	  SP%                  V P&                  V P(                  V P*                  R7      pVP-                  RR R7      w  rV P/                  V P                  4      w  rRV	RV P(                  P0                  P3                  R4      R	V.pS'       d   SP                  4        Uu. uF'  q@P(                  P0                  P3                  V4      NK)  	  ppR
RP5                  V4      R.VORNV P(                  P0                  P3                  R4      Np\        V
4      V,           pV'       dd   . pV F9  pV P/                  V4      w  ppVP                  V4       VP7                  V4       K;  	  VP7                  RRP5                  V4      .4       W3# u upppi u uppi u uppi u upi )Tr`   c                   < V '       d   V P                  4       pVS9   d   K!  SP                  V4      ;p'       d   VSV&   KA  \        V\        4      '       d"   V P	                  VP                  4       4       Kx  \        V\        4      '       d5   VP                  S9  d"   V P	                  VP                  4       4       K  K  \        S4      pR V 2pSP                  V4       SP                  W4       VSV&   K  R# )qualN)popr   r   r   r   get_source_expressionsr   r,   rf   r   r   )	r   r   select_aliasnum_qual_aliasinner_queryqual_aliasesreplacementsrJ   select_aliasess	   &   r/   collect_replacements9SQLCompiler.get_qualify_sql.<locals>.collect_replacements  s    "(<'%+ZZ%55\5)5L&f--&&t'B'B'DEc**yy6#**4+F+F+HI 7 &)%6N%).)9#:L $$\2..tB)5L&! r1   )r6   rH   F)with_limitsra   SELECT * FROM ()rq   WHERESELECT, zFROM (qualify_maskzORDER BY)rm   r   rp   rF   r5  r(  r.   re   r}   valuesr   rq   leavesreplace_expressionsr   r   rl   r?  r#  rG   r6   rH   r7   r   r  r  r*  r   )r+   where_partsr   r   r   rF  rv   order_by_exprinner_query_compiler	inner_sqlinner_paramsqualify_sqlqualify_paramsr   r   r   ordering_sqlsr   ordering_sqlordering_paramsrB  rC  rD  rJ   rE  s   &                   @@@@@r/   get_qualify_sqlSQLCompiler.get_qualify_sql  s=   :::tzz*;;;t{{+jj&&(#'--77D /3ooto.TUV.W
.WNDU%K.W
 V]]_-u	6 	6& 	T$,,"5"5"789||777C7I7I7KL7KT3u##7KL
 !%!2!2!4M !E!E!GHOO11?K?Q?Q?ST?ST3u++?ST "5  +77JJ4??@P@P  8  
 #7"="=  " #> #
	 '+ll4<<&@#OO**95
  HN}}WeOO''2259DW		$ 	
  ##..~>F l#n4 M$04X0F-o$$\2o. % MM:tyy'?@A~c
8 M U4 Xs    NN
N-Nc                .   V P                   P                  P                  4       p V P                   P                  pT P	                  T;'       g    \        V4      R7      w  rVpRpT;'       d    V P                   P                  p	V P                   P                  pV P                  P                  p
V'       de   \        V
RP                  V4      4      '       g   \        RP                  V4      4      hV P                  W@P                   P                  4      w  rEM@V P                  '       d   V P                  4       w  rRpEMV P!                  4       w  rV P#                  4       w  pp V P$                  e   V P'                  V P$                  4      MR. 3w  pp V P.                  e   V P'                  V P.                  4      MR. 3w  ppR.p. pV P                   P0                  '       d;   V P                  P2                  P5                  VV4      w  ppVV,          pW,          p. pV P6                  V,            F`  w  pw  pppV'       d-   V: RV P                  P2                  P9                  V4      : 2pVP;                  V4       VP=                  V4       Kb  	  VR	P?                  V4      .,          pV'       d   VR
.VO,          pMMV P                  P                  P@                  '       d(   WP                  P                  P@                  .,          pVP;                  V4       V P                   PB                  '       Ed   V
PD                  '       Ed   V P                  PG                  4       '       d   V
PH                  '       d   \K        R4      hV	'       d   V
PL                  '       g   \        R4      hV P                   PN                  pV P                   PP                  pV P                   PR                  pV P                   PT                  pV'       d   V
PV                  '       g   \        R4      hV'       d   V
PX                  '       g   \        R4      hV'       d   V
PZ                  '       g   \        R4      hV'       d   V
P\                  '       g   \        R4      hV P                  P2                  P_                  VVV Pa                  4       VR7      pV'       d$   V
Pb                  '       d   VP=                  V4       V'       d*   VP=                  RV,          4       VP;                  V4       . pV F(  w  p p!VP=                  V 4       VP;                  V!4       K*  	  V'       d}   V'       d   \e        R4      hT;'       g%    V P                  P2                  Pg                  4       pVP=                  RR	P?                  V4      ,          4       V Ph                  '       d   RpV'       de   V'       g4   VP;                  V P                  P2                  Pk                  4       4       VP=                  RV,          4       VP;                  V4       V P                   Pl                  '       dt   VPo                  ^ V P                  P2                  Pp                  ! V P                   Pl                  P                  3/ V P                   Pl                  Pr                  B 4       V'       d   . p"V F,  w  pw  p#p$pV"P=                  V#4       VP;                  V$4       K.  	  RR	P?                  V"4      ,          p%V'       d   V
Pt                  '       d   R.VORNV%NpMVP=                  V%4       V	'       d^   VP=                  V P                  P2                  Pw                  V P                   Px                  V P                   Pz                  4      4       V'       d$   V
Pb                  '       g   VP=                  V4       V P                   P|                  '       EdN   V'       EdE   . p&. p'\        V P6                  ^R7       F  w  p(w  p)ppV'       da   V&P=                  V P                  P2                  P9                  R4      : RV P                  P2                  P9                  V4      : 24       Kr  V)P                  V)P                  R/4      p*V*P                  W P                  4      w  p+p,V&P=                  V+4       V'P;                  V,4       K  	  RR	P?                  V&4      : RRP?                  V4      : R2\        V'V,           4      3V P                   P                  V4       # RP?                  V4      \        V4      3V P                   P                  V4       #   \(         d    T P*                  '       d   h R. pp EL0\,         d	    R. pp ELAi ; i  \,         d	    R. pp EL&i ; i  T P                   P                  T4       i ; i) z
Create the SQL for this query. Return the SQL string and list of
parameters.

If 'with_limits' is False, any limit/offset information is not included
in the query.
r`   Nzsupports_select_{}z-{} is not supported on this database backend. z0 = 1rL  z AS rM  FROMz:select_for_update cannot be used outside of a transaction.zNLIMIT/OFFSET is not supported with select_for_update on this database backend.z1NOWAIT is not supported on this database backend.z6SKIP LOCKED is not supported on this database backend.z8FOR UPDATE OF is not supported on this database backend.z<FOR NO KEY UPDATE is not supported on this database backend.)nowaitskip_lockedofno_keyWHERE %sz1annotate() + distinct(fields) is not implemented.zGROUP BY %sz	HAVING %szORDER BY %srI  rJ  r{   r(  r   SELECT  FROM ( 
) subquery)ErF   rZ   r   r   rx   rs   r%  r6   r   r   r  r	   r2  combinator_allrq   r\  get_distinctget_from_clauserm   r   r   rH   r   rp   r  r  distinct_sqlrJ   r  r   r   r*  bare_select_suffixselect_for_updatehas_select_for_updateget_autocommitsupports_transactionsr    %supports_select_for_update_with_limitselect_for_update_nowaitselect_for_update_skip_lockedselect_for_update_ofselect_for_no_key_updatehas_select_for_update_nowait!has_select_for_update_skip_lockedhas_select_for_update_ofhas_select_for_no_key_updatefor_update_sql"get_select_for_update_of_argumentsfor_update_after_fromr   force_no_orderingrM   force_group_byexplain_infoinsertexplain_query_prefixoptions#requires_compound_order_by_subquerylimit_offset_sqllow_mark	high_markr(  r   relabeled_cloner   r7   tuplereset_refcounts)-r+   rH  ra   refcounts_beforer   rw   rv   ro   for_update_partwith_limit_offsetr   r   r   r	  distinct_paramsfrom_f_paramsrm   w_paramsrp   h_paramsdistinct_resultout_colsr   s_sqls_paramsr   ra  rb  rc  rd  groupingg_sqlg_paramsr   o_sqlo_paramsorder_by_sqlsub_selects
sub_paramsr   rJ   select_clone	subselect	subparamss-   &&&                                          r/   r7   SQLCompiler.as_sql  sA     ::4499;X	9..J/3/A/A!1!E!ET*5E 0B 0,LH #O + D D

0D0D..J//Hx)=)D)DZ)PQQ+GNN& 
 "&!8!8

 9 9" !%!5!5!7373D3D3F0 #'"6"6"8x
-48JJ4JTZZ0QSUWPX $E8.  ;;2 T[[1 "X %FH #::&&&7;7J7J7W7W''84O_ o-F-F37;;3M3M/A(x%! OO//::5A! MM(+OOE* 4N 499X.//v...F__--@@@77JJKKFh'::///H4R4R4R6688 %:::8X 
 * ( N N N/J  "ZZ@@F"&**"J"JK88B!ZZ@@F h&K&K&K/O  %X-W-W-W/T  H$E$E$E/V   (M(M(M/0  '+oo&9&9&H&H%$/BBD%	 'I 'O #x'E'E'EMM/2MM*u"45MM(+'/OE8OOE*MM(+ (0 &1O   (RR4??+>+>+P+P+RHMM-$))H2E"EF***#'#doo&9&9&H&H&JKMM+"67MM(+zz&&&OO''<<

//66**1199 /7+A+xOOE*MM(+ 08  -tyy/BB("N"N"N/L&L#L|LFMM,/ OO''88

++TZZ-A-A x'E'E'Eo.zz"""|| !
1:4;;a1P-E-FAu#** !% 3 3 > >z J $ 3 3 > >u E (.'='=#\\:6( 0</B/B //0,	9 $**95")))4# 2Q& IIk*HHV$ f,-. JJ&&'78 88F#U6]2 JJ&&'78q & 2'''&-r8E8$ -&("8E8- % .')2HFH.V JJ&&'78sb  )g7 g7 /A
g7 :A5g7 0;g7 ,0f' 0g!  g7 .Cg7 2g7 5Ag7 
g7 g7 =g7 g7 "g7 4A*g7 g7 1g7 g7 g7 )g7 ;g7 g7  A	g7 *g7 <g7 A g7 6g7 >g7 Ag7 0	g7 :g7 A7g7 :A:g7 5Ag7 	g7 "g7 >A$g7 #g7 5-g7 #g7 ,D(g7 0g7 'gg	g7 ggg7 gg7 !g40g7 3g44g7 7hNc                   . pVf!   V P                   P                  4       ;pf   V# T;'       g    V P                   P                  4       pRV/p\        \        P
                  ! V4      4      pVP                   F  pVP                  P                  P                  p	WP                  8X  d   Rp	V'       dA   V	e=   \        VP                  P                  V	P                  P                  4      '       d   K}  V'       d	   W9  d   K  V P                   P                  W9W&4      p
VP                  V
4      pVP                  V4       K  	  V# )a  
Compute the default columns for selecting every field in the base
model. Will sometimes be called to pull in related models (e.g. via
select_related), in which case "opts" and "start_alias" will be given
to provide a starting point for the traversal.

Return a list of strings, quoted appropriately for use in SQL
directly, as well as a set of aliases used in the select statement (if
'as_pairs' is True, return a list of (alias, col_name) pairs instead
of strings as the first component and None as the second component).
N)rF   r   rd   r}   r   unnestconcrete_fieldsrR   _metaconcrete_model
issubclassjoin_parent_modelget_colr   )r+   r   start_aliasoptsr   r   seen_modelsselect_mask_fieldsr   rR   r   r   s   &&&&&       r/   r   SQLCompiler.get_default_columns  s    <

++--6!CCTZZ%A%A%C [) !1!1+!>?))EKK%%44E 

"%%%44ekk6P6P  u>JJ00kWE]]5)FMM&!/ *0 r1   c                <   . p. pV P                   P                  4       pV P                   P                   F  pVP                  \        4      pV P                  WSR4      w  rgrrpV P                   P                  WyV
4      w  rxpV F  pW@P                   P                  9   d7   VP                  V P                  P                  P                  V4      4       KS  V P                  V! W4      4      w  rVP                  V4       VP                  V4       K  	  K  	  W3# )z
Return a quoted list of fields to use in DISTINCT ON part of the query.

This method can alter the tables in the query, and thus it must be
called before get_from_clause().
N)rF   r   r	  r   r
   _setup_joins
trim_joinsr   r   r6   r  r  r   )r+   r   r   r  r   r,  r   targetsr   joinspathtransform_functionr   r  ps   &              r/   rk  SQLCompiler.get_distinct
  s     zz""$JJ..DJJz*EDHDUDUTEAAd/A !%

 5 5gd KGA!::777MM$//"5"5"@"@"FG<<(:6(IJDAMM!$MM!$ " / ~r1   c                R  a a \        SV4      w  opVR8H  pSP                  \        4      pS P                  WV4      w  p	p
pppppV	P                  '       Ed   VP
                  '       Edt   \        V	RR4      VR,          8w  EdZ   SR8w  EdR   \        VRR4      '       Eg>   T;'       g    \        4       p\        ;QJ d    . V 3R lV 4       F  NK  	  5M! V 3R lV 4       4      pW9   d   \        R4      hVP                  V4       . pVP
                   F  p\        VR	4      '       d?   \        V\        4      '       g)   V'       d   VP                  4       MVP                  4       p\        V\        4      '       d-   VP!                  VP#                  S \         24      R34       K  VP%                  V3R
 lS P'                  VW#We4       4       4       K  	  V# S P(                  P+                  WV4      w  rpV
 Uu. uF  p\        V! VV4      VR7      R3NK  	  up# u upi )z
Return the table alias (the name might be ambiguous, the alias will
not be) and column name for ordering by the given 'name' parameter.
The 'name' is of the form 'field1__field2__...__fieldN'.
r   attnameNpkhas_transformsFc              3   t   <"   T F-  p\        SP                  P                  V,          R R4      x  K/  	  R# 5i)	join_colsN)r   rF   rc   )r[   jr+   s   & r/   r]   1SQLCompiler.find_ordering_name.<locals>.<genexpr>F  s/      MR

,,Q/dCCUs   58z!Infinite loop caused by ordering.r   c              3   ^   <"   T F"  w  rVP                  S \         24      V3x  K$  	  R # 5ir'   )prefix_referencesr
   )r[   r   r   r   s   &  r/   r]   r  X  s7      ) ++tfZL,ABFK)s   *-r   )r   r   r
   r  is_relationr   r   r}   r  r   r   r~   r   r   descr   r   r  r   r   rF   r  )r+   r   r  r   r   already_seenr   r   piecesr   r  r  r  r  
join_tupleresultsitemr   r
  s   ff&&&&             r/   r   SQLCompiler.find_ordering_name$  s    $D-8ef_
J' fE2	
 y$/6":=.0@%HH (0035L MR MR J ) !DEEZ(G4!566z'@ @ +5499;$((*DdG,,NN//4&0EFN  (,(?(?d5)  &  N JJ11'$G 
 '51jI5Q
 	
 
s   H$c                    T;'       g    V P                   P                  4       pV P                   P                  WV4      w  rEr&rxVR,          pWEW6WrV3# )z
Helper method for get_order_by() and get_distinct().

get_ordering() and get_distinct() must produce same target columns on
same input, as the prefixes of get_ordering() and get_distinct() must
match. Executing SQL where this is not true is an error.
r  )rF   rd   setup_joins)	r+   r  r  r   r   r  r  r  r  s	   &&&&     r/   r  SQLCompiler._setup_joinse  sZ     77557@D

@V@V%A
=T b	uT9KKKr1   c                n   . p. p\        V P                  P                  P                  4       4       F_  w  r4V P                  P                  V,          '       g   K*  V P                  V4      w  rVVP                  V4       VP                  V4       Ka  	  V P                  P                   F  pV P                  P                  V4      w  r8W0P                  P                  9  g%   V P                  P                  V,          ^8X  g   K^  VP                  RV P                  V4      ,          4       K  	  W3# )a  
Return a list of strings that are joined together to go after the
"FROM" part of the query, as well as a list any extra parameters that
need to be included. Subclasses, can override this to create a
from-clause via a "select".

This should only be called after any SQL construction methods that
might change the tables that are needed. This means the select columns,
ordering, and distinct must be done first.
z, %s)r  rF   rc   r   rZ   r   r   r   extra_tablestable_aliasr   )	r+   r   r   r   from_clause
clause_sqlclause_paramsr
  r   s	   &        r/   rl  SQLCompiler.get_from_clauset  s      #(

(<(<(B(B(D"EE::,,U33(,[(A%JMM*%MM-( #F ((Azz--a0HE
 ZZ111::,,U3q8ft'C'CE'JJK ) ~r1   c                |  a a VV 3R lp. p	V'       g   VS P                   P                  8  d   V	# S'       g5   S P                   P                  4       oS P                   P                  4       p\	        4       p
VfC   \        S P                   P                  \        4      pV'       d   S P                   P                  pR pSP                   EF-  pV
P                  VP                  4       V'       d   VP                  VP                  / 4      pVP                  '       gU   V'       g   VP                  V9   d<   \        RVP                  : RRP                  V! 4       4      ;'       g    R: 24      hMRp\        WWb4      '       g   K  VP                  V4      ;'       g    / pR	VP                   P"                  R
TRRRVP$                  RVP&                  '       d   VP                   P$                  MR RR/pV	P)                  V4       . pS P                   P+                  VP                  .SV4      w    pp pVR,          pS P-                  VVVP                   P"                  P.                  R7      pV F0  pVP)                  \1        V4      4       VP)                  VR34       K2  	  VVR&   S P3                  VVVP                   P"                  P.                  VV^,           VV4      pV! VV4       EK0  	  V'       Ed1   SP4                   Uu. uFN  pVP6                  P&                  '       g   K!  VP8                  '       d   K5  VVP6                  VP:                  3NKP  	  ppV EF  w  ppp\        VVVV4      '       g   K  VP                  V4      ;'       g    / pVP=                  4       pV
P                  V4       S P                   P+                  V.SV4      pVP>                  R,          p\A        VSP"                  4      ;'       d    VSP"                  JpR	VR
VRRRVP$                  RVP$                  RV/pV	P)                  V4       . pS P-                  VVVP.                  SP"                  R7      pV F0  pVP)                  \1        V4      4       VP)                  VR34       K2  	  VVR&   VP                  V/ 4      pS P3                  VVVP.                  VV^,           VV4      pV! VV4       EK  	  R pR p R p!\C        V4       EF  p"V^8  d    EMV"S P                   PD                  9   g   K+  V
P                  V"4       S P                   P+                  V".SV4      w  p#pp$p pV$P"                  pVR,          p\A        VSP"                  4      ;'       d    VSP"                  JpR	TR
T#RRR\1        V4      ^8:  d   \G        VV#4      MT R\G        V!V"4      RV/pV	P)                  V4       . pVP                  V"V#34      ;'       g    / p%S P-                  V%VVP.                  SP"                  R7      pV F0  pVP)                  \1        V4      4       VP)                  VR34       K2  	  VVR&   VP                  V"/ 4      p&S P3                  VV%VP.                  VV^,           V&VR7      pV! VV4       EK  	  \	        V4      PI                  V
4      p'V''       dJ   R V' 4       p(\        RRP                  V(4      : RRP                  V! 4       4      ;'       g    R: 24      hV	# u upi )z
Fill in the information needed for a select_related query. The current
depth is measured as the number of connections away from the root model
(for example, cur_depth=1 means we are looking at models with direct
connections to the root model).
c                     < R  SP                    4       p R SP                   4       p\        WSP                  P                  4      # )c              3   `   "   T F$  qP                   '       g   K  VP                  x  K&  	  R # 5ir'   )r  r   r[   fs   & r/   r]   QSQLCompiler.get_related_selections.<locals>._get_field_choices.<locals>.<genexpr>  s     Kk]]faffks   ..c              3      "   T F=  pVP                   P                  '       g   K!  VP                   P                  4       x  K?  	  R # 5ir'   )r   uniquerelated_query_namer  s   & r/   r]   r    s4      -A77>> -**,,-s
   A"A)fieldsrelated_objectsr   rF   _filtered_relations)direct_choicesreverse_choicesr  r+   s     r/   _get_field_choices>SQLCompiler.get_related_selections.<locals>._get_field_choices  sD    KdkkKN--O
 1O1O r1   Nc                     WR &   R# )r   Nr3   )rL   r   s   &&r/   get_related_klass_infosCSQLCompiler.get_related_selections.<locals>.get_related_klass_infos  s    0C,-r1   z/Non-relational field given in select_related: 'z'. Choices are: rM  z(none)FrR   r   reverselocal_setterremote_setterc                     R # r'   r3   )xys   &&r/   <lambda>4SQLCompiler.get_related_selections.<locals>.<lambda>  s    RVr1   r   )r  r  r   T)r  r  r   c                 P    V'       d   V P                   P                  W!4       R # R # r'   )remote_fieldset_cached_value)final_fieldobjfrom_objs   &&&r/   r  8SQLCompiler.get_related_selections.<locals>.local_setter5  s    ,,==hL r1   c                     R # r'   r3   )r  r  s   &&r/   local_setter_noop=SQLCompiler.get_related_selections.<locals>.local_setter_noop:  s    r1   c                     \        W V4       R # r'   )setattr)r   r  r  s   &&&r/   r  9SQLCompiler.get_related_selections.<locals>.remote_setter=  s    ,r1   )r  
root_alias	cur_depth	requested
restrictedc              3   4   "   T F  pR V,          x  K  	  R# 5i)z'%s'Nr3   )r[   ss   & r/   r]   5SQLCompiler.get_related_selections.<locals>.<genexpr>t  s     !G6F&1**6F   z/Invalid field name(s) given in select_related: z. Choices are: r  )%rF   	max_depthr   rd   r}   r   r   dictr  r   r   r   r  r   r*  r   r  rR   r  r  r   r  r   r  rf   r   r  r   many_to_manyrelated_modelr  r  r  r   r  r   r  ))r+   rJ   r   r  r  r   r  r  r  r   fields_foundr  r  nextrelated_select_maskrL   r   r   r  r   columnsr   next_klass_infosorelated_fieldsrelated_objectrelated_fieldrR   related_field_name	join_infor   r  r  r  r   r  	join_optsfield_select_masknext_requestedfields_not_foundinvalid_fieldss)   f&&f&&&&                                 r/   r   "SQLCompiler.get_related_selections  s   "		 !i$***>*>>&&::&&(D557J u#DJJ$=$=tDJ JJ55		D AQVV$ }}QVVR0}}} qvv2( !" $		*<*> ? K K8 K	  )!PP"-//!"4":":--5 2 278xxxANN33EVu	J  &&z2M#'::#9#9166(D*#U Aq!UAq"IE..#Q^^=Q=Q=W=W / G $$S[1sDk*  +8J'#::#$$**A  $J0@Ak n : ---A77>> .*+.. .AGGQ__--  
 9G4u-"	  &1oon&E&K&K#%2%E%E%G"  !34 JJ22'($
	 "+(

;WWTZZ@WU]t"N$C$C#]%C%C!;
 $**:6 "22' % $

	 3  #C!((V5MM3+. # /<
?+ }}%7<#'#>#>'KKM$  (
4DEa 9GdM
- Yq=4::999 $$T*=AZZ=S=Sj>:KIua &OOE!"IE"5$**5QQ%tzz:Q    !4&"5zQ $L+>!2')E%{"J (..z:$&M(3{8K(L(R(RPR%"66)$)"[[$(JJ	 7 G  '%,,S[9sDk2  ' 3@J/%.]]4%<N'+'B'B)"[[#("+a-"0#- (C ($ ,J8HIc (d  #9~88F!G6F!G  		.1		"4"67CC8C	  #"s   \98\9\9c           	       a a V 3R loV 3R lpVV 3R lpS P                   '       g   . # . p. pS P                  P                   EF=  pS P                   pVR8X  d
   V! V4      pMVP                  \        4       Fe  p. VP                  R. 4      OS! V4      O5p	V	 F=  p
V
R,          pV
R,          '       d   VP                  pVP                  V8X  g   K:  T
p Ka  	  Rp M	  Vf   VP                  V4       K  V! V4      pVf   K  S P                  P                  P                  '       d+   VP                  S P                  V4      ^ ,          4       EK  VP                  S P                  VP                  4      4       EK@  	  V'       d8   \        R	R
P!                  V4      : RR
P!                  V! 4       4      : R24      hV# )zS
Return a quoted list of arguments for the SELECT FOR UPDATE OF part of
the query.
c              3     <"   V R ,          P                   P                  pVP                   P                  P                  4        F  w  r#VP                   P                  pR TRTRRRV R,           Uu. uFm  pSP
                  V,          ^ ,          P                  P                  V8X  g6   SP
                  V,          ^ ,          P                  P                  V9   g   Kk  VNKo  	  up/x  K  	  R# u upi 5i)rR   r   r  Fr   N)r  r  parentsr   all_parentsrJ   r   rR   )rL   r  parent_modelparent_linkr  select_indexr+   s   &     r/   _get_parent_klass_infoNSQLCompiler.get_select_for_update_of_arguments.<locals>._get_parent_klass_info  s     '066EEN-;-A-A-I-I-O-O-Q)*00<<\[u#,6,G&,GL !KK5a8??EEU#{{<8;BBHHKW %,G&	  .R&s   A/C62A(C1C1%C6c                   < V R,          P                   P                  pV R,           FR  pSP                  V,          ^ ,          P                  P                  V8X  g   K8  SP                  V,          ^ ,          u # 	  R# )z
Find the first selected column from a model. If it doesn't exist,
don't lock a model.

select_fields is filled recursively, so it also contains fields
from the parent models.
rR   r   N)r  r  rJ   r   rR   )rL   r  r"  r+   s   &  r/   "_get_first_selected_col_from_modelZSQLCompiler.get_select_for_update_of_arguments.<locals>._get_first_selected_col_from_model  sc     (066EEN *? ; ;;;|,Q/66<<N;;|4Q77 !<r1   c               3    <a"   \         P                  ! RSP                  3.4      p V '       d   V P                  4       w  rVf   . oRx  MLVR,          pVR,          '       d   VP                  p. VOVP
                  No\        P                  ! S4      x  V P                  V3R lS! V4       4       4       V P                  V3R lVP                  R. 4       4       4       K  R# 5i)z<Yield all allowed field paths in breadth-first search order.Nr+   r   r  c              3   ,   <"   T F	  pSV3x  K  	  R # 5ir'   r3   r[   rL   r  s   & r/   r]   ]SQLCompiler.get_select_for_update_of_arguments.<locals>._get_field_choices.<locals>.<genexpr>  s      &H
 :&&H   c              3   ,   <"   T F	  pSV3x  K  	  R # 5ir'   r3   r*  s   & r/   r]   r+    s      &O
 :&&Or,  r   )
collectionsdequerL   popleftr  r   r
   r*  r   r   )queueparent_pathrL   r   r  r#  r+   s       @r/   r  JSQLCompiler.get_select_for_update_of_arguments.<locals>._get_field_choices  s     %%doo'>&?@E*/--/'&D L&w/E!),, % 2 25[5%**5D$//$// &<Z&H   &0nn5JB&O  s   +C)4C)%BC)r+   r   r   r  Nz<Invalid field name(s) given in select_for_update(of=(...)): rM  zI. Only relational fields followed in the query are allowed. Choices are: r   )rL   rF   rv  r   r
   r   r  r   r   r6   r   select_for_update_of_columnr   r   r   r   r*  )r+   r&  r  r   invalid_namesr   rL   r   r1  klass_infosrelated_klass_infor   r#  s   f           @r/   r}  .SQLCompiler.get_select_for_update_of_arguments  s   	&	8	. IJJ33DJv~8D JJz2D##(=rB#/
;#K /:* 27 ;-i88$)$6$6E ::-);J! /: &*
 3 %!((.8D??++GGGMM$,,s"3A"67MM$">">syy"IJ9 4: 
 IIm,II023  r1   c                   ^ p/ pV F  p\        V\        4      '       d^   VP                  4       pV P                  V4      pVP	                  4        F  w  pw  rW3W2V,           &   K  	  V\        V4      ,          pKv  V'       dh   V P                  P                  P                  V4      p
VP                  V P                  4      pV
'       g	   V'       d   W,           V3W2&   V^,          pK  V^,          pK  	  V# )r   )	r   r   r?  get_convertersr   rf   r6   r  get_db_converters)r+   r   i
convertersr   r   cols_convertersr  convsr   backend_convertersfield_converterss   &&          r/   r:  SQLCompiler.get_converters  s    
%J*h//!88:"&"5"5d";'6'<'<'>OA|).J1u% (?S_$%)__%8%8%J%J:%V"#-#?#?#P %)9%7%JJ$WJMQQ &  r1   c              #     "   V P                   p\        VP                  4       4      p\        \        V4       F3  pV F&  w  pw  rgWE,          pV F  p	V	! WV4      pK  	  WV&   K(  	  Vx  K5  	  R # 5ir'   )r6   r   r   map)
r+   rowsr=  r6   rowposr?  r   value	converters
   &&&       r/   apply_convertersSQLCompiler.apply_converters  sn     __
***,-
tT?C,6((e!&I%eDE "' C	 -7
 I #s   A/A1c                j    \         ;QJ d    R  V 4       F  '       g   K   R# 	  R# ! R  V 4       4      # )c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir'   )r   r   )r[   r   s   & r/   r]   3SQLCompiler.has_composite_fields.<locals>.<genexpr>  s     Rk
:j(33ks   TF)any)r+   r   s   &&r/   has_composite_fields SQLCompiler.has_composite_fields
  s-     sRkRssRsRsRkRRRr1   c              #  (  "   \        V4       UUu. uF8  w  r4\        V\        4      '       g   K  \        W3\	        V4      ,           4      NK:  	  ppp\        \        V4       F$  pV F  p\        Wg,          4      3Wg&   K  	  Vx  K&  	  R # u uppi 5ir'   )r   r   r   slicerf   rD  r   r  )r+   rE  r   r<  r   col_pair_slicesrF  rG  s   &&&     r/   composite_fields_to_tuples&SQLCompiler.composite_fields_to_tuples  s      "+;!7
!7*h/ *E!Z()!7 	 
 tT?C&!#(O- ' I	 #
s   BBBABc                   Vf   V P                  \        W4R7      pV P                  ^ V P                    Uu. uF  qU^ ,          NK  	  ppV P	                  V4      p\
        P                  ! V4      pV'       d   V P                  W4      pV P                  V4      '       d   V P                  W4      pV'       d   \        \        V4      pV# u upi )z>Return an iterator over the results from executing this query.)chunked_fetch
chunk_size)execute_sqlr   rJ   rg   r:  r   from_iterablerJ  rP  rU  rD  r  )	r+   r  tuple_expectedrX  rY  r  r  r=  rE  s	   &&&&&    r/   results_iterSQLCompiler.results_iter  s     ?&&] ' G !%A ?@ ?1A$$ ?@((0
""7+((:D$$V,,224@Dud#D As   Cc                >    \        V P                  \        4      4      # )zh
Backends (e.g. NoSQL) can override this in order to use optimized
versions of "query has any results."
)rs   rZ  r   rS   s   &r/   has_resultsSQLCompiler.has_results3  s    
 D$$V,--r1   c                D   T;'       g    \         p V P                  4       w  rEV'       g   \        h T'       d   T P
                  P                  4       pMT P
                  P                  4       p TP                  YE4       T\        8X  d    TP                  TP                  4        # T\        8X  d   T# T\        8X  dK    TP                  4       pT'       d    T^ T P                    TP                  4        # TTP                  4        # T\         8X  d   TP                  4        R# \#        TT P
                  P$                  P&                  T P(                  '       d   T P                   MRT4      pT'       d'   T P
                  P$                  P*                  '       g   \-        T4      # T#   \         d    T\        8X  d   \	        . 4      u #  R# i ; i  \         d    TP                  4        h i ; i  TP                  4        i ; i  TP                  4        i ; i)a  
Run the query against the database and return the result(s). The
return value depends on the value of result_type.

When result_type is:
- MULTI: Retrieves all rows using fetchmany(). Wraps in an iterator for
   chunked reads when supported.
- SINGLE: Retrieves a single row using fetchone().
- ROW_COUNT: Retrieves the number of rows in the result.
- CURSOR: Runs the query, and returns the cursor object. It is the
   caller's responsibility to close the cursor.
N)r   r7   r   r   iterr6   chunked_cursorcursorexecute	Exceptioncloser   rowcountr   r   fetchonerg   cursor_iterr   empty_fetchmany_valuert   can_use_chunked_readsr   )	r+   result_typerX  rY  r   r   re  valr   s	   &&&&     r/   rZ  SQLCompiler.execute_sql:  s    "//Z	++-KC$$  __335F__++-F	NN3' )#& M& oo'q4>>2   *$LLNOO$$::"333DNN	
 DOO$<$<$R$R$R
 <c  	e#Bx		  	LLN	  sA    F. 1G G8 H H :H .!GGG58H
Hc           
   #    "   \        V P                  4       4      pV P                  P                  P                  pV'       d&   VP                  4       R 8X  d   \        P                  M\        pV FP  pV FG  p\        V\        4      '       g+   RP                  V Uu. uF
  qc! V4      NK  	  up4      x  KC  Vx  KI  	  KR  	  R# u upi 5i)jsonrh  N)r   rZ  rF   r  r  lowerrr  dumpsr4   r   r*  )r+   r   format_output_formatterrF  rH  cs   &      r/   explain_querySQLCompiler.explain_query  s     d&&() **))00)0W]]_5N4::TWC!%--((#GA$4Q$7#GHHK	   $Hs   BCC.C)rM   rK   rg   r6   rH   rt   rp   rL   rq   rF   rI   rJ   rG   rm   )T)F)TF)NNN)Nr   N)NNr  NN),r9   r:   r;   r<   r#   re	MULTILINEDOTALLr   r*   rT   rh   rx   ru   r   re   r   rl   rr   r   r   r2  r&  r\  r7   r   rk  r   r  rl  r   r}  r:  rJ  rP  rU  r   r]  r`  r   rZ  rx  r=   r>   rA   s   @r/   rC   rC   (   s     % 
ryy N
#$
*0 eN@h,TM^;z,3j#4^@a9F1f4?
BL Dg#RhT,	S
 *..  uAXEN   r1   rC   c                   P   a  ] tR tRt o RtR
tR tR tR tR t	R t
RR ltR	tV tR# )SQLInsertCompileri  Nc                    Vf   T. rTMD\        VR4      '       d   V P                  V4      w  rEMVe   V! W0V P                  4      V.rTMRV.rTV P                  P                  P	                  WE4      pWE3# )aD  
Take a field and a value intended to be saved on that field, and
return placeholder SQL and accompanying params. Check for raw values,
expressions, and fields with get_placeholder() defined in that order.

When field is None, consider the value raw and use it as the
placeholder, with no corresponding parameters returned.
r7   %s)r~   r   r6   r  modify_insert_params)r+   r   get_placeholderro  r   r   s   &&&&  r/   field_as_sqlSQLInsertCompiler.field_as_sql  sz     =rS(##,,s+KC( *#T__Eu  $$99#F{r1   c                   \        VR4      '       d   VP                  V P                  RRR7      pVP                  '       d   \	        RV: RV: R24      hVP
                  '       d   \        RVP                  : R	V: R
24      hVP                  '       d   \        RVP                  : R	V: R
24      hVP                  W P                  R7      # )z
Prepare a value to be used in a query by resolving it if it is an
expression and otherwise calling the field's get_db_prep_save().
r   FTr   for_savezFailed to insert expression "z" on z<. F() expressions can only be used to update, not to insert.3Aggregate functions are not allowed in this query (=).2Window expressions are not allowed in this query (r6   )r~   r   rF   contains_column_references
ValueErrorcontains_aggregater   r   contains_over_clauseget_db_prep_saver6   )r+   r   rH  s   &&&r/   prepare_valueSQLInsertCompiler.prepare_value  s    
 5.//,,

 - E /// DI5R  ''' "'**e5  ))) zz5*  %%e%HHr1   c                    V P                   P                  '       d   \        W!P                  4      # VP	                  VRR7      # )z
Get the given field's value off the given obj. pre_save() is used for
things like auto_now on DateTimeField. Skip it if this is a raw query.
T)r   )rF   rawr   r  pre_save)r+   r   r  s   &&&r/   pre_save_valSQLInsertCompiler.pre_save_val  s3    
 ::>>>3..~~ct~,,r1   c                "  a aa V'       g   . . 3# S Uu. uF  p\        VRR4      NK  	  upoVVV 3R lV 4       pR V 4       p\        V!  w  rgV UU	U
u. uF  q U	U
u. uF  q F  qNK  	  K  	  up
p	NK  	  pp	pp
Wg3# u upi u up
p	i u up
p	pi )a  
Take a sequence of N fields and a sequence of M rows of values, and
generate placeholder SQL and parameters for each field and value.
Return a pair containing:
 * a sequence of M rows of N SQL placeholder strings, and
 * a sequence of M rows of corresponding parameter values.

Each placeholder string may contain any number of '%s' interpolation
strings, and each parameter row will contain exactly as many params
as the total number of '%s's in the corresponding placeholder row.
r  Nc              3   R   <"   T F  pV3R  l\        SSV4       4       x  K  	  R# 5i)c              3   N   <"   T F  w  rpSP                  WV4      x  K  	  R # 5ir'   )r  )r[   r   r  rH  r+   s   &   r/   r]   >SQLInsertCompiler.assemble_as_sql.<locals>.<genexpr>.<genexpr>  s-      5W1EE !!%%@@5Wr"  Nr)  )r[   rF  r  get_placeholdersr+   s   & r/   r]   4SQLInsertCompiler.assemble_as_sql.<locals>.<genexpr>  s4      !

 "	58AQSV5W  "s   $'c              3   4   "   T F  p\        V!  x  K  	  R # 5ir'   r  )r[   rF  s   & r/   r]   r    s     "N8M398Mr  )r   r)  )r+   r  
value_rowsr   rows_of_fields_as_sqlsql_and_param_pair_rowsplaceholder_rows
param_rowsrF  psr  r  s   ff&        @r/   assemble_as_sql!SQLInsertCompiler.assemble_as_sql  s     r6M RXXQWGE+<dCQWX!

 "!
 #O8M"N (+,C'D$ @JJz333R1qq33z
J++) Y$ 4Js   A?	B
B0B
B
c                  aa V P                   P                  P                  oV P                  P	                  4       pV P                   P                  P                  V P                  P                  R 7      pV: RS! VP                  4      : 2.p\        V P                  P                  4      ;p'       Ed   ^ RI
Ho V P                   P                  P                  p. p\        V4       EFP  p\        V P                  V4      p\        V P                   V4      p	V P                  P"                   U
u. uF  q! V	! V
4      4      NK  	  pp
VP%                  4       '       g   VP'                  V4       K  \)        V4      ^8  dT   \*        ;QJ d    V3R lV 4       F  '       d   K   RM	  RM! V3R lV 4       4      '       d   VP-                  V4       K  V'       d   VP'                  V4       EK  V! VP.                  4      pV Uu. uF  p\1        VS4      '       d   TMTNK  	  ppVP'                  V4       EKS  	  \        \3        V!  4      pVP'                  RRP5                  V3R lV 4       4      ,          4       M|V P                  P"                   Uu. uF'  qP                   P                  P7                  4       .NK)  	  ppR	.pVP'                  RS! VP8                  P:                  4      ,          4       V P<                  '       * ;'       d!    V P                   P                  P>                  pV PA                  WN4      w  ppV P                   P                  PC                  VV P                  P                  R
 V P                  PD                   4       R V P                  PF                   4       4      pV P<                  '       Edl   V P                   P                  PH                  '       EdE   V P                   P                  PJ                  '       d9   VP'                  V P                   P                  PM                  VV4      4       TpM8VP'                  RRP5                  V^ ,          4      ,          4       V^ ,          .pV'       d   VP'                  V4       V P                   P                  PO                  V P<                  4      w  pV n(        V'       d&   VP'                  V4       VV PP                  .,          pRP5                  V4      \S        \T        PV                  ! V4      4      3.# V'       d   VP'                  V P                   P                  PM                  VV4      4       V'       d   VP'                  V4       RP5                  V4      \R        ;QJ d    . R V 4       F  NK  	  53.# ! R V 4       4      3.# V'       d   VP'                  V4       \3        VV4       UUu. uF3  w  ppRP5                  . VORRP5                  V4      ,          N4      V3NK5  	  upp# u up
i u upi u upi u uppi ))on_conflictrh  )DatabaseDefaultc              3   <   <"   T F  p\        VS4      x  K  	  R # 5ir'   )r   )r[   rH  r  s   & r/   r]   +SQLInsertCompiler.as_sql.<locals>.<genexpr>   s      +DP5Juo66Ls   FTz(%s)rM  c              3   H   <"   T F  pS! VP                   4      x  K  	  R # 5ir'   r   )r[   r  qns   & r/   r]   r  9  s     ,J6aR\\6   "Nc              3   8   "   T F  qP                   x  K  	  R # 5ir'   r  r  s   & r/   r]   r  R       87!XX7   c              3   8   "   T F  qP                   x  K  	  R # 5ir'   r  r  s   & r/   r]   r  S  r  r  zVALUES (%s)c              3   4   "   T F  q F  q"x  K  	  K  	  R # 5ir'   r3   )r[   r  r  s   &  r/   r]   r  q  s     ,P2RQRQr  ),r6   r  r  rF   r   insert_statementr  db_tabler   r  django.db.models.expressionsr  r   'supports_default_keyword_in_bulk_insertr   r  r  objshas_db_defaultr   rf   rb   remove
db_defaultr   r)  r*  pk_default_valuer  r   returning_fieldshas_bulk_insertr  on_conflict_suffix_sqlupdate_fieldsunique_fieldscan_return_columns_from_insert can_return_rows_from_bulk_insertbulk_insert_sqlreturning_columnsreturning_paramsr  r   r[  )r+   r  r  r   r  r  
value_colsr   field_preparefield_pre_saver  field_valuesprepared_db_defaultrH  r  r   can_bulkr  r  r  r   r_sqlr  valsr  r  s   &                       @@r/   r7   SQLInsertCompiler.as_sql   s    __  ++zz""$??..??

.. @ 
 .r$--/@AB$**++,,6,D ((PP 4 Jf '(:(:E B!():):E!BBF**// BQ3M."56/    ++--%%l3 v;?ss +DP+sss +DP+ ( ( MM%(:%%l3 '4E4D4D&E# ".  ". &e_== ,"# ".    !!,/M &N c:./JMM&499,J6,J#JJK CG**//BQQ$$5578/   VFMM&2dggnn#556 %%%RR$//*B*B*R*R 	 (,';';F'O$*!%!4!4!K!KJJ""8tzz7788tzz778	"
 !!!((GGG''HHHOO''77@PQ $mdii8H8K.LLM$Q-%45 ,0??+>+>+P+P%%,(E4( e$40011XXf%uU-@-@-H'IJKKMM$//--==fFVWX%45XXf%uu,P,PuQRRu,P,P'PQRR%45  ##3Z@@GAt AFAMDIIaL$@ABDI@ C 6  ls   4X9
X>-Y<9Yc                B   V'       dM   \        V P                  P                  4      ^8w  d)   V P                  P                  P
                  '       g   Q hV P                  P                  4       pWn        . pV P                  P                  4       ;_uu_ 4       pV P                  4        F  w  rVVP                  WV4       K  	  V P                  '       g   . uuRRR4       # \        V P                  P                  4      pV P                  P                  P
                  '       d   V^8  g.   V P                  P                  P                  '       dk   V^8X  dd   V P                  P                  P                  W@P                  4      pV P                   U	u. uF  qP                  VP                   4      NK  	  pp	MV'       dz   \#        V^ ,          ;p
\$        4      '       d[   V
P                  VP                   4      .pV P                  P                  P'                  VVP                   V
P(                  4      3.pM. uuRRR4       # RRR4       V P+                  V4      pV'       d   V P-                  XV4      p\/        X4      # u up	i   + '       g   i     LK; ir  )rf   rF   r  r6   r   r  r   r  re  r7   rf  r  r  fetch_returned_rowsr  r  r  r   r   last_insert_idr   r:  rJ  r   )r+   r  r  r   re  r   r   obj_lenrE  r   returning_fieldr=  s   &&          r/   rZ  SQLInsertCompiler.execute_sqlz  s   DJJOO$)OO,,MMM	
 

 zz""$ 0__##%%#{{}s+  -(((	 &%
 $**//*G((IIIaK((GGGGWXL**>>11 CGBWBWXBWdmm4BWX!j#3A#66	' ' (//>? ++::" MM+22 A &%%B ((.
((z:DDz+ Y &%s9   <JJ"A1JAJ#J	;
JA:J	JJ	r  r  r3   r'   )r9   r:   r;   r<   r  r  r  r  r  r  r7   rZ  r=   r>   r}  s   @r/   r  r    s9     @I:-%,Nxt- -r1   r  c                   \   a  ] tR tRt o ]R 4       t]R 4       t]R 4       tR t	R t
RtV tR# )	SQLDeleteCompileri  c                   a  S P                   P                  4        \        V 3R  lS P                   P                   4       4      ^8H  # )c              3   d   <"   T F%  pSP                   P                  V,          ^ 8  x  K'  	  R# 5irX   rY   )r[   r
  r+   s   & r/   r]   1SQLDeleteCompiler.single_alias.<locals>.<genexpr>  s'     R=Q4::,,Q/!3=Qr_   )rF   rd   sumrc   rS   s   fr/   single_aliasSQLDeleteCompiler.single_alias  s6     	

$$&RTZZ=Q=QRRVWWWr1   c                (  a a \        V\        4      '       d   VP                  S8H  # \        VR 4      '       g   R# \        ;QJ d.    VV 3R lVP                  4        4       F  '       g   K   R# 	  R# ! VV 3R lVP                  4        4       4      # )r?  Fc              3   H   <"   T F  pSP                  VS4      x  K  	  R # 5ir'   )_expr_refs_base_model)r[   source_expr
base_modelclss   & r/   r]   :SQLDeleteCompiler._expr_refs_base_model.<locals>.<genexpr>  s(      
< %%k:>><r  T)r   r   rR   r~   rO  r?  )r  r   r  s   f&fr/   r  'SQLDeleteCompiler._expr_refs_base_model  s}    dE""::++t566s 
#::<
ss 	
s 	
s 
#::<
 
 	
r1   c                  a  \         ;QJ di    V 3R  l\        S P                  P                  P	                  4       S P                  P
                  P                  4       4       F  '       g   K   R# 	  R# ! V 3R  l\        S P                  P                  P	                  4       S P                  P
                  P                  4       4       4      # )c              3   p   <"   T F+  pSP                  VSP                  P                  4      x  K-  	  R # 5ir'   )r  rF   rR   )r[   r   r+   s   & r/   r]   ESQLDeleteCompiler.contains_self_reference_subquery.<locals>.<genexpr>  s6      
 &&tTZZ-=-=>>s   36TF)rO  r   rF   r   rO  rm   childrenrS   s   fr/    contains_self_reference_subquery2SQLDeleteCompiler.contains_self_reference_subquery  s    s 


&&--/1A1A1J1J
ss 	
s 	
s 


&&--/1A1A1J1J
 
 	
r1   c                    R V P                  VP                  4      ,          p V P                  VP                  4      w  r4T RT 2\        T4      3#   \         d    TR3u # i ; i)zDELETE FROM %sz WHERE r3   )r   
base_tabler   rm   r   r  )r+   rF   deleterm   r   s   &&   r/   _as_sqlSQLDeleteCompiler._as_sql  sm    !D$@$@AQAQ$RR	 LL5ME (%-77  	2:	s   A A%$A%c                6   V P                   '       dT   V P                  P                  P                  '       g   V P                  '       g   V P                  V P                  4      # V P                  P                  4       p\        Vn	        VP                  4        V P                  P                  P                  P                  pVP                  V P                  P                  4       4      .Vn        \        V P                  P                  4      pV P                  P                  P"                  '       g@   VP%                  V P                  R7      P'                  4       w  rE\)        RV,          V4      pVP+                  RV4       V P                  V4      # )N
Create the SQL for this query. Return the SQL string and list of
parameters.
r  zSELECT * FROM (%s) subquerypk__in)r  r6   r   "delete_can_self_reference_subqueryr  r  rF   r5  r   r.   clear_select_clauserR   r  r  r  rd   rJ   update_can_self_selectr#  r7   r   
add_filter)r+   innerqr  outerqr   r   s   &     r/   r7   SQLDeleteCompiler.as_sql  s%   
 OO$$GGG888<<

++!!# ""$ZZ##&&DJJ$@$@$BCDtzz''(''>>> !---IPPRKC9C?HF(F+||F##r1   r3   N)r9   r:   r;   r<   r!   r  classmethodr  r  r  r7   r=   r>   r}  s   @r/   r  r    sP     X X
 
 
 
 
8$ $r1   r  c                   R   a a ] tR tRt oRtRtR tV 3R ltR tV 3R lt	Rt
VtV ;t# )	SQLUpdateCompileri  Nc           
     l   V P                  4        V P                  P                  '       g   R# V P                  p. . r2V P                  P                   EF6  w  rEp\	        VR4      '       d   VP                  V P                  RRR7      pVP                  '       d   \        RVP                  : RV: R24      hVP                  '       d   \        RVP                  : RV: R24      h\        V\        4      '       d   \        R	VP                  ,          4      hMb\	        VR
4      '       dQ   VP                  '       d   VP                  V4      pM,\        RV: RV: RVP                  P                   : R24      hVP#                  W`P$                  R7      p\	        VR4      '       d   VP'                  W`V P$                  4      pMRpVP(                  p\	        VR4      '       dL   V P+                  V4      w  rVP-                  V! V4      : RWy,          : 24       VP/                  V
4       EK  Ve3   VP-                  V! V4      : RV: 24       VP-                  V4       EK  VP-                  RV! V4      ,          4       EK9  	  V P                  P0                  pRV! V4      ,          RP3                  V4      .p V P+                  V P                  P4                  4      w  rVP-                  RV,          4       V P8                  '       dk   V P$                  P:                  P=                  V P8                  4      w  qn        V'       d-   VP-                  V4       V
P/                  V P>                  4       RP3                  V4      \A        W:,           4      3#   \6         d    . p
 Li ; i)r  r   FTr  r  r  r  r  zNComposite primary keys expressions are not allowed in this query (%s=F('pk')).prepare_database_savezTried to update field z with a model instance, z. Use a value compatible with r   r  r  r  r7   z = z	%s = NULLzUPDATE %s SETrM  re  rh  )r_  r3   )!rx   rF   rO  r   r~   r   r  r   r   r  r   r   r  r  	TypeErrorr.   r9   r  r6   r  r   r   r   r   r  r*  rm   r   r  r  r  r  r  )r+   r  rO  update_paramsr   rR   ro  placeholderr   r   r   r   r   rm   r  s   &              r/   r7   SQLUpdateCompiler.as_sql  s   
 	zz   M)) "B!%!2!2E#s011,,JJED -  )))$&+jj#7  +++$&+jj#7  c8,,$68=

C  -
 566%%%33E:C# !#u'?'?A 
 (((IC u/00#33CtO"<<DsH%%"ll3/2d8[5FGH$$V,2d8[AB$$S)kBtH45[ "3\ 

%%bi'IIf
	. LL)9)9:ME MM*u,-    ,0??+>+>+P+P%%,(E( e$d334xx}'=!>>>  	F	s   'N# #N32N3c                  < \         SV `  V4      pVRJ pT;'       g    ^ pV P                  P                  4        FE  pVP	                  V P
                  4      P                  V4      pV'       g   K7  V'       g   KA  TpRpKG  	  V# )z
Execute the specified update. Return the number of rows affected by
the primary update query. The "primary update query" is the first
non-empty query that is executed. Row counts for any subsequent,
related queries are not available.
NF)r)   rZ  rF   get_related_updatesr#  rG   )r+   rn  	row_countis_emptyrF   aux_row_countr.   s   &&    r/   rZ  SQLUpdateCompiler.execute_sql8  s|     G'4	$NN	ZZ335E!..tzz:FF{SMxMM *	  6 r1   c                .   V P                   P                  4       '       d   \        R4      hV'       d'   V P                  P                  P
                  '       g    V P                  \        4      pR.V,          # Wn        V P                  P                  4       ;_uu_ 4       pV P                  4       w  rEVP                  WE4       V P                  P                  P                  W0P                  4      pRRR4       V P                   P                  4       pV P                   Uu. uF  qP!                  VP"                  4      NK  	  p	pV P%                  V	4      p
V
'       d   V P'                  XV
4      p\)        X4      #   + '       g   i     L; iu upi )z
Execute the specified update and return rows of the returned columns
associated with the specified returning_field if the backend supports
it.
zEUpdate returning is not implemented for queries with related updates.Nr3   )rF   r
  r   r6   r   can_return_rows_from_updaterZ  r   r  re  r7   rf  r  r  r  r   r  r  r:  rJ  r   )r+   r  r  re  r   r   rE  r  r   r   r=  s   &&         r/   execute_returning_sql'SQLUpdateCompiler.execute_returning_sqlM  s3    ::))++%W 
 !??++GGG((3I4)## 0__##%%++-KCNN3'??&&::--D & zz""$:>:O:OP:Odmm,:OP((.
((z:DDz &% Qs   !AE?$#F?F	c                  <a V P                   P                  P                  4       pV P                   P                  4        V P                   P	                  4       pV P                   P
                  '       g
   V^8X  d   R# V P                   P                  \        R7      pRVn        VP                  RR7       / Vn
        . Vn        VP                  4       pVP                  P                  .p. pV P                   P
                   F  p\        ;QJ d+    R VP!                  V4       4       F  '       d   K   RM 	  RM! R VP!                  V4       4       4      '       d   VP#                  V^ 34       Kp  VP#                  V\%        V4      34       VP#                  VP&                  P                  P                  4       K  	  VP)                  V4       \*        SV `Y  4        VP.                  pV^8  ;'       d&    V P0                  P2                  P4                  '       * p	V P                   P7                  4        V P                   P
                  '       g	   V	'       d   . p
\8        P:                  ! \<        4      pVP?                  V P@                  4      PC                  \D        4       Fb  pV Uu. uF  q'       d   TMV^ ,          NK  	  ppV
PG                  V4       V F'  w  poW,          PG                  V3R lV 4       4       K)  	  Kd  	  V P                   PI                  RV
4       WP                   n%        MV P                   PI                  RV4       V P                   PM                  V4       R# u upi )	a  
If the update depends on results from other tables, munge the "where"
conditions to match the format required for (portable) SQL updates.

If multiple updates are required, pull out the id values to update at
this point so that they don't change as a result of the progressive
updates.
N)klassFT)forcec              3   L   "   T F  qP                   P                  x  K  	  R # 5ir'   )
join_fieldr   )r[   r  s   & r/   r]   2SQLUpdateCompiler.pre_sql_setup.<locals>.<genexpr>  s      8X++8Xs   "$c              3   4   <"   T F  qS,          x  K  	  R # 5ir'   r3   )r[   r  r   s   & r/   r]   r    s     .FAxxs   r  )'rF   rZ   r   rd   count_active_tablesrelated_updatesr   r   r   clear_orderingr   rJ   r   r  r   rb   get_path_to_parentr   rf   r  
add_fieldsr)   rx   is_composite_pkr6   r   r  clear_wherer.  defaultdictr   r#  rG   rZ  r   r   r  related_idsr  )r+   r  countrF   r   r  related_ids_indexrelatedr  must_pre_selectidentsr"  rE  rF  r   parentr   r.   s   &               @r/   rx   SQLUpdateCompiler.pre_sql_setupm  s     ::4499;

$$&

..0zz)))eqj

  u -$4(~~'',,zz11Gs 8<8O8OPW8Xsss 8<8O8OPW8X  
 "(('16
 "(('3v;)?@gmm..334 2 	 ..AIMMdoo66MMM 	 	

 ::%%% F%11$7K**4::6BB5IEIJTcos3q69TJc"%6MFE'...F.FF &7 J
 JJ!!(F3%0JJ" JJ!!(E2

""#34 Ks   1M6r  r3   )r9   r:   r;   r<   r  r  r7   rZ  r  rx   r=   r>   r?   r@   s   @@r/   r  r    s-     L?\*@?5 ?5r1   r  c                   &   a  ] tR tRt o R tRtV tR# )SQLAggregateCompileri  c                6   . . r!V P                   P                  P                  4        FL  pV P                  V4      w  rEVP	                  WV4      w  rEVP                  V4       VP                  V4       KN  	  \        V P                   P                  4      V n        RP                  V4      p\        V4      pV P                   P                  P                  V P                  V P                  R7      P                  RR7      w  rgRV: RV: R2pW',          pW3# )r  rM  )rH   Tr`   rf  rg  ri  )rF   r   rO  r   r   r   r   rf   rg   r*  r  rB  r#  rG   rH   r7   )r+   r   r   
annotationann_sql
ann_paramsinner_query_sqlinner_query_paramss   &       r/   r7   SQLAggregateCompiler.as_sql  s    
 "V**66==?J"&,,z":G",":":4*"UGJJwMM*%	 @
 TZZ99:iinv.2jj.D.D.Q.QJJ(( /R /
 &$&
' 	,+ 14_E${r1   )rg   N)r9   r:   r;   r<   r7   r=   r>   r}  s   @r/   r+  r+    s      r1   r+  c              #     a a"    \        V V3R lV4       F  pVf   TMV Uu. uF  qURV NK	  	  upx  K!  	  S P                  4        R# u upi   S P                  4        i ; i5i)zO
Yield blocks of rows from a cursor and ensure the cursor is closed when
done.
c                  &   < S P                  S4      # r'   )	fetchmany)re  itersizes   r/   r  cursor_iter.<locals>.<lambda>  s    &"2"28"<r1   N)rc  rh  )re  sentinelrg   r6  rE  r  s   f&&f  r/   rk  rk    sY     
<xHD#+$1NAJY-1NN I 	 2Os+   A&A A	A A&A A##A&);r.  rr  rz  	functoolsr   	itertoolsr   django.core.exceptionsr   r   r   	django.dbr   r	   django.db.models.constantsr
   r  r   r   r   r   r   r   django.db.models.fieldsr   r   django.db.models.functionsr   r   django.db.models.lookupsr   django.db.models.query_utilsr   django.db.models.sql.constantsr   r   r   r   r   r   r   django.db.models.sql.queryr   r   django.db.transactionr    django.utils.functionalr!   django.utils.hashabler"   django.utils.regex_helperr#   r%   rC   r  r  r  r+  rk  r3   r1   r/   <module>rH     s      	   L L 6 1 Q Q 8 3 + ?   < < 3 / 6%# %d  d N3X Xv9$ 9$xF5 F5R; 2	r1   