
    +hF                     @   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 d	d
lm
Z
 d	dlmZ  ej                  dd      Zd Z	 d$dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z	 d%dZ	 d%dZ G d dej8                        Zd Zd Zd  Z d! Z!d" Z"d# Z#y)&ziFunctions used by compiler.py to determine the parameters rendered
within INSERT and UPDATE statements.

    N   )	coercions)dml)elements)roles)Select   )exc)utilREQUIREDa8  
Placeholder for the value within a :class:`.BindParameter`
which is required to be present when the statement is passed
to :meth:`_engine.Connection.execute`.

This symbol is typically used when a :func:`_expression.insert`
or :func:`_expression.update` statement is compiled without parameter
values present.

c                    g | _         g | _        g | _        g | _        t	        | ||      x\  }}}|| _        | j
                  Y|j                  rM|j                  j                  D cg c]-  }|| j                  j                  |      t        | |dd      f/ c}S |j                  r?|j                  d   }t        |j                               }	|D 
ch c]
  }
 |
       c}
n|j                   r/|j"                  }|j                   }	|D 
ch c]
  }
 |
       c}
nN|j"                  r<|j"                  }t        |j                               }	|D 
ch c]
  }
 |
       c}
ndx}	x}| j
                  i }n@|	r t%        fd| j
                  D              }nt%        fd| j
                  D              }g }|	t'        | |||	||       i }|j(                  r|j*                  rt-        | |||	|||||	       |j.                  r!|j0                  rt3        | ||||||||
       nt5        | ||||||||
       |rd|	rbt7        |      j9                  fd|	D              j;                  |      }|r.t=        j>                  dd	jA                  d
 |D              z        |j                  rtC        | ||||      }|S |so| jD                  rc| jF                  jH                  rM|j                  j                  d   | j                  j                  |j                  j                  d         dfg}|S c c}w c c}
w c c}
w c c}
w )aQ  create a set of tuples representing column/string pairs for use
    in an INSERT or UPDATE statement.

    Also generates the Compiled object's postfetch, prefetch, and
    returning column collections, used for default handling and ultimately
    populating the CursorResult's prefetch_cols() and postfetch_cols()
    collections.

    NT)requiredr   c              3   B   K   | ]  }|vr |      t         f  y wNr   ).0key_column_as_keyspd_str_keys     F/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/sql/crud.py	<genexpr>z#_get_crud_params.<locals>.<genexpr>a   s+      
+% C (+
s   c              3   :   K   | ]  } |      t         f  y wr   r   )r   r   r   s     r   r   z#_get_crud_params.<locals>.<genexpr>g   s       
03^C (+
s   c              3   4   K   | ]  \  }} |        y wr    )r   kvr   s      r   r   z#_get_crud_params.<locals>.<genexpr>   s     N1.+Ns   zUnconsumed column names: %s, c              3   "   K   | ]  }| 	 y wr   r   )r   cs     r   r   z#_get_crud_params.<locals>.<genexpr>   s     8QQ[8s   DEFAULT)%	postfetchinsert_prefetchupdate_prefetch	returning_key_getters_for_crud_columncolumn_keys_no_parameterstablecolumnspreparerformat_column_create_bind_param_has_multi_parameters_multi_parameterslistitems_ordered_values_dict_parametersdict!_get_stmt_parameter_tuples_paramsisupdateis_multitable_get_update_multitable_paramsisinsert_select_names_scan_insert_from_select_cols
_scan_colssetintersection
differencer
   CompileErrorjoin_extend_values_for_multiparamsfor_executemanydialectsupports_default_metavalue)compilerstmtcompile_statekw_getattr_col_key_col_bind_namegettersr   spdstmt_parameter_tuplesr   
