
    hK                     r   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j4                        Z G d dej4                        Z G d dej4                        ZdZy)    )DecimalN   )testing   )fixtures)eq_)requirements)Column)Table   )Double)Float)Identity)Integer)literal)literal_column)Numeric)select)String)LargeBinary)UUID)Uuidc                   ^    e Zd ZdZdZdZed        Zd Zd Z	d Z
ej                  d        Zy	)
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       y )N
autoinc_pkidTprimary_keytest_needs_autoincrementdata2   Fimplicit_returning	manual_pkr"   autoincrementr   r
   r   r   clsmetadatas     MD:\EasyAligner\venv\Lib\site-packages\sqlalchemy/testing/suite/test_insert.pydefine_tableszLastrowidTest.define_tables'   sc    g4$ 66":&$	
 	4d%H66":&$	
    c                     |j                  |j                               j                         }t        ||j                  j
                  df       y N	some dataexecuter   firstr   dialectdefault_sequence_baseselftableconnrows       r/   _assert_round_tripz LastrowidTest._assert_round_trip;   ?    ll5<<>*00222	
r1   c                     |j                  | j                  j                  j                         t	        d             | j                  | j                  j                  |       y Nr4   r$   r6   tablesr   insertdictr?   r;   
connections     r/   test_autoincrement_on_insertz*LastrowidTest.test_autoincrement_on_insertE   I    KK""))+T{-C	
 	 6 6
Cr1   c                 2   |j                  | j                  j                  j                         t	        d            }|j                  t        | j                  j                  j                  j                              }t        |j                  |f       y 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   n    KK""))+T{-C
 vdkk&<&<&>&>&A&ABCA""RE*r1   c                 4   |j                  | j                  j                  j                         t	        d            }|j
                  }|j                  t        | j                  j                  j                  j                              }t        ||       y 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   so    KK""))+T{-C
 KK	vdkk&<&<&>&>&A&ABCIrr1   N)__name__
__module____qualname__run_deletes__backend____requires__classmethodr0   r?   rJ   rT   r	   dbapi_lastrowidrX    r1   r/   r   r       sM    KKEL
 
