
    gB                     P   d dl 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  G d dej(                        Z G d dej(                        Z G d dej.                  ej0                        Zy)    N   )engines)fixtures)eq_)requirements)Column)Table   )DateTime)func)Integer)select)sql)String)testingtextc                   r    e Zd ZdZed        Zed        Zd Zd Zd Z	d Z
ej                  d        Zd	 Zy
)RowFetchTestTc                     t        d|t        dt        d      t        dt        d                   t        d|t        dt        d      t        dt                     y )	Nplain_pkidT)primary_keydata2   	has_datestoday)r	   r   r   r   r   clsmetadatas     d/var/www/html/AdoubleTech/venv/lib/python3.12/site-packages/sqlalchemy/testing/suite/test_results.pydefine_tableszRowFetchTest.define_tables   sP    4d366":&		
 	4d37H%		
    c                 $   |j                  | j                  j                  j                         dddddddddg       |j                  | j                  j                  j                         dt        j
                  dd	d
d
dd      dg       y )N   d1)r   r   r   d2r
   d3        r   )r   r   )executetablesr   insertr   datetime)r   
connections     r!   insert_datazRowFetchTest.insert_data.   s    JJ&&($'$'$'	
 	JJ  '') 1 1$2r1a HIJ	
r#   c                 L   |j                  | j                  j                  j                         j	                  | j                  j                  j
                  j                              j                         }t        |j                  d       t        |j                  d       y Nr%   r&   )
r,   r-   r   r   order_bycr   firstr   r   selfr0   rows      r!   test_via_attrzRowFetchTest.test_via_attr>   sp      KK  '')224;;3G3G3I3I3L3LM

%' 	 	CFFACHHdr#   c                 X   |j                  | j                  j                  j                         j	                  | j                  j                  j
                  j                              j                         }t        |j                  d   d       t        |j                  d   d       y )Nr   r%   r   r&   )
r,   r-   r   r   r4   r5   r   r6   r   _mappingr7   s      r!   test_via_stringzRowFetchTest.test_via_stringF   s{      KK  '')224;;3G3G3I3I3L3LM

%' 	 	CLL"CLL $'r#   c                 0   |j                  | j                  j                  j                         j	                  | j                  j                  j
                  j                              j                         }t        |d   d       t        |d   d       y )Nr   r%   r&   )	r,   r-   r   r   r4   r5   r   r6   r   r7   s      r!   test_via_intzRowFetchTest.test_via_intN   sp      KK  '')224;;3G3G3I3I3L3LM

%' 	 	CFACFDr#   c                    |j                  | j                  j                  j                         j	                  | j                  j                  j
                  j                              j                         }t        |j                  | j                  j                  j
                  j                     d       t        |j                  | j                  j                  j
                  j                     d       y r3   )r,   r-   r   r   r4   r5   r   r6   r   r<   r   r7   s      r!   test_via_col_objectz RowFetchTest.test_via_col_objectV   s      KK  '')224;;3G3G3I3I3L3LM

%' 	 	CLL--//223Q7CLL--//445t<r#   c                    |j                  t        | j                  j                  j                  j
                  | j                  j                  j                  j
                  j                  d            j                  | j                  j                  j                  j                              }|j                         }t        |j                         ddg       t        |d       y )Nr   )r&   r&   )r,   r   r-   r   r5   r   labelr4   r   r6   r   keys)r8   r0   resultr9   s       r!   test_row_with_dupe_namesz%RowFetchTest.test_row_with_dupe_names^   s    ##$$&&++$$&&++11&9 ht{{++--001	
 llnFKKMFF+,Cr#   c                    | j                   j                  }t        |j                  d      j                  j
                        j                         }t        |j                  j                  |j                  d            }|j                  |      j                         }t        |j                  t        j                  dddddd             y)ztest that a scalar select as a column is returned as such
        and that type conversion works OK.

        (this is half a SQLAlchemy Core test and half to catch database
        backends that may have unusual behavior with scalar selects.)

        x	somelabelr)   r*   r+   r   N)r-   r   r   aliasr5   r   scalar_subqueryr   rC   r,   r6   r   rI   r/   )r8   r0   	datetabless2r9   s         r!   test_row_w_scalar_selectz%RowFetchTest.test_row_w_scalar_selectj   s     KK))	9??3'))//0@@BIKKNNAGGK$89  $**,CMM8,,T1b"aCDr#   N)__name__
__module____qualname____backend__classmethodr"   r1   r:   r=   r?   rA   r   %duplicate_names_in_cursor_descriptionrF   rO    r#   r!   r   r      sa    K
 
 
 
