
    [hI                     h   d dl m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 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 ddlmZ ddlmZ ddlmZ ddlmZ  G d dej                  Z G d dej                  Z G d dej                  ZdZdS )    )DecimalN   )testing   )fixtures)eq_)requirements)Column)Table   )Double)Float)Identity)Integer)literal)literal_column)Numeric)select)String)LargeBinary)UUID)Uuidc                   b    e Zd ZdZdZdZed             Zd Zd Z	d Z
ej        d             Zd	S )
LastrowidTesteachT)implements_get_lastrowidautoincrement_insertc                    t          d|t          dt          dd          t          dt          d                    d           t          d	|t          dt          dd
          t          dt          d                    d           d S )N
autoinc_pkidTprimary_keytest_needs_autoincrementdata2   Fimplicit_returning	manual_pkr"   autoincrementr   r
   r   r   clsmetadatas     s/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/sqlalchemy/testing/suite/test_insert.pydefine_tableszLastrowidTest.define_tables'   s    g4$   66"::&&$	
 	
 	
 	
 	4d%HHH66"::&&$	
 	
 	
 	
 	
 	
    c                     |                     |                                                                          }t          ||j        j        df           d S N	some dataexecuter   firstr   dialectdefault_sequence_baseselftableconnrows       r/   _assert_round_tripz LastrowidTest._assert_round_trip;   V    ll5<<>>**00222	
 	
 	
 	
 	
r1   c                     |                     | j        j                                        t	          d                     |                     | j        j        |           d S Nr4   r$   r6   tablesr   insertdictr?   r;   
connections     r/   test_autoincrement_on_insertz*LastrowidTest.test_autoincrement_on_insertE   ^    K"))++T{-C-C-C	
 	
 	
 	 6
CCCCCr1   c                    |                     | j        j                                        t	          d                    }|                    t          | j        j        j        j                            }t          |j
        |f           d S rB   r6   rE   r   rF   rG   scalarr   cr    r   inserted_primary_keyr;   rI   rpks       r/   test_last_inserted_idz#LastrowidTest.test_last_inserted_idK   {    K"))++T{-C-C-C
 
 vdk&<&>&ABBCCA"RE*****r1   c                     |                     | j        j                                        t	          d                    }|j        }|                    t          | j        j        j        j	                            }t          ||           d S rB   )r6   rE   r   rF   rG   	lastrowidrN   r   rO   r    r   )r;   rI   rR   rW   rS   s        r/   test_native_lastrowid_autoincz+LastrowidTest.test_native_lastrowid_autoincR   s}    K"))++T{-C-C-C
 
 K	vdk&<&>&ABBCCIrr1   N)__name__