parametersvaluescheck_columnscheckr   r   s                  @@r   _get_crud_paramsrR   &   s    H!H!HH /x}M	N ,3H) #(D(D ZZ''
 	 !!//2"8QtD
 	
 **--a0 $SYY[ 169:s~c*:		&	&,, - = =69:s~c*:		'	',, $SYY[ 169:s~c*:4888k #
	 
++
 

  
7?7K7K
 


 F()!	
 M -"="=%!
	
 $"4"4%	
 		
 +
O\N8MNNZ& 	
 ""-998%88: 
 **/
2 M! $$77 

""1%!!//

0B0B10EF
 MO
 ; ; ;s   )2L;M MM
c                     ||j                   }t        j                  |||j                  |      }d|_        |r |j
                  | fi |}|S )N)type_r   T)r   r   BindParametertype_is_crud_compiler_dispatch)rE   colvalueprocessr   namerH   	bindparams           r   r,   r,      sY     |ww&&e388hI I0I00@R@	    c                 ,   d|v }|sK|j                   r?t        |j                  t        j                        r|| j
                  d|j                  f<   |j                  j                  r|j                  |j                        } |j                  | fi |S )Nvisiting_cter]   )
unique
isinstancer   r   _truncated_labeltruncated_namesrV   _isnull_with_binary_element_typerX   )rE   rY   rZ   r\   rH   is_ctes         r   _handle_values_anonymous_paramrh      s    ( r!F LLuyy(";";<=A  +uyy!9:zz //9#5##H333r^   c                    |j                   rd|j                  rXt        |j                        t        j                  t
        j                  t        j                        fd}fd}fd}nIt        j                  t
        j                  t        j                        }t        j                  d      x}}|||fS )Nc                 |     |       }t        | d      r&| j                  v r| j                  j                  |fS |S )Nr(   )hasattrr(   r\   )r   str_key_et
c_key_roles     r   r   z4_key_getters_for_crud_column.<locals>._column_as_key  s9     oGsG$c)9		00r^   c                 |    | j                   v r"| j                   j                  | j                  fS | j                  S r   r(   r\   r   rY   rm   s    r   rI   z6_key_getters_for_crud_column.<locals>._getattr_col_key  s/    yyC		00wwr^   c                     | j                   v r%| j                   j                  d| j                  S | j                  S )N_rp   rq   s    r   rJ   z4_key_getters_for_crud_column.<locals>._col_bind_name  s/    yyC"%))..#''::wwr^   r   )r5   _extra_fromsr<   	functoolspartialr   expect_as_keyr   DMLColumnRoleoperator
attrgetter)rE   rF   rG   r   rI   rJ   rm   rn   s         @@r   r%   r%     s    -"<"< -,,-&&##U%8%8

			 #**##U%8%8
 -5,?,?,FF>+^;;r^   c
           	         t        | ||      \  }
}}}|j                  D cg c]!  }|j                  j                   ||         # }}| j                  d   d   |u sJ |j
                  | j                  d   d<   g }|j                  rIt        |      }|j                  j                  D ]%  }||vs|j                  s|j                  |       ' |D ]`  } ||      }||v rC||vr?|j                  |       |j                  || j                  j                  |      d f       Rt        | ||||	       b |r|j                  |       | j                  d   d   }t!        |t"              s/t%        j&                  ddj)                  d |D              d      |j+                         }t-        |j.                        |D cg c]  \  }}}|
 c}}}z   |_        || j                  d   d<   y y c c}w c c}}}w )N
selectableinsert_from_selectz_Can't extend statement for INSERT..FROM SELECT to include additional default-holding column(s) r   c              3   :   K   | ]  \  }}}t        |        y wr   )repr)r   rs   r   s      r   r   z0_scan_insert_from_select_cols.<locals>.<genexpr>a  s     H91c1T#YHs   z~.  Convert the selectable to a subquery() first, or pass include_defaults=False to Insert.from_select() to skip these columns.)_get_returning_modifiersr9   r(   r   stackselect#include_insert_from_select_defaultsr<   r)   defaultappendpopr*   r+   &_append_param_insert_select_hasdefaultextendrb   r   r
   r?   r@   	_generater/   _raw_columns)rE   rF   rG   rN   rI   r   rJ   rP   rO   rH   need_pksimplicit_returningimplicit_return_defaultspostfetch_lastrowidr\   colsadd_select_colscol_setrY   r   col_keyins_from_selectcol_exprexprs                           r   r:   r:   ,  s   $ 	!4?  <@;M;MN4DJJLL-.NDN>>"l+t333/3{{HNN2+,O//d)::%% 	!C'!ckkC 	!  "1%j WM%ANN7#MM1h//==a@$GH2$?B o&"..,-AB/62"" 99HHHK  *335'+O,H,H'I,;M
 M