(= 77	 8	Er#   r   c                   ^    e Zd ZdZdZdZed        Zd Zd Z	e
j                  d        Zd Zy	)
PercentSchemaNamesTestztests using percent signs, spaces in table and column names.

    This didn't work for PostgreSQL / MySQL drivers for a long time
    but is now supported.

    )percent_schema_namesTc           	         t        d|t        dt              t        dt                    | j                  _        t        j                  dt        j                  d      t        j                  d            | j                  _        y )Nzpercent%tablepercent%spaces % more spaces)	r	   r   r   r-   percent_tabler   tablecolumnlightweight_percent_tabler   s     r!   r"   z$PercentSchemaNamesTest.define_tables   sa    #(:w')73	$


  03yyJJz"JJ-.0


,r#   c                     | j                   j                  }ddddddddddddfD ]"  }|j                  |j                         |       $ | j	                  |       y Nr*   r+   r[   r\         	   
   r-   r]   r,   r.   _assert_table)r8   r0   r]   paramss       r!   test_single_roundtripz,PercentSchemaNamesTest.test_single_roundtrip   sm    11B7B7B7Q7	
 	?F }335v>	? 	:&r#   c                     | j                   j                  }|j                  |j                         ddd       |j                  |j                         dddddddddg       | j	                  |       y rb   rh   )r8   r0   r]   s      r!   test_executemany_roundtripz1PercentSchemaNamesTest.test_executemany_roundtrip   s{    11  "B$O	
 	  ";;;	
 	:&r#   c                 |   | j                   j                  }|j                  |j                         ddd       |j                  |j                         j	                  |j
                  d   |j
                  d         ddddd	ddddg      }t        |j                         g d
       | j                  |       y )Nr*   r+   rc   r[   r\   rd   re   rf   rg   )rd   re   rf   rg   re   rf   )	r-   r]   r,   r.   	returningr5   r   allri   )r8   r0   r]   rE   s       r!   $test_executemany_returning_roundtripz;PercentSchemaNamesTest.test_executemany_returning_roundtrip   s    11  "B$O	
 ##  ",,
+ 67
 ;;;

 	FJJL56:&r#   c                    | j                   j                  }| j                   j                  }||j                         ||j                         fD ]  }t	        t        |j                  |j                         j                  |j                  d                     g d       t	        t        |j                  |j                         j                  |j                  d   j                  ddg            j                  |j                  d                     ddg       |j                  |j                         j                  |j                  d               j                         }t	        |j                  d   d       t	        |j                  d   d	       t	        |j                  |j                  d      d       t	        |j                  |j                  d      d	        |j                  |j                         j                  |j                  d   d