&
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y)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                y )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`   s    g4$ 66":&	
 	4d%H66":&		
 	#g4$ 66":&$	
 	g4$ 66":&3+&s':WQZG	
r1   styleplainreturn_defaultsexecutemanyFc                     | j                   j                  }|j                         }|j                  r|j                         }|rddiddiddiddiddig}nddi}|j	                  ||      }|j
                  rJ y)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1||~  '')DD D>DtT*>>!!>r1   c                    |j                  | j                  j                  j                         t	        d            }|j
                  sJ |j                  rJ |j                  sJ |j                  r|j                         J y y 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   st    KK""))+T{-C
 ~~~88|{{{ >>QZZ\%999%9>r1   c                 v   |j                  | j                  j                  j                         j	                         t        d            }|j                  sJ |j                  rJ |j                  sJ |j                  sJ t        |j                         d        t        |j                         dg       y )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     KK""))+;;=k"
 ~~~88|{{{ ~~~ 	AJJL$ 	AFFHtfr1   c                    |j                  | j                  j                  j                               }|j                  sJ |j
                  rJ |j                  | j                  j                  j                         j                  | j                  j                  j                  j                  d k7              }t        t        |j                               d       y )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5<<>?~~~88|KK""))+11&&((++t3

 	CL!r1   c                    |j                  | j                  j                  j                         i i i g      }|j                  sJ |j
                  rJ |j                  | j                  j                  j                         j                  | j                  j                  j                  j                  d k7              }t        t        |j                               d       y )Nr   r   r   s      r/   test_empty_insert_multiplez-InsertBehaviorTest.test_empty_insert_multiple   s    t{{55<<>RM~~~88|KK""))+11&&((++t3
 	CL!r1   c                    | j                   j                  }| j                   j                  }|j                  |j	                         t        dd      t        dd      t        dd      g       |j                  |j	                         j                  dt        |j                  j                        j                  |j                  j                  j                  ddg                        }t        |j                  d	       |j                  t        |j                  j                        j                  |j                  j                              }t        |j                         d
dg       y )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   s$   KK))	[[++
(((	
 ##++y{{''(..KK$$(('7);<
 	F''1##:<<$$%..z||/@/@A
 	FOO
J78r1   c                 ^   | j                   j                  }| j                   j                  }|j                  |j	                         j                  dt        |j                  j                        j                  |j                  j                  j                  ddg                        }t        |j                  d       |j                  t        |j                  j                        j                  |j                  j                              }t        |j                         g        y )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    KK))	[[++
##++y{{''(..KK$$(('7);<
 	F''1##:<<$$%..z||/@/@A
 	FOOr"r1   c                    | j                   j                  }|j                  |j                         t	        dd      t	        dd      t	        dd      g       |j                  |j                         j                         j                  dt        |j                  j                  dz   |j                  j                        j                  |j                  j                  j                  ddg                         t        |j                  t        |j                  j                        j                  |j                  j                              j                         g d	       y )
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  s   %%LLN(((	
 	LLNVX[uwwzzA~uww||4::GGLL$$gw%78		
 	uww||$--eggll;hjH		
r1   c                    | j                   j                  }|j                  |j                         t	        dd      t	        dd      t	        dd      g       |j                  |j                         j                         j                  dt        |j                  j                  dz   |j                  j                        j                  |j                  j                  j                  ddg                         t        |j                  t        |      j                  |j                  j                  |j                  j                              j                         g d	       y )
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:  s   --LLN(((	
 	LLNVX[uwwzzA~uww||4::GGLL$$gw%78		
 	u&&uww||UWWZZ@hj		
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   \   s3   KK%
 %
N Ww*; <=W}tUm4" 5 >"2 &&: ': "" #6 
  
 ++ , $$9 %98 $$# %#( $$
 %
: $$!
 %!
r1   rc   c                      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(                  j0                  f eddd       ed      dfd       ej4                  dddg       ej4                  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j4                  dddg       ej4                  dddg      ej(                  jF                  d'                             Z$y())ReturningTestr   )r   r   Tc                     |j                  |j                               j                         }t        ||j                  j
                  df       y r3   r5   r:   s       r/   r?   z ReturningTest._assert_round_tripd  r@   r1   c                 h    t        d|t        dt        dd      t        dt        d                   y )Nr   r    Tr!   r$   r%   r+   r,   s     r/   r0   zReturningTest.define_tablesn  s1    g4$ 66":&	
r1   c                 d   | j                   j                  }|j                  |j                         j	                  |j
                  j                        t        d            }|j                         d   }|j                  t        |j
                  j                              }t        ||       y 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|    &&LLN$$UWWZZ0$K2H
 WWYq\&&veggjj'9:
Jr1   c                 d   | j                   j                  }|j                  |j                         j	                  |j
                  j                        t        d            }|j                         d   }|j                  t        |j
                  j                              }t        ||       y r   r   r   s         r/   (test_explicit_returning_pk_no_autocommitz6ReturningTest.test_explicit_returning_pk_no_autocommit  s|    &&LLN$$UWWZZ0$K2H
 WWYq\&&veggjj'9:
Jr1   c                     |j                  | j                  j                  j                         t	        d             | j                  | j                  j                  |       y rB   rD   rH   s     r/   /test_autoincrement_on_insert_implicit_returningz=ReturningTest.test_autoincrement_on_insert_implicit_returning  rK   r1   c                 2   |j                  | j                  j                  j                         t	        d            }|j                  t        | j                  j                  j                  j                              }t        |j                  |f       y 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                  j                  j
                  j                        ddiddiddiddiddig      }|j                         }|j                  t        | j                  j                  j
                  j                              }t        ||j                                y )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    KK""))+55&&((++ 	
 uuw  (>(>(@(@(C(C!D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                  |j                  j                  |j                  j                  t        |            |rt        d      D 	cg c]  }	d|i c}	nd|i      }
|rt        dd	      }nt        dd
      }|rt        |
D ch c]  \  }}|t        |d      f c}}|D ch c]  }|t        |d      f c}       t        |j                  t!        |j                  j                              D ch c]  }t        |d       c}t        |d      h       yt        t#        |
      |D ch c]  }||f c}       t        t#        |j                  t!        |j                  j                                    |h       yc c}	w c c}}w c c}w c c}w c c}w )zvtest #9701.

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

        f_tr    Tr"   valuer   
   r      r   rh   N)r   r
   r   r   creater6   rF   r   rO   r    r   boolranger   roundscalarsr   set)r;   rI   r.   r   rl   r   do_roundingr   tir   i_rangeid_val_s                 r/   test_insert_w_floatsz"ReturningTest.test_insert_w_floats  s   ^  4(*$?7E"
 	
##HHJ  		(,-D(E !  ! ,1959a'5!95u%
 ArlGAqkG 8>?93#uT1~&?3:;7C#uUA'7;
  !+ 2 26!##))3D E E $N E ua! F)01##u1
 J&&vaccii'89:M 6* @; 2s   /G+
,G0
G6
G;H 
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                  |j                  j                  |j                  j                  t        |            |rt        d      D cg c]  }d|i c}nd|i      }	|rt        dd	      }
nt        dd
      }
t        t        |	      |
D ch c]  }||f c}       t        t        |j                  t!        |j                  j                                    |h       yc c}w c c}w )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   r   r   r   r   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   r   r   s               r/   test_imv_returning_datatypesz*ReturningTest.test_imv_returning_datatypes  s(   j 4(*$?7E"	
 	
##HHJ  		(,-D(E !  ! ,1959a'5!95u%
 ArlGAqkGK%,-Wcc5\W-	

 	
""6!##))#456G	
! 6 .s   /E
3E
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+ .. /& W	9d#2JJJ		
 
&$!HJJ		
 be<33		
 bd;K 	

 +58 W04-@Wu6M 7 A9<M^ WU#DJJL	
 "E2


	
 "T"DJJL++		
 &D1


++		
 
w'7'7'F'FGM	

 
5? B W04-@Wu6&&4
 ' 7 AC H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H'' 9x@
,, @
FT
H'' T
n Cr1   