(S(DDM
 (
$ 4Cr/0# / OJM
s   &G2G7
c
                    t        | ||      \  }
}}}|j                  r|j                  D cg c]
  } ||       }}t        |      }|D cg c]M  }t        |t        j
                        r1||j                  j                  v r|j                  j                  |   O c}|j                  j                  D cg c]  }|j                  |vs| c}z   }n|j                  j                  }|D ]^  } ||      }||v r||vrt        | ||||||||||	       *|j                  r	|j                  r$|
r"|rt        | ||||	       Wt        | ||||	       g|j                  t!        | |||||	       |j"                  K|r ||v r| j$                  j'                  |       |j                  r| j(                  j'                  |       |r ||v r| j$                  j'                  |       |j                  s||j                  j*                  us%|j,                  r3t/        |       @|j0                  sNt3        | ||||||	       a y c c}w c c}w c c}w r   )r   _parameter_orderingr<   rb   r   string_typesr(   r   r   r)   _append_param_parameterr8   primary_key!_append_param_insert_pk_returning$_append_param_insert_pk_no_returningr   _append_param_insert_hasdefaultserver_defaultr$   r   r!   _autoincrement_columnnullable"_warn_pk_with_no_anticipated_valuer5   _append_param_update)rE   rF   rG   rN   rI   r   rJ   rP   rO   rH   r   r   r   r   r   parameter_orderingordered_keysr   r   r   s                       r   r;   r;   k  si   " 	!4?  ((+8+L+L
$'N3
 
 -. *
#t001cTZZ\\6I JJLL
 

B1\(AQB	C zz!! T #1%j WM%A $"( ## }}
 &
 6 $62 9 $62 & 0dA'? !!- ,5M0M&&--a0&&--a0)a3K.K""))!,TZZ===

215## !(YT

 Cs   IAI9IIc                    |j                  |      }| j                  j                  ||j                        }t	        j
                  |      r6t        | ||f|t        u |j                  s ||      n
d ||      z  d|
}n*|j                  r.t        | ||fd|j                  s ||      n
d ||      z  i|
}n | j                  |j                         fi |
}|j                  r>|r ||v r| j                  j                  |       n| j                   j                  |       n|j"                  r<|r| j                  j                  |       n[| j$                  j&                  rEd| _        n=|r ||v r| j                  j                  |       n| j                   j                  |       |	j                  |||f       y )N	use_tablez%s_m0r   r\   r\   T)r   r*   r+   include_table_with_column_exprsr   _is_literalr,   r   r-   _is_bind_parameterrh   r[   
self_groupr5   r$   r   r!   r   rC   r   )rE   rF   rG   r   r   rN   rJ   r   r   rO   rH   rZ   	col_values                r   r   r     s    NN7#E!!//	]BB 0 I U#"	
 h& 66  ">!,,	
 	
 
	!	!.

 !66  ">!,,
 
 !  !1!1!3:r:!!'A1I,I""))!, ""))!,}}%&&--a0%%9937H0)a3K.K""))!, ""))!,
