
    +h6                     T   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  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)text)utilc                   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     X/var/www/html/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   selfr1   rows      r"   test_via_attrzRowFetchTest.test_via_attr6   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   r5   r6   r   r7   r   _mappingr8   s      r"   test_via_stringzRowFetchTest.test_via_string>   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   r5   r6   r   r7   r   r8   s      r"   test_via_intzRowFetchTest.test_via_intF   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 r4   )r-   r.   r   r   r5   r6   r   r7   r   r=   r   r8   s      r"   test_via_col_objectz RowFetchTest.test_via_col_objectN   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   r6   r   labelr5   r   r7   r   keys)r9   r1   resultr:   s       r"   test_row_with_dupe_namesz%RowFetchTest.test_row_with_dupe_namesV   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   aliasr6   r   scalar_subqueryr   rD   r-   r7   r   rJ   r0   )r9   r1   	datetabless2r:   s         r"   test_row_w_scalar_selectz%RowFetchTest.test_row_w_scalar_selectb   s     KK))	9??3'))//0@@BIKKNNAGGK$89  $**,CMM8,,T1b"aCDr$   N)__name__
__module____qualname____backend__classmethodr#   r2   r;   r>   r@   rB   r   %duplicate_names_in_cursor_descriptionrG   rP    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	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)r9   r1   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 rc   rh   )r9   r1   r^   s      r"   test_executemany_roundtripz1PercentSchemaNamesTest.test_executemany_roundtrip   s{    11  "B$O	
 	  ";;;	
 	:&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,   )rd   re   rf   rg   re   rf   r]   rf   rg   ro   rp   r+   r,      ))r+   rq   )rd   rq   )rf   rq   )re   rq   )r.   r^   ra   rK   r   listr-   r   r5   r6   wherein_r7   r=   updatevalues)r9   connr^   ra   r_   r:   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)rQ   rR   rS   __doc____requires__rT   rU   r#   rk   rm   ri   rW   r$   r"   rY   rY   r   s4     -LK
 
	''4
r$   rY   c                      e Zd ZdZdZd Zd Z ej                  ddd e	d      dfdd e
d	      dfd
d e	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      fdd e	d      dfdd e	d      j                  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 y)Npsycopg2pymysqlzpymysql.cursors)aiomysqlasyncmymysqldbzMySQLdb.cursorsmariadbconnector)asyncpg	aiosqlitepg8000server_sideF)enginedialectdriverboolname
__import__cursorsSSCursor
isinstancer   bufferedgetattr)r9   cursorsscursors      r"   _is_server_sidez%ServerSideCursorsTest._is_server_side   s=    ;;%%3$$[[  ''94!"34<<EEHfh//[[  ''+BB%%%[[  ''94!"34<<EEHfh//[[  ''+==&&[[  ''+CC%%%[[  ''83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   )r9   r|   s     r"   _fixturezServerSideCursorsTest._fixture   s    **  &4424GH {{ "00.0CDDK {{ {{s   A33B)global_stringTselect 1Tglobal_textr   global_exprr&   global_off_explicitFstmt_optionstream_resultsstmt_option_disabledfor_update_exprfor_update_stringzSELECT 1 FOR UPDATEsqlite
text_no_ssz	select 42text_ss_optioniaaaz*engine_ss_arg, statement, cursor_ss_status)id_argnamesc                 T   | j                  |      }|j                         5 }t        |t        j                        r|j                  |      }n|j                  |      }t        | j                  |j                        |       |j                          d d d        y # 1 sw Y   y xY w)N)r   beginr   r   string_typesexec_driver_sqlr-   r   r   r   close)r9   engine_ss_arg	statementcursor_ss_statusr   rw   rF   s          r"   test_ss_cursor_statusz+ServerSideCursorsTest.test_ss_cursor_status  s    N }-\\^ 	t)T%6%67--i8i0$$V]]35EFLLN	 	 	s   A3BB'c                     | j                  d      }|j                         5 }|j                  d      j                  d      }| j	                  |j
                        sJ 	 d d d        y # 1 sw Y   y xY w)NFTr   r   )r   connectexecution_optionsr   r   r   )r9   r   rw   rF   s       r"   test_conn_optionz&ServerSideCursorsTest.test_conn_option<  sp    u%^^ 	7++# , oj)  ''666	7 	7 	7s   ?A++A4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   )r9   r   rN   rw   rF   s        r"   &test_stmt_enabled_conn_option_disabledz<ServerSideCursorsTest.test_stmt_enabled_conn_option_disabledF  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1rI   Tr   r&   )r   r   r   literal_columnrD   r   subqueryr   r-   r   r   r   select_from)r9   r   s1rw   rF   rO   s         r"   test_aliases_and_ssz)ServerSideCursorsTest.test_aliases_and_ssP  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      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   r   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   r5   r6   r   fetchallru   rs   rv   r   deletescalarr   countr   )r9   r!   mdr   r   r1   s         r"   test_roundtrip_fetchallz-ServerSideCursorsTest.test_roundtrip_fetchalld  s   ]]t$4d3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      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   r5   r6   r   r   	fetchmanyr   )r9   r!   r   r   r   r1   irF   s           r"   test_roundtrip_fetchmanyz.ServerSideCursorsTest.test_roundtrip_fetchmany  s   ]]t$4d3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*1A,F>F/+*F>F4#)F>F9F>*F>>GN)rQ   rR   rS   ry   rT   r   r   r   combinationsr   r   r   with_for_updateskip_ifr   r   r   r   r   r   rW   r$   r"   r{   r{      sP    ,LK," W1	d:.5	fQi.	tJ'7?1I''t'<		
 #1I''u'=		
 
D&)";";"=tD  !GOOH%	
 
ud;/7//t/D		
 =E#H
I#H
7;(&POr$   r{   )r0    r   r   
assertionsr   configr   schemar   r	   r   r   r   r   r   r   r   r   r   
TablesTestr   rY   TestBaseAssertsExecutionResultsr{   rW   r$   r"   <module>r      s        !           [E8&& [E|h
X00 h
VMOw66MOr$   