a
    [gI                     @   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(   r/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/sqlalchemy/testing/suite/test_insert.pydefine_tables'   s     
zLastrowidTest.define_tablesc                 C   s(   | |  }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;   s    z LastrowidTest._assert_round_tripc                 C   s.   | | jj tdd | | jj| d S Nr,   r   r.   tablesr   insertdictr6   r2   
connectionr(   r(   r)   test_autoincrement_on_insertE   s    z*LastrowidTest.test_autoincrement_on_insertc                 C   sB   | | jj tdd}|t| jjjj}t	|j
|f d S r7   r.   r:   r   r;   r<   scalarr   cr   r   inserted_primary_keyr2   r>   rpkr(   r(   r)   test_last_inserted_idK   s
    z#LastrowidTest.test_last_inserted_idc                 C   sD   | | jj tdd}|j}|t| jjjj	}t
|| d S r7   )r.   r:   r   r;   r<   	lastrowidrA   r   rB   r   r   )r2   r>   rE   rH   rF   r(   r(   r)   test_native_lastrowid_autoincR   s    z+LastrowidTest.test_native_lastrowid_autoincN)__name__
__module____qualname__run_deletes__backend____requires__classmethodr*   r6   r?   rG   r   Zdbapi_lastrowidrI   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| }|rFddiddiddiddiddig}nddi}|||}|jrdJ dS )z-test another INSERT issue found during #10453r   d1d2d3d4d5N)r:   rR   r;   r\   r.   returns_rows)r2   r>   rZ   r]   r3   stmtr   rE   r(   r(   r)   (test_no_results_for_non_returning_insert   s    z;InsertBehaviorTest.test_no_results_for_non_returning_insertc                 C   sR   | | jj tdd}|js$J |jr.J |js8J |jrN|	 d u sNJ d S r7   )
r.   r:   r   r;   r<   _soft_closedclosed	is_insertrc   fetchoner2   r>   rE   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r2J |js<J |j	sFJ t
| d  t
| dg d S )Nr,   r8   r   )r.   r:   r   r;   r\   r<   rf   rg   rh   rc   r   ri   keysrj   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;   rf   rg   r   whererB   r   r   lenallrj   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   rn   rj   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   data3r8   Nrv   rw   )r:   r"   r   r.   r;   r<   from_selectr   rB   r   ro   in_r   rC   order_byfetchallr2   r>   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 )Nr8   rv   rw   rx   )r:   r"   r   r.   r;   r{   r   rB   r   ro   r|   r   rC   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   rt   ru   r   rv   r   rw   rU   ))rt   ry   ry   rz   rz   )r:   r"   r.   r;   r<   inliner{   r   rB   r   r   ro   r|   r   r}   r~   r2   r>   r3   r(   r(   r)   test_insert_from_select  s,    


	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   rt   ru   r   rv   r   rw   rU   ))r   rt   rU      )r   rv   rU   r   )   rv   rU   r   )r   rw   rU   r   )   rw   rU   r   )r:   rS   r.   r;   r<   r   r{   r   rB   r   r   ro   r|   r   r}   r~   r   r(   r(   r)   %test_insert_from_select_with_defaults:  s,    


	z8InsertBehaviorTest.test_insert_from_select_with_defaultsN)rJ   rK   rL   rM   rN   rP   r*   r   	variationre   r   r   rk   insert_returningrm   Zempty_insertsrr   Zempty_inserts_executemanyrs   Zinsert_from_selectr   r   r   r   r(   r(   r(   r)   rQ   \   s.   
'






rQ   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   s(   | |  }t||jjdf d S r+   r-   r1   r(   r(   r)   r6   d  s    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   sT   | j j}|| |jjtdd}| d }|	t
|jj}t|| d S Nr,   r8   r   r:   r   r.   r;   	returningrB   r   r<   r/   rA   r   r   r2   r>   r3   rE   rF   Z
fetched_pkr(   r(   r)   %test_explicit_returning_pk_autocommity  s    z3ReturningTest.test_explicit_returning_pk_autocommitc                 C   sT   | j j}|| |jjtdd}| d }|	t
|jj}t|| d S r   r   r   r(   r(   r)   (test_explicit_returning_pk_no_autocommit  s    z6ReturningTest.test_explicit_returning_pk_no_autocommitc                 C   s.   | | jj tdd | | jj| d S r7   r9   r=   r(   r(   r)   /test_autoincrement_on_insert_implicit_returning  s    z=ReturningTest.test_autoincrement_on_insert_implicit_returningc                 C   sB   | | jj tdd}|t| jjjj}t	|j
|f d S r7   r@   rD   r(   r(   r)   (test_last_inserted_id_implicit_returning  s
    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   r^   r_   r`   ra   rb   )
r.   r:   r   r;   r   rB   r   rq   r   r   )r2   r>   rE   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|rh fddtd	D nd i}	|rtd
d}
n
td
d}
|rtdd |	D  fdd|
D  tdd |t|jj
D t dh n: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                    s   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 rU   round)r   id_val_r(   r(   r)   	<setcomp>  r   z5ReturningTest.test_insert_w_floats.<locals>.<setcomp>c                    s   h | ]}|t  d fqS r   r   r   r   r   r(   r)   r     r   c                 S   s   h | ]}t |d qS r   r   )r   r   r(   r(   r)   r   
  s   rU   c                    s   h | ]}| fqS r(   r(   r   r   r(   r)   r     r   N)r
   r	   r   r   creater.   r;   r   rB   r   r   boolranger   scalarsr   r   set)r2   r>   r'   r   rY   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|rh fddtd	D nd i}|rt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                    s   g | ]}d  iqS r   r(   r   r   r(   r)   r   `  r   z>ReturningTest.test_imv_returning_datatypes.<locals>.<listcomp>r   r   r   r   c                    s   h | ]}| fqS 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   rB   r   r   r   r   r   r   r   r   )
r2   r>   r'   r   rY   r   r   r   r   r   r(   r   r)   test_imv_returning_datatypes  s8    5

z*ReturningTest.test_imv_returning_datatypesN)%rJ   rK   rL   Zrun_create_tablesrO   rN   r6   rP   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   rQ   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   rQ   r   __all__r(   r(   r(   r)   <module>	   s6   <    