__module____qualname__run_deletes__backend____requires__classmethodr0   r?   rJ   rT   r	   dbapi_lastrowidrX    r1   r/   r   r       s        KKEL
 
 [
&
 
 
D D D+ + + !  "!  r1   r   c                      e Zd ZdZdZed             Z ej        dddg           ej        dddg          d	                         Z	e
j        d
             Ze
j        d             Ze
j        d             Ze
j        d             Ze
j        d             Ze
j        d             Ze
j        d             Ze
j        d             ZdS )InsertBehaviorTestr   Tc                    t          d|t          dt          dd          t          dt          d                               t          d|t          dt          dd	          t          dt          d                               t          d
|t          dt          dd          t          dt          d                    d           t          d|t          dt          dd          t          dt          d                    t          dt          d          t          dt          t	          dt                    t          d          z                        d S )Nr   r    Tr!   r$   r%   r(   Fr)   no_implicit_returningr&   includes_defaultsx   )defaulty2)type_r   )r   r
   r   r   r   r   r,   s     r/   r0   z InsertBehaviorTest.define_tables`   sv   g4$   66"::&&	
 	
 	
 	4d%HHH66"::&&		
 	
 	
 	#g4$   66"::&&$	
 	
 	
 	
 	g4$   66"::&&3+++&s':::WQZZG  	
 	
 	
 	
 	
r1   styleplainreturn_defaultsexecutemanyFc                     | j         j        }|                                }|j        r|                                }|rddiddiddiddiddig}nddi}|                    ||          }|j        rJ dS )z-test another INSERT issue found during #10453r$   d1d2d3d4d5N)rE   re   rF   ro   r6   returns_rows)r;   rI   rm   rp   r<   stmtr$   rR   s           r/   (test_no_results_for_non_returning_insertz;InsertBehaviorTest.test_no_results_for_non_returning_insert   s     1||~~  	*''))D 		"DD D>DtT**>!!!!!r1   c                     |                     | j        j                                        t	          d                    }|j        sJ |j        rJ |j        sJ |j        r|	                                J d S d S rB   )
r6   rE   r   rF   rG   _soft_closedclosed	is_insertrw   fetchoner;   rI   rR   s      r/   test_autoclose_on_insertz+InsertBehaviorTest.test_autoclose_on_insert   s    K"))++T{-C-C-C
 
 ~8{ >9QZZ\\%9%9%999%9%9r1   c                 |   |                     | j        j                                                                        t          d                    }|j        sJ |j        rJ |j        sJ |j	        sJ t          |                                d            t          |                                dg           d S )Nr4   rC   r    )r6   rE   r   rF   ro   rG   r{   r|   r}   rw   r   r~   keysr   s      r/   +test_autoclose_on_insert_implicit_returningz>InsertBehaviorTest.test_autoclose_on_insert_implicit_returning   s     K"))++;;==k"""
 
 ~8{ ~ 	AJJLL$ 	AFFHHtfr1   c                    |                     | j        j                                                  }|j        sJ |j        rJ |                     | j        j                                                            | j        j        j        j	        d k                        }t          t          |                                          d           d S )Nr   r6   rE   r   rF   r{   r|   r   whererO   r    r   lenallr   s      r/   test_empty_insertz$InsertBehaviorTest.test_empty_insert   s    t{5<<>>??~8K"))++11&(+t3 
 

 	CLL!r1   c                    |                     | j        j                                        i i i g          }|j        sJ |j        rJ |                     | j        j                                                            | j        j        j        j	        d k                        }t          t          |                                          d           d S )Nr   r   r   s      r/   test_empty_insert_multiplez-InsertBehaviorTest.test_empty_insert_multiple   s    t{5<<>>RMM~8K"))++11&(+t3 
 
 	CLL!r1   c                    | j         j        }| j         j        }|                    |                                t          dd          t          dd          t          dd          g           |                    |                                                    dt          |j        j	                  
                    |j        j	                            ddg                                        }t          |j        d	           |                    t          |j        j	                                      |j        j	                            }t          |                                d
dg           d S )Nr   data1r    r$   r   data2r   data3rC   Nr   r   )rE   r(   r   r6   rF   rG   from_selectr   rO   r$   r   in_r   rP   order_byfetchallr;   rI   	src_table
dest_tableresults        r/   test_insert_from_select_autoincz2InsertBehaviorTest.test_insert_from_select_autoinc   sZ   K)	[+
(((((((((	
 	
 	
 ##++y{'((..K$(('7);<<  
 
 	F'111##:<$%%..z|/@AA
 
 	FOO
J788888r1   c                 >   | j         j        }| j         j        }|                    |                                                    dt          |j        j                  	                    |j        j        
                    ddg                                        }t          |j        d           |                    t          |j        j                                      |j        j                            }t          |                                g            d S )NrC   r   r   r   )rE   r(   r   r6   rF   r   r   rO   r$   r   r   r   rP   r   r   r   s        r/   'test_insert_from_select_autoinc_no_rowsz:InsertBehaviorTest.test_insert_from_select_autoinc_no_rows  s    K)	[+
##++y{'((..K$(('7);<<  
 
 	F'111##:<$%%..z|/@AA
 
 	FOOr"""""r1   c                    | j         j        }|                    |                                t	          dd          t	          dd          t	          dd          g           |                    |                                                                                    dt          |j        j	        dz   |j        j
                                      |j        j
                            ddg                                         t          |                    t          |j        j
                                      |j        j
                                                            g d	           d S )
Nr   r   r   r   r   r   r   rh   ))r   r   r   r   r   )rE   r(   r6   rF   rG   inliner   r   rO   r    r$   r   r   r   r   r   r;   rI   r<   s      r/   test_insert_from_selectz*InsertBehaviorTest.test_insert_from_select  sK   %LLNN(((((((((	
 	
 	
 	LLNNVXX[uwzA~uw|44::GL$$gw%788  		
 		
 		
 	uw|$$--egl;; hjjHHH		
 	
 	
 	
 	
r1   c                    | j         j        }|                    |                                t	          dd          t	          dd          t	          dd          g           |                    |                                                                                    dt          |j        j	        dz   |j        j
                                      |j        j
                            ddg                                         t          |                    t          |                              |j        j
        |j        j	                                                            g d	           d S )
Nr   r   r   r   r   r   r   rh   ))r   r   rh      )r   r   rh   r   )   r   rh   r   )r   r   rh   r   )   r   rh   r   )rE   rf   r6   rF   rG   r   r   r   rO   r    r$   r   r   r   r   r   r   s      r/   %test_insert_from_select_with_defaultsz8InsertBehaviorTest.test_insert_from_select_with_defaults:  sQ   -LLNN(((((((((	
 	
 	
 	LLNNVXX[uwzA~uw|44::GL$$gw%788  		
 		
 		
 	u&&uw|UWZ@@ hjj  		
 	
 	
 	
 	
r1   N)rY   rZ   r[   r\   r]   r_   r0   r   	variationry   r	   r   r   insert_returningr   empty_insertsr   empty_inserts_executemanyr   insert_from_selectr   r   r   r   ra   r1   r/   rc   rc   \   s       KK%
 %
 [%
N Ww*; <==W}tUm44" " 54 >="2 &: : '&: "  #"6 
 
  
 +  ,+ $9 9 %$98 $# # %$#( $
 
 %$
: $!
 !
 %$!
 !
 !
r1   rc   c                   z   e Zd ZdZdZdZd Zed             Ze	j
        d             Zd Zd Zd	 Ze	j        d
             Z ej         e            ddf ed          ddej        j        f e            ddf ed          ddej        j        f eddd          ddej        j        f eddd           ed          dfd           ej        dddg           ej        dddg          d                                     Z ej        d ed           ej                    fd edd           e ej                              fd ed           ej                    ej        j         fd edd           e ej                              ej        j         fd e!             ej                    ej        j         fd  e"            d!fd" e"            d#fd$d%&	  	         ej        dddg           ej        dddg          ej        j#        d'                                                 Z$d(S ))ReturningTestr   )r   r   Tc                     |                     |                                                                          }t          ||j        j        df           d S r3   r5   r:   s       r/   r?   z ReturningTest._assert_round_tripd  r@   r1   c                     t          d|t          dt          dd          t          dt          d                               d S )Nr   r    Tr!   r$   r%   r+   r,   s     r/   r0   zReturningTest.define_tablesn  sT    g4$   66"::&&	
 	
 	
 	
 	
r1   c                 p   | j         j        }|                    |                                                    |j        j                  t          d                    }|                                d         }|	                    t          |j        j                            }t          ||           d S Nr4   rC   r   rE   r   r6   rF   	returningrO   r    rG   r7   rN   r   r   r;   rI   r<   rR   rS   
fetched_pks         r/   %test_explicit_returning_pk_autocommitz3ReturningTest.test_explicit_returning_pk_autocommity  s    &LLNN$$UWZ00$K2H2H2H
 
 WWYYq\&&vegj'9'9::
Jr1   c                 p   | j         j        }|                    |                                                    |j        j                  t          d                    }|                                d         }|	                    t          |j        j                            }t          ||           d S r   r   r   s         r/   (test_explicit_returning_pk_no_autocommitz6ReturningTest.test_explicit_returning_pk_no_autocommit  s    &LLNN$$UWZ00$K2H2H2H
 
 WWYYq\&&vegj'9'9::
Jr1   c                     |                     | j        j                                        t	          d                     |                     | j        j        |           d S rB   rD   rH   s     r/   /test_autoincrement_on_insert_implicit_returningz=ReturningTest.test_autoincrement_on_insert_implicit_returning  rK   r1   c                    |                     | j        j                                        t	          d                    }|                    t          | j        j        j        j                            }t          |j
        |f           d S rB   rM   rQ   s       r/   (test_last_inserted_id_implicit_returningz6ReturningTest.test_last_inserted_id_implicit_returning  rU   r1   c           	         |                     | j        j                                                            | j        j        j        j                  ddiddiddiddiddig          }|                                }|                     t          | j        j        j        j                            }t          ||                                           d S )Nr$   rr   rs   rt   ru   rv   )
r6   rE   r   rF   r   rO   r    r   r   r   )r;   rI   rR   rallpkss        r/   test_insertmanyvalues_returningz-ReturningTest.test_insertmanyvalues_returning  s    K"))++55&(+  	
 
 uuww  (>(@(C!D!DEED#''))r1   gxXM|Z!@5   g_Q!@r         F)	precisionscale	asdecimalz	8.5514716ztype_,value,do_rounding)argnamessort_by_parameter_ordermultiple_rowsc           
         t          d|t          dt          t                      d          t          d|                    }|                    |           |                    |                                                    |j        j	        |j        j
        t          |                    |rfdt          d          D             ndi          }	|rt          d	d
          }
nt          d	d          }
|r{t          d |	D             fd|
D                        t          d |                    t          |j        j
                            D             t!          d          h           dS t          t#          |	          fd|
D                        t          t#          |                    t          |j        j
                                      h           dS )zvtest #9701.

        this tests insertmanyvalues as well as decimal / floating point
        RETURNING types

        f_tr    Tr"   valuer   c                     g | ]}d iS r   ra   .0ir   s     r/   
<listcomp>z6ReturningTest.test_insert_w_floats.<locals>.<listcomp>      555a'5!555r1   
   r      r   c                 8    h | ]\  }}|t          |d           fS rh   round)r   id_val_s      r/   	<setcomp>z5ReturningTest.test_insert_w_floats.<locals>.<setcomp>  s)    ???93#uT1~~&???r1   c                 4    h | ]}|t          d           fS r   r   r   r   r   s     r/   r   z5ReturningTest.test_insert_w_floats.<locals>.<setcomp>  s&    ;;;C#uUA';;;r1   c                 .    h | ]}t          |d           S r   r   )r   r   s     r/   r   z5ReturningTest.test_insert_w_floats.<locals>.<setcomp>
  s0        $NN  r1   rh   c                     h | ]}|fS ra   ra   r   s     r/   r   z5ReturningTest.test_insert_w_floats.<locals>.<setcomp>  s    111##u111r1   N)r   r
   r   r   creater6   rF   r   rO   r    r   boolranger   scalarsr   r   set)r;   rI   r.   r   rl   r   do_roundingr   tr   i_ranges        `     r/   test_insert_w_floatsz"ReturningTest.test_insert_w_floats  s!   ^  4(**$???7E""
 
 	