MM1i'(r^   c           	         |j                   |j                   j                  r| j                  j                  rt|j                   j                  r| j                  j
                  sH|j                  || j                  j                  |       | j                  |j                   fi |f       | j                  j                  |       y|j                   j                  r||j                  || j                  j                  |       | j                  |j                   j                  j                         fi |f       | j                  j                  |       y|j                  || j                  j                  |      t        | |fi |f       y||j                  j                   u s|j"                  | j                  j                  |       y|j$                  st'        |       yy)zCreate a primary key expression in the INSERT statement where
    we want to populate result.inserted_primary_key and RETURNING
    is available.

    N)r   is_sequencerC   supports_sequencesoptionalsequences_optionalr   r*   r+   r[   r$   is_clause_elementargr   "_create_insert_prefetch_bind_paramr(   r   r   r   r   rE   rF   r   rO   rH   s        r   r   r   ,  s    	yy99  22II&&'':: ))77:(((9b9 %%a(YY((MM%%33A6$H$$QYY]]%=%=%?F2F %%a(
 MM%%33A66xIbI 
djj..	.!2B2B2N!!!$ZZ 	+1- r^   c           	         |j                   X|j                   j                  r| j                  j                  r,|j                   j                  r| j                  j
                  r||j                  j                  u r| j                  j                  s|j                   ,|j                   j                  r| j                  j                  s"|j                   O| j                  j                  r9|j                  || j                  j                  |      t        | |fi |f       y|j                   <|j                  0|j                  s$||j                  j                  urt!        |       y| j                  j                  rd| _        yy)ao  Create a primary key expression in the INSERT statement where
    we want to populate result.inserted_primary_key and we cannot use
    RETURNING.

    Depending on the kind of default here we may create a bound parameter
    in the INSERT statement and pre-execute a default generation function,
    or we may use cursor.lastrowid if supported by the dialect.


    NT)r   r   rC   r   r   r   r(   r   r   "preexecute_autoincrement_sequencesr   r*   r+   r   r   r   r   r   s        r   r   r   \  sB    	
		 		%%  33		**#++>> 	
TZZ---   44 II)		-- ((;; II% ((KK 	!!//228QE"E	
 	
		$

TZZ555 	+1-				-	-
 (,$ 
.r^   c           	         |j                   j                  r| j                  j                  r|j                   j                  r| j                  j
                  s|j                  || j                  j                  |       | j                  |j                   fi |f       |r ||v r| j                  j                  |       y |j                  s| j                  j                  |       y y y y |j                   j                  r|j                  || j                  j                  |       | j                  |j                   j                  j                         fi |f       |r ||v r| j                  j                  |       y |j                  s| j                  j                  |       y y |j                  || j                  j                  |      t!        | |fi |f       y r   )r   r   rC   r   r   r   r   r*   r+   r[   r$   r   r!   r   r   r   r   )rE   rF   r   r   rO   rH   s         r   r   r     s    	yy..		""(*:*:*M*MMM%%33A6$H$$QYY5"5 (A1I,I""))!,]]""))!, # +N / 
	$	$!!//2   !9!9!;BrB	
 $-E(E%%a(%%a(  	!!//228QE"E	
r^   c           	         |j                   j                  r| j                  j                  rs|j                   j                  r| j                  j
                  sF|j                  || j                  j                  |      |j                   j                         f       y y y |j                   j                  rP|j                  || j                  j                  |      |j                   j                  j                         f       y |j                  || j                  j                  |      t        | |fddi|f       y )Nr[   F)r   r   rC   r   r   r   r   r*   r+   
next_valuer   r   r   r   r   s        r   r   r     s   yy..		""(*:*:*M*MMMH%%33A6		8L8L8NO +N / 
	$	$!!//2AIIMM4L4L4NO	
 	!!//22a).24	
r^   c           	      P   |j                   }|j                  |j                  j                  s|j                  j                  r|j	                  || j
                  j                  ||       | j                  |j                  j                  j                         fi |f       |r ||v r| j                  j	                  |       y | j                  j	                  |       y |j	                  || j
                  j                  ||      t        | |fi |f       y |j                  >|r ||v r| j                  j	                  |       y | j                  j	                  |       y |r:|j                  s|j                  s!||v r| j                  j	                  |       y y y y )Nr   )r   onupdater   r   r   r*   r+   r[   r   r   r$   r!   "_create_update_prefetch_bind_paramserver_onupdate_return_defaults_columns_return_defaults)rE   rG   rF   r   r   rO   rH   include_tables           r   r   r     s    "AAMzzajj&<&<::''MM%%33"/ 4  %H$$QZZ^^%>%>%@GBG	 (A1I,I""))!,""))!,MM%%33"/ 4  7xIbI	 
			&#-E(E%%a(%%a( **$2G2G))!!!$ * 3H 	!r^   c                 ^    t        | |d f||d|}| j                  j                  |       |S N)r[   r\   )r,   r"   r   rE   r   r[   r\   rH   params         r   r   r     sB     !T#*9;E ##A&Lr^   c                 ^    t        | |d f||d|}| j                  j                  |       |S r   )r,   r#   r   r   s         r   r   r   #  sB     !T#*9;E ##A&Lr^   c                   (    e Zd ZdZd Zd Zd Zd Zy)_multiparam_columnTc                     || _         d|j                  |dz   fz  | _        || _        |j                  | _        |j                  | _        y )N%s_m%dr   )indexr   originalr   rV   )selfr   r   s      r   __init__z_multiparam_column.__init__0  sA    
x||UQY77 ''MM	r^   c                     t               r   NotImplementedErrorr   otherrH   s      r   comparez_multiparam_column.compare7      !##r^   c                     t               r   r   r   s      r   _copy_internalsz"_multiparam_column._copy_internals:  r   r^   c                     t        |t              xr4 |j                  | j                  k(  xr |j                  | j                  k(  S r   )rb   r   r   r   )r   r   s     r   __eq__z_multiparam_column.__eq__=  s<    u01 0		TXX%0$--/	
r^   N)__name__
__module____qualname___is_multiparam_columnr   r   r   r   r   r^   r   r   r   -  s     "$$
r^   r   c                    |j                   st        j                  d|z        |j                   j                  r5 | j                  |j                   j
                  j                         fi |S |j                   j                  r | j                  |j                   fi |S t        ||      }t        |t        j                        rt        | |fi |S t        | |fi |S )NzINSERT value for column %s is explicitly rendered as a boundparameter in the VALUES clause; a Python-side value or SQL expression is required)r   r
   r?   r   r[   r   r   r   r   rb   r   Insertr   r   )rE   rF   r   r   rH   rY   s         r    _process_multiparam_default_bindr   E  s    99@BCD
 	

 
	$	$x		 8 8 :AbAA	
		  x		0R00 E*dCJJ'5hJrJJ5hJrJJr^   c	                    t        d |D              }	|j                  }
t               }|j                  D ]  }|j                  D ]  }||	v s|j                  |       || ||      <   |	|   }| j                  ||
      }t        j                  |      rt        | ||f|t        u  ||      d|}n_|j                  rt        | ||fd ||      i|}n<| j                  j                  |        | j                  |j                         fi |}|j                  |||f         |D ](  }|j                  D ]  }||	v r	|j                   |j                   j"                  s|j                   j$                  rt|j                  || j                  ||
       | j                  |j                   j&                  j                         fi |f       | j                  j                  |       |j                  || j                  ||
      t)        | |fd ||      i|f       |j*                  | j                  j                  |        + y )Nc              3   n   K   | ]-  \  }}t        j                  t        j                  |      |f / y wr   )r   expectr   rx   )r   r   r   s      r   r   z0_get_update_multitable_params.<locals>.<genexpr>k  s4      Au 
		%--q	159s   35r   r   r\   )r3   r   r<   rt   r   addr[   r   r   r,   r   r   rh   r!   r   r   r   r   r   r   r   r   )rE   rF   rG   rM   rP   rJ   rI   rO   rH   normalized_paramsr   affected_tablestr   rZ   r   s                   r   r7   r7   `  s     - 
 "AAMeO'' 5 	5A%%##A&56.q12)!,$,,Qm,L	((/.  "'(!2+A. E --: !U1?1BFHE &&--a0,H,,U-=-=-?F2FEq)U34/	556  - 	-A%%'

0F0F:://MM$,,Qm,L,H,, !

 9 9 ;?A &&--a0MM$,,Qm,L> (!2@2CGI "".""))!,5	--r^   c           
      *   |}|g}t        |j                  dd        D ]  \  }}g }	|j                         D 
ci c]  \  }
} ||
      | }}
}|D ]  \  }}}|j                  |v ro|j                  }
t	        j
                  ||
         r&t        | |||
   fdd|j                  |dz   fz  i|}n4 | j                  ||
   j                         fi |}nt        | ||||      }|	j                  |||f        |j                  |	        |S c c}}
w )Nr   r\   r   )	enumerater.   r0   r   r   r   r,   r[   r   r   r   )rE   rF   rG   rO   r   rH   values_0irow	extensionr   r   rY   r   r   	new_params                   r   rA   rA     sG    HXFM;;AB?@ !3	47IIK@&#q~c"A%@@&. 	9"S(Eww#~gg((S2 2 C! &!a%(88	!
 !I !1 0 0S1D1D1F M" MI<dCB	 c8Y78'	9* 	i 5!8 M3 As   Dc                    |D ]  \  }} ||      }	|	|j                  |	|       #| j                  ||j                        }
t        j                  |      r4 | j                  t        j                  d ||j                        fi |}n^|j                  r1|j                  j                  r|j                  |j                        } | j                  |j                         fi |}|j                  ||
|f        y )Nr   )rT   )
setdefaultr[   r   r   r   r   rU   rV   r   re   rf   r   r   )rE   rG   rN   rM   r   rO   rH   r   r   colkeyr   s              r   r4   r4     s     & ,1"!!&!,  ''!N!N ( H $$Q'$H$$**4!&&AEG ''AFFNN 33AFF;A$H$$Q\\^:r:MM1h*+;,r^   c                    |j                   xr` |j                   xrQ | j                   xs$ | j                  j                  xr |j
                  xr |j                   xr |j                   }|xr. | j                  j                  xr |j                  j                  }|j                   r|xr |j
                  }nK|j                  r=| j                  j                  xr$ |j                  j                  xr |j
                  }nd}|rA|j                  s t        |j                  j                        }nt        |j                        }|xr | j                  j                  }||||fS )NF)r8   _inlinerB   rC   insert_executemany_returningr   
