
    ؄_%                        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ej                  Z G d dej                  Z G d dej                  ZdZdS )   )config)engines)fixtures)eq_)requirements)Column)Table   )Integer)literal)literal_column)select)Stringc                   j    e Zd ZdZdZdZddiZed             Zd Z	d Z
d	 Zej        d
             ZdS )LastrowidTesteachT)implements_get_lastrowidautoincrement_insertimplicit_returningFc                    t          d|t          dt          dd          t          dt          d                               t          d|t          dt          dd	          t          dt          d                               d S )
N
autoinc_pkidTprimary_keytest_needs_autoincrementdata2   	manual_pkFr   autoincrementr	   r   r   r   clsmetadatas     i/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/sqlalchemy/testing/suite/test_insert.pydefine_tableszLastrowidTest.define_tables   s    g4$   66"::&&	
 	
 	
 	4d%HHH66"::&&		
 	
 	
 	
 	
    c                     |                     |                                                                          }t          |t          j        j        j        df           d S N	some dataexecuter   firstr   r   dbdialectdefault_sequence_baseselftableconnrows       r%   _assert_round_tripz LastrowidTest._assert_round_trip*   J    ll5<<>>**0022C&)#9;GHHHHHr'   c                     t           j                            | j        j                                        d           |                     | j        j        t           j                   d S Nr*   r   r   r.   r,   tablesr   insertr6   r2   s    r%   test_autoincrement_on_insertz*LastrowidTest.test_autoincrement_on_insert.   Q    	$+07799LLL 6	BBBBBr'   c                 .   t           j                            | j        j                                        d          }t           j                            t          | j        j        j        j	        g                    }t          |j        |g           d S r9   r   r.   r,   r<   r   r=   scalarr   cr   r   inserted_primary_keyr2   rpks      r%   test_last_inserted_idz#LastrowidTest.test_last_inserted_id3   |    IK"))+++  
 
 Yfdk&<&>&A%BCCDDA"RD)))))r'   c                 0   t           j                            | j        j                                        d          }|j        }t           j                            t          | j        j        j	        j
        g                    }t          ||           d S r9   )r   r.   r,   r<   r   r=   	lastrowidrC   r   rD   r   r   )r2   rG   rL   rH   s       r%   test_native_lastrowid_autoincz+LastrowidTest.test_native_lastrowid_autoinc?   s~    IK"))+++  
 
 K	Yfdk&<&>&A%BCCDDIrr'   N)__name__
__module____qualname__run_deletes__backend____requires____engine_options__classmethodr&   r6   r?   rI   r   dbapi_lastrowidrM    r'   r%   r   r      s        KKEL.6
 
 [
"I I IC C C
* * * !  "!  r'   r   c                       e Zd ZdZdZed             Zd Zej	        d             Z
ej        d             Zej        d             Zej        d             Zej        d	             Zej        d
             ZdS )InsertBehaviorTestr   Tc                 8   t          d|t          dt          dd          t          dt          d                               t          d|t          dt          dd	          t          dt          d                               t          d
|t          dt          dd          t          dt          d                    t          dt          d          t          dt          t	          dt                    t          d          z                        d S )Nr   r   Tr   r   r   r   Fr   includes_defaultsx   )defaulty2)type_r   )r	   r   r   r   r   r   r"   s     r%   r&   z InsertBehaviorTest.define_tablesM   s$   g4$   66"::&&	
 	
 	
 	4d%HHH66"::&&		
 	
 	
 	g4$   66"::&&3+++&s':::WQZZG  	
 	
 	
 	
 	
r'   c                 v   t           j        j        rt          j        ddi          }nt
          j        }|                                5 }|                    | j	        j
                                        d          }d d d            n# 1 swxY w Y   |j        sJ |j        rJ |j        sJ |j        rJ d S )Nr   F)optionsr*   r:   )r   	returningenabledr   testing_enginer   r.   beginr,   r<   r   r=   _soft_closedclosed	is_insertreturns_rows)r2   enginer4   rG   s       r%   test_autoclose_on_insertz+InsertBehaviorTest.test_autoclose_on_insertl   s   !) 	+-u5  FF YF\\^^ 	PtT[3::<<;OOA	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P~8{>!!!!!s   
