
    ,h*             	         % S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSKJ!r!  SSK"J#r#  SSK"J$r$  SSK"J!r%  SS K&J'r'  SS!K(J)r)  SS"K(J*r*  SS#K(J+r+  SS$K(J,r,  SS%K(J-r-  SS&K.J/r/  SS'K!J0r0  SS(K1J2r2  SS)K1J3r3  \R&                  (       aN  SS*K4J5r5  SS+K6J7r7  SS,K8J9r9  SS-K8J:r:  SS.K8J;r;  SS/K8J<r<  SS0KJ=r=  SS1KJ>r>  SS2KJ?r?  SS3KJ@r@  SS4KJArA  SS5KJBrB  SS6K.JCrC  \" S7\S89rDSrES9\FS:'    SrGS;\FS<'    SrHS=\FS>'    S?rIS@\FSA'    SBrJSC\FSD'    SErKSF\FSG'    SHrLSI\FSJ'    \\\M   \M\\   \N\N\SK   \\N   4   rO\SL\O4   rP\\M\M\\   \N\N\SK   \N4   rQ " SM SN\5      rR " SO SP5      rS " SQ SR\S5      rT " SS ST\T5      rU\U" 5       rV " SU SV\T5      rW\W" 5       rX " SW SX\S5      rY\Y" 5       rZ " SY SZ\Y5      r[ " S[ S\\Y5      r\ " S] S^\5      r]\]" 5       r^SbS_ jr_ " S` Sa\\D   5      r`\`rag)czNDefine cursor-specific result set constructs including
:class:`.CursorResult`.    )annotationsN)Any)cast)ClassVar)Dict)Iterable)Iterator)List)Mapping)NoReturn)Optional)Sequence)Tuple)TYPE_CHECKING)TypeVar)Union   )IteratorResult)MergedResult)Result)ResultMetaData)SimpleResultMetaData)tuplegetter)Row   )exc)util)elements)sqltypes)_generative)ResultColumnsEntry)RM_NAME)
RM_OBJECTS)RM_RENDERED_NAME)RM_TYPE)
TypeEngine)compat)Literal)Self)
Connection)DefaultExecutionContext)_DBAPICursorDescription)DBAPICursor)Dialect)ExecutionContext)_KeyIndexType)_KeyMapRecType)_KeyMapType)_KeyType)_ProcessorsType)_TupleGetterType)_ResultProcessorType_T)boundz
Literal[0]MD_INDEXz
Literal[1]MD_RESULT_MAP_INDEXz
Literal[2]
MD_OBJECTS   z
Literal[3]MD_LOOKUP_KEY   z
Literal[4]MD_RENDERED_NAME   z
Literal[5]MD_PROCESSOR   z
Literal[6]MD_UNTRANSLATEDz_ResultProcessorType[Any]r3   c                     \ rS rSr% SrSrS\S'   S\S'   S\S	'   S
\S'   S
\S'   S\S'   SrS\S'   S)S jrS*S jr	                  S+S jr
S,S jr    S-S jrS.S jrS/S jr    S0S jrS rS rS rS r\ S1     S2S jj5       rS r\(       d   S3       S4S  jjrS! rS3S5S" jjrS# r    S6S$ jrS% rS& rS'rg()7CursorResultMetaData   z"Result metadata for DBAPI cursors.)	_keymap_processors_keys_keymap_by_result_column_idx_tuplefilter_translated_indexes_safe_for_cache
_unpickled_key_to_index_CursorKeyMapTyperG   r4   rH   z#Optional[Dict[int, _KeyMapRecType]]rJ   boolrN   rM   Optional[List[int]]rL   TzClassVar[bool]returns_rowsc                    XR                   ;   $ N)rG   selfkeys     P/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/engine/cursor.py_has_keyCursorResultMetaData._has_key   s    ll""    c                    [        U R                  U R                   Vs/ s H  oR                  U   [           PM     snS9$ s  snf )N)extra)r   rI   rG   r;   rV   s     rY   _for_freeze CursorResultMetaData._for_freeze   s;    #JJ<@JJGJS<<$Z0JG
 	
Gs   A
c                   U R                   R                  U R                   5      n	Xl        X)l        X9l        XIl        XYl        Xil        Xyl        Xl	        U R                  U[        5      U	l        U	$ rU   )	__class____new__rN   rH   rI   rG   rK   rL   rM   rJ   _make_key_to_indexr9   rO   )
rW   	unpickled
processorskeyskeymaptuplefiltertranslated_indexessafe_for_cachekeymap_by_result_column_idxnew_objs
             rY   _make_new_metadata'CursorResultMetaData._make_new_metadata   sd     ..((8&( *&8#"0/J, $ 7 7 Ir\   c                P   U R                   (       a   eU R                  U R                  S /[        U R                  5      -  S S U R
                  R                  5        VVs0 s H  u  pXSS S-   USS  -   _M     snnU R                  U R                  U R                  S9$ s  snnf )Nr   r@   rU   rB   )re   rf   ri   rj   rh   rg   rk   rl   )
rK   rn   rN   lenrH   rG   itemsrI   rM   rJ   )rW   rX   values      rY   _remove_processors'CursorResultMetaData._remove_processors   s    $$$$&&oovD$4$4 55# #',,"4"4"6"6JC 1QZ')E!"I55"6 //(,(I(I ' 
 	

s   !B"c                P   U R                   (       a   e[        U R                  5      n[        U R                  5      nUR                  UR                  R                  5        VVs0 s H)  u  pEUUS   b  XB;  a  US   U-   OS US   U-   /USS  Q7_M+     snn5        U R                  U R                  U R                  UR                  -   S S U R                  UR                  -   UU R                  UR                  5        Vs0 s H  nU[           U_M     snS9$ s  snnf s  snf )Nr   r   r   )re   rf   ri   rj   rg   rh   rk   rl   )rK   dictrG   rq   rI   updaterr   rn   rN   rH   rM   valuesr:   )rW   otherrh   offsetrX   rs   metadata_entrys          rY   _splice_horizontally)CursorResultMetaData._splice_horizontally   sA    $$$$dll#TZZ #(--"5"5"7 #8JC  !8/C4E a6)!!Hv%	 12Y	 	 #8	
 &&oo''%*;*;;#ekk)// '-mmo)&5N 23^C&5) ' 
 	
,)s   &0D
D#c                b   [        U R                  U5      5      nU Vs/ s H  o3[           PM     nnU Vs/ s H  o3[           PM     nnU R                  (       a  U Vs/ s H  o`R                  U   PM     nn[        U6 n[        U5       VVs/ s H  u  pU4USS  -   PM     n	nnU	 Vs0 s H  o3[           U_M     n
nU
R                  S U	 5       5        U R                  U R                  U R                  UUUU
U R                  U R                  S9$ s  snf s  snf s  snf s  snnf s  snf )Nr   c              3  \   #    U  H"  nU[            =(       d    S   H  nX!4v   M
     M$     g7f) N)r;   ).0new_reces      rY   	<genexpr>/CursorResultMetaData._reduce.<locals>.<genexpr>  s3      
#Z(.B. L. #s   *,)re   rf   rg   ri   rj   rh   rk   rl   )list_metadata_for_keysr9   r=   rL   r   	enumeraterx   rn   rN   rH   rM   rJ   )rW   rg   recsrecindexesnew_keysidxtupindexnew_recsrh   s              rY   _reduceCursorResultMetaData._reduce   s.   D++D12,01DSx=D1=ABTc=1TB##@GH//4GH7#9B4I:5UHs12w&I5=>Xcm$c)X> 	 
#
 	
 &&oo''&//(,(I(I ' 	
 		
