a
    •˜ëjˆI  ã                   @   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Údataé2   F©Zimplicit_returningÚ	manual_pk©r   Zautoincrement©r
   r	   r   r   ©ÚclsÚmetadata© r(   úc/mnt/bigstor/www/usecases/.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)Z	precisionZ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¡}	|r‚td
dƒ}
n
td
dƒ}
|rÞt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   7çŸz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¡}|r‚t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   <    