4B

BBc                     t           j                            | j        j                                        d          }|j        sJ |j        rJ |j        sJ |j	        rJ d S r9   )
r   r.   r,   r<   r   r=   rh   ri   rj   rk   r2   rG   s     r%   +test_autoclose_on_insert_implicit_returningz>InsertBehaviorTest.test_autoclose_on_insert_implicit_returning{   st    IK"))+++  
 
 ~8{>!!!!!r'   c                    t           j                            | j        j                                                  }|j        sJ |j        rJ t           j                            | j        j                                        	                    | j        j        j
        j        d k                        }t          |                                          sJ d S )N)r   r.   r,   r<   r   r=   rh   ri   r   whererD   r   lenfetchallro   s     r%   test_empty_insertz$InsertBehaviorTest.test_empty_insert   s    Idk4;;==>>~8IK"))++11&(+t3 
 
 1::<<       r'   c                 4   | j         j        }| j         j        }t          j                            |                                t          dd          t          dd          t          dd          g           t          j                            |                                                    dt          |j
        j        g                              |j
        j                            ddg                                        }t          |j        d g           t          j                            t          |j
        j        g                              |j
        j                            }t          |                                d	d
g           d S )N   data1r   r   r   data2r
   data3r:   rz   r{   )r<   r   r   r   r.   r,   r=   dictfrom_selectr   rD   r   rr   in_r   rE   order_byrt   r2   	src_table
