o
     ZhI                     @   s*  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 dejZG dd dejZG d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                   @   sJ   e Zd ZdZdZdZedd Zdd Zdd	 Z	d
d Z
ejdd ZdS )LastrowidTesteachT)Zimplements_get_lastrowidautoincrement_insertc              	   C   sT   t d|tdtdddtdtddd t d	|tdtddd
tdtddd d S )N
autoinc_pkidTprimary_keyZtest_needs_autoincrementdata2   FZimplicit_returning	manual_pkr   Zautoincrementr
   r	   r   r   clsmetadata r(   [/var/www/html/lang_env/lib/python3.10/site-packages/sqlalchemy/testing/suite/test_insert.pydefine_tables'   s    

zLastrowidTest.define_tablesc                 C   (   | |  }t||jjdf d S N	some dataexecuter   firstr   dialectZdefault_sequence_baseselftableconnrowr(   r(   r)   _assert_round_trip;      z LastrowidTest._assert_round_tripc                 C   .   | | jj tdd | | jj| d S Nr-   r   r/   tablesr   insertdictr7   r3   
connectionr(   r(   r)   test_autoincrement_on_insertE      z*LastrowidTest.test_autoincrement_on_insertc                 C   B   | | jj tdd}|t| jjjj}t	|j
|f d S r:   r/   r=   r   r>   r?   scalarr   cr   r   inserted_primary_keyr3   rA   rpkr(   r(   r)   test_last_inserted_idK   
   z#LastrowidTest.test_last_inserted_idc                 C   sD   | | jj tdd}|j}|t| jjjj	}t
|| d S r:   )r/   r=   r   r>   r?   	lastrowidrF   r   rG   r   r   )r3   rA   rJ   rN   rK   r(   r(   r)   test_native_lastrowid_autoincR   s   z+LastrowidTest.test_native_lastrowid_autoincN)__name__
__module____qualname__run_deletes__backend____requires__classmethodr*   r7   rB   rL   r   Zdbapi_lastrowidrO   r(   r(   r(   r)   r       s    

r   c                   @   s   e Zd ZdZdZedd Zedddgeddd	gd
d Z	e
jdd Ze
jdd Ze
jdd Ze
jdd Ze
jdd Ze
jdd Ze
jdd Ze
jdd ZdS )InsertBehaviorTestr   Tc                 C   s   t d|tdtdddtdtd t d|tdtddd	tdtd t d
|tdtdddtdtddd t d|tdtdddtdtdtdtddtdttdtdtd d 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%   r(   r(   r)   r*   `   sJ   	z InsertBehaviorTest.define_tablesstyleplainreturn_defaultsexecutemanyFc                 C   sh   | 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r2J dS )z-test another INSERT issue found during #10453r   d1d2d3d4d5N)r=   rX   r>   rb   r/   returns_rows)r3   rA   r`   rc   r4   stmtr   rJ   r(   r(   r)   (test_no_results_for_non_returning_insert   s   z;InsertBehaviorTest.test_no_results_for_non_returning_insertc                 C   sV   | | jj tdd}|jsJ |jrJ |jsJ |jr'|	 d u s)J d S d S r:   )
r/   r=   r   r>   r?   _soft_closedclosed	is_insertri   fetchoner3   rA   rJ   r(   r(   r)   test_autoclose_on_insert   s   


z+InsertBehaviorTest.test_autoclose_on_insertc                 C   sh   | | jj  tdd}|jsJ |jrJ |jsJ |j	s#J t
| d  t
| dg d S )Nr-   r;   r   )r/   r=   r   r>   rb   r?   rl   rm   rn   ri   r   ro   keysrp   r(   r(   r)   +test_autoclose_on_insert_implicit_returning   s   



z>InsertBehaviorTest.test_autoclose_on_insert_implicit_returningc                 C   s`   | | jj }|jsJ |jrJ | | jj | jjjj	d k}t
t| d d S )Nr   r/   r=   r   r>   rl   rm   r   whererG   r   r   lenallrp   r(   r(   r)   test_empty_insert   s   

z$InsertBehaviorTest.test_empty_insertc                 C   sh   | | 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   rt   rp   r(   r(   r)   test_empty_insert_multiple   s   

z-InsertBehaviorTest.test_empty_insert_multiplec                 C   s   | j j}| j j}|| tdddtdddtd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   data3r;   Nr|   r}   )r=   r"   r   r/   r>   r?   from_selectr   rG   r   ru   in_r   rH   order_byfetchallr3   rA   Z	src_tableZ
dest_tableresultr(   r(   r)   test_insert_from_select_autoinc   s,   


		z2InsertBehaviorTest.test_insert_from_select_autoincc                 C   s|   | 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 )Nr;   r|   r}   r~   )r=   r"   r   r/   r>   r   r   rG   r   ru   r   r   rH   r   r   r   r(   r(   r)   'test_insert_from_select_autoinc_no_rows  s   z:InsertBehaviorTest.test_insert_from_select_autoinc_no_rowsc                 C   s   | j j}|| tdddtdddtdddg ||  dt|jj	d |jj
|jj
ddg t|t|jj
|jj
 g d	 d S )
Nr   rz   r{   r   r|   r   r}   r[   ))rz   r   r   r   r   )r=   r"   r/   r>   r?   inliner   r   rG   r   r   ru   r   r   r   r   r3   rA   r4   r(   r(   r)   test_insert_from_select  s2   


	z*InsertBehaviorTest.test_insert_from_selectc                 C   s   | j j}|| tdddtdddtdddg ||  dt|jj	d |jj
|jj
ddg t|t||jj
|jj	 g d	 d S )
Nr   rz   r{   r   r|   r   r}   r[   ))r   rz   r[      )r   r|   r[   r   )   r|   r[   r   )r   r}   r[   r   )   r}   r[   r   )r=   rY   r/   r>   r?   r   r   r   rG   r   r   ru   r   r   r   r   r   r(   r(   r)   %test_insert_from_select_with_defaults:  s2   


	z8InsertBehaviorTest.test_insert_from_select_with_defaultsN)rP   rQ   rR   rS   rT   rV   r*   r   	variationrk   r   r   rq   insert_returningrs   Zempty_insertsrx   Zempty_inserts_executemanyry   Zinsert_from_selectr   r   r   r   r(   r(   r(   r)   rW   \   s0    
'






rW   c                   @   s  e Zd ZdZdZdZdd Zedd Ze	j
dd	 Zd
d Zdd Zdd Ze	jd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dejjfeddddeddfddedddgedddgdd  Zejd!edd"e fd#eddd$ee fd%edd"e ejj fd&eddd$ee ejj fd'e! e ejj fd(e" d)fd*e" d+fd,d-d.	edddgedddgejj#d/d0 Z$d1S )2ReturningTestr   )r   r   Tc                 C   r+   r,   r.   r2   r(   r(   r)   r7   d  r8   z ReturningTest._assert_round_tripc              	   C   s(   t d|tdtdddtdtd d S )Nr   r   Tr   r   r    r$   r%   r(   r(   r)   r*   n  s   zReturningTest.define_tablesc                 C   T   | j j}|| |jjtdd}| d }|	t
|jj}t|| d S Nr-   r;   r   r=   r   r/   r>   	returningrG   r   r?   r0   rF   r   r   r3   rA   r4   rJ   rK   Z
fetched_pkr(   r(   r)   %test_explicit_returning_pk_autocommity  s   z3ReturningTest.test_explicit_returning_pk_autocommitc                 C   r   r   r   r   r(   r(   r)   (test_explicit_returning_pk_no_autocommit  s   z6ReturningTest.test_explicit_returning_pk_no_autocommitc                 C   r9   r:   r<   r@   r(   r(   r)   /test_autoincrement_on_insert_implicit_returning  rC   z=ReturningTest.test_autoincrement_on_insert_implicit_returningc                 C   rD   r:   rE   rI   r(   r(   r)   (test_last_inserted_id_implicit_returning  rM   z6ReturningTest.test_last_inserted_id_implicit_returningc              	   C   sp   | | 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   rd   re   rf   rg   rh   )
r/   r=   r   r>   r   rG   r   rw   r   r   )r3   rA   rJ   ZrallZpksr(   r(   r)   test_insertmanyvalues_returning  s   
z-ReturningTest.test_insertmanyvalues_returninggxXM|Z!@5   g_Q!@r         F)	precisionscaleZ	asdecimalz	8.5514716ztype_,value,do_rounding)argnamessort_by_parameter_ordermultiple_rowsc              	      s  t d|tdtt ddtd|}|| || j|jj	|jj
t|d|r4 fddtd	D nd i}	|rAtd
d}
ntd
d}
|rptdd |	D  fdd|
D  tdd |t|jj
D t dh dS tt|	 fdd|
D  tt|t|jj
 h dS )zvtest #9701.

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

        Zf_tr   Tr   valuer   c                       g | ]}d  iqS r   r(   .0ir   r(   r)   
<listcomp>      z6ReturningTest.test_insert_w_floats.<locals>.<listcomp>
   r      r   c                 S   s   h | ]\}}|t |d fqS r[   round)r   id_val_r(   r(   r)   	<setcomp>  s    z5ReturningTest.test_insert_w_floats.<locals>.<setcomp>c                    s   h | ]	}|t  d fqS r   r   r   r   r   r(   r)   r     s    c                 S   s   h | ]}t |d qS r   r   )r   r   r(   r(   r)   r   
  s    r[   c                       h | ]}| fqS r(   r(   r   r   r(   r)   r     r   N)r
   r	   r   r   creater/   r>   r   rG   r   r   boolranger   scalarsr   r   set)r3   rA   r'   r   r_   r   Zdo_roundingr   tr   i_ranger(   r   r)   test_insert_w_floats  sN   /




z"ReturningTest.test_insert_w_floatsZnon_native_uuid)native_uuidZnon_native_uuid_str)Zas_uuidr   Zgeneric_native_uuidZgeneric_native_uuid_strr   ZLargeBinary1s   this is binaryZLargeBinary2s   7ztype_,valueZiaa)r   r   c           
   	      s   t d|tdtt ddtd|}|| || j|jj	|jj
t|d|r4 fddtd	D nd i}|rAtd
d}	ntd
d}	tt| fd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

        Zd_tr   Tr   r   r   c                    r   r   r(   r   r   r(   r)   r   `  r   z>ReturningTest.test_imv_returning_datatypes.<locals>.<listcomp>r   r   r   r   c                    r   r(   r(   r   r   r(   r)   r   m  r   z=ReturningTest.test_imv_returning_datatypes.<locals>.<setcomp>N)r
   r	   r   r   r   r/   r>   r   rG   r   r   r   r   r   r   r   r   )
r3   rA   r'   r   r_   r   r   r   r   r   r(   r   r)   test_imv_returning_datatypes  s8   5

z*ReturningTest.test_imv_returning_datatypesN)%rP   rQ   rR   Zrun_create_tablesrU   rT   r7   rV   r*   r   Zfetch_rows_post_commitr   r   r   r   Zinsert_executemany_returningr   r   combinationsr   requiresZ-float_or_double_precision_behaves_genericallyr   r   Zliteral_float_coercionr   r   r   r   uuiduuid4strZuuid_data_typer   r   r   r   r(   r(   r(   r)   r   _  s    



	



O




!r   )r   rW   r   )decimalr   r    r   r   Z
assertionsr   configr   Zschemar	   r
   r   r   r   r   r   r   r   r   r   typesr   r   r   Z
TablesTestr   rW   r   __all__r(   r(   r(   r)   <module>   s8   <    