
    +h                       d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 d	d
l
mZ d	dl
mZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ  ej0                  d      ZdZdZd	ZdZdZdZdZ  G d de      Z! G d de!      Z" G d de#      Z$ G d de$      Z% G d  d!e%      Z& e&       Z' G d" d#e%      Z( e(       Z) G d$ d%e$      Z* e*       Z+ G d& d'e*      Z, G d( d)e*      Z- G d* d+e      Z. G d, d-e.      Z/ e.       Z0 e/       Z1 G d. d/e#      Z2 G d0 d1e2e      Z3 G d2 d3e3      Z4e4Z5 G d4 d5e5      Z6 G d6 d7e5      Z7 G d8 d9e	      Z8 G d: d;e5      Z9y)<zjDefine cursor-specific result set constructs including
:class:`.BaseCursorResult`, :class:`.CursorResult`.    N   )Result)ResultMetaData)SimpleResultMetaData)tuplegetter)	LegacyRow   )exc)util)
expression)sqltypes)_generative)RM_NAME)
RM_OBJECTS)RM_RENDERED_NAME)RM_TYPE	unpickled            c                       e Zd ZdZdZdZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Ze	 	 dd       Zd ZddZd ZddZd Zd Zd Zd Zy)CursorResultMetaDataz"Result metadata for DBAPI cursors.)_keymapcase_sensitive_processors_keys_keymap_by_result_column_idx_tuplefilter_translated_indexes_safe_for_cacheTc                     || j                   v S N)r   selfkeys     K/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/engine/cursor.py_has_keyzCursorResultMetaData._has_key?   s    dll""    c                     t        | j                  | j                  D cg c]  }| j                  |   t            c}      S c c}w )N)extra)r   r   r   
MD_OBJECTSr$   s     r'   _for_freezez CursorResultMetaData._for_freezeB   s9    #JJ<@JJGS4<<$Z0G
 	
Gs   A
c           	         t        | j                  |            }|D cg c]  }|t            }}|D cg c]  }|t            }}| j                  r|D cg c]  }| j                  |    }}t        | }| j                  j                  | j                        }| j                  |_        | j                  |_	        ||_
        ||_        ||_        t        | j                  |            D 	cg c]  \  }	}|	f|dd  z    }
}	}|
D ci c]  }|t           | c}|_        |j                  j                  |
D ci c]  }|t           xs dD ]  }||  c}}       |S c c}w c c}w c c}w c c}}	w c c}w c c}}w )Nr    )list_metadata_for_keysMD_INDEXMD_LOOKUP_KEYr    r   	__class____new__r   r   r   r   	enumerater   updater,   )r%   keysrecsrecindexesnew_keysidxtupnew_metadataindexnew_recsnew_reces                r'   _reducezCursorResultMetaData._reduceH   s   D++D12,01S3x=112673C&77##@GHt//4HGH7#~~--dnn=&*&9&9##'#3#3 %$'!+2( ((?(?(EF
s Hs12w
 
 DLLCM 2C 7L
 	##  ( ,2  7
	
 A 27 I
  Ms"   E#E(E-0E2
E8=E=
c                    |j                   j                  s| S |j                   j                  }|j                  }||u r| S | j                  j                  | j                        }t        | j                        |_        | j                  }t        |j                        D ]  \  }}	 ||   }||j                  |<    | j                  |_        | j                  |_        | j                  rJ d|_        d|_        | j                   |_        | j                  |_        | j"                  |_        |S # t        $ r Y w xY w)a[  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)compiled_result_columns	statementinvoked_statementr4   r5   dictr   r   r6   _all_selected_columnsKeyErrorr   r   r   r    r   r!   )	r%   contextcompiled_statementrI   mdkeymap_by_positionr=   newr:   s	            r'   _adapt_to_contextz&CursorResultMetaData._adapt_to_contextm   s4    //K$--77#55!22K ^^##DNN3$,,'
!>>!"3"I"IJ 	&HC&(- #&

3	& !//))$$$$!%::*.*K*K'!11	   s   (D11	D=<D=c           
         |j                   }|j                  }d | _        d | _        |j                  | _        d| _        |j                  r|j                  \  }}}}}	t        |      }
ndx}x}x}
x}x}	}| j                  ||||
||||	      }i | _	        |D cg c]  }|t            c}| _        |j                  r|D ci c]  }|t           | c}| _        t        |D cg c]  }|t            |f c}      }|
rVt        |      |
k7  ri }t#               }|D ]  }|t$           f|t&           xs dz   D ]h  }| j                  s*t)        |t*        j,                        r|j/                         }|t0           }|j3                  ||      |k7  sX|j5                  |       j  | j                  j7                  |D cg c]!  }|t&           r|t&           D ]
  }||vr||f # c}}       |j7                  |D ci c]	  }|d d d|f c}       nD| j                  j7                  |D cg c]  }|t&           r|t&           D ]  }||f  c}}       | j                  j7                  |       |
s]|j8                  rP| j                  j7                  |D cg c]*  }|t:           r|t:           | j                  |t               f, c}       y y y c c}w c c}w c c}w c c}}w c c}w c c}}w c c}w )NFr/   )rM   dialectr   r    r   r!   result_column_structlen_merge_cursor_descriptionr   MD_PROCESSORr   rF   MD_RESULT_MAP_INDEXr   rJ   r3   setMD_RENDERED_NAMEr,   
isinstancer   string_typeslowerr2   
setdefaultaddr7   _translate_colnameMD_UNTRANSLATED)r%   parentcursor_descriptionrM   rT   result_columnscols_are_orderedtextual_orderedad_hoc_textualloose_column_name_matchingnum_ctx_colsrawmetadata_entryby_keyindex_by_keydupesr&   r=   obj_elems                      r'   __init__zCursorResultMetaData.__init__   s|   ..// #' %44$'' ,, *~.L @EEN E E E
 E +_ ,,&	
 
 @C