dest_tableresults       r%   test_insert_from_select_autoincz2InsertBehaviorTest.test_insert_from_select_autoinc   sh   K)	[+
	(((((((((	
 	
 	
 ""++	()**00K$(('7);<<  
 
 	F'$000""JL%&''001BCC
 
 	FOO
J788888r'   c                 l   | j         j        }| j         j        }t          j                            |                                                    dt          |j	        j
        g                              |j	        j
                            ddg                                        }t          |j        d g           t          j                            t          |j	        j
        g                              |j	        j
                            }t          |                                g            d S )Nr:   rz   r{   )r<   r   r   r   r.   r,   r=   r   r   rD   r   rr   r   r   rE   r   rt   r   s       r%   'test_insert_from_select_autoinc_no_rowsz:InsertBehaviorTest.test_insert_from_select_autoinc_no_rows   s   K)	[+
""++	()**00K$(('7);<<  
 
 	F'$000""JL%&''001BCC
 
 	FOOr"""""r'   c                    | j         j        }t          j                            |                                t          dd          t          dd          t          dd          g           t          j                            |                    d	                              dt          |j	        j
        d
z   |j	        j        g                              |j	        j                            ddg                                         t          t          j                            t          |j	        j        g                              |j	        j                                                            g d           d S )Nrw   rx   ry   r   rz   r
   r{   Tinliner]   ))rx   r|   r|   r}   r}   )r<   r   r   r.   r,   r=   r~   r   r   rD   r   r   rr   r   r   r   rt   r2   r3   s     r%   test_insert_from_selectz*InsertBehaviorTest.test_insert_from_select   sT   %	LLNN(((((((((	
 	
 	
 		LLL%%11
Q566<<GL$$gw%788  	
 	
 	
 	I~&&//== hjjHHH		
 	
 	
 	
 	
r'   c                    | j         j        }t          j                            |                                t          dd          t          dd          t          dd          g           t          j                            |                    d	                              dt          |j	        j
        d
z   |j	        j        g                              |j	        j                            ddg                                         t          t          j                            t          |g                              |j	        j        |j	        j
                                                            g d           d S )Nrw   rx   ry   r   rz   r
   r{   Tr   r]   ))rw   rx   r]      )r   rz   r]   r   )   rz   r]   r   )r
   r{   r]   r   )   r{   r]   r   )r<   r[   r   r.   r,   r=   r~   r   r   rD   r   r   rr   r   r   r   rt   r   s     r%   %test_insert_from_select_with_defaultsz8InsertBehaviorTest.test_insert_from_select_with_defaults   sZ   -	LLNN(((((((((	
 	
 	
 		LLL%%11
Q566<<GL$$gw%788  	
 	
 	
 	Iw((uwzBB hjj  		
 	
 	
 	
 	
r'   N)rN   rO   rP   rQ   rR   rU   r&   rm   r   rd   rp   empty_insertsru   insert_from_selectr   r   r   r   rW   r'   r%   rY   rY   I   s        KK
 
 [
<" " " " " " ! !  ! $9 9 %$98 $# # %$#( $
 
 %$
6 $
 
 %$
 
 
r'   rY   c                   p    e Zd ZdZdZdZddiZd Zed             Z	e
j        d             Zd Zd	 Zd
 ZdS )ReturningTestr   )rd   r   Tr   c                     |                     |                                                                          }t          |t          j        j        j        df           d S r)   r+   r1   s       r%   r6   z ReturningTest._assert_round_trip  r7   r'   c                     t          d|t          dt          dd          t          dt          d                               d S )Nr   r   Tr   r   r   r!   r"   s     r%   r&   zReturningTest.define_tables  sT    g4$   66"::&&	
 	
 	
 	
 	
r'   c                    t           j        }| j        j        }|                                5 }|                    |                                                    |j        j	                  d          }d d d            n# 1 swxY w Y   |
                                d         }t           j                            t          |j        j	        g                    }t          ||           d S Nr*   r:       r   r.   r<   r   rg   r,   r=   rd   rD   r   r-   rC   r   r   r2   rl   r3   r4   rG   rH   
fetched_pks          r%   %test_explicit_returning_pk_autocommitz3ReturningTest.test_explicit_returning_pk_autocommit  s    &\\^^ 	t((44;   A	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 WWYYq\Y%%fegj\&:&:;;
Js   AB  BBc                    t           j        }| j        j        }|                                5 }|                    |                                                    |j        j	                  d          }|
                                d         }d d d            n# 1 swxY w Y   t           j                            t          |j        j	        g                    }t          ||           d S r   r   r   s          r%   (test_explicit_returning_pk_no_autocommitz6ReturningTest.test_explicit_returning_pk_no_autocommit&  s    &\\^^ 	t((44;   A 1B		 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 Y%%fegj\&:&:;;
Js   A!BB!Bc                     t           j                            | j        j                                        d           |                     | j        j        t           j                   d S r9   r;   r>   s    r%   /test_autoincrement_on_insert_implicit_returningz=ReturningTest.test_autoincrement_on_insert_implicit_returning1  r@   r'   c                 .   t           j                            | j        j                                        d          }t           j                            t          | j        j        j        j	        g                    }t          |j        |g           d S r9   rB   rF   s      r%   (test_last_inserted_id_implicit_returningz6ReturningTest.test_last_inserted_id_implicit_returning6  rJ   r'   N)rN   rO   rP   run_create_tablesrS   rR   rT   r6   rU   r&   r   fetch_rows_post_commitr   r   r   r   rW   r'   r%   r   r     s        6LK.5I I I 
 
 [
 (	 	 )(		 	 	C C C
* * * * *r'   r   )r   rY   r   N) r   r   r   
assertionsr   r   schemar   r	   r   r   r   r   r   
TablesTestr   rY   r   __all__rW   r'   r%   <module>r      s{                           ! ! ! ! ! !                                          7 7 7 7 7H' 7 7 7tx
 x
 x
 x
 x
, x
 x
 x
v8* 8* 8* 8* 8*H' 8* 8* 8*v Cr'   