i             t	        t        |j                  |j                         j                  |j                  d                     g d       y )Nr[   ))r*   r+   ro   rp   rq   r\   rf   rg   rp   rq   r*   r+      ))r*   rv   )rd   rv   )rf   rv   )re   rv   )r-   r]   r`   rJ   r   listr,   r   r4   r5   wherein_r6   r<   updatevalues)r8   connr]   r`   r^   r9   s         r!   ri   z$PercentSchemaNamesTest._assert_table   s   11$(KK$I$I! !%%++-	
 	CE LL!8!89L!MN 5	 LLuww'=>BBAr7KL!%''*"56 '"	 ,,''
(;<eg  Z(!,34b9UWWZ0115UWW%;<=rB?	CB 	  "))!78"=	
 	!((*33%
3 2		
r#   N)rP   rQ   rR   __doc____requires__rS   rT   r"   rk   rm   r   insert_executemany_returningrt   ri   rV   r#   r!   rX   rX   z   sN     -LK
 
	'' ..' /'&4
r#   rX   c                      e Zd ZdZdZd Zd Zd Z ej                  ddd dfddd	 dfd
d e
d      dfddd dfdd e
d      j                  d      dfdd e
d      j                  d      dfdd e
d      j                         dfddd d ej                  ddg      fddd dfddd dfdd      d        Zd Zd  Zd! Zd" Zd# Zy$)%ServerSideCursorsTest)server_side_cursorsTc                    | j                   j                  j                  dk(  rt        |j                        S | j                   j                  j                  dk(  r+t        d      j                  j                  }t        ||      S | j                   j                  j                  dv r|j                  S | j                   j                  j                  dk(  r+t        d      j                  j                  }t        ||      S | j                   j                  j                  dk(  r|j                   S | j                   j                  j                  dv r|j                  S | j                   j                  j                  d	k(  rt        |d
d      S | j                   j                  j                  dk(  rt        t        |dd            S | j                   j                  j                  dk(  rt        |d
d      S y)Npsycopg2pymysqlzpymysql.cursors)aiomysqlasyncmyaioodbcmysqldbzMySQLdb.cursorsmariadbconnector)asyncpg	aiosqlitepg8000server_sideFpsycopgnameoracledb)enginedialectdriverboolr   
__import__cursorsSSCursor
isinstancer   bufferedgetattr)r8   cursorsscursors      r!   _is_server_sidez%ServerSideCursorsTest._is_server_side   s    ;;%%3$$[[  ''94!"34<<EEHfh//[[  ''+MM%%%[[  ''94!"34<<EEHfh//[[  ''+==&&[[  ''+CC%%%[[  ''836=%88[[  ''94677[[  '':56=%88r#   c                    |rGt        j                  d      5  t        j                  d|i      | _        d d d        | j                  S t        j                  d|i      | _        | j                  S # 1 sw Y   | j                  S xY w)NzThe create_engine.server_side_cursors parameter is deprecated and will be removed in a future release.  Please use the Connection.execution_options.stream_results parameter.r   )options)r   expect_deprecatedr   testing_enginer   )r8   r   s     r!   _fixturezServerSideCursorsTest._fixture  s    **  &4424GH {{ "00.0CDDK {{ {{s   A33Bc                 l    t        j                  dt         j                        j                  d |      S )NzSELECT (\d+)c           	          t        t        t        | j                  d                  j	                  t
        j                              S )Nr%   )strr   intgroupcompiler   db)ms    r!   <lambda>z1ServerSideCursorsTest.stringify.<locals>.<lambda>-  s+    c&QWWQZ199'**EF r#   )rer   Isub)r8   str_s     r!   	stringifyzServerSideCursorsTest.stringify+  s)    zz/244044F
 	
r#   global_stringc                      | d      S Nselect 1rV   r   s    r!   r   zServerSideCursorsTest.<lambda>1  s    )J2G r#   global_textc                 $    t         | d            S r   r   r   s    r!   r   zServerSideCursorsTest.<lambda>5      d9Z#89 r#   global_exprr%   global_off_explicitFc                 $    t         | d            S r   r   r   s    r!   r   zServerSideCursorsTest.<lambda><  r   r#   stmt_optionstream_resultsstmt_option_disabledfor_update_exprfor_update_stringc                      | d      S )NzSELECT 1 FOR UPDATErV   r   s    r!   r   zServerSideCursorsTest.<lambda>P  s    i(=> r#   sqlitemssql
text_no_ssc                 $    t         | d            S )N	select 42r   r   s    r!   r   zServerSideCursorsTest.<lambda>W  s    d9[#9: r#   text_ss_optionc                 D    t         | d            j                  d      S )Nr   Tr   )r   execution_optionsr   s    r!   r   zServerSideCursorsTest.<lambda>]  s$    d9[#9:LL# M  r#   iaaaz*engine_ss_arg, statement, cursor_ss_status)id_argnamesc                    | j                  |      }|j                         5 }t        |      r!t        j                  || j
                        }t        |t              r|j                  |      }n|j                  |      }t        | j                  |j                        |       |j                          d d d        y # 1 sw Y   y xY w)Nr   )r   begincallabler   resolve_lambdar   r   r   exec_driver_sqlr,   r   r   r   close)r8   engine_ss_arg	statementcursor_ss_statusr   r|   rE   s          r!   test_ss_cursor_statusz+ServerSideCursorsTest.test_ss_cursor_status0  s    p }-\\^ 	t	"#22	 )S)--i8i0$$V]]35EFLLN	 	 	s   BC  C	c                 *   | j                  d      }|j                         5 }|j                  d      j                  | j	                  d            }| j                  |j                        sJ |j                          d d d        y # 1 sw Y   y xY w)NFTr   r   )r   connectr   r   r   r   r   r   )r8   r   r|   rE   s       r!   test_conn_optionz&ServerSideCursorsTest.test_conn_optionv  s    u%^^ 	++# , odnnZ89  ''666 LLN'	 	 	s   AB		Bc                 $   | j                  d      }t        d      j                  d      }|j                         5 }|j                  d      j	                  |      }| j                  |j                        rJ 	 d d d        y # 1 sw Y   y xY w)NFr%   Tr   )r   r   r   r   r,   r   r   )r8   r   rM   r|   rE   s        r!   &test_stmt_enabled_conn_option_disabledz<ServerSideCursorsTest.test_stmt_enabled_conn_option_disabled  s    u%1I''t'<^^ 	;++5+AII!LF++FMM::::	; 	; 	;s   ?BBc                    | j                  d      }t        t        j                  d      j	                  d            j                  d      j                         }|j                         5 }|j                  |j                               }| j                  |j                        rJ |j                          d d d        t        d      j                  |      }|j                         5 }|j                  |      }| j                  |j                        rJ |j                          d d d        y # 1 sw Y   {xY w# 1 sw Y   y xY w)NF1rH   Tr   r%   )r   r   r   literal_columnrC   r   subqueryr   r,   r   r   r   select_from)r8   r   s1r|   rE   rN   s         r!   test_aliases_and_ssz)ServerSideCursorsTest.test_aliases_and_ss  s	   u%3%%c*0056d3XZ 	 \\^ 	t\\"))+.F++FMM:::LLN	
 AY""2&\\^ 	t\\"%F++FMM:::LLN	 		 		 	s   -AD4,?E 4D= E	c                    | j                   }| j                  d      }t        d|t        dt        dd      t        dt        d                  }|j                         5 }|j                  |d       |j                  |j                         t        d	             |j                  |j                         t        d
	             t        |j                  |j                         j                  |j                  j                              j!                         ddg       |j                  |j#                         j%                  |j                  j                  dk(        j'                  |j                  j(                  dz   	             t        |j                  |j                         j                  |j                  j                              j!                         ddg       |j                  |j+                                t        |j-                  t        t/        j0                  d            j3                  |            d       d d d        y # 1 sw Y   y xY w)NT