% 2B II>s   DD D!D&,D,c                   UR                   (       a  UR                   R                  (       d  U $ UR                   R                  nUR                  n[        (       a!  [        U[        R                  5      (       d   eX#L a  U $ Uc   eU R                  nUc9  U R                  R                  5        Vs0 s H  nU[           U_M     sn=o@l        U R                  (       a   eU R                  [        R                  " U R                  [!        UR"                  5       VVs0 s H  u  pgXd;   d  M  XtU   _M     snn5      U R$                  U R&                  SSU R(                  U R*                  U R                  S9$ s  snf s  snnf )a3  When using a cached Compiled construct that has a _result_map,
for a new statement that used the cached Compiled, we need to ensure
the keymap has the Column objects from our new statement as keys.
So here we rewrite keymap with new entries for the new columns
as matched to those of the cached statement.

N)rh   re   rf   ri   rj   rg   rk   rl   )compiled_result_columns	statementinvoked_statementr   
isinstancer   ClauseElementrJ   rG   ry   r:   rK   rn   r'   
dict_unionr   _all_selected_columnsrN   rH   rI   rM   )rW   contextcompiled_statementr   keymap_by_positionr|   r   news           rY   _adapt_to_context&CursorResultMetaData._adapt_to_context  s    w'7'7'G'GK$--77#55=/1G1GHHHH2K ,,, ">>%
 '+ll&9&9&;F&;N 23^C&;F !B
 $$$$&&$$ %.)??%% 0	 1CC00%	 oo''#//(,(I(I# ' 
 	
Fs   3E<!F0	Fc                   UR                   nS U l        S U l        S=U l        U l        UR
                  (       a  UR
                  u  nnnnn[        U5      n	OS=n=n=n	=n=nnU R                  UUUU	UUUU5      n
U
 Vs/ s H  o[           PM     snU l	        S U l
        U	(       GaZ  U
 Vs0 s H  nU[           U_M     nn[        U5      U	:w  a  0 n[        5       nU
 HY  nU[           4U[           =(       d    S-    H5  nU[           nUR!                  UU5      U:w  d  M$  UR#                  U5        M7     M[     U
 VVs0 s H/  nU[           (       d  M  U[             H  nUU;  d  M  UU_M     M1     snnU l        UR'                  U Vs0 s H  nUS S / XS S 4_M     sn5        O<U
 VVs0 s H'  nU[           (       d  M  U[             H  nUU_M     M)     snnU l        U R$                  R'                  U5        O U
 Vs0 s H  nU[           U_M     snU l        U	(       di  UR(                  (       aX  U R$                  R'                  U
 Vs0 s H1  nU[*           (       d  M  U[*           U R$                  U[              _M3     sn5        U R-                  U R$                  [        5      U l        g s  snf s  snf s  snnf s  snf s  snnf s  snf s  snf )NFr   )r   rK   rL   rM   rN   result_column_structrq   _merge_cursor_descriptionrA   rH   rJ   r=   setr?   r;   r9   
setdefaultaddrG   rx   _translate_colnamerC   rd   rO   )rW   parentcursor_descriptionr   result_columnscols_are_orderedtextual_orderedad_hoc_textualloose_column_name_matchingnum_ctx_colsrawr|   by_keyindex_by_keydupesrX   r   obj_elems                     rY   __init__CursorResultMetaData.__init__\  sM   
 .. #' 166t'' ,, *~.L 	N - !;
 ,,&	
 @C
?B^<(s
 -1)
  '*&)N }-~=&)  
 6{l* 02&)N ./? @B&z28b  -X6 (223<C!IIcN  '* +. *-%j1  %3:$>u,	 -Hn, %? *-   $)#(C dD"cdCC#( +. *-%j1  %3:$> n, %? *-  LL'
 '*&)N }-~=&)DL  : :LL
 +.	 +.%o6	N?3T\\&}56  +.	 "44T\\8LU
D  sB    J9-J>KK-KK	0KKKK*"Kc	                   U(       a  U(       a  U(       d  U[        U5      :X  a  U V	s/ s H  oS   PM	     sn	U l        SU l        [        U5       V
Vs/ s HG  u  pU
U
U[           U[
           U[           UR                  U[           U[           X*   S   5      S4PMI     snn
$ U(       d  U(       a)  [        U5      U:X  a  SU l        U R                  XU5      nO;U(       a  SU l        U R                  UUUU5      nOSU l        U R                  X5      nU V
VVVVVVs/ s H$  u  n
nnnnnnU
UUUUUR                  XU5      U4PM&     snnnnnnn
$ s  sn	f s  snn
f s  snnnnnnn
f )a
  Merge a cursor.description with compiled result column information.

There are at least four separate strategies used here, selected
depending on the type of SQL construct used to start with.

The most common case is that of the compiled SQL expression construct,
which generated the column names present in the raw SQL string and
which has the identical number of columns as were reported by
cursor.description.  In this case, we assume a 1-1 positional mapping
between the entries in cursor.description and the compiled object.
This is also the most performant case as we disregard extracting /
decoding the column names present in cursor.description since we
already have the desired name we generated in the compiled SQL
construct.

The next common case is that of the completely raw string SQL,
such as passed to connection.execute().  In this case we have no
compiled construct to work with, so we extract and decode the
names from cursor.description and index those as the primary
result row target keys.

The remaining fairly common case is that of the textual SQL
that includes at least partial column information; this is when
we use a :class:`_expression.TextualSelect` construct.
This construct may have
unordered or ordered column information.  In the ordered case, we
merge the cursor.description and the compiled construct's information
positionally, and warn if there are additional description names
present, however we still decode the names in cursor.description
as we don't have a guarantee that the names in the columns match
on these.   In the unordered case, we match names in cursor.description
to that of the compiled construct based on name matching.
In both of these cases, the cursor.description names and the column
expression objects and names are indexed as result row target keys.

The final case is much less common, where we have a compiled
non-textual SQL expression construct, but the number of columns
in cursor.description doesn't match what's in the compiled
construct.  We make the guess here that there might be textual
column expressions in the compiled construct that themselves include
a comma in them causing them to split.  We do the same name-matching
as with textual non-ordered columns.

The name-matched system of merging is the same as that used by
SQLAlchemy for all cases up through the 0.9 series.   Positional
matching for compiled SQL expressions was introduced in 1.0 as a
major performance feature, and positional matching for textual
:class:`_expression.TextualSelect` objects in 1.1.
As name matching is no longer
a common case, it was acceptable to factor it into smaller generator-
oriented methods that are easier to understand, but incur slightly
more performance overhead.

r   Tr   NF)rq   rI   rM   r   r#   r"   r$   get_result_processorr%   _merge_textual_cols_by_position_merge_cols_by_name_merge_cols_by_none)rW   r   r   r   r   r   r   r   r   elemr   
rmap_entryraw_iteratorridxcursor_colnamemapped_typecoltypeobjuntranslateds                      rY   r   .CursorResultMetaData._merge_cursor_description  s   F  #$6 77.<=ndq'n=DJ $(D  (1'@ (AOC z*w'/000"7+"#34*/2
  (A ( 3'9#:l#J'+$#CC  
 (-$#77&".	  (-$#77 0 ") ( "" # ""00#W !
& ") s >` s   EAE"+E!c              #  J  #    UR                   nUR                  nUR                  (       a  UR                  OSnSn/ U l        [        U5       HP  u  pxUS   n	US   n
U(       a
  U" U	5      u  pU(       a  U" U	5      n	U R                  R                  U	5        XyXj4v   MR     g7f)zExtract column names and data types from a cursor.description.

Applies unicode decoding, column translation, "normalization",
and case sensitivity rules to the names based on the dialect.

Nr   r   )dialectr   requires_name_normalizenormalize_namerI   r   append)rW   r   r   r   translate_colnamer   r   r   r   colnamer   s              rY   _colnames_from_description/CursorResultMetaData._colnames_from_description  s      //#66&-&E&EG""4 	 
!"45HC!fG!fG (9'(B%(1JJg&55 6s   B!B#c              #    #    [        U5      nU[        U5      :  a$  [        R                  " SU[        U5      4-  5        [        5       nU R	                  X5       H{  u  nnnn	Xd:  aR  X6   n
U
[
           nUnU
[           nUS   U;   a  [        R                  " SUS   -  5      eUR                  US   5        O[        R                  nS nS nXlX}XU4v   M}     g 7f)NzVNumber of columns in textual SQL (%d) is smaller than number of columns requested (%d)r   z8Duplicate column expression requested in textual SQL: %r)rq   r   warnr   r   r#   r%   r   InvalidRequestErrorr   r   NULLTYPE)rW   r   r   r   r   seenr   r   r   r   ctx_recr   r   r   s                 rY   r   4CursorResultMetaData._merge_textual_cols_by_position  s      >*#011II@%7!89:
 u ,,WI
!(-j)%g.q6T>11-/21v6  Q &//W7MM! Js   CCc              #     #    U R                  X45      nU R                  X5       H'  u  nnnn	 XW   n
U
S   nU
S   nU
S   nUUUUU	UU4v   M)     g ! [         a    [        R                  nS nS n N0f = f7f)Nr   r   r<   )_create_description_match_mapr   KeyErrorr   r   )rW   r   r   r   r   	match_mapr   r   r   r   r   r   r   result_columns_idxs                 rY   r   (CursorResultMetaData._merge_cols_by_name  s      66
	 ,,WI
	0#, aj%aj%,QZ""  J  *&//%)"*s'   +A5AA5A2/A51A22A5c           	     @   0 n[        U5       H  u  pEU[           nXc;   a  X6   u  pxpXxU[           -   X4X6'   OU[           U[           U[           U4X6'   U(       d  MQ  U[            H.  nUR                  UU[           U[           U[           U45        M0     M     U$ )zwhen matching cursor.description to a set of names that are present
in a Compiled object, as is the case with TextualSelect, get all the
names we expect might match those in cursor.description.
)r   r$   r#   r"   r%   r   )clsr   r   dr   r   rX   e_namee_obje_typee_ridxr_keys               rY   r   2CursorResultMetaData._create_description_match_map  s       	
 $N3JD'(Cx
 12-vj)9!96Gw-j)94=$O)) "*-ELLgZ(8$w-N .% 4. r\   c              #  x   #    U R                  X5       H!  u  nnnnUS U[        R                  US U4v   M#     g 7frU   )r   r   r   )rW   r   r   r   r   r   r   s          rY   r   (CursorResultMetaData._merge_cols_by_none  sS      ,,WI
 !!  Js   8:c                    U(       au  U R                   (       a6  [        U[        R                  5      (       a  [        R
                  " S5      Ue[        R
                  " S[        R                  " U5      -  5      Ueg )Nz9Row was unpickled; lookup by ColumnElement is unsupportedz.Could not locate column in row for column '%s')rN   r   r   ColumnElementr   NoSuchColumnErrorr   string_or_unprintable)rW   rX   errraiseerrs       rY   _key_fallback"CursorResultMetaData._key_fallback/  sr     ??z#x7M7M'N'N//) 
 //H44S9: 
 r\   c                B    [         R                  " SU[           -  5      e)Nz<Ambiguous column name '%s' in result set column descriptions)r   r   r=   )rW   r   s     rY    _raise_for_ambiguous_column_name5CursorResultMetaData._raise_for_ambiguous_column_name@  s(    %%-/2=/AB
 	
r\   c                    [        U[        5      (       a  U R                  U   n U R                  U   nUS   nUc  U R                  U5        U$ ! [         a!  nU R                  XU5      nUb   e S nAg S nAff = fNr   )r   intrI   rG   r   r   r   )rW   rX   r   r   kexr   s          rY   _index_for_key#CursorResultMetaData._index_for_keyF  s     c3**S/C	,,s#C A=11#6  	""3H5A99	s   A 
A;A66A;c                     U Vs/ s H  o R                   U   S   PM     sn$ s  snf ! [         a-  n[        R                  XR                  S   U5         S nAg S nAff = fr   )rG   r   rE   r   args)rW   rg   rX   r   s       rY   _indexes_for_keys&CursorResultMetaData._indexes_for_keysY  sY    	E489DSLL%a(D999 	E ..tWWQZDD	Es    ) $) ) 
A #AA c              #  j  #    U Ho  n[         UR                  R                  ;   a  U R                  U   n U R                  U   nW[           nUc  U R                  U5        [        [        U5      v   Mq     g ! [
         a-  n[        R                  XR                  S   U5         S nANfS nAff = f7fr   )r   rb   __mro__rI   rG   r   rE   r   r   r9   r   r   _NonAmbigCursorKeyMapRecType)rW   rg   rX   r   r   r   s         rY   r   'CursorResultMetaData._metadata_for_keys`  s      Ccmm+++jjoIll3'
 ME}55c:3S99   I$224RHHIs.   3B3A94B39
B0#B+&B3+B00B3c                   U R                   R                  5        VVs0 s HA  u  p[        U[        [        45      (       d  M"  UU[
           U[           / UU[           S S 4_MC     snnU R                  U R                  S.$ s  snnf )N)rG   rI   rL   )
rG   rr   r   strr   r9   r:   r?   rI   rL   )rW   rX   r   s      rY   __getstate__!CursorResultMetaData.__getstate__t  s     !% 2 2 4 !5HCcC:.M+,()  !5 ZZ#'#;#;
 	
s   !B#Bc                ~   [        [        US   5      5       Vs/ s H  nS PM     snU l        US   U l        S U l        U R                  U R                  [        5      U l        US   U l        SU l	        US   (       a,  [        SUS   5      U l        [        U R                  6 U l        g S =U l        U l        g s  snf )NrI   rG   TrL   z	List[int])rangerq   rH   rG   rJ   rd   r9   rO   rI   rN   r   rL   r   rK   )rW   state_s      rY   __setstate__!CursorResultMetaData.__setstate__  s    */E'N0C*DE*DQD*DEY',0)!44T\\8L7^
&''+U#89(D$ !,T-E-E FD;??D$t'8 Fs   B:)	rO   rG   rJ   rI   rH   rM   rL   rK   rN   N)rX   r   returnrQ   )r  r   )re   rQ   rf   r4   rg   zSequence[str]rh   r2   ri   zOptional[_TupleGetterType]rj   rR   rk   rQ   rl   r   r  rE   )r  rE   )rz   rE   r  rE   )rg   zSequence[_KeyIndexType]r  r   )r   r/   r  r   )r   CursorResult[Any]r   r,   F)r   zList[ResultColumnsEntry]r   rQ   r  zKDict[Union[str, object], Tuple[str, Tuple[Any, ...], TypeEngine[Any], int]])T)rX   r   r   zOptional[Exception]r   rQ   r  zOptional[NoReturn])rX   r   r   rQ   r  Optional[int])rg   zSequence[Any]r  z&Iterator[_NonAmbigCursorKeyMapRecType]) __name__
__module____qualname____firstlineno____doc__	__slots____annotations__rS   rZ   r_   rn   rt   r}   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r   r  r  __static_attributes__r   r\   rY   rE   rE      s   ,I   "EE,,#'L.'#
  $	
   0 0  &) 
0
 "
)"
	"
H
@<
|SM!SM 4SMjVp6>"NH$L  ,1'0' %)'
	' 'R"  HL		!4	@D		"
&E:!:	/:(
(@r\   rE   c                      \ rS rSr% SrSrSrS\S'         SS jr      SS jr	        SS	 jr
 S       SS
 jjr S       SS jjr      SS jr        SS jrSrg)ResultFetchStrategyi  zIDefine a fetching strategy for a result object.


.. versionadded:: 1.4

r   N!Optional[_DBAPICursorDescription]alternate_cursor_descriptionc                    [        5       erU   NotImplementedErrorrW   resultdbapi_cursors      rY   
soft_closeResultFetchStrategy.soft_close       "##r\   c                    [        5       erU   r  r!  s      rY   
hard_closeResultFetchStrategy.hard_close  r&  r\   c                    g rU   r   rW   r"  r#  nums       rY   	yield_perResultFetchStrategy.yield_per  s     	r\   c                    [        5       erU   r  rW   r"  r#  r(  s       rY   fetchoneResultFetchStrategy.fetchone       "##r\   c                    [        5       erU   r  rW   r"  r#  sizes       rY   	fetchmanyResultFetchStrategy.fetchmany  r3  r\   c                    [        5       erU   r  r!  s      rY   fetchallResultFetchStrategy.fetchall  s    
 "##r\   c                    UerU   r   rW   r"  r#  r   s       rY   handle_exception$ResultFetchStrategy.handle_exception  s	     	r\   r"  r  r#  Optional[DBAPICursor]r  Noner"  r  r#  rA  r,  r   r  rB  r  r"  r  r#  r-   r(  rQ   r  r   rU   r"  r  r#  r-   r6  r  r  r   r"  r  r#  r-   r  r   r"  r  r#  rA  r   BaseExceptionr  r   )r  r  r  r  r  r  r  r  r$  r(  r-  r1  r7  r:  r>  r  r   r\   rY   r  r    s+    IFJ "CJ$'$7L$	$
$'$7L$	$
! , 	
 
 !	$!$ "$ 	$
 
$ #	$!$ "$ 	$
 
$$!$ "$ 
	$! , 	
 
r\   r  c                  L    \ rS rSrSrSrS rS rSS jrSS jr	S	 r
SS
 jrSrg)NoCursorFetchStrategyi  zCursor strategy for a result that has no open cursor.

There are two varieties of this strategy, one for DQL and one for
DML (and also DDL), each of which represent a result that had a cursor
but no longer has one.

r   c                    g rU   r   r!  s      rY   r$   NoCursorFetchStrategy.soft_close      r\   c                    g rU   r   r!  s      rY   r(   NoCursorFetchStrategy.hard_close  rM  r\   c                &    U R                  US 5      $ rU   _non_resultr0  s       rY   r1  NoCursorFetchStrategy.fetchone  s    --r\   Nc                &    U R                  U/ 5      $ rU   rQ  r5  s       rY   r7  NoCursorFetchStrategy.fetchmany      ++r\   c                &    U R                  U/ 5      $ rU   rQ  r!  s      rY   r:  NoCursorFetchStrategy.fetchall  rV  r\   c                    [        5       erU   r  rW   r"  defaultr   s       rY   rR  !NoCursorFetchStrategy._non_result  s    !##r\   r  rU   )r  r  r  r  r  r  r$  r(  r1  r7  r:  rR  r  r   r\   rY   rJ  rJ    s,     I.,,$r\   rJ  c                  &    \ rS rSrSrSrSS jrSrg)NoCursorDQLFetchStrategyi  a  Cursor strategy for a DQL result that has no open cursor.

This is a result set that can return rows, i.e. for a SELECT, or for an
INSERT, UPDATE, DELETE that includes RETURNING. However it is in the state
where the cursor is closed and no rows remain available.  The owning result
object may or may not be "hard closed", which determines if the fetch
methods send empty results or raise for closed result.

r   Nc                V    UR                   (       a  [        R                  " S5      UeU$ )NzThis result object is closed.)closedr   ResourceClosedErrorrZ  s       rY   rR  $NoCursorDQLFetchStrategy._non_result  s)    ==))/ Nr\   rU   r  r  r  r  r  r  rR  r  r   r\   rY   r^  r^    s     Ir\   r^  c                  &    \ rS rSrSrSrSS jrSrg)NoCursorDMLFetchStrategyi  zCursor strategy for a DML result that has no open cursor.

This is a result set that does not return rows, i.e. for an INSERT,
UPDATE, DELETE that does not include RETURNING.

r   Nc                t    UR                   R                  (       a   eUR                   R                  U5        g rU   )	_metadatarS   _we_dont_return_rowsrZ  s       rY   rR  $NoCursorDMLFetchStrategy._non_result  s+    ##0000--c2r\   rU   rc  r   r\   rY   re  re    s     I3r\   re  c                      \ rS rSrSrSr      SS jr      SS jr        SS jr        SS jr	 S       SS jjr
 S       SS
 jjr      SS jrSrg	)CursorFetchStrategyi   zCall fetch methods from a DBAPI cursor.

Alternate versions of this class may instead buffer the rows from
cursors or not use cursors at all.

r   c                    [         Ul        g rU   _NO_CURSOR_DQLcursor_strategyr!  s      rY   r$  CursorFetchStrategy.soft_close*       "0r\   c                    [         Ul        g rU   rm  r!  s      rY   r(  CursorFetchStrategy.hard_close/  rq  r\   c                T    UR                   R                  US S X!R                  5        g rU   )
connection_handle_dbapi_exceptionr   r=  s       rY   r>  $CursorFetchStrategy.handle_exception4  s%     	11t\>>	
r\   c                P    [        USU0[        R                  " 5       SS9Ul        g )Nmax_row_bufferr   )initial_buffergrowth_factor)BufferedRowCursorFetchStrategycollectionsdequero  r+  s       rY   r-  CursorFetchStrategy.yield_per>  s,     "@s#&,,.	"
r\   c                     UR                  5       nUc  UR                  US9  U$ ! [         a  nU R                  XU5         S nAg S nAff = fNhard)r1  _soft_closerH  r>  )rW   r"  r#  r(  rowr   s         rY   r1  CursorFetchStrategy.fetchoneK  sS    	;'')C{""
"3J 	;!!&::	;s   #& 
AAANc                     Uc  UR                  5       nOUR                  U5      nU(       d  UR                  5         U$ ! [         a  nU R                  XU5         S nAg S nAff = frU   )r7  r  rH  r>  )rW   r"  r#  r6  lr   s         rY   r7  CursorFetchStrategy.fetchmanyY  sa    
	;| **, **40""$H 	;!!&::	;s   =A   
A&
A!!A&c                     UR                  5       nUR                  5         U$ ! [         a  nU R                  XU5         S nAg S nAff = frU   )r:  r  rH  r>  )rW   r"  r#  rowsr   s        rY   r:  CursorFetchStrategy.fetchallk  sI    
	;((*D K 	;!!&::	;s   !$ 
A
AA
r@  rG  rC  r  rD  rU   rE  rF  )r  r  r  r  r  r  r$  r(  r>  r-  r1  r7  r:  r  r   r\   rY   rk  rk     s    I0'07L0	0
0'07L0	0

!
 ,
 	

 


!
 ,
 	

 

" !	;!; "; 	;
 
;$ #	;!; "; 	;
 
;$
;!
; "
; 
	
;r\   rk  c                     ^  \ rS rSrSrSr  SS jr\S 5       rS r	S r
U 4S jrU 4S	 jrSS
 jrSS jrS rSrU =r$ )r|  i{  a  A cursor fetch strategy with row buffering behavior.

This strategy buffers the contents of a selection of rows
before ``fetchone()`` is called.  This is to allow the results of
``cursor.description`` to be available immediately, when
interfacing with a DB-API that requires rows to be consumed before
this information is available (currently psycopg2, when used with
server-side cursors).

The pre-fetching behavior fetches only one row initially, and then
grows its buffer size by a fixed amount with each successive need
for additional rows up the ``max_row_buffer`` size, which defaults
to 1000::

    with psycopg2_engine.connect() as conn:

        result = conn.execution_options(
            stream_results=True, max_row_buffer=50
        ).execute(text("select * from table"))

.. versionadded:: 1.4 ``max_row_buffer`` may now exceed 1000 rows.

.. seealso::

    :ref:`psycopg2_execution_options`
)_max_row_buffer
_rowbuffer_bufsize_growth_factorc                "   UR                  SS5      U l        Ub  X@l        O*[        R                  " UR                  S5      5      U l        X0l        U(       a&  [        U R                  U R                  5      U l        g U R                  U l        g )Nry  i  r   )	getr  r  r}  r~  r7  r  minr  )rW   r#  execution_optionsr{  rz  s        rY   r   'BufferedRowCursorFetchStrategy.__init__  sr      1445EtL%,O)//0F0Fq0IJDO+ 4 4d6I6IJDM 00DMr\   c                V    [        UR                  UR                  R                  5      $ rU   )r|  cursorr   r  )r   r"  s     rY   create%BufferedRowCursorFetchStrategy.create  s#    -MMNN,,
 	
r\   c                   U R                   n US:  a  UR                  5       nOUR                  U5      n W(       d  g[
        R                  " U5      U l        U R                  (       a8  X0R                  :  a(  [        U R                  X0R                  -  5      U l         ggg! [         a  nU R	                  XU5         SnANSnAff = f)z*this is currently used only by fetchone().r   N)r  r:  r7  rH  r>  r}  r~  r  r  r  r  )rW   r"  r#  r6  new_rowsr   s         rY   _buffer_rows+BufferedRowCursorFetchStrategy._buffer_rows  s     }}	;ax'002'11$7 %++H54*>*>#>$$d-@-@&@DM $?  	;!!&::	;s   B$ B$ $
C
.CC
c                .    SU l         U=U l        U l        g r   )r  r  r  r+  s       rY   r-  (BufferedRowCursorFetchStrategy.yield_per  s    /22t}r\   c                X   > U R                   R                  5         [        TU ]  X5        g rU   r  clearsuperr$  rW   r"  r#  rb   s      rY   r$  )BufferedRowCursorFetchStrategy.soft_close       60r\   c                X   > U R                   R                  5         [        TU ]  X5        g rU   r  r  r  r(  r  s      rY   r(  )BufferedRowCursorFetchStrategy.hard_close  r  r\   c                   U R                   (       d3  U R                  X5        U R                   (       d   UR                  US9  g U R                   R                  5       $ ! [         a  nU R	                  XU5         S nAg S nAff = fr  )r  r  r  rH  r>  popleft)rW   r"  r#  r(  r   s        rY   r1  'BufferedRowCursorFetchStrategy.fetchone  sw    f3??C&&J&7 &&(( % C))&BBCs   A 
B)B  Bc                   Uc  U R                  X5      $ U R                  n[        U5      nSnX5:  a0   UR                  X5-
  5      nU(       d  SnOUR	                  U5         [        [        U[        U5      5      5       V	s/ s H  oR                  5       PM     n
n	U(       a  UR                  5         U
$ ! [
         a  nU R                  XU5         S nANuS nAff = fs  sn	f )NFT)r:  r  rq   r7  extendrH  r>  r  r  r  r  )rW   r"  r#  r6  rblbcloser   r   r
  ress              rY   r7  (BufferedRowCursorFetchStrategy.fetchmany  s    <==66__W9	#",,TY7  EIIcN%*3tSW+=%>?%>zz|%>? 
 ! ?%%fA>>? @s   B7 C 7
CCCc                    [        U R                  5      [        UR                  5       5      -   nU R                  R                  5         UR	                  5         U$ ! [
         a  nU R                  XU5         S nAg S nAff = frU   )r   r  r:  r  r  rH  r>  )rW   r"  r#  retr   s        rY   r:  'BufferedRowCursorFetchStrategy.fetchall  sl    	;t'$|/D/D/F*GGCOO!!# J 	;!!&::	;s   AA 
B'A>>B)r  r  r  r  )r@   Nr  rU   )r  r  r  r  r  r  r   r  r  r  r-  r$  r(  r1  r7  r:  r  __classcell__rb   s   @rY   r|  r|  {  sY    6 PI 1( 
 
(311	)0; ;r\   r|  c                  x   ^  \ rS rSrSrSr  S     SS jjrS rU 4S jrU 4S jr	SS jr
SS	 jrS
 rSrU =r$ ) FullyBufferedCursorFetchStrategyi  zA cursor strategy that buffers rows fully upon creation.

Used for operations where a result is to be delivered
after the database conversation can not be continued,
such as MSSQL INSERT...OUTPUT after an autocommit.

)r  r  c                    X l         Ub  [        R                  " U5      U l        g Uc   e[        R                  " UR	                  5       5      U l        g rU   )r  r}  r~  r  r:  )rW   r#  alternate_descriptionrz  s       rY   r   )FullyBufferedCursorFetchStrategy.__init__  sJ     -B)%)//?DO+++)//0E0E0GHDOr\   c                    g rU   r   r+  s       rY   r-  *FullyBufferedCursorFetchStrategy.yield_per  rM  r\   c                X   > U R                   R                  5         [        TU ]  X5        g rU   r  r  s      rY   r$  +FullyBufferedCursorFetchStrategy.soft_close  r  r\   c                X   > U R                   R                  5         [        TU ]  X5        g rU   r  r  s      rY   r(  +FullyBufferedCursorFetchStrategy.hard_close   r  r\   c                x    U R                   (       a  U R                   R                  5       $ UR                  US9  g r  )r  r  r  r0  s       rY   r1  )FullyBufferedCursorFetchStrategy.fetchone$  s0    ????**,,J/r\   c                    Uc  U R                  X5      $ U R                  n[        [        U[	        U5      5      5       Vs/ s H  oTR                  5       PM     nnU(       d  UR                  5         U$ s  snf rU   )r:  r  r  r  rq   r  r  )rW   r"  r#  r6  r  r
  r  s          rY   r7  *FullyBufferedCursorFetchStrategy.fetchmany+  sc    <==66__&+Cc"g,>&?@&?

&?@  As   A5c                r    U R                   n[        R                  " 5       U l         UR                  5         U$ rU   )r  r}  r~  r  )rW   r"  r#  r  s       rY   r:  )FullyBufferedCursorFetchStrategy.fetchall5  s,    oo%++-
r\   )NN)r#  rA  r  r  rz  zOptional[Iterable[Any]]r  rU   )r  r  r  r  r  r  r   r-  r$  r(  r1  r7  r:  r  r  r  s   @rY   r  r    sb     ?I
 DH26	I+I  AI 0	I11 r\   r  c                  x    \ rS rSrSrSrSS jrS rS rS r	\
S	 5       r\
S
 5       r\
S 5       r\
S 5       rSrg)_NoResultMetaDatai<  r   FNc                0    [         R                  " S5      Ue)NzJThis result object does not return rows. It has been closed automatically.)r   ra  )rW   r   s     rY   rh  &_NoResultMetaData._we_dont_return_rowsA  s    %%0
 	r\   c                $    U R                  5         g rU   rh  )rW   rg   r   s      rY   r    _NoResultMetaData._index_for_keyG      !!#r\   c                $    U R                  5         g rU   r  rV   s     rY   r   $_NoResultMetaData._metadata_for_keysJ  r  r\   c                $    U R                  5         g rU   r  )rW   rg   s     rY   r   _NoResultMetaData._reduceM  r  r\   c                $    U R                  5         g rU   r  rW   s    rY   rG   _NoResultMetaData._keymapP      !!#r\   c                $    U R                  5         g rU   r  r  s    rY   rO   _NoResultMetaData._key_to_indexT  r  r\   c                $    U R                  5         g rU   r  r  s    rY   rH   _NoResultMetaData._processorsX  r  r\   c                $    U R                  5         g rU   r  r  s    rY   rg   _NoResultMetaData.keys\  r  r\   rU   )r  r  r  r  r  rS   rh  r   r   r   propertyrG   rO   rH   rg   r  r   r\   rY   r  r  <  sp    IL$$$ $ $ $ $ $ $ $ $r\   r  c                 `    [        [        5       [        / 5      5      n U R                  5         U $ rU   )r   r  iterr  )its    rY   null_dml_resultr  d  s%    ,->-@$r(KBNNIr\   c                    ^  \ rS rSr% SrSrS\S'   \rSr	S\S'   Sr
S\S	'   S
rS\S'   S\S'   S\S'   S\S'         S1S jrS rS2S jr\S 5       r\S 5       rS rS r\S 5       rS rS rS r\S 5       rS rS  rS! rS" rS# r\R>                  S3S$ j5       r \S% 5       r!\S& 5       r"\S' 5       r#S( r$S2S) jr%S* r&S4S+ jr'S, r(S5U 4S- jjr)S6S. jr*\+S7S/ j5       r,S0r-U =r.$ )8CursorResultij  a  A Result that is representing state from a DBAPI cursor.

.. versionchanged:: 1.4  The :class:`.CursorResult``
   class replaces the previous :class:`.ResultProxy` interface.
   This classes are based on the :class:`.Result` calling API
   which provides an updated usage model and calling facade for
   SQLAlchemy Core and SQLAlchemy ORM.

Returns database rows via the :class:`.Row` class, which provides
additional API features and behaviors on top of the raw data returned by
the DBAPI.   Through the use of filters such as the :meth:`.Result.scalars`
method, other kinds of objects may also be returned.

.. seealso::

    :ref:`tutorial_selecting_data` - introductory material for accessing
    :class:`_engine.CursorResult` and :class:`.Row` objects.

)r   r   r  ro  _echoru  z.Union[CursorResultMetaData, _NoResultMetaData]rg  FrQ   _soft_closedr`  Tr+   r   r.   r   r  ro  r*   ru  c                  ^	^
^^^ Xl         UR                  U l        UR                  U l        X l        UR                  U l        U R
                  R                  =(       a    UR                  R                  5       =U l        nUb  U R                  X5      n[        R                  " [        UUR                  UR                  5      m
UR                  (       a4  [         R"                  " [%        UR                  * 5      5      mU
U4S jnUmOT
mU(       a7  U R                   R
                  R&                  mU4S jm	T	U l        U	U4S jnUnOTnU R+                  SU5        g UR                  S:X  d   eU R,                  U l        g )Nc                    > T" T" U 5      5      $ rU   r   )raw_data	_make_rowsentinel_filters    rY   _sliced_row*CursorResult.__init__.<locals>._sliced_row  s    $_X%>??r\   c                B   > T" S[         R                  " U 5      5        U $ )NzRow %r)sql_util	_repr_row)r  logs    rY   _log_row'CursorResult.__init__.<locals>._log_row  s    ("4"4S"9:Jr\   c                    > T" T" U 5      5      $ rU   r   )r  r  
sliced_rows    rY   _make_row_2*CursorResult.__init__.<locals>._make_row_2  s    #JsO44r\   _row_getterr   )r   r   r  ro  root_connectionru  r  engine_should_log_debug_init_metadata	functoolspartialr   _effective_processorsrO   _num_sentinel_colsoperator
itemgetterslice
_log_debug_row_logging_fn_set_memoized_attribute_no_result_metadatarg  )rW   r   ro  r   echometadatar  r  make_rowr  r  r  r  r  s            @@@@@rY   r   CursorResult.__init__  sJ    nn.!11OO!!Hgnn&F&F&H	

T )
 **7GH "))..&&	I ))"*"5"575556#@ )
&
ll--88 (0$5 '%((A --222!55DNr\   c                j   UR                   (       a  UR                   nUR                  (       a  UR                  nO"[        X5      nUR                  (       a  XCl        UR                  R                  SS5      (       d^  UR                  (       aM  UR                  UR                  R                  L a*  UR                  UR                  La  UR                  U5      nX@l        O[        X5      =U l        nU R                  (       a,  UR                  R!                  S[#        S U 5       5      5        U$ )N _result_disable_adapt_to_contextFzCol %rc              3  *   #    U  H	  oS    v   M     g7f)r   Nr   )r   r   s     rY   r   .CursorResult._init_metadata.<locals>.<genexpr>  s     A.@!.@s   )r   _cached_metadatarE   rM   r  r  r   	cache_hitr   	CACHE_HITr   r   r   rg  r  ru  r  tuple)rW   r   r   r   r  s        rY   r  CursorResult._init_metadata  s    ''H((#44/I++08-" --116  ,,%%)B)BB&&g.G.GG#55g>%N )=) DNX ::))%A.@AA r\   c                   U(       d  U R                   (       d  U(       a  U R                  (       a  gU(       a-  SU l        U R                  R                  X R                  5        O%U R                  R                  X R                  5        U R                   (       d6  U R                  nSU l        U R                  R                  U5        SU l         gg)a  Soft close this :class:`_engine.CursorResult`.

This releases all DBAPI cursor resources, but leaves the
CursorResult "open" from a semantic perspective, meaning the
fetchXXX() methods will continue to return empty results.

This method is called automatically when:

* all result rows are exhausted using the fetchXXX() methods.
* cursor.description is None.

This method is **not public**, but is documented in order to clarify
the "autoclose" process used.

.. seealso::

    :meth:`_engine.CursorResult.close`


NT)r  r`  ro  r(  r  r$  ru  _safe_close_cursor)rW   r  r  s      rY   r  CursorResult._soft_close  s    , **DK  ++D++>  ++D++>  [[FDKOO..v6 $D	 !r\   c                T   U R                   R                  (       d  [        R                  " S5      eU R                   R                  (       d  [        R                  " S5      eU R                   R
                  (       a  [        R                  " S5      eU R                   R                  $ )a  Return the value of
:attr:`_engine.CursorResult.inserted_primary_key`
as a row contained within a list; some dialects may support a
multiple row form as well.

.. note:: As indicated below, in current SQLAlchemy versions this
   accessor is only useful beyond what's already supplied by
   :attr:`_engine.CursorResult.inserted_primary_key` when using the
   :ref:`postgresql_psycopg2` dialect.   Future versions hope to
   generalize this feature to more dialects.

This accessor is added to support dialects that offer the feature
that is currently implemented by the :ref:`psycopg2_executemany_mode`
feature, currently **only the psycopg2 dialect**, which provides
for many rows to be INSERTed at once while still retaining the
behavior of being able to return server-generated primary key values.

* **When using the psycopg2 dialect, or other dialects that may support
  "fast executemany" style inserts in upcoming releases** : When
  invoking an INSERT statement while passing a list of rows as the
  second argument to :meth:`_engine.Connection.execute`, this accessor
  will then provide a list of rows, where each row contains the primary
  key value for each row that was INSERTed.

* **When using all other dialects / backends that don't yet support
  this feature**: This accessor is only useful for **single row INSERT
  statements**, and returns the same information as that of the
  :attr:`_engine.CursorResult.inserted_primary_key` within a
  single-element list. When an INSERT statement is executed in
  conjunction with a list of rows to be INSERTed, the list will contain
  one row per row inserted in the statement, however it will contain
  ``None`` for any server-generated values.

Future releases of SQLAlchemy will further generalize the
"fast execution helper" feature of psycopg2 to suit other dialects,
thus allowing this accessor to be of more general use.

.. versionadded:: 1.4

.. seealso::

    :attr:`_engine.CursorResult.inserted_primary_key`

1Statement is not a compiled expression construct.2Statement is not an insert() expression construct.z9Can't call inserted_primary_key when returning() is used.)r   r   r   r   isinsert_is_explicit_returninginserted_primary_key_rowsr  s    rY   r   &CursorResult.inserted_primary_key_rows&  s    \ ||$$))C  &&))D  \\00)) 
 ||555r\   c                    U R                   R                  (       a  [        R                  " S5      eU R                  nU(       a  US   $ g)a  Return the primary key for the row just inserted.

The return value is a :class:`_result.Row` object representing
a named tuple of primary key values in the order in which the
primary key columns are configured in the source
:class:`_schema.Table`.

.. versionchanged:: 1.4.8 - the
   :attr:`_engine.CursorResult.inserted_primary_key`
   value is now a named tuple via the :class:`_result.Row` class,
   rather than a plain tuple.

This accessor only applies to single row :func:`_expression.insert`
constructs which did not explicitly specify
:meth:`_expression.Insert.returning`.    Support for multirow inserts,
while not yet available for most backends, would be accessed using
the :attr:`_engine.CursorResult.inserted_primary_key_rows` accessor.

Note that primary key columns which specify a server_default clause, or
otherwise do not qualify as "autoincrement" columns (see the notes at
:class:`_schema.Column`), and were generated using the database-side
default, will appear in this list as ``None`` unless the backend
supports "returning" and the insert statement executed with the
"implicit returning" enabled.

Raises :class:`~sqlalchemy.exc.InvalidRequestError` if the executed
statement is not a compiled expression construct
or is not an insert() construct.

zuThis statement was an executemany call; if primary key returning is supported, please use .inserted_primary_key_rows.r   N)r   executemanyr   r   r   )rW   ikps     rY   inserted_primary_key!CursorResult.inserted_primary_keyd  sF    B <<##))2  ,,q6Mr\   c                Z   U R                   R                  (       d  [        R                  " S5      eU R                   R                  (       d  [        R                  " S5      eU R                   R
                  (       a  U R                   R                  $ U R                   R                  S   $ )zReturn the collection of updated parameters from this
execution.

Raises :class:`~sqlalchemy.exc.InvalidRequestError` if the executed
statement is not a compiled expression construct
or is not an update() construct.

r  z2Statement is not an update() expression construct.r   )r   r   r   r   isupdater#  compiled_parametersr  s    rY   last_updated_params CursorResult.last_updated_params       ||$$))C  &&))D  \\%%<<333<<33A66r\   c                Z   U R                   R                  (       d  [        R                  " S5      eU R                   R                  (       d  [        R                  " S5      eU R                   R
                  (       a  U R                   R                  $ U R                   R                  S   $ )zReturn the collection of inserted parameters from this
execution.

Raises :class:`~sqlalchemy.exc.InvalidRequestError` if the executed
statement is not a compiled expression construct
or is not an insert() construct.

r  r  r   )r   r   r   r   r  r#  r)  r  s    rY   last_inserted_params!CursorResult.last_inserted_params  r,  r\   c                .    U R                   R                  $ )zReturn a list of rows each containing the values of default
columns that were fetched using
the :meth:`.ValuesBase.return_defaults` feature.

The return value is a list of :class:`.Row` objects.

.. versionadded:: 1.4

)r   returned_default_rowsr  s    rY   returned_defaults_rows#CursorResult.returned_defaults_rows  s     ||111r\   c                   U R                  5       n[        [        U R                  5       5      [        UR                  5       5      5       VVs/ s H  u  p4[	        U5      [	        U5      -   PM     nnnUR
                  R                  UR
                  5      Ul        [        SUS9Ul        UR                  5         U$ s  snnf )a+  Return a new :class:`.CursorResult` that "horizontally splices"
together the rows of this :class:`.CursorResult` with that of another
:class:`.CursorResult`.

.. tip::  This method is for the benefit of the SQLAlchemy ORM and is
   not intended for general use.

"horizontally splices" means that for each row in the first and second
result sets, a new row that concatenates the two rows together is
produced, which then becomes the new row.  The incoming
:class:`.CursorResult` must have the identical number of rows.  It is
typically expected that the two result sets come from the same sort
order as well, as the result rows are spliced together based on their
position in the result.

The expected use case here is so that multiple INSERT..RETURNING
statements (which definitely need to be sorted) against different
tables can produce a single result that looks like a JOIN of those two
tables.

E.g.::

    r1 = connection.execute(
        users.insert().returning(
            users.c.user_name, users.c.user_id, sort_by_parameter_order=True
        ),
        user_values,
    )

    r2 = connection.execute(
        addresses.insert().returning(
            addresses.c.address_id,
            addresses.c.address,
            addresses.c.user_id,
            sort_by_parameter_order=True,
        ),
        address_values,
    )

    rows = r1.splice_horizontally(r2).all()
    assert rows == [
        ("john", 1, 1, "foo@bar.com", 1),
        ("jack", 2, 2, "bar@bat.com", 2),
    ]

.. versionadded:: 2.0

.. seealso::

    :meth:`.CursorResult.splice_vertically`


Nrz  )
	_generatezipr   _raw_row_iteratorr  rg  r}   r  ro  _reset_memoizations)rW   rz   cloner1r2
total_rowss         rY   splice_horizontally CursorResult.splice_horizontally  s    n   T++-.U,,./
 "Ib	! 	 
  //>>uO @%!
 	!!#
s   #B?c                    U R                  5       n[        U R                  5       5      [        UR                  5       5      -   n[        SUS9Ul        UR                  5         U$ )am  Return a new :class:`.CursorResult` that "vertically splices",
i.e. "extends", the rows of this :class:`.CursorResult` with that of
another :class:`.CursorResult`.

.. tip::  This method is for the benefit of the SQLAlchemy ORM and is
   not intended for general use.

"vertically splices" means the rows of the given result are appended to
the rows of this cursor result. The incoming :class:`.CursorResult`
must have rows that represent the identical list of columns in the
identical order as they are in this :class:`.CursorResult`.

.. versionadded:: 2.0

.. seealso::

    :meth:`.CursorResult.splice_horizontally`

Nr5  )r6  r   r8  r  ro  r9  )rW   rz   r:  r=  s       rY   splice_verticallyCursorResult.splice_vertically  sd    (  $0023d##%7
 

 !A%!
 	!!#r\   c                   U R                   (       a/  U R                  R                  R                  S[	        U5      5        [        [        U R                  5      R                  5       U l        [        SUS9U l
        U R                  5         U $ )zrewind this result back to the given rowset.

this is used internally for the case where an :class:`.Insert`
construct combines the use of
:meth:`.Insert.return_defaults` along with the
"supplemental columns" feature.

zCursorResult rewound %d row(s)Nr5  )r  r   ru  r  rq   r   rE   rg  rt   r  ro  r9  rW   r  s     rY   _rewindCursorResult._rewind4  sz     ::LL##..0#d)  $..



 	  @   
 	  "r\   c                    U R                   R                  (       a  [        R                  " S5      eU R                   R                  nU(       a  US   $ g)a@  Return the values of default columns that were fetched using
the :meth:`.ValuesBase.return_defaults` feature.

The value is an instance of :class:`.Row`, or ``None``
if :meth:`.ValuesBase.return_defaults` was not used or if the
backend does not support RETURNING.

.. seealso::

    :meth:`.ValuesBase.return_defaults`

zlThis statement was an executemany call; if return defaults is supported, please use .returned_defaults_rows.r   N)r   r#  r   r   r1  rD  s     rY   returned_defaultsCursorResult.returned_defaultsT  sJ     <<##))D 
 ||117Nr\   c                6    U R                   R                  5       $ )zReturn ``lastrow_has_defaults()`` from the underlying
:class:`.ExecutionContext`.

See :class:`.ExecutionContext` for details.

)r   lastrow_has_defaultsr  s    rY   rK  !CursorResult.lastrow_has_defaultso  s     ||0022r\   c                (   U R                   R                  (       d  [        R                  " S5      eU R                   R                  (       d1  U R                   R
                  (       d  [        R                  " S5      eU R                   R                  $ )a  Return ``postfetch_cols()`` from the underlying
:class:`.ExecutionContext`.

See :class:`.ExecutionContext` for details.

Raises :class:`~sqlalchemy.exc.InvalidRequestError` if the executed
statement is not a compiled expression construct
or is not an insert() or update() construct.

r  >Statement is not an insert() or update() expression construct.)r   r   r   r   r  r(  postfetch_colsr  s    rY   rO  CursorResult.postfetch_colsy  sl     ||$$))C  &&t||/D/D))(  ||***r\   c                (   U R                   R                  (       d  [        R                  " S5      eU R                   R                  (       d1  U R                   R
                  (       d  [        R                  " S5      eU R                   R                  $ )a  Return ``prefetch_cols()`` from the underlying
:class:`.ExecutionContext`.

See :class:`.ExecutionContext` for details.

Raises :class:`~sqlalchemy.exc.InvalidRequestError` if the executed
statement is not a compiled expression construct
or is not an insert() or update() construct.

r  rN  )r   r   r   r   r  r(  prefetch_colsr  s    rY   rR  CursorResult.prefetch_cols  sl     ||$$))C  &&t||/D/D))(  ||)))r\   c                .    U R                   R                  $ )zpReturn ``supports_sane_rowcount`` from the dialect.

See :attr:`_engine.CursorResult.rowcount` for background.

)r   supports_sane_rowcountr  s    rY   rU  #CursorResult.supports_sane_rowcount  s     ||222r\   c                .    U R                   R                  $ )zvReturn ``supports_sane_multi_rowcount`` from the dialect.

See :attr:`_engine.CursorResult.rowcount` for background.

)r   supports_sane_multi_rowcountr  s    rY   rX  )CursorResult.supports_sane_multi_rowcount  s     ||888r\   c                     U R                   R                  $ ! [         a,  nU R                  R	                  X R
                  U5        e SnAff = f)a0  Return the 'rowcount' for this result.

The primary purpose of 'rowcount' is to report the number of rows
matched by the WHERE criterion of an UPDATE or DELETE statement
executed once (i.e. for a single parameter set), which may then be
compared to the number of rows expected to be updated or deleted as a
means of asserting data integrity.

This attribute is transferred from the ``cursor.rowcount`` attribute
of the DBAPI before the cursor is closed, to support DBAPIs that
don't make this value available after cursor close.   Some DBAPIs may
offer meaningful values for other kinds of statements, such as INSERT
and SELECT statements as well.  In order to retrieve ``cursor.rowcount``
for these statements, set the
:paramref:`.Connection.execution_options.preserve_rowcount`
execution option to True, which will cause the ``cursor.rowcount``
value to be unconditionally memoized before any results are returned
or the cursor is closed, regardless of statement type.

For cases where the DBAPI does not support rowcount for a particular
kind of statement and/or execution, the returned value will be ``-1``,
which is delivered directly from the DBAPI and is part of :pep:`249`.
All DBAPIs should support rowcount for single-parameter-set
UPDATE and DELETE statements, however.

.. note::

   Notes regarding :attr:`_engine.CursorResult.rowcount`:


   * This attribute returns the number of rows *matched*,
     which is not necessarily the same as the number of rows
     that were actually *modified*. For example, an UPDATE statement
     may have no net change on a given row if the SET values
     given are the same as those present in the row already.
     Such a row would be matched but not modified.
     On backends that feature both styles, such as MySQL,
     rowcount is configured to return the match
     count in all cases.

   * :attr:`_engine.CursorResult.rowcount` in the default case is
     *only* useful in conjunction with an UPDATE or DELETE statement,
     and only with a single set of parameters. For other kinds of
     statements, SQLAlchemy will not attempt to pre-memoize the value
     unless the
     :paramref:`.Connection.execution_options.preserve_rowcount`
     execution option is used.  Note that contrary to :pep:`249`, many
     DBAPIs do not support rowcount values for statements that are not
     UPDATE or DELETE, particularly when rows are being returned which
     are not fully pre-buffered.   DBAPIs that dont support rowcount
     for a particular kind of statement should return the value ``-1``
     for such statements.

   * :attr:`_engine.CursorResult.rowcount` may not be meaningful
     when executing a single statement with multiple parameter sets
     (i.e. an :term:`executemany`). Most DBAPIs do not sum "rowcount"
     values across multiple parameter sets and will return ``-1``
     when accessed.

   * SQLAlchemy's :ref:`engine_insertmanyvalues` feature does support
     a correct population of :attr:`_engine.CursorResult.rowcount`
     when the :paramref:`.Connection.execution_options.preserve_rowcount`
     execution option is set to True.

   * Statements that use RETURNING may not support rowcount, returning
     a ``-1`` value instead.

.. seealso::

    :ref:`tutorial_update_delete_rowcount` - in the :ref:`unified_tutorial`

    :paramref:`.Connection.execution_options.preserve_rowcount`

N)r   rowcountrH  ro  r>  r  rW   r   s     rY   r[  CursorResult.rowcount  sE    X	<<((( 	  11$QG	s    
A'A		Ac                     U R                   R                  5       $ ! [         a0  nU R                  R	                  X R
                  U5         SnAgSnAff = f)a  Return the 'lastrowid' accessor on the DBAPI cursor.

This is a DBAPI specific method and is only functional
for those backends which support it, for statements
where it is appropriate.  It's behavior is not
consistent across backends.

Usage of this method is normally unnecessary when
using insert() expression constructs; the
:attr:`~CursorResult.inserted_primary_key` attribute provides a
tuple of primary key values for a newly inserted row,
regardless of database backend.

N)r   get_lastrowidrH  ro  r>  r  r\  s     rY   	lastrowidCursorResult.lastrowid  sJ     	H<<--// 	H  11$QGG	Hs    
A&AAc                .    U R                   R                  $ )a  True if this :class:`_engine.CursorResult` returns zero or more
rows.

I.e. if it is legal to call the methods
:meth:`_engine.CursorResult.fetchone`,
:meth:`_engine.CursorResult.fetchmany`
:meth:`_engine.CursorResult.fetchall`.

Overall, the value of :attr:`_engine.CursorResult.returns_rows` should
always be synonymous with whether or not the DBAPI cursor had a
``.description`` attribute, indicating the presence of result columns,
noting that a cursor that returns zero rows still has a
``.description`` if a row-returning statement was emitted.

This attribute should be True for all results that are against
SELECT statements, as well as for DML statements INSERT/UPDATE/DELETE
that use RETURNING.   For INSERT/UPDATE/DELETE statements that were
not using RETURNING, the value will usually be False, however
there are some dialect-specific exceptions to this, such as when
using the MSSQL / pyodbc dialect a SELECT is emitted inline in
order to retrieve an inserted primary key value.


)rg  rS   r  s    rY   rS   CursorResult.returns_rows   s    4 ~~***r\   c                .    U R                   R                  $ )a4  True if this :class:`_engine.CursorResult` is the result
of a executing an expression language compiled
:func:`_expression.insert` construct.

When True, this implies that the
:attr:`inserted_primary_key` attribute is accessible,
assuming the statement did not include
a user defined "returning" construct.

)r   r  r  s    rY   	is_insertCursorResult.is_insert<  s     ||$$$r\   c              #  p   #    U R                   R                  n U" X R                  5      nUc  g Uv   M  7frU   ro  r1  r  )rW   r1  r  s      rY   _fetchiter_implCursorResult._fetchiter_implJ  s9     ''004-C{I	 s   46c                N    U R                   R                  X R                  U5      $ rU   rh  )rW   r(  s     rY   _fetchone_implCursorResult._fetchone_implS  s    ##,,T;;
KKr\   c                L    U R                   R                  X R                  5      $ rU   )ro  r:  r  r  s    rY   _fetchall_implCursorResult._fetchall_implV  s    ##,,T;;??r\   c                N    U R                   R                  X R                  U5      $ rU   )ro  r7  r  )rW   r6  s     rY   _fetchmany_implCursorResult._fetchmany_implY  s    ##--dKKFFr\   c                "    U R                  5       $ rU   )ri  r  s    rY   r8  CursorResult._raw_row_iterator\  s    ##%%r\   c                   > [         TU ]  " U6 nU R                  R                  (       a  [	        S U 4U-    5       5      Ul        U$ )Nc              3  N   #    U  H  n[        S U5      R                  v   M     g7f)r  N)r   r[  )r   r"  s     rY   r   %CursorResult.merge.<locals>.<genexpr>b  s%      ).F (&1::.s   #%)r  merger   _has_rowcountsumr[  )rW   othersmerged_resultrb   s      rY   ry  CursorResult.merge_  sG    v.<<%%%( )#g.) &M" r\   c                "    U R                  SS9  g)a  Close this :class:`_engine.CursorResult`.

This closes out the underlying DBAPI cursor corresponding to the
statement execution, if one is still present.  Note that the DBAPI
cursor is automatically released when the :class:`_engine.CursorResult`
exhausts all available rows.  :meth:`_engine.CursorResult.close` is
generally an optional method except in the case when discarding a
:class:`_engine.CursorResult` that still has additional rows pending
for fetch.

After this method is called, it is no longer valid to call upon
the fetch methods, which will raise a :class:`.ResourceClosedError`
on subsequent use.

.. seealso::

    :ref:`connections_toplevel`

Tr  N)r  r  s    rY   r  CursorResult.closeh  s    ( 	d#r\   c                ^    Xl         U R                  R                  X R                  U5        U $ rU   )
_yield_perro  r-  r  )rW   r,  s     rY   r-  CursorResult.yield_per~  s&    &&t[[#>r\   )r  rg  r  r  r  r`  ru  r   r  ro  r   )r   r+   ro  r  r   r  r  )r  r   rU   )r|  zResult[Any]r  zMergedResult[Any])r  r   )r,  r   r  r)   )/r  r  r  r  r  r  r  _NO_RESULT_METADATAr
  r  r`  
_is_cursorr   r  r  r  r   r%  r*  r.  r2  r>  rA  rE  rH  rK  rO  rR  rU  rX  r   memoized_propertyr[  r`  rS   re  ri  rl  ro  rr  r8  ry  r  r    r-  r  r  r  s   @rY   r  r  j  s   (I >=-L$FDJ$$((=6(=6 -=6 >	=6~-^#%J ;6 ;6z + +Z7,7, 
2 
2GR@@  43+.*.39 
O Ob H H( + +6 % %L@G&$,  r\   r  )r  zIteratorResult[Any])br  
__future__r   r}  r   r  typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r"  r   r   r   r   r   r   r  r    r   r   sqlr   r   r  sql.baser    sql.compilerr!   r"   r#   r$   r%   sql.type_apir&   r'   util.typingr(   r)   baser*   r[  r+   
interfacesr,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r9   r  r:   r;   r=   r?   rA   rC   r   r  _CursorKeyMapRecTyperP   r  rE   r  rJ  r^  rn  re  _NO_CURSOR_DMLrk  _DEFAULT_FETCHr|  r  r  r  r  r  ResultProxyr   r\   rY   <module>r     s|   #                     "    " (       " " - " % + " %  !  
 03'#,%&# '(3 T *  #$ Z # /
J  z   ! *   j  3  & SMI()SM  J(<<=   %I()	  F@> F@R; ;|$/ $<4 , *+34 3  *+U;- U;p %&C;%8 C;L8': 8v"$ "$J () X6": Xv r\   