-;N<(
  '*1" 23^C1D-  '*"  .?
 6{l*  "&) +N ./? @B&z28b  +  $22z!2!28 #&))+C,X6 (223<C!IIcN++  ## /2*)*5(6z(B	 %#50	 ">22 UKcsT4S$99KL
 ## /2*)*5(6z(B	 % ">22 	F#  : :LL +.
 '%o6	 '7^M%BC	 !;|o

1Z Ls*   K K"K=&K
:K$*"K)
/K/c	                    |j                   j                  }	|r|r|s|t        |      k(  r|D 
cg c]  }
|
d   	 c}
| _        d| _        t        |      D cg c]a  \  }}|||t           |	s|t           j                         n|t           |t           |j                  |t           |t           ||   d         dfc c}}S |s|r)t        |      |k(  rd| _        | j                  |||      }n7|rd| _        | j                  ||||      }nd| _        | j                  ||      }|D cg c]$  \  }}}}}}}||||||j                  |||      |f& c}}}}}}}S c c}
w c c}}w c c}}}}}}}w )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 te 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)rT   r   rV   r   r!   r6   r   r   r^   r   get_result_processorr   _merge_textual_cols_by_position_merge_cols_by_name_merge_cols_by_none)r%   rM   rd   re   rj   rf   rg   rh   ri   r   elemr=   
rmap_entryraw_iteratorridxcursor_colnamemapped_typecoltypeobjuntranslateds                       r'   rW   z.CursorResultMetaData._merge_cursor_description)  s   D !77  #$6 77.<=d$q'=DJ $(D " (1'@!  $C z*) w'--/#G,/000"7+"#34*3/2
  . 3'9#:l#J'+$#CC/  
 (-$#77&".	  (-$#77/ 0 ") " # ""00#^W !
  u >f s   E"A&E'0)E-c              #     K   |j                   }|j                  }|j                  }|j                  r|j                  nd}|j
                  r|j                  nd}d}g | _        t        |      D ]e  \  }	}
|
d   }|
d   }|r ||      }|r ||      \  }}|r ||      }| j                  j                  |       |s|j                         }|	|||f g yw)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   )rT   r   ra   description_encoding_description_decoderrequires_name_normalizenormalize_namer   r6   appendr^   )r%   rM   rd   rT   r   translate_colnamedescription_decoderr   r   r=   r:   colnamer}   s                r'   _colnames_from_descriptionz/CursorResultMetaData._colnames_from_description  s      // //#66 ++ (( 	 '.&E&EG""4 	 
!"45 	6HC!fG!fG"-g6 (9'(B%(1JJg&!!--/wg55#	6s   CCc              #     K   |rt        |      nd }|t        |      kD  r#t        j                  d|t        |      fz         t               }| j	                  ||      D ]{  \  }}}}	||k  rP||   }
|
t
           }|}|
