
    ؄_!e                     j   d 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  ej        d	d
          Z ej        d          Z	 ej        d          Z
 ej        d          Zd Zd Z	 d&dZd Zd Zd Zd Zd Zd'dZd'dZ G d dej                  Zd Zd Zd Zd Zd  Zd! Zd" Zd# Zd$ Z d% Z!dS )(ziFunctions used by compiler.py to determine the parameters rendered
within INSERT and UPDATE statements.

    N   )dml)elements   )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.

ISINSERTISUPDATEISDELETEc                    | j         }| j        }| j        }|p|p|pt          | j                  dk    pd|v }|t
          u rd| _        d| _         n5|t          u rd| _        d| _         n|t          u r
|sd| _        n
J d            	 |t
          t          fv r&t          | |fi ||r|| _         || _        || _        S S 	 |r|| _         || _        || _        d S d S # |r|| _         || _        || _        w xY w)Nr   visiting_cteFTz(ISINSERT, ISUPDATE, or ISDELETE expected)	isinsertisupdateisdeletelenstackr
   r   r   _get_crud_params)compilerstmtlocal_stmt_typekwrestore_isinsertrestore_isupdaterestore_isdeleteshould_restores           X/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/sqlalchemy/sql/crud.py_setup_crud_paramsr   '   su   ((( 
	A-	A1A 	 x~"	 R  (""! 	H	$	$ !	H	$	$ 	% $H@@@@@1x222#Hd99b99 	1 0H 0H 0H	1 3  	1 0H 0H 0H	1 	1> 	1 0H 0H 0H0000s   C C1c                 h   	
 g  _         g  _        g  _        g  _         j        |j         fd|j        j        D             S |j        r|j        d         
n|j        
t           |          \  	}} j        i }n!t          	
fd j        D                       }g }
t           |
	||           i } j        r|j        r
rt           |
|||||            j        r|j        rt#           |||	||||	  	         nt%           |||	||||	  	         |ry
rwt'          |                              	fd
D                                           |          }|r4t-          j        dd                    d |D                       z            |j        rt3           |||          }|S )	aP  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 ResultProxy's prefetch_cols() and postfetch_cols()
    collections.

    Nc           	      :    g | ]}|t          |d d          fS )NT)required)_create_bind_param).0cr   s     r   
<listcomp>z$_get_crud_params.<locals>.<listcomp>[   s@     
 
 
 "8QtDDDE
 
 
    r   c              3   H   K   | ]}r|v |          t           fV  d S N)r	   )r#   key_column_as_keystmt_parameterss     r   	<genexpr>z#_get_crud_params.<locals>.<genexpr>s   sS       
 
"
 '*&@&@ ^C  (+&@&@&@&@
 