_returningr-   r   r(   r5   r   r<   r   r   )rE   rF   rG   r   r   r   r   s          r   r   r      sj    	 
	4
	4 (((   == *))
	4 
	4 333  	 	*//	*JJ))  #5#O$:O:O 			// &

--&%% 	! $) ,,'*4::<<'8$'*4+H+H'I$"Kx'7'7'K'K 	 	 r^   c                     d| j                   j                  d| j                  d| j                   j                  d}t        | j                   j                        dkD  r|dz  }t        j                  |       y )NzColumn '.z6' is marked as a member of the primary key for table 'z', but has no Python-side or server-side default generator indicated, nor does it indicate 'autoincrement=True' or 'nullable=True', and no explicit value is passed.  Primary key columns typically may not store NULL.r   a0   Note that as of SQLAlchemy 1.1, 'autoincrement=True' must be indicated explicitly for composite (e.g. multicolumn) primary keys if AUTO_INCREMENT/SERIAL/IDENTITY behavior is expected for one of the columns in the primary key. CREATE TABLE statements are impacted by this change as well on most backends.)r(   fullnamer\   lenr   r   warn)r   msgs     r   r   r   3  sb     77QVVQWW%5%5	7  177!#	
 	IIcNr^   )TFN)TN)$__doc__ru   ry    r   r   r   r   r}   r   r
   r   symbolr   rR   r,   rh   r%   r:   r;   r   r   r   r   r   r   r   r   ColumnElementr   r   r7   rA   r4   r   r   r   r^   r   <module>r     s            4;;	eR >B#4L'<T<C~upF)R-.`I,X'
T
2*%\ %) %)
// 
0K6I-X'T',T0fr^   