t           }|d   |v rt        j                  d|d   z        |j                  |d          nt        j                  }d }d }|||||	||f } y w)NzVNumber of columns in textual SQL (%d) is smaller than number of columns requested (%d)r   z8Duplicate column expression requested in textual SQL: %r)rV   r   warnrZ   r   r   r   r
   InvalidRequestErrorr`   r   NULLTYPE)r%   rM   rd   re   rj   seenr=   r   r   r}   ctx_recr~   rz   r|   s                 r'   rt   z4CursorResultMetaData._merge_textual_cols_by_position  s     /=s>*$#011II@%7!89:
 u ,,W6HI	N 
\!(-j)%g.q6T>11-/21v6  Q &//tWk7CMM+	Ns   CCc              #      K   |j                   }|j                  }| j                  |||      }| j                  ||      D ]'  \  }}	}
}	 ||	   }|d   }|d   }|d   }|||	||||
f ) y # t        $ r t
        j                  }d }d }Y -w xY ww)Nr   r	   r   )rT   r   _create_description_match_mapr   rL   r   r   )r%   rM   rd   re   ri   rT   r   	match_mapr=   r   r   r}   r   r~   r|   result_columns_idxs                   r'   ru   z(CursorResultMetaData._merge_cols_by_name  s      // //66N,F
	 ,,W6HI	 
	0#G, aj%aj%,QZ"" !	  *&//%)"*s*   AB	A+B+BB
BBc           	      ^   i }t        |      D ]  \  }}|t           }|s|j                         }||v r||   \  }}	}
}||	|t           z   |
|f||<   n|t           |t           |t
           |f||<   |sd|t           D ]-  }|j                  ||t           |t           |t
           |f       /  |S )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.
        )r6   r   r^   r   r   r   r_   )clsre   r   ri   drz   rw   r&   e_namee_obje_typee_ridxr_keys                r'   r   z2CursorResultMetaData._create_description_match_map7  s     #N3 	JD$'(C!iikax
 12#-vvj)9!964G#w-j)94=$O#) "*- ELLgZ(8$w-N+	6 r)   c              #   v   K   | j                  ||      D ]   \  }}}}|d |t        j                  |d |f " y wr#   )r   r   r   )r%   rM   rd   r=   r   r   r}   s          r'   rv   z(CursorResultMetaData._merge_cols_by_nonea  s[      ,,W6HI	 
 !! 	s   79c                     |rAt        j                  t        j                  dt        j                  |      z        |       y y )N.Could not locate column in row for column '%s'replace_context)r   raise_r
   NoSuchColumnErrorstring_or_unprintable)r%   r&   errraiseerrs       r'   _key_fallbackz"CursorResultMetaData._key_fallbackr  s?    KK%%D0056 !$ r)   c                 @    t        j                  d|t           z        )Nz<Ambiguous column name '%s' in result set column descriptions)r
   r   r3   )r%   r:   s     r'    _raise_for_ambiguous_column_namez5CursorResultMetaData._raise_for_ambiguous_column_name~  s(    %%-/2=/AB
 	
r)   c                     t        |t              r| j                  |   }	 | j                  |   }|d   }|| j                  |       |S # t        $ r$}| j                  |||      }|Y d }~y Y d }~Bd }~ww xY wNr   )r\   intr   r   rL   r   r   )r%   r&   r   r:   ker@   s         r'   _index_for_keyz#CursorResultMetaData._index_for_key  s     c3**S/C	,,s#C A=11#6  	$$S"h7C{ 	s   A
 
	A7A22A7c                     	 |D cg c]  }| j                   |   d    c}S c c}w # t        $ r.}t        j                  | |j                  d   |       Y d }~y d }~ww xY wr   )r   rL   r   r   args)r%   r8   r&   r   s       r'   _indexes_for_keysz&CursorResultMetaData._indexes_for_keys  sY    	E489SDLL%a(999 	E ..tRWWQZDD	Es    ' "' ' 	A$AAc              #   <  K   |D ]Y  }t         |j                  j                  v r| j                  |   }	 | j                  |   }d   }|| j                  |       | [ y # t
        $ r.}t        j                  | |j                  d   |       Y d }~Qd }~ww xY wwr   )
r   r4   __mro__r   r   rL   r   r   r   r   )r%   r8   r&   r:   r   r@   s         r'   r1   z'CursorResultMetaData._metadata_for_keys  s      	Ccmm+++jjoIll3'
 FE}55c:I	  I$224RHHIs.   1BA"B"	B+$BBBBc           	      H   | j                   j                         D ci c]I  \  }}t        |t        j                  t        j
                  z         r||t           |t           t        |fK c}}| j                  | j                  | j                  | j                  dS c c}}w )N)r   r   r   r    r   )r   itemsr\   r   r]   	int_typesr2   rY   
_UNPICKLEDr   r   r    r   )r%   r&   r:   s      r'   __getstate__z!CursorResultMetaData.__getstate__  s     !% 2 2 4Cc4#4#4t~~#EF c(mS)<%=z3OO
 ZZ"11#'#;#; --

 
	
s   ABc                 |   t        t        |d               D cg c]  }d  c}| _        |d   | _        | j                  j	                         D ci c]  }|t
           | c}| _        |d   | _        |d   | _        |d   r"|d   | _	        t        | j                   | _        y d x| _	        | _        y c c}w c c}w )Nr   r   r   r    )rangerV   r   r   valuesrY   r   r   r   r    r   r   )r%   state_r:   s       r'   __setstate__z!CursorResultMetaData.__setstate__  s    */E'N0C*DEQDEY' 6:\\5H5H5J-
.1C#$c)-
) 7^
#$45&'',-B'CD$ +T-E-E FD;??D$t'8 F-
s   	B4B9N)TFT)__name__
__module____qualname____doc__	__slots__returns_rowsr(   r-   rD   rR   rq   rW   r   rt   ru   classmethodr   rv   r   r   r   r   r1   r   r   r/   r)   r'   r   r   -   s    ,I L#
#J,\L\Yv(6T!NF$L  #(	' 'R"

&E$
@r)   r   c                   *    e Zd ZdZd ZddZd Zd Zy)LegacyCursorResultMetaDatar/   c                 x    |}|| j                   v rt        j                  d       y| j                  |d d      d uS )NzUsing the 'in' operator to test for string or column keys, or integer indexes, in a :class:`.Row` object is deprecated and will be removed in a future release. Use the `Row._fields` or `Row._mapping` attribute, i.e. 'key in row._fields'TF)r   r   warn_deprecated_20r   )r%   valuerowr&   s       r'   	_containsz$LegacyCursorResultMetaData._contains  sE    $,,##' %%c47tCCr)   c                 D   | j                   }d }t        |t        j                        r/|j	                  | j
                  r|n|j                               }n|t        |t        j                        ra|j                  rj| j
                  r|j                  n|j                  j                         |v r6|| j
                  r|j                  n|j                  j                            }nut        |d      ri| j
                  r|j                  n|j                  j                         |v r5|| j
                  r|j                  n|j                  j                            }|4|t           d t        fvr#|t           D ]  }|j                  |      s n d }|>|t           t        u rt        j                  dd       nt        j                  dd       |E|rBt        j                   t#        j$                  dt        j&                  |      z        |       |S y |||<   |S )NnamezRetrieving row values using Column objects from a row that was unpickled is deprecated; adequate state cannot be pickled for this to be efficient.   This usage will raise KeyError in a future release.z1.4)versionzRetrieving row values using Column objects with only matching names as keys is deprecated, and will raise KeyError in a future release; only Column objects that are explicitly part of the statement object should be used.r   r   )r   r\   r   r]   getr   r^   r   ColumnElement	_tq_labelhasattrr   r,   r   _compare_name_for_resultwarn_deprecatedr   r
   r   r   )r%   r&   r   r   map_resultr~   s          r'   r   z(LegacyCursorResultMetaData._key_fallback  s   ||c4,,-XXT%8%8cciikJFZ556 ** MM,,. ** MM,,. V$!%!4!4SXX#((..:J  $ 3 3CHH9I !fZ&8A ' "*- "C33C8" "F!*%3((N !& ((1
 !& >))H44S9: %(  DIr)   c                 2    t        j                  dd       y )NzUsing non-integer/slice indices on Row is deprecated and will be removed in version 2.0; please use row._mapping[<key>], or the mappings() accessor on the Result object.r   )
stacklevelr   r   r$   s     r'   _warn_for_nonintz+LegacyCursorResultMetaData._warn_for_nonint.  s    < 		
r)   c                 J    || j                   v ry| j                  |d d      d uS )NTF)r   r   r$   s     r'   r(   z#LegacyCursorResultMetaData._has_key6  s+    $,,%%c47tCCr)   Nr   )r   r   r   r   r   r   r   r(   r/   r)   r'   r   r     s    IDKZ
Dr)   r   c                   F    e Zd ZdZdZdZd Zd Zd ZddZ	ddZ
d	 Zd
 Zy)ResultFetchStrategyzQDefine a fetching strategy for a result object.


    .. versionadded:: 1.4

    r/   Nc                     t               r#   NotImplementedErrorr%   r   dbapi_cursors      r'   
soft_closezResultFetchStrategy.soft_closeI      !##r)   c                     t               r#   r   r   s      r'   
hard_closezResultFetchStrategy.hard_closeL  r   r)   c                      y r#   r/   r%   r   r   nums       r'   	yield_perzResultFetchStrategy.yield_perO  s    r)   c                     t               r#   r   r%   r   r   r   s       r'   fetchonezResultFetchStrategy.fetchoneR  r   r)   c                     t               r#   r   r%   r   r   sizes       r'   	fetchmanyzResultFetchStrategy.fetchmanyU  r   r)   c                     t               r#   r   )r%   r   s     r'   fetchallzResultFetchStrategy.fetchallX  r   r)   c                     |r#   r/   r%   r   r   r   s       r'   handle_exceptionz$ResultFetchStrategy.handle_exception[  s    	r)   Fr#   )r   r   r   r   r   alternate_cursor_descriptionr   r   r   r   r   r   r   r/   r)   r'   r   r   =  s7     I#' $$$$$r)   r   c                   >    e Zd ZdZdZd Zd Zd
dZddZd Z	dd	Z
y)NoCursorFetchStrategyzCursor 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                      y r#   r/   r   s      r'   r   z NoCursorFetchStrategy.soft_closej      r)   c                      y r#   r/   r   s      r'   r   z NoCursorFetchStrategy.hard_closem  r   r)   c                 &    | j                  |d       S r#   _non_resultr   s       r'   r   zNoCursorFetchStrategy.fetchonep  s    --r)   Nc                 &    | j                  |g       S r#   r   r   s       r'   r   zNoCursorFetchStrategy.fetchmanys      ++r)   c                 &    | j                  |g       S r#   r   r   s      r'   r   zNoCursorFetchStrategy.fetchallv  r  r)   c                     t               r#   r   r%   r   defaultr   s       r'   r  z!NoCursorFetchStrategy._non_resulty  r   r)   r   r#   )r   r   r   r   r   r   r   r   r   r   r  r/   r)   r'   r   r   _  s,     I.,,$r)   r   c                       e Zd ZdZdZddZy)NoCursorDQLFetchStrategya  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                 t    |j                   r+t        j                  t        j                  d      |       y |S )NzThis result object is closed.r   )closedr   r   r
   ResourceClosedErrorr  s       r'   r  z$NoCursorDQLFetchStrategy._non_result  s.    ==KK''(GH #
 Nr)   r#   r   r   r   r   r   r  r/   r)   r'   r	  r	  }  s     Ir)   r	  c                       e Zd ZdZdZddZy)NoCursorDMLFetchStrategyzCursor 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                 j    |j                   j                  rJ |j                   j                  |       y r#   )	_metadatar   _we_dont_return_rowsr  s       r'   r  z$NoCursorDMLFetchStrategy._non_result  s+    ##0000--c2r)   r#   r  r/   r)   r'   r  r    s     I3r)   r  c                   B    e Zd ZdZdZd Zd Zd Zd ZddZ	dd	Z
d
 Zy)CursorFetchStrategyzCall 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                     t         |_        y r#   _NO_CURSOR_DQLcursor_strategyr   s      r'   r   zCursorFetchStrategy.soft_close  
    !/r)   c                     t         |_        y r#   r  r   s      r'   r   zCursorFetchStrategy.hard_close  r  r)   c                 V    |j                   j                  |d d ||j                         y r#   )
connection_handle_dbapi_exceptionrM   r   s       r'   r   z$CursorFetchStrategy.handle_exception  s%    11t\6>>	
r)   c                 T    t        |d|it        j                         d      |_        y )Nmax_row_bufferr   )initial_buffergrowth_factor)BufferedRowCursorFetchStrategycollectionsdequer  r   s       r'   r   zCursorFetchStrategy.yield_per  s)    !?s#&,,.	"
r)   c                     	 |j                         }||j                  |       |S # t        $ r}| j                  |||       Y d }~y d }~ww xY wNhard)r   _soft_closeBaseExceptionr   )r%   r   r   r   r   rC   s         r'   r   zCursorFetchStrategy.fetchone  sU    	;'')C{""
"3J 	;!!&,::	;s   %( 	AA		ANc                     	 ||j                         }n|j                  |      }|s|j                          |S # t        $ r}| j                  |||       Y d }~y d }~ww xY wr#   )r   r)  r*  r   )r%   r   r   r   lrC   s         r'   r   zCursorFetchStrategy.fetchmany  sc    
	;| **, **40""$H 	;!!&,::	;s   7: 	A AA c                     	 |j                         }|j                          |S # t        $ r}| j                  |||       Y d }~y d }~ww xY wr#   )r   r)  r*  r   )r%   r   r   rowsrC   s        r'   r   zCursorFetchStrategy.fetchall  sK    	;((*D K 	;!!&,::	;s   !$ 	A
AA
r   r#   )r   r   r   r   r   r   r   r   r   r   r   r   r/   r)   r'   r  r    s1     I00


;;;r)   r  c                   n     e Zd ZdZdZ	 	 ddZed        Zd Zd Z	 fdZ
 fdZdd	Zdd
Zd Z xZS )r"  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                    |j                  dd      | _        ||| _        n)t        j                  |j                  d            | _        || _        |r&t        | j                  | j                        | _        y | j                  | _        y )Nr  i  r   )	r   r0  r1  r#  r$  r   r3  minr2  )r%   r   execution_optionsr!  r   s        r'   rq   z'BufferedRowCursorFetchStrategy.__init__  sv      1445EtL%,DO)//0F0Fq0IJDO+ 4 4d6I6IJDM 00DMr)   c                 V    t        |j                  |j                  j                        S r#   )r"  cursorrM   r6  )r   r   s     r'   createz%BufferedRowCursorFetchStrategy.create  s#    -MMNN,,
 	
r)   c                    | j                   }	 |dk  r|j                         }n|j                  |      }syt        j                  |      | _        | j                  r9|| j                  k  r)t        | j                  || j                  z        | _         yyy# t        $ r}| j	                  |||       Y d}~d}~ww xY w)z*this is currently used only by fetchone().r   N)r2  r   r   r*  r   r#  r$  r1  r3  r0  r5  )r%   r   r   r   new_rowsrC   s         r'   _buffer_rowsz+BufferedRowCursorFetchStrategy._buffer_rows"  s     }}	;ax'002'11$7 %++H54$*>*>#>$$dT-@-@&@DM $?  	;!!&,::	;s   'B 	B>!B99B>c                 .    d| _         |x| _        | _        y r   )r3  r0  r2  r   s       r'   r   z(BufferedRowCursorFetchStrategy.yield_per6  s    /22t}r)   c                 b    | j                   j                          t        t        |   ||       y r#   )r1  clearsuperr"  r   r%   r   r   r4   s      r'   r   z)BufferedRowCursorFetchStrategy.soft_close:  (    ,d>L	
r)   c                 b    | j                   j                          t        t        |   ||       y r#   )r1  r?  r@  r"  r   rA  s      r'   r   z)BufferedRowCursorFetchStrategy.hard_close@  rB  r)   c                    | j                   s2| j                  ||       | j                   s	 |j                  |       y | j                   j                         S # t        $ r}| j	                  |||       Y d }~y d }~ww xY wr&  )r1  r<  r)  r*  r   popleft)r%   r   r   r   rC   s        r'   r   z'BufferedRowCursorFetchStrategy.fetchoneF  s{    fl3??C&&J&7 &&(( % C))&,BBCs   A 	A?"A::A?c                    || j                  ||      S t        | j                        }t        |      }||kD  r:	 |j	                  ||z
        }|s|j                          n|j                  |       	 |d| }t        j                  ||d        | _        |S # t        $ r}| j                  |||       Y d }~Ed }~ww xY wr   )r   r0   r1  rV   r   r)  extendr*  r   r#  r$  )r%   r   r   r   buflbrQ   rC   s           r'   r   z(BufferedRowCursorFetchStrategy.fetchmanyQ  s    <==664??#X"9$",,TBY7 &&(JJsOQt%++CJ7 ! ?%%flA>>?s   B 	B>!B99B>c                    	 t        | j                        t        |j                               z   }| j                  j                          |j	                          |S # t
        $ r}| j                  |||       Y d }~y d }~ww xY wr#   )r0   r1  r   r?  r)  r*  r   )r%   r   r   retrC   s        r'   r   z'BufferedRowCursorFetchStrategy.fetchallf  sn    	;t'$|/D/D/F*GGCOO!!# J 	;!!&,::	;s   AA 	B&A>>B)r   Nr   r#   )r   r   r   r   r   rq   r   r9  r<  r   r   r   r   r   r   __classcell__r4   s   @r'   r"  r"    sT    6 PI 1( 
 
(3

	)*;r)   r"  c                   V     e Zd ZdZdZ	 d
dZd Z fdZ fdZddZ	ddZ
d	 Z xZS ) FullyBufferedCursorFetchStrategyzA 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.

    )r1  r   c                     || _         |t        j                  |      | _        y t        j                  |j	                               | _        y r#   )r   r#  r$  r1  r   )r%   r   alternate_descriptionr   s       r'   rq   z)FullyBufferedCursorFetchStrategy.__init__{  s@     -B)%)//?DO)//0E0E0GHDOr)   c                      y r#   r/   r   s       r'   r   z*FullyBufferedCursorFetchStrategy.yield_per  r   r)   c                 b    | j                   j                          t        t        |   ||       y r#   )r1  r?  r@  rO  r   rA  s      r'   r   z+FullyBufferedCursorFetchStrategy.soft_close  (    .@L	
r)   c                 b    | j                   j                          t        t        |   ||       y r#   )r1  r?  r@  rO  r   rA  s      r'   r   z+FullyBufferedCursorFetchStrategy.hard_close  rT  r)   c                 t    | j                   r| j                   j                         S |j                  |       y r&  )r1  rE  r)  r   s       r'   r   z)FullyBufferedCursorFetchStrategy.fetchone  s0    ????**,,J/r)   c                     || j                  ||      S t        | j                        }|d| }t        j                  ||d        | _        |s|j                          |S r   )r   r0   r1  r#  r$  r)  )r%   r   r   r   rH  r.  s         r'   r   z*FullyBufferedCursorFetchStrategy.fetchmany  s]    <==664??#1T{%++CJ7 r)   c                 p    | j                   }t        j                         | _         |j                          |S r#   )r1  r#  r$  r)  )r%   r   r   rK  s       r'   r   z)FullyBufferedCursorFetchStrategy.fetchall  s,    oo%++-
r)   )NNr   r#   )r   r   r   r   r   rq   r   r   r   r   r   r   rL  rM  s   @r'   rO  rO  p  s:     ?I HLI

	r)   rO  c                   N    e Zd ZdZdZd
dZd Zd Zd Ze	d        Z
e	d	        Zy)_NoResultMetaDatar/   FNc                 X    t        j                  t        j                  d      |       y )NzJThis result object does not return rows. It has been closed automatically.r   )r   r   r
   r  )r%   r   s     r'   r  z&_NoResultMetaData._we_dont_return_rows  s&    ##4  	
r)   c                 $    | j                          y r#   r  )r%   r8   r   s      r'   r   z _NoResultMetaData._index_for_key      !!#r)   c                 $    | j                          y r#   r]  r$   s     r'   r1   z$_NoResultMetaData._metadata_for_keys  r^  r)   c                 $    | j                          y r#   r]  )r%   r8   s     r'   rD   z_NoResultMetaData._reduce  r^  r)   c                 $    | j                          y r#   r]  r%   s    r'   r   z_NoResultMetaData._keymap      !!#r)   c                 $    | j                          y r#   r]  rb  s    r'   r8   z_NoResultMetaData.keys  rc  r)   r#   )r   r   r   r   r   r  r   r1   rD   propertyr   r8   r/   r)   r'   rZ  rZ    sH    IL
$$$ $ $ $ $r)   rZ  c                       e Zd Zed        Zy)_LegacyNoResultMetaDatac                 0    t        j                  d       g S )NzCalling the .keys() method on a result set that does not return rows is deprecated and will raise ResourceClosedError in SQLAlchemy 2.0.r   rb  s    r'   r8   z_LegacyNoResultMetaData.keys  s    	

 	r)   N)r   r   r   re  r8   r/   r)   r'   rg  rg    s     r)   rg  c                       e Zd ZdZdZdZdZdZd Zd Z	ddZ
ed        Zed        Zd	 Zd
 Zed        Zed        Zd Zd Zd Zd Zd Zej0                  d        Zed        Zed        Zed        Zy)BaseCursorResultz'Base class for database result objects.NFc                 x   || _         |j                  | _        |j                  | _        || _        |j                  | _        | j
                  j                  xr |j                  j                         x| _        }||r-| j                   j
                  j                  fd| _
        nd | j                  ||      }|j                  }|j                  }| j                  }|j                  }	t!        j"                  |||||	      rfd}
n}
| j%                  d|
       y | j&                  | _        y )Nc                 @     dt        j                  |              | S )NzRow %r)sql_util	_repr_row)r   logs    r'   log_rowz*BaseCursorResult.__init__.<locals>.log_row  s    ("4"4S"9:Jr)   c                 (     |       } |       |S r#   r/   )r   made_row	_make_rowrp  s     r'   make_rowz+BaseCursorResult.__init__.<locals>.make_row  s    (~HH%#Or)   _row_getter)rM   rT   r8  r  root_connectionr  _echoengine_should_log_debug
_log_debug_row_logging_fn_init_metadatar   r   _process_row_default_key_style	functoolspartial_set_memoized_attribute_no_result_metadatar  )r%   rM   r  rd   echometadatakeymap
processorsprocess_row	key_stylert  rs  ro  rp  s              @@@r'   rq   zBaseCursorResult.__init__  s   nn.!11OO!!Hgnn&F&F&H	

T )
 ll--88 (/$**74FGH%%F!--J++K#66I!))Xz69I $ %((A "55DNr)   c                    |j                   r|j                   j                  r!| j                  j                   j                  }n/| j                  | |      }|j                  r||j                   _        |j                   }|rs|j
                  rg|j                  |j                  j                  u rE|j                  j                  dd      s)|j                  |j                  ur|j                  |      }|| _        n| j                  | |      x| _        }| j                  r,|j                   j#                  dt%        d |D                     |S )N _result_disable_adapt_to_contextFzCol %rc              3   &   K   | ]	  }|d      yw)r   Nr/   ).0xs     r'   	<genexpr>z2BaseCursorResult._init_metadata.<locals>.<genexpr>@  s     A!As   )rF   _cached_metadatarM   _cursor_metadatar!   rG   	cache_hitrT   	CACHE_HITr6  r   rH   rI   rR   r  rw  r  rz  tuple)r%   rM   rd   r  rF   s        r'   r|  zBaseCursorResult._init_metadata  s&   00<<00AA007IJ++8@G$$5  ''H,,%%)B)BB11556 &&g.G.GG#55g>%DN )-(=(=() DNX ::))%A.@AA r)   c                 n   |s| j                   s|r| j                  ry|r.d| _        | j                  j                  | | j                         n&| j                  j                  | | j                         | j                   s6| j                  }d| _        | j                  j                  |       d| _         yy)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.

        .. versionadded:: 1.0.0

        .. seealso::

            :meth:`_engine.CursorResult.close`


        NT)_soft_closedr  r  r   r8  r   r  _safe_close_cursor)r%   r(  r8  s      r'   r)  zBaseCursorResult._soft_closeD  s    . **DK  ++D$++>  ++D$++>  [[FDKOO..v6 $D	 !r)   c                 0   | j                   j                  st        j                  d      | j                   j                  st        j                  d      | j                   j
                  rt        j                  d      | j                   j                  S )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.)rM   rF   r
   r   isinsert_is_explicit_returninginserted_primary_key_rowsrb  s    r'   r  z*BaseCursorResult.inserted_primary_key_rowsj  s    \ ||$$))F  &&))G  \\00)) 
 ||555r)   c                     | j                   j                  rt        j                  d      | j                  }|r|d   S y)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)rM   executemanyr
   r   r  )r%   ikps     r'   inserted_primary_keyz%BaseCursorResult.inserted_primary_key  sF    B <<##))2  ,,q6Mr)   c                 8   | j                   j                  st        j                  d      | j                   j                  st        j                  d      | j                   j
                  r| j                   j                  S | j                   j                  d   S )a  Return 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   )rM   rF   r
   r   isupdater  compiled_parametersrb  s    r'   last_updated_paramsz$BaseCursorResult.last_updated_params       ||$$))F  &&))G  \\%%<<333<<33A66r)   c                 8   | j                   j                  st        j                  d      | j                   j                  st        j                  d      | j                   j
                  r| j                   j                  S | j                   j                  d   S )a  Return 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   )rM   rF   r
   r   r  r  r  rb  s    r'   last_inserted_paramsz%BaseCursorResult.last_inserted_params  r  r)   c                 .    | j                   j                  S )a  Return 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

        )rM   returned_default_rowsrb  s    r'   returned_defaults_rowsz'BaseCursorResult.returned_defaults_rows  s     ||111r)   c                     | j                   j                  rt        j                  d      | j                   j                  }|r|d   S y)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.

        .. versionadded:: 0.9.0

        .. seealso::

            :meth:`.ValuesBase.return_defaults`

        zlThis statement was an executemany call; if return defaults is supported, please use .returned_defaults_rows.r   N)rM   r  r
   r   r  )r%   r.  s     r'   returned_defaultsz"BaseCursorResult.returned_defaults  sJ    " <<##))D 
 ||117Nr)   c                 6    | j                   j                         S )zReturn ``lastrow_has_defaults()`` from the underlying
        :class:`.ExecutionContext`.

        See :class:`.ExecutionContext` for details.

        )rM   lastrow_has_defaultsrb  s    r'   r  z%BaseCursorResult.lastrow_has_defaults,  s     ||0022r)   c                    | j                   j                  st        j                  d      | j                   j                  s+| j                   j
                  st        j                  d      | j                   j                  S )aM  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.)rM   rF   r
   r   r  r  postfetch_colsrb  s    r'   r  zBaseCursorResult.postfetch_cols6  sl     ||$$))F  &&t||/D/D))(  ||***r)   c                    | j                   j                  st        j                  d      | j                   j                  s+| j                   j
                  st        j                  d      | j                   j                  S )aL  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  r  )rM   rF   r
   r   r  r  prefetch_colsrb  s    r'   r  zBaseCursorResult.prefetch_colsM  sl     ||$$))F  &&t||/D/D))(  ||)))r)   c                 .    | j                   j                  S )zReturn ``supports_sane_rowcount`` from the dialect.

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

        )rT   supports_sane_rowcountrb  s    r'   r  z'BaseCursorResult.supports_sane_rowcountd  s     ||222r)   c                 .    | j                   j                  S )zReturn ``supports_sane_multi_rowcount`` from the dialect.

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

        )rT   supports_sane_multi_rowcountrb  s    r'   r  z-BaseCursorResult.supports_sane_multi_rowcountm  s     ||888r)   c                     	 | j                   j                  S # t        $ r1}| j                  j	                  | | j
                  |       Y d}~yd}~ww xY w)a~  Return the 'rowcount' for this result.

        The 'rowcount' reports the number of rows *matched*
        by the WHERE criterion of an UPDATE or DELETE statement.

        .. 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* - an UPDATE statement, for example,
             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 by default to return the match
             count in all cases.

           * :attr:`_engine.CursorResult.rowcount`
             is *only* useful in conjunction
             with an UPDATE or DELETE statement.  Contrary to what the Python
             DBAPI says, it does *not* return the
             number of rows available from the results of a SELECT statement
             as DBAPIs cannot support this functionality when rows are
             unbuffered.

           * :attr:`_engine.CursorResult.rowcount`
             may not be fully implemented by
             all dialects.  In particular, most DBAPIs do not support an
             aggregate rowcount result from an executemany call.
             The :meth:`_engine.CursorResult.supports_sane_rowcount` and
             :meth:`_engine.CursorResult.supports_sane_multi_rowcount` methods
             will report from the dialect if each usage is known to be
             supported.

           * Statements that use RETURNING may not return a correct
             rowcount.

        .. seealso::

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

        N)rM   rowcountr*  r  r   r8  r%   rC   s     r'   r  zBaseCursorResult.rowcountv  sJ    `	H<<((( 	H  11$QGG	Hs    	A'AAc                     	 | j                   j                         S # t        $ r1}| j                  j	                  | | j
                  |       Y d}~yd}~ww xY w)a0  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)rM   get_lastrowidr*  r  r   r8  r  s     r'   	lastrowidzBaseCursorResult.lastrowid  sL     	H<<--// 	H  11$QGG	Hs    	A'AAc                 .    | j                   j                  S )aq  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.


        )r  r   rb  s    r'   r   zBaseCursorResult.returns_rows  s    4 ~~***r)   c                 .    | j                   j                  S )al  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.

        )rM   r  rb  s    r'   	is_insertzBaseCursorResult.is_insert  s     ||$$$r)   r   )r   r   r   r   out_parametersr  r  r  rq   r|  r)  re  r  r  r  r  r  r  r  r  r  r  r  r   memoized_propertyr  r  r   r  r/   r)   r'   rj  rj    s    1NILF/6b.`$%L ;6 ;6z + +Z7,7, 
2 
2  83+.*.39 
2H 2Hh H H( + +6 % %r)   rj  c                   j     e Zd ZdZeZeZeZ	dZ
d ZddZd ZddZd Z fdZd	 Zed
        Z xZS )CursorResultaH  A Result that is representing state from a DBAPI cursor.

    .. versionchanged:: 1.4  The :class:`.CursorResult` and
       :class:`.LegacyCursorResult`
       classes replace the previous :class:`.ResultProxy` interface.
       These 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.

    Within the scope of the 1.x series of SQLAlchemy, Core SQL results in
    version 1.4 return an instance of :class:`._engine.LegacyCursorResult`
    which takes the place of the ``CursorResult`` class used for the 1.3 series
    and previously.  This object returns rows as :class:`.LegacyRow` objects,
    which maintains Python mapping (i.e. dictionary) like behaviors upon the
    object itself.  Going forward, the :attr:`.Row._mapping` attribute should
    be used for dictionary behaviors.

    .. seealso::

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

    Tc              #   n   K   | j                   j                  }	  || | j                        }|y | wr#   r  r   r8  )r%   r   r   s      r'   _fetchiter_implzCursorResult._fetchiter_impl  s<     ''004-C{I	 s   35c                 P    | j                   j                  | | j                  |      S r#   r  )r%   r   s     r'   _fetchone_implzCursorResult._fetchone_impl  s!    ##,,T4;;
KKr)   c                 N    | j                   j                  | | j                        S r#   )r  r   r8  rb  s    r'   _fetchall_implzCursorResult._fetchall_impl  s    ##,,T4;;??r)   c                 P    | j                   j                  | | j                  |      S r#   )r  r   r8  )r%   r   s     r'   _fetchmany_implzCursorResult._fetchmany_impl  s!    ##--dDKKFFr)   c                 "    | j                         S r#   )r  rb  s    r'   _raw_row_iteratorzCursorResult._raw_row_iterator   s    ##%%r)   c                     t        t        | 
  | }| j                  j                   }|rt        d | f|z   D              |_        |S )Nc              3   4   K   | ]  }|j                     y wr#   )r  )r  r   s     r'   r  z%CursorResult.merge.<locals>.<genexpr>'  s      )$*)s   )r@  r  merger  r   sumr  )r%   othersmerged_resultsetup_rowcountsr4   s       r'   r  zCursorResult.merge#  sR    lD7@"nn999%( )/3g.>) &M" r)   c                 (    | j                  d       y)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)  rb  s    r'   closezCursorResult.close,  s    ( 	d#r)   c                 `    || _         | j                  j                  | | j                  |       y r#   )