test_tabler   r   test_needs_autoincrementr   r   
checkfirstdata1r   data2)r%   r   )r   r   r   z updated)r   zdata2 updated*r   )r    r   r	   r   r   r   r   creater,   r.   dictr   r   r4   r5   r   fetchallrz   rx   r{   r   deletescalarr   countr   )r8   r    mdr   r   r0   s         r!   test_roundtrip_fetchallz-ServerSideCursorsTest.test_roundtrip_fetchall  s   ]]t$g4$ 66":&

 \\^ 	zjT:z002Dg4FGz002Dg4FG""%%'00A(*|,	 !!#z||!+,Z\\..;<
 ""%%'00A(*34	 z0023!!4::c?+77
C 	-	 	 	s    G1II#c                    | j                   }| j                  d      }t        d|t        dt        dd      t        dt        d                  }|j                         5 }|j                  |d       |j                  |j                         t        dd	      D cg c]  }t        d
|z         c}       |j                  |j                         j                  |j                  j                              }t!        |j#                  d      t        dd      D cg c]	  }|d
|z  f c}       t!        |j#                  d      t        dd      D cg c]	  }|d
|z  f c}       t!        |j%                         t        dd	      D cg c]	  }|d
|z  f c}       d d d        y c c}w c c}w c c}w c c}w # 1 sw Y   y xY w)NTr   r   r   r   r   r   r%      zdata%dr   r*      rg      )r    r   r	   r   r   r   r   r   r,   r.   ranger   r   r4   r5   r   r   	fetchmanyr   )r8   r    r   r   r   r0   irE   s           r!   test_roundtrip_fetchmanyz.ServerSideCursorsTest.test_roundtrip_fetchmany  s   ]]t$g4$ 66":&

 \\^ 	OzjT:!!#272,?Q8a<(?
  ''!!#,,Z\\__=F   #,1!QK8q!X\"8   $,1!RL9q!X\"9 !uR}#M!Q1$5#MN'	O 	O @ 9 :#M'	O 	OsC    <F?F+2A,F?F0,*F?F5$)F?F:F?+F??GN)rP   rQ   rR   r~   rS   r   r   r   r   combinationsr   r   with_for_updateskip_ifr   r   r   r   r   r   rV   r#   r!   r   r      s[    ,LK4"

 W	$ GN9		
 
fQi.!9		
 1I''t'<		
 #1I''u'=		
 
D&)";";"=tD  >GOOXw/0	
 :		
  	
 =g4jk4j"0;((T Or#   r   )r/   r    r   r   
assertionsr   configr   schemar   r	   r   r   r   r   r   r   r   r   
TablesTestr   rX   TestBaseAssertsExecutionResultsr   rV   r#   r!   <module>r	     s     	    !          [E8&& [E||
X00 |
~}Ow66}Or#   