o
    Šågˆ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)Ú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Údataé2   F©Úimplicit_returningÚ	manual_pk©r   Úautoincrement©r
   r	   r   r   ©ÚclsÚmetadata© r,   ú`/var/www/html/flaskapp/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   7çŸz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   <    