_yield_perr  r   r8  )r%   r   s     r'   r   zCursorResult.yield_perB  s%    &&tT[[#>r)   r   r#   )r   r   r   r   r   r  r  _cursor_strategy_cls_NO_RESULT_METADATAr  
_is_cursorr  r  r  r  r  r  r  r   r   rL  rM  s   @r'   r  r    s[    : ,.-JL@G&$, ? ?r)   r  c                   >     e Zd ZdZdZeZeZe	Z
eZd Zd fd	Z xZS )LegacyCursorResulta
  Legacy version of :class:`.CursorResult`.

    This class includes connection "connection autoclose" behavior for use with
    "connectionless" execution, as well as delivers rows using the
    :class:`.LegacyRow` row implementation.

    .. versionadded:: 1.4

    Fc                 (    | j                  d       y)aE  Close this :class:`_engine.LegacyCursorResult`.

        This method has the same behavior as that of
        :meth:`._engine.CursorResult`, but it also may close
        the underlying :class:`.Connection` for the case of "connectionless"
        execution.

        .. deprecated:: 2.0 "connectionless" execution is deprecated and will
           be removed in version 2.0.   Version 2.0 will feature the
           :class:`_future.Result`
           object that will no longer affect the status
           of the originating connection in any case.

        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`

            :ref:`dbengine_implicit`
        Tr'  Nr  rb  s    r'   r  zLegacyCursorResult.closeZ  s    0 	d#r)   c                     | j                   }t        t        |   |       |s5| j                   r(| j                  r| j
                  j                          y y y y r&  )r  r@  r  r)  _autoclose_connectionr  r  )r%   r(  soft_closedr4   s      r'   r)  zLegacyCursorResult._soft_closet  sU    '' $33>!!**OO!!# + " r)   r   )r   r   r   r   r  r   r}  r   r  r  r  _LEGACY_NO_RESULT_METADATAr  r  r)  rL  rM  s   @r'   r  r  H  s6     "L1.4$4$ $r)   r  c                       e Zd ZdZeZy)BufferedRowResultProxyzA ResultProxy with row buffering behavior.

    .. deprecated::  1.4 this class is now supplied using a strategy object.
       See :class:`.BufferedRowCursorFetchStrategy`.

    N)r   r   r   r   r"  r  r/   r)   r'   r  r    s     :r)   r  c                       e Zd ZdZeZy)FullyBufferedResultProxyzA result proxy that buffers rows fully upon creation.

    .. deprecated::  1.4 this class is now supplied using a strategy object.
       See :class:`.FullyBufferedCursorFetchStrategy`.

    N)r   r   r   r   rO  r  r/   r)   r'   r  r    s     <r)   r  c                       e Zd ZdZy)BufferedColumnRowz&Row is now BufferedColumn in all casesN)r   r   r   r   r/   r)   r'   r  r    s    0r)   r  c                       e Zd ZdZeZy)BufferedColumnResultProxyzA ResultProxy with column buffering behavior.

    .. versionchanged:: 1.4   This is now the default behavior of the Row
       and this class does not change behavior in any way.

    N)r   r   r   r   r  r}  r/   r)   r'   r  r    s     %Lr)   r  ):r   r#  r  r   r   r   r   r   r   r    r
   r   sqlr   r   rm  sql.baser   sql.compilerr   r   r   r   symbolr   r2   rY   r,   r3   r[   rX   rb   r   r   objectr   r   r	  r  r  _NO_CURSOR_DMLr  _DEFAULT_FETCHr"  rO  rZ  rg  r  r  rj  r  r  ResultProxyr  r  r  r  r/   r)   r'   <module>r     s  7    " (       " " " % + "T[[%

  
 _
@> _
@DkD!5 kD\& D$/ $<4 . *+34 3  *+9;- 9;x %&D;%8 D;N9': 9x$ $@/  () 46 M%v M%`Z?#V Z?z4$ 4$n !:[ :<{ <1	 1% %r)   