r&   c              3   .   K   | ]} |          V  d S r(    )r#   kr*   s     r   r,   z#_get_crud_params.<locals>.<genexpr>   s-      EE..++EEEEEEr&   zUnconsumed column names: %sz, c              3       K   | ]	}d |z  V  
dS )z%sNr.   )r#   r$   s     r   r,   z#_get_crud_params.<locals>.<genexpr>   s&      55!TAX555555r&   )	postfetchinsert_prefetchupdate_prefetch	returningcolumn_keys
parameterstablecolumns_has_multi_parameters_key_getters_for_crud_columndict_get_stmt_parameters_paramsr   _extra_froms_get_multitable_paramsr   select_names_scan_insert_from_select_cols
_scan_colssetintersection
differencer   CompileErrorjoin_extend_values_for_multiparams)r   r   r   _getattr_col_key_col_bind_namer6   valuescheck_columnscheckr*   r+   s   `        @@r   r   r   H   s    H!H!HH #(?
 
 
 
Z'
 
 
 	

 ! */!,/ 	%Xt44	
 #

 
 
 
 
 
+
 
 
 
 

 F"#j/>62	
 	
 	
 M  

T. 

? 

		
 		
 		
  
T. 
%
	
 
	
 
	
 
	
 	
	
 
	
 
	
  
o 

OO\EEEE_EEEEEZ&& 	
  	"-9955u555557  
 ! L/$KKMr&   TFc                     ||j         }t          j        |||j        |          }d|_        |r |j        | fi |}|S )N)type_r!   T)r)   r   BindParametertype_is_crud_compiler_dispatch)r   colvalueprocessr!   namer   	bindparams           r   r"   r"      se     |w&e38h  I I A0I0@@R@@	r&   c                     | j         r+|j        r$t          |j                  fd}fd}fd}n"t          j        }t          j        d          x}}|||fS )Nc                 ~    t          j        |           }t          | d          r| j        v r| j        j        |fS |S )Nr7   )r   r*   hasattrr7   rV   )r)   str_key_ets     r   r*   z4_key_getters_for_crud_column.<locals>._column_as_key   sE    -c22GsG$$ c)9)9	00r&   c                 J    | j         v r| j         j        | j        fS | j        S r(   r7   rV   r)   rS   r\   s    r   rH   z6_key_getters_for_crud_column.<locals>._getattr_col_key   s(    yC	00wr&   c                 P    | j         v r| j         j        d| j        S | j        S )N_r^   r_   s    r   rI   z4_key_getters_for_crud_column.<locals>._col_bind_name   s.    yC"%)...#''::wr&   r)   )r   r=   rB   r   r*   operator
attrgetter)r   r   r*   rH   rI   r\   s        @r   r:   r:      s     GT. G $#$$	 	 	 	 		 	 	 	 		 	 	 	 	 	 "0,4,?,F,FF>+^;;r&   c	                    t          |           \  }	}
}}fdj        D             }j        | _        g }j        r>t          |          }j        j        D ]"}||vr|j        r|	                    |           #|D ]U} ||          }||v r1||vr-|
                    |           |	                    |d f           Bt          | |||           V|rr|                    |           | j                                        | _        t          | j        j                  t          d |D                       z   | j        _        d S d S )Nc                 F    g | ]}j         j         |                   S r.   r7   r$   )r#   rV   r*   r   s     r   r%   z1_scan_insert_from_select_cols.<locals>.<listcomp>  s,    MMM4DJL--.MMMr&   c              3       K   | ]	\  }}|V  
d S r(   r.   )r#   rS   exprs      r   r,   z0_scan_insert_from_select_cols.<locals>.<genexpr>  s&      8893$888888r&   )_get_returning_modifiersr?   select_insert_from_select#include_insert_from_select_defaultsrB   r7   r8   defaultappendpop&_append_param_insert_select_hasdefaultextend	_generatetuple_raw_columns)r   r   r6   rH   r*   rI   rK   rJ   r   need_pksimplicit_returningimplicit_return_defaultspostfetch_lastrowidcolsadd_select_colscol_setrS   r$   col_keys    `  `              r   r@   r@      s   " 	!400  NMMMM4;LMMMD#';H O/ !d)):% 	! 	!C'!!ck!C     ""1%%j  WM%A%ANN7###MM1d)$$$$2$?B     9o&&&'/'C'M'M'O'O$49(55
 5
888888859$1119 9r&   c	                    t          |           \  }	}
}}j        rJfdj        D             }t          |          fd|D             fdj        j        D             z   }nj        j        }|D ]K} ||          }||v r||vrt          | |||||
|||
  
         /| j        r|j        r>|	r<|
s|r|j        j	        ur*|
rt          | |||           gt          | |||           {|j        t          | ||||           |j        C|r||v r| j                            |           |j        s| j                            |           |r ||v r| j                            |           |j        r$|j        j	        ur|j        st'          |           0| j        rt+          | ||||           Md S )Nc                 &    g | ]} |          S r.   r.   )r#   r)   r*   s     r   r%   z_scan_cols.<locals>.<listcomp>2  s0     
 
 
$'NN3
 
 
r&   c                 4    g | ]}j         j        |         S r.   rf   )r#   r)   r   s     r   r%   z_scan_cols.<locals>.<listcomp>6  s"    @@@c
S!@@@r&   c                 &    g | ]}|j         v|S r.   )r)   )r#   r$   ordered_keyss     r   r%   z_scan_cols.<locals>.<listcomp>6  s/     D
 D
 D
quL'@'@A'@'@'@r&   )ri   _parameter_orderingrB   r7   r$   r8   _append_param_parameterr   primary_key_autoincrement_column!_append_param_insert_pk_returning_append_param_insert_pkrm   _append_param_insert_hasdefaultserver_defaultr4   rn   r1   nullable"_warn_pk_with_no_anticipated_valuer   _append_param_update)r   r   r6   rH   r*   rI   rK   rJ   r   ru   rv   rw   rx   parameter_orderingry   r$   r|   r   s    `  `            @r   rA   rA     s   " 	!400   	"
 
 
 
+/+C
 
 
 -..@@@@-?@@@ D
 D
 D
 D
z|D
 D
 D
 
 z! ; ;""1%%j  WM%A%A#"(     )	#6#6 '	#6
 /#6 
 @@@ & K5 $62    ,HdAvrJJJJ&/dA'?    !-+ 15M0M0M&--a0000 1&--a000) 6a3K.K.K"))!,,,,6TZ===
 > 31555 	 $#;VR  s; ;r&   c
                    |                     |          }
t          j        |
          r9t          | ||
f|
t          u |j        s ||          nd ||          z  d|	}
nt          |
t          j                  r,|
j        j	        r |

                                }
|j        |
_        |j        r=|r;| j                            |            | j        |
                                fi |	}
n|r?||v r;| j                            |            | j        |
                                fi |	}
nA|j        s| j                            |            | j        |
                                fi |	}
|                    ||
f           d S )Nz%s_m0r!   rV   )ro   r   _is_literalr"   r	   r9   
isinstancerO   rP   _isnull_cloner   r4   rn   rU   
self_groupr1   )r   r   r$   r|   r6   rI   rv   rw   rJ   r   rT   s              r   r   r   z  s    NN7##EE"" ?"	
 h&--""">>!,,,	
 	
 	
 	
 eX344 	 9K 	 LLNNEEJ= 	?/ 	?%%a((($H$U%5%5%7%7>>2>>EE% 
	?!/G*G*G%%a((($H$U%5%5%7%7>>2>>EE = -"))!,,,$H$U%5%5%7%7>>2>>E
MM1e*r&   c                    |j         |j         j        rj| j        j        rB|j         j        r| j        j        s* | j        |j         fi |}|                    ||f           | j                            |           dS |j         j	        r[|                    | | j        |j         j
                                        fi |f           | j                            |           dS |                    |t          | |          f           dS ||j        j        u s|j        | j                            |           dS |j        st#          |           dS dS )a  Create a primary key expression in the INSERT statement and
    possibly a RETURNING clause for it.

    If the column has a Python-side default, we will create a bound
    parameter for it and "pre-execute" the Python function.  If
    the column has a SQL expression default, or is a sequence,
    we will add it directly into the INSERT statement and add a
    RETURNING element to get the new value.  If the column has a
    server side default or is marked as the "autoincrement" column,
    we will add a RETRUNING element to get at the value.

    If all the above tests fail, that indicates a primary key column with no
    noted default generation capabilities that has no parameter passed;
    raise an exception.

    N)rm   is_sequencedialectsupports_sequencesoptionalsequences_optionalrU   rn   r4   is_clause_elementargr   "_create_insert_prefetch_bind_paramr7   r   r   r   r   r   r   r$   rJ   r   procs         r   r   r     s   " 	y9  	P2 )I&)':) (x'	88R88q$i(((%%a(((((Y( 	PMM$H$QY]%=%=%?%?FF2FFG   %%a(((((MM1@1MMNOOOOO	
dj.	.	.!2B2N!!!$$$$$Z . 	+1-----. .r&   c                 b    t          | |d ||          }| j                            |           |S N)rU   rV   )r"   r2   rn   r   r$   rU   rV   params        r   r   r     6    xD'MMME##A&&&Lr&   c                 b    t          | |d ||          }| j                            |           |S r   )r"   r3   rn   r   s        r   "_create_update_prefetch_bind_paramr     r   r&   c                       e Zd ZdZd Zd ZdS )_multiparam_columnTc                 z    || _         d|j        |dz   fz  | _        || _        |j        | _        |j        | _        d S )N%s_m%dr   )indexr)   originalrm   rP   )selfr   r   s      r   __init__z_multiparam_column.__init__  s>    
x|UQY77 'M			r&   c                 l    t          |t                    o|j        | j        k    o|j        | j        k    S r(   )r   r   r)   r   )r   others     r   __eq__z_multiparam_column.__eq__  s7    u011 0	TX%0$-/	
r&   N)__name__
__module____qualname___is_multiparam_columnr   r   r.   r&   r   r   r     s8         " " "
 
 
 
 
r&   r   c                 >   |j         st          j        d|z            |j         j        r* | j        |j         j                                        fi |S t          ||          }t          |t          j
                  rt          | |          S t          | |          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)rm   r   rE   r   rU   r   r   r   r   r   Insertr   r   )r   r   r$   r   r   rS   s         r    _process_multiparam_default_bindr     s    9 E@BCD
 
 	

 
	$ Ex	 8 8 : :AAbAAA E**dCJ'' 	E5hDDD5hDDDr&   c                 2   |j         |j         j        r2| j        j        s&||j        j        u r?| j        j        s| j        j        r'|                    |t          | |          f           dS |j         |j	        |j
        st          |           dS dS dS dS )a  Create a bound parameter in the INSERT statement to receive a
    'prefetched' default value.

    The 'prefetched' value indicates that we are to invoke a Python-side
    default function or expliclt SQL expression before the INSERT statement
    proceeds, so that we have a primary key value available.

    if the column has no noted default generation capabilities, it has
    no value passed in either; raise an exception.

    N)rm   r   r   r   r7   r   "preexecute_autoincrement_sequencesrn   r   r   r   r   )r   r   r$   rJ   r   s        r   r   r     s     	
	 	% 	 2	 	 	
TZ--- /	 	.
 B 	. 	q<XqIIJKKKKK	
	q/7
7 	+1----- 
	7777r&   c                    |j         j        r| j        j        r|j         j        r| j        j        sq | j        |j         fi |}|                    ||f           |r ||v r| j                            |           d S |j	        s | j
                            |           d S d S d S d S |j         j        r | j        |j         j                                        fi |}|                    ||f           |r ||v r| j                            |           d S |j	        s| j
                            |           d S d S |                    |t          | |          f           d S r(   )rm   r   r   r   r   r   rU   rn   r4   r   r1   r   r   r   r   )r   r   r$   rw   rJ   r   r   s          r   r   r   &  s    	y L. 	-	"	-*2*:*M	- $8#AI4444DMM1d)$$$' -A1I,I,I"))!,,,,,] -"))!,,,,,	- 	- 	- 	-- -	
	$ 
Lx	 8 8 : :AAbAAq$i   # 	)-E(E(E%%a((((( 	)%%a(((((	) 	) 	q<XqIIJKKKKKr&   c                    |j         j        rZ| j        j        rJ|j         j        r| j        j        s4|j         }|                    ||                                f           d S d S d S |j         j        r7|j         j	        
                                }|                    ||f           d S |                    |t          | |d          f           d S )NF)rU   )rm   r   r   r   r   r   rn   
next_valuer   r   r   r   r   s         r   rp   rp   A  s    y 
. 	2	"	2*2*:*M	2 9DMM1doo//011111		2 	2 	2 	2
 
	$ 
y}''))q$i     28QNNNO	
 	
 	
 	
 	
r&   c                 t   |j         |j         j        s|j         j        r}|                    | | j        |j         j                                        fi |f           |r ||v r| j                            |           d S | j                            |           d S |                    |t          | |          f           d S |j
        >|r ||v r| j                            |           d S | j                            |           d S |r)|j        dur"||v r | j                            |           d S d S d S d S )NT)onupdater   r   rn   rU   r   r   r4   r1   r   server_onupdate_return_defaults)r   r   r$   rw   rJ   r   s         r   r   r   R  s    	zaj&<:' 		PMM$H$QZ^%>%>%@%@GGBGGH   ( -A1I,I,I"))!,,,,,"))!,,,,,MM1@1MMNOOOOO	
		&# 	)-E(E(E%%a(((((%%a((((( %!--)))!!!$$$$$% %--))r&   c                    t          d |                                D                       }t                      }	|j        D ]}
|
j        D ]}||v r|	                    |
           || ||          <   ||         }t          j        |          r%t          | |||t          u  ||                    }n:| j
                            |            | j        |                                fi |}|                    ||f           |	D ]}
|
j        D ]}||v r|j        |j        j        s|j        j        rZ|                    | | j        |j        j                                        fi |f           | j
                            |           |                    |t%          | | ||                    f           |j        | j
                            |           ӌd S )Nc              3   H   K   | ]\  }}t          j        |          |fV  d S r(   )r   _clause_element_as_expr)r#   r$   r   s      r   r,   z)_get_multitable_params.<locals>.<genexpr>y  sJ        Au 
	)!	,	,e4     r&   r   )rV   )r;   itemsrB   r=   r$   addr   r   r"   r	   r1   rn   rU   r   r   r   r   r   r   r   )r   r   r+   rK   rI   rH   rJ   r   normalized_paramsaffected_tablestr$   rT   s                r   r>   r>   n  s      '--//     eeO * * 	* 	*A%%%##A&&&56..q112)!,'.. 
G. !&(!2+^A..  EE &--a000,H,U-=-=-?-?FF2FFEq%j)))!	*&  - - 	- 	-A%%%'
0F':/ MM,H, !
 9 9 ; ; ?A    &--a0000MM> (!..2C2C      "."))!,,,1	-- -r&   c           
         |}|g}t          |j        dd                    D ]\  }}g }|D ]\  }}	||v s	|j        |v rs||v r|n|j        }
t          j        ||
                   r%t          | |||
         fdd|j        |dz   fz  i|}n: | j        ||
                                         fi |}nt          | ||||          }|	                    ||f           |	                    |           |S )Nr   rV   r   )
	enumerater6   r)   r   r   r"   rU   r   r   rn   )r   r   rJ   r   values_0irow	extensionrS   r   r)   	new_params               r   rG   rG     sQ   HXFDOABB/00 ! !3	$ 	/ 	/LS%czzSW^^ CZZccSW'C11 	N 2 C! ! &!a%(88	!
 ! !II !1 0S1D1D1F1F M M" M MII<dCB 	 c9-....i    Mr&   c                 j   |                                 D ]\  }} ||          }||                    ||           )t          j        |          r) | j        t          j        d ||j                  fi |}n  | j        |                                fi |}|                    ||f           d S )N)rN   )	r   
setdefaultr   r   rU   rO   rP   r   rn   )	r   r6   r+   r*   rJ   r   r/   vcolkeys	            r   r<   r<     s      %%'' " "1""!!&!,,,,
 #A&& ;$H$*4!&AAA EG  %H$Q\\^^::r::MM1a&!!!!" "r&   c                    | j         o| j         o|j         o|j         }|o| j        j        o|j        j        }| j         r
|o|j        }n)| j        r | j        j        o|j        j        o|j        }nd}|r7|j        du rt          |j        j
                  }nt          |j                  }|o| j        j        }||||fS )NFT)r   inline
_returningr9   r   rv   r7   r   r   rB   r$   rx   )r   r   ru   rv   rw   rx   s         r   ri   ri     s    	+	+	+ **	  	 	*/	*J)   )#5#O$:O  		 	)/ &
-&% 	!  $)  B D(('*4:<'8'8$$'*4+@'A'A$"Kx'7'K 	 	 r&   c                     d| j         j        d| j        d| j         j        d}t          | j         j                  dk    r|dz  }t          j        |           d S )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.)r7   fullnamerV   r   r   r   warn)r$   msgs     r   r   r     so      7QVVVQW%5%5%5	7  17!##	
 	IcNNNNNr&   )TFN)TN)"__doc__rb    r   r   r   r   symbolr	   r
   r   r   r   r   r"   r:   r@   rA   r   r   r   r   ColumnElementr   r   r   r   rp   r   r>   rG   r<   ri   r   r.   r&   r   <module>r      sC                             4;	  4;z""4;z""4;z""1 1 1Bq q qj >B   !< !< !<H-9 -9 -9`Y Y Yx+ + +\&. &. &.R      
 
 
 
 
/ 
 
 
$E E E$". ". ".JL L L6
 
 
"% % %8=- =- =-@  @" " "*( ( (V    r&   