##HHJJ  	(,-D(E(E !   !&55555995555u%
 
  	"ArllGGAqkkG  	?????;;;;7;;;  
   * 2 26!#)3D3D E E   ua!     F1111111  
 J&&vaci'8'899::    r1   non_native_uuid)native_uuidnon_native_uuid_str)as_uuidr   generic_native_uuidgeneric_native_uuid_strr   LargeBinary1s   this is binaryLargeBinary2s   7ztype_,valueiaa)r   r   c           
         t          d|t          dt          t                      d          t          d|                    }|                    |           |                    |                                                    |j        j	        |j        j
        t          |                    |rfdt          d          D             ndi          }|rt          d	d
          }	nt          d	d          }	t          t          |          fd|	D                        t          t          |                    t!          |j        j
                                      h           dS )a  test #9739, #9808 (similar to #9701).

        this tests insertmanyvalues in conjunction with various datatypes.

        These tests are particularly for the asyncpg driver which needs
        most types to be explicitly cast for the new IMV format

        d_tr    Tr   r   r   c                     g | ]}d iS r   ra   r   s     r/   r   z>ReturningTest.test_imv_returning_datatypes.<locals>.<listcomp>`  r   r1   r   r   r   r   c                     h | ]}|fS ra   ra   r   s     r/   r   z=ReturningTest.test_imv_returning_datatypes.<locals>.<setcomp>m  s    ---cc5\---r1   N)r   r
   r   r   r   r6   rF   r   rO   r    r   r   r   r   r   r   r   )
r;   rI   r.   r   rl   r   r   r   r   r   s
        `    r/   test_imv_returning_datatypesz*ReturningTest.test_imv_returning_datatypes  su   j 4(**$???7E""	
 
 	
##HHJJ  	(,-D(E(E !   !&55555995555u%
 
  	"ArllGGAqkkGKK----W---	
 	
 	

 	
""6!#)#4#45566G	
 	
 	
 	
 	
r1   N)%rY   rZ   r[   run_create_tablesr^   r]   r?   r_   r0   r	   fetch_rows_post_commitr   r   r   r   insert_executemany_returningr   r   combinationsr   requires-float_or_double_precision_behaves_genericallyr   r   literal_float_coercionr   r   r   r   uuiduuid4struuid_data_typer   r   r   r   ra   r1   r/   r   r   _  s|       =LK
 
 
 
 
 [
 (  )(  D D D+ + + .  /.& W	9d#F2JJJ		
 
&$E!HHJ		
 Gbe<<<3		
 Gbd;;;GK  	

 +5  8 W04-@@Wu66M M 76 A@9 <M^ WDU###DJLL	
 "DE222C

	
 "DT"""DJLL+		
 &DD111C

+		
 
w'7'FGKMM	

 
5?     B W04-@@Wu66&4
 4
 '& 76 A@C   H4
 4
 4
r1   r   )r   rc   r   )decimalr   r   r   r   
assertionsr   configr	   schemar
   r   r   r   r   r   r   r   r   r   r   typesr   r   r   
TablesTestr   rc   r   __all__ra   r1   r/   <module>r     s                            ! ! ! ! ! !                                                                                          9 9 9 9 9H' 9 9 9x@
 @
 @
 @
 @
, @
 @
 @
FT
 T
 T
 T
 T
H' T
 T
 T
n Cr1   