o
    hI                     @   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)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_keytest_needs_autoincrementdata2   Fimplicit_returning	manual_pkr   autoincrementr
   r	   r   r   clsmetadata r,   x/var/www/html/construction_image-detection-poc/venv/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   dialect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 Nr1   r!   r3   tablesr   insertdictr<   r8   
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?   r3   rB   r   rC   rD   scalarr   cr   r   inserted_primary_keyr8   rF   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?   )r3   rB   r   rC   rD   	lastrowidrK   r   rL   r   r   )r8   rF   rO   rS   rP   r,   r,   r-   test_native_lastrowid_autoincR   s   z+LastrowidTest.test_native_lastrowid_autoincN)__name__
__module____qualname__run_deletes__backend____requires__classmethodr.   r<   rG   rQ   r   dbapi_lastrowidrT   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)rB   r^   rC   rh   r3   returns_rows)r8   rF   rf   ri   r9   stmtr!   rO   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?   )
r3   rB   r   rC   rD   _soft_closedclosed	is_insertro   fetchoner8   rF   rO   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 )Nr1   r@   r   )r3   rB   r   rC   rh   rD   rr   rs   rt   ro   r   ru   keysrv   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   r3   rB   r   rC   rr   rs   r   whererL   r   r   lenallrv   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   rz   rv   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   )rB   r%   r   r3   rC   rD   from_selectr   rL   r!   r{   in_r   rM   order_byfetchallr8   rF   	src_table
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   )rB   r%   r   r3   rC   r   r   rL   r!   r{   r   r   rM   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   r   r   r   r   r   r   ra   ))r   r   r   r   r   )rB   r%   r3   rC   rD   inliner   r   rL   r   r!   r{   r   r   r   r   r8   rF   r9   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   r   r   r   r   r   r   ra   ))r   r   ra      )r   r   ra   r   )   r   ra   r   )r   r   ra   r   )   r   ra   r   )rB   r_   r3   rC   rD   r   r   r   rL   r   r!   r{   r   r   r   r   r   r,   r,   r-   %test_insert_from_select_with_defaults:  s2   


	z8InsertBehaviorTest.test_insert_from_select_with_defaultsN)rU   rV   rW   rX   rY   r[   r.   r   	variationrq   r   r   rw   insert_returningry   empty_insertsr~   empty_inserts_executemanyr   insert_from_selectr   r   r   r   r,   r,   r,   r-   r]   \   s0    
'






r]   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/   r0   r2   r7   r,   r,   r-   r<   d  r=   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 Nr1   r@   r   rB   r   r3   rC   	returningrL   r   rD   r4   rK   r   r   r8   rF   r9   rO   rP   
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   r>   r?   rA   rE   r,   r,   r-   /test_autoincrement_on_insert_implicit_returning  rH   z=ReturningTest.test_autoincrement_on_insert_implicit_returningc                 C   rI   r?   rJ   rN   r,   r,   r-   (test_last_inserted_id_implicit_returning  rR   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!   rj   rk   rl   rm   rn   )
r3   rB   r   rC   r   rL   r   r}   r   r   )r8   rF   rO   rallpksr,   r,   r-   test_insertmanyvalues_returning  s   
z-ReturningTest.test_insertmanyvalues_returninggxXM|Z!@5   g_Q!@r         F)	precisionscale	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

        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 ra   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    ra   c                       h | ]}| fqS r,   r,   r   r   r,   r-   r     r   N)r
   r	   r   r   creater3   rC   r   rL   r   r   boolranger   scalarsr   r   set)r8   rF   r+   r   re   r   do_roundingr   tr   i_ranger,   r   r-   test_insert_w_floats  sN   /




z"ReturningTest.test_insert_w_floats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           
   	      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

        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   r3   rC   r   rL   r   r   r   r   r   r   r   r   )
r8   rF   r+   r   re   r   r   r   r   r   r,   r   r-   test_imv_returning_datatypes  s8   5

z*ReturningTest.test_imv_returning_datatypesN)%rU   rV   rW   run_create_tablesrZ   rY   r<   r[   r.   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   r,   r,   r,   r-   r   _  s    



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