o
    i(                     @   sr  d Z ddlZddl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 edejejB ZedejejB ZG dd dejZG dd deZG dd deejZ G dd deej!Z"G dd deej#Z$G dd deZ%G d d! d!ej&Z'e'e_(dS )"a  Default implementations of per-dialect sqlalchemy.engine classes.

These are semi-private implementation classes which are only of importance
to database dialect authors; dialects will usually use the classes here
as the base class for their own corresponding classes.

    N   )
interfaces)
reflection)result   )event)exc)pool)
processors)types)util)compiler)
expression)schema)quoted_namez-\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER)z	\s*SELECTc                   @   s  e Zd ZdZejZejZej	Z
ejZdZdZdZdZ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e "dfde j#fde "d	fd
e "d	fde j#fde j#fde j#fde j$fgZ%dZ&e j'rodZ(dZ)dZ*dZ+ndZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1i Z2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:dZ;	 dZ<dZ=e ! Z>	 e j?dd											dcddZ@e jAdd ZBeCdd ZDeCdd  ZEeFd!d" ZGeFd#d$ ZHd%d& ZId'd( ZJd)d* ZKddd+d,ZLd-d. ZMd/d0 ZNd1d2 ZOddd3d4ZPd5d6 ZQd7d8 ZRd9d: ZSd;d< ZTd=d> ZUd?d@ ZVdAdB ZWdCdD ZXdEdF ZYdGdH ZZe jAdIdJ Z[dKdL Z\dMdN Z]dOdP Z^dQdR Z_dSdT Z`dddUdVZadddWdXZbdddYdZZcd[d\ Zdd]d^ Zed_d` Zfdadb ZgdS )eDefaultDialectz!Default implementation of DialectTFr   convert_unicodeforcepool_timeoutechodebug	echo_poolpool_recycle	pool_sizemax_overflowpool_threadlocalNuse_encodingdefaulti'  named )z1.3zThe :paramref:`_sa.create_engine.convert_unicode` parameter and corresponding dialect-level parameters are deprecated, and will be removed in a future release.  Modern DBAPIs support Python Unicode natively and this parameter is unnecessary.)r   utf-8staticc                 K   s`  t | ddstd| j  || _|| _d| _d | _|| _|d ur%|| _	n| jd ur0| jj	| _	n| j
| _	|d ur;|| _| j	dv | _| | | _| | | _|d urT|| _|d ur[|| _|| _|	| _|	dkrid| _n|	dv rvd| _|	dk| _ntd	|
| _| jr| j| _|| _| jd
krt|| _n| jd urt| j| _t| j| _ t| j| _!d S )Nported_sqla_06Tz2The %s dialect is not yet ported to the 0.6 formatF)qmarkformatnumericr!   )dynamicdynamic_warnr'   z?empty_in_strategy may be 'static', 'dynamic', or 'dynamic_warn'r   )"getattrr   warnnamer   encoding
positional_ischemadbapi
paramstyledefault_paramstyleimplicit_returningprepareridentifier_preparertype_compilersupports_right_nested_joinssupports_native_booleancase_sensitiveempty_in_strategy_use_static_in_warn_on_empty_inr   ArgumentError#_user_defined_max_identifier_lengthmax_identifier_lengthlabel_lengthdescription_encodingr
   to_unicode_processor_factory_description_decodercodecs
getencoder_encoder_decoder)selfr   r+   r/   r.   r1   r5   r7   r6   r8   r=   r>   kwargsr   r   T/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py__init__   sh   


zDefaultDialect.__init__c                 C   s   t  S N)weakrefWeakKeyDictionaryrF   r   r   rH   _type_memos     zDefaultDialect._type_memosc                 C   s   | j d | j S )N+)r*   driverrM   r   r   rH   dialect_description  s   z"DefaultDialect.dialect_descriptionc                 C   s   | j S )zTrue if this dialect supports sane rowcount even if RETURNING is
        in use.

        For dialects that don't support RETURNING, this is synomous
        with supports_sane_rowcount.

        )supports_sane_rowcountrM   r   r   rH    supports_sane_rowcount_returning  s   	z/DefaultDialect.supports_sane_rowcount_returningc                 C   s   t | dtjS )N	poolclass)r(   r	   	QueuePool)clsurlr   r   rH   get_pool_class*     zDefaultDialect.get_pool_classc                 C   sB   d | jddd }z	t|d  W d S  ty    Y d S w )N.r   z
.provision)join
__module__split
__import__ImportError)rW   packager   r   rH   load_provisioning.  s   z DefaultDialect.load_provisioningc                 C   s   z|  || _W n ty   d | _Y nw z| || _W n ty)   d | _Y nw z	| |j| _W n ty?   d | _Y nw | || _	| j
d urV| |rVd  | _| _
| jsc| |}|rc|| _| jrw| j| jkrytd| j| jf d S d S )NzQLabel length of %d is greater than this dialect's maximum identifier length of %d)_get_server_version_infoserver_version_infoNotImplementedError_get_default_schema_namedefault_schema_nameget_isolation_level
connectiondefault_isolation_level_check_unicode_returnsreturns_unicode_stringsr?   _check_unicode_descriptionrA   r<   _check_max_identifier_lengthr=   r>   r   r;   )rF   rj   max_ident_lengthr   r   rH   
initialize6  sP   








zDefaultDialect.initializec                 C      d S rJ   r   rM   r   r   rH   
on_connectb  s   zDefaultDialect.on_connectc                 C      dS )zPerform a connection / server version specific check to determine
        the max_identifier_length.

        If the dialect's class level max_identifier_length should be used,
        can return None.

        .. versionadded:: 1.3.9

        Nr   )rF   rj   r   r   rH   ro   f  s   
z+DefaultDialect._check_max_identifier_lengthc                    s   t jr
js
t j nt j jr ni  fddtt	dt
dtt	dt
dg}|r>||7 }fdd|D }|dd	grPd
S |dhkS )Nc              
      s    t | gjd}zj }|| | }|  W n tj	y= } zt
d|  W Y d }~dS d }~ww t|d t
jS )Ndialectz2Exception attempting to detect unicode returns: %rFr   )r   selectcompilerj   cursor_cursor_executefetchonecloser   
DBAPIErrorr   r)   
isinstance	text_type)test	statementry   rowde)cast_torj   
parametersrF   r   rH   check_unicode}  s$   
	z<DefaultDialect._check_unicode_returns.<locals>.check_unicodez'test plain returns'<   z'test unicode returns'c                    s   h | ]} |qS r   r   ).0r   )r   r   rH   	<setcomp>  s    z8DefaultDialect._check_unicode_returns.<locals>.<setcomp>TFconditional)r   py2ksupports_unicode_statementsbinary_typer   r,   execute_sequence_formatr   castliteral_columnsqltypesVARCHARUnicode
issuperset)rF   rj   additional_teststestsresultsr   )r   r   rj   r   rF   rH   rl   r  s,   

z%DefaultDialect._check_unicode_returnsc                 C   sz   t jr
| js
t j}nt j}|j }z%||t	t
ddgj| d t|jd d t jW |  S |  w )Nz'x'
some_labelru   r   )r   r   r   r   r   rj   ry   executer   rw   r   labelrx   r~   descriptionr|   )rF   rj   r   ry   r   r   rH   rn     s    
z)DefaultDialect._check_unicode_descriptionc                 C   s   t || jS )a)  Provide a database-specific :class:`.TypeEngine` object, given
        the generic object which comes from the types module.

        This method looks for a dictionary called
        ``colspecs`` as a class or instance-level variable,
        and passes on to :func:`_types.adapt_type`.

        )r   
adapt_typecolspecs)rF   typeobjr   r   rH   type_descriptor  s   	zDefaultDialect.type_descriptorc                 K   s$   t j|}|j||||fi |S rJ   )r   	Inspectorfrom_enginereflecttable)rF   rj   tableinclude_columnsexclude_columnsresolve_fksoptsinspr   r   rH   r     s   	zDefaultDialect.reflecttablec                 K   s   d| j ||fd|i|iS )zCompatibility method, adapts the result of get_primary_keys()
        for those dialects which don't implement get_pk_constraint().

        constrained_columnsr   )get_primary_keys)rF   conn
table_namer   kwr   r   rH   get_pk_constraint  s   z DefaultDialect.get_pk_constraintc                 C   s&   t || jkrtd|| jf d S )Nz7Identifier '%s' exceeds maximum length of %d characters)lenr=   r   IdentifierError)rF   identr   r   rH   validate_identifier  s   z"DefaultDialect.validate_identifierc                 O   s   | j j|i |S rJ   )r.   connect)rF   cargscparamsr   r   rH   r     s   zDefaultDialect.connectc                 C   s   |  }||j g |gS rJ   )translate_connect_argsupdatequery)rF   rX   r   r   r   rH   create_connect_args  s   z"DefaultDialect.create_connect_argsc                    sf   d|v r|d t |dfdd}d|v r1t|d   |_t |d fdd}d S d S )Nisolation_levelengine_connectc                    s   |s
 |   d S d S rJ   )_set_connection_isolationrj   branch)r   rF   r   rH   set_isolation  s   zBDefaultDialect.set_engine_execution_options.<locals>.set_isolationschema_translate_mapc                    s
    | _ d S rJ   )schema_for_objectr   )getterr   rH   set_schema_translate_map     
zMDefaultDialect.set_engine_execution_options.<locals>.set_schema_translate_map)r   listens_forr   _schema_getterr   )rF   enginer   r   r   r   )r   r   rF   rH   set_engine_execution_options  s   

z+DefaultDialect.set_engine_execution_optionsc                 C   s<   d|v r|  ||d  d|v rt|d }||_d S d S )Nr   r   )r   r   r   r   )rF   rj   r   r   r   r   rH    set_connection_execution_options  s   
z/DefaultDialect.set_connection_execution_optionsc                 C   s6   |  r	td | |j| |jjj| j d S )NzConnection is already established with a Transaction; setting isolation_level may implicitly rollback or commit the existing transaction, or have no effect until next transaction)	in_transactionr   r)   set_isolation_levelrj   _connection_recordfinalize_callbackappendreset_isolation_level)rF   rj   levelr   r   rH   r     s   
z(DefaultDialect._set_connection_isolationc                 C   rr   rJ   r   rF   dbapi_connectionr   r   rH   do_begin     zDefaultDialect.do_beginc                 C      |   d S rJ   )rollbackr   r   r   rH   do_rollback     zDefaultDialect.do_rollbackc                 C   r   rJ   )commitr   r   r   rH   	do_commit!  r   zDefaultDialect.do_commitc                 C   r   rJ   )r|   r   r   r   rH   do_close$  r   zDefaultDialect.do_closec                 C   s   t tdgj| dS )Nr   ru   )strr   rw   rx   rM   r   r   rH   _dialect_specific_select_one'  s   z+DefaultDialect._dialect_specific_select_onec              
   C   sp   d }z|  }z|| j W |  W dS |  w  | jjy7 } z| |||r2W Y d }~dS  d }~ww )NFT)ry   r   r   r|   r.   Erroris_disconnect)rF   r   ry   errr   r   rH   do_ping+  s   

zDefaultDialect.do_pingc                 C   s   dt ddd  S )zCreate a random two-phase transaction ID.

        This id will be passed to do_begin_twophase(), do_rollback_twophase(),
        do_commit_twophase().  Its format is unspecified.
        z	_sa_%032xr   r      )randomrandintrM   r   r   rH   
create_xid;  s   zDefaultDialect.create_xidc                 C      | t| d S rJ   )r   r   SavepointClauserF   rj   r*   r   r   rH   do_savepointD     zDefaultDialect.do_savepointc                 C   r   rJ   )r   r   RollbackToSavepointClauser   r   r   rH   do_rollback_to_savepointG  r   z'DefaultDialect.do_rollback_to_savepointc                 C   r   rJ   )r   r   ReleaseSavepointClauser   r   r   rH   do_release_savepointJ  r   z#DefaultDialect.do_release_savepointc                 C      | || d S rJ   )executemanyrF   ry   r   r   contextr   r   rH   do_executemanyM     zDefaultDialect.do_executemanyc                 C   r   rJ   r   r   r   r   rH   
do_executeP  r   zDefaultDialect.do_executec                 C   s   | | d S rJ   r   )rF   ry   r   r   r   r   rH   do_execute_no_paramsS     z#DefaultDialect.do_execute_no_paramsc                 C   rt   )NFr   )rF   erj   ry   r   r   rH   r   V  r   zDefaultDialect.is_disconnectc                 C   s   |  || j d S rJ   )r   rk   )rF   
dbapi_connr   r   rH   r   Y  s   z$DefaultDialect.reset_isolation_levelc                 C   st   |d u rd S t jrt|tr|| j}| }| }||kr"|S ||kr.| j	|s.|S ||kr8t
|ddS |S )NT)quote)r   r   r~   r   decoder+   lowerupperr3   _requires_quotesr   rF   r*   
name_lower
name_upperr   r   rH   normalize_name_  s$   
zDefaultDialect.normalize_namec                 C   sh   |d u rd S |  }| }||kr|S ||kr | j|s |}tjr2| js.|| j}|S t	|}|S rJ   )
r   r   r3   r   r   r   supports_unicode_bindsencoder+   unicoder   r   r   rH   denormalize_name|  s$   zDefaultDialect.denormalize_name)Fr    NNNNTNr!   NNrJ   )h__name__r^   __qualname____doc__r   SQLCompilerstatement_compilerDDLCompilerddl_compilerGenericTypeCompilerr4   IdentifierPreparerr2   supports_altersupports_commentsinline_commentsdefault_sequence_basetupler   supports_viewssupports_sequencessequences_optional"preexecute_autoincrement_sequencespostfetch_lastrowidr1   r5   cte_follows_insertsupports_native_enumr6   #non_native_boolean_check_constraintsupports_simple_order_by_labeltuple_in_valuesr   immutabledictbool_or_strasintasboolengine_config_typessupports_native_decimalpy3kr   r  rm   r?   r*   r=   r<   max_index_name_lengthrS   supports_sane_multi_rowcountr   r0   supports_default_valuessupports_empty_insertsupports_multivalues_insertsupports_is_distinct_fromsupports_server_side_cursorssupports_for_update_ofre   construct_argumentsrequires_name_normalizereflection_optionsdbapi_exception_translation_mapdeprecated_paramsrI   memoized_propertyrN   propertyrR   rT   classmethodrY   rc   rq   rs   ro   rl   rn   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  r  r   r   r   rH   r   ,   s    )J





,
7

	


r   c                   @   s   e Zd Zdd ZdS )_RendersLiteralc                 C   s   dd }|S )Nc                 S   s   d|  S )Nz'%s'r   )valuer   r   rH   process     z2_RendersLiteral.literal_processor.<locals>.processr   )rF   rv   r9  r   r   rH   literal_processor  s   z!_RendersLiteral.literal_processorN)r  r^   r	  r;  r   r   r   rH   r7    s    r7  c                   @      e Zd ZdS )_StrDateTimeNr  r^   r	  r   r   r   rH   r=        r=  c                   @   r<  )_StrDateNr>  r   r   r   rH   r@    r?  r@  c                   @   r<  )_StrTimeNr>  r   r   r   rH   rA    r?  rA  c                   @   sR   e Zd ZejZejZejZ	ej
ZdZdZdZdZdZdZejeejeejeiZdS )StrCompileDialectTFN)r  r^   r	  r   StrSQLCompilerr  r  r  StrSQLTypeCompilerr4   r  r2   r  r  r  r1   r6   r  r   DateTimer=  Dater@  TimerA  r   r   r   r   rH   rB    s    rB  c                   @   s  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dZdZe Zedd Zedd Zdd Zed	d
 Zedd Zejdd Zejdd Zejdd Zejdd Zejdd Zejdd Z dd Z!e"dd Z#dd Z$dd  Z%d!d" Z&d#d$ Z'd%d& Z(d'd( Z)d)d* Z*d+d, Z+d-d. Z,d/d0 Z-e"d1d2 Z.d3d4 Z/d5d6 Z0d7d8 Z1d9d: Z2d;d< Z3d=d> Z4d?d@ Z5	dPdAdBZ6dCdD Z7dZ8	 dQdFdGZ9dHdI Z:dJdK Z;dLdM Z<dNdO Z=dS )RDefaultExecutionContextFNc                 C   s   |  | }||_||_|j|_| |_}d|_|j|_|jr+t|j|_|j	|j |j
s>t||_||jd |_n	t| |_|_| |_g |_|jrZ| g|_|S i g|_|S )z8Initialize execution context for a DDLElement construct.Tr   )__new__root_connection_dbapi_connectionrv   compiledisddlexecution_options_execution_optionsdictr   r   r   r   unicode_statementrD   r   create_cursorry   compiled_parametersr,   r   r   )rW   rv   rj   r   compiled_ddlrF   rL  r   r   rH   	_init_ddl  s*   


z!DefaultExecutionContext._init_ddlc                    s@  |  | }||_||_|j|_ |_ jsJ  j|j|_ j	 j
 jf|_t |_js;|j|jj|_n|j|_ j|_ j|_ j|_ j|_|sX  g|_n fddt|D |_t|dk|_| |_|jsy|jsy|jrd|_ t! jj"|_#t! j$o jj" |_%|jj&s|jj'r|jr|(  n|)   j* j+rt,|- }n j.r|jj/}g } j.r|jD ](g }|D ]}	|	v r|0|	 |	  q|0|	  q|01| qn,j }
|jD ]$|
rt,fddD }nt,fddD }|0| q1||_2|S )z6Initialize execution context for a Compiled construct.c                    s   g | ]\}} j ||d qS ))_group_number)construct_params)r   grpm)rL  r   rH   
<listcomp>  s    z:DefaultExecutionContext._init_compiled.<locals>.<listcomp>r   Tc                 3   s>    | ]} |d  |v r|  | n | fV  qdS )r   NrD   r   key)compiled_paramsrv   r
   r   rH   	<genexpr>P  s    
z9DefaultExecutionContext._init_compiled.<locals>.<genexpr>c                 3   s4    | ]}||v r|  | n | fV  qd S rJ   r   r\  )r^  r
   r   rH   r_  Z  s    
)3rI  rJ  rK  rv   rL  can_executerN  unionrO  _result_columns_ordered_columns_textual_ordered_columnsresult_column_structr   r   rQ  r   r  r+   r   isinsertisupdateisdeleteisplaintextis_textrW  rS  	enumerater   r   rR  ry   is_crudbool
_returning_is_explicit_returning	returning_is_implicit_returninginsert_prefetchupdate_prefetch_process_executemany_defaults_process_executesingle_defaults_bind_processorscontains_expanding_parametersrP  _expand_in_parametersr,   positiontupr   r   r   )rW   rv   rj   r   rL  r   rF   ry  paramr]  r  r   )rL  r^  rv   r
   rH   _init_compiled  s   





	



z&DefaultExecutionContext._init_compiledc           	         s  j rtdjjrjjrtdi _jd }|jr"g }nd}i i }|jr/jj	njj
D ] jj
  }|jr v rG|  no| }|seg  | < j|jr]|jn|jg < nQt|d ttfr fddt|dD  | < jjrdnd	d
fddt|D   < n fddt|dD  | < d
fddD  < |  fddD  |jr|dd D  dd D j < q3|jr|  q3fdd}td|j_|S )zhandle special 'expanding' parameters, IN tuples that are rendered
        on a per-parameter basis for an otherwise fixed SQL statement string.

        z7'expanding' parameters can't be used with executemany()zQ'expanding' bind parameters not supported with 'numeric' paramstyle at this time.r   Nc                    s6   g | ]\}}t |d D ]\}}d ||f |fqqS )r   z%s_%s_%s)rk  )r   ituple_elementjr8  r*   r   rH   rZ    s    zADefaultExecutionContext._expand_in_parameters.<locals>.<listcomp>r   zVALUES  , c                 3   s:    | ]\ d d  fddtD  V  qdS )z(%s)r  c                 3   s8    | ]\}}j jd  t |  d i V  qdS )r*   r   N)rL  bindtemplater   )r   r~  r8  )r|  rF   	to_updater}  r   rH   r_    s    
zJDefaultExecutionContext._expand_in_parameters.<locals>.<genexpr>.<genexpr>N)r]   rk  r   )rF   r  )r|  r}  rH   r_    s    
z@DefaultExecutionContext._expand_in_parameters.<locals>.<genexpr>c                    s    g | ]\}}d  |f |fqS )z%s_%sr   )r   r|  r8  r  r   rH   rZ    s    c                 3   s$    | ]\}} j jd |i V  qdS )r*   N)rL  r  r   r]  r8  rM   r   rH   r_    s
    
c                 3   s(    | ]\}} v r|  fV  qd S rJ   r   r  )r*   r
   r   rH   r_    s    
c                 s   s    | ]\}}|V  qd S rJ   r   )r   r*   r8  r   r   rH   r_    s    c                 S   s   g | ]\}}|qS r   r   )r   
expand_keyr8  r   r   rH   rZ    s    c                    s    |  d S )Nr   )group)rY  )replacement_expressionsr   rH   process_expanding  r   zHDefaultExecutionContext._expand_in_parameters.<locals>.process_expandingz\[EXPANDING_(\S+)\])r   r   InvalidRequestErrorrL  r,   _numeric_bindsrf   _expanded_parametersrS  ry  binds	expandingpopvisit_empty_set_expr_expanding_in_typestyper~   r  listrk  rv   r  r]   r   extendr   resubr   )	rF   rL  r
   r^  ry  to_update_sets	parametervaluesr  r   )r*   r
   r  rF   r  rH   rx  j  s   








z-DefaultExecutionContext._expand_in_parametersc                    s  |  | }||_||_|j|_d|_|j|_|s(|jjr#  g|_	n7i g|_	n2t
|d  jr4||_	n&t
|d trP jrB||_	n fdd|D pMi g|_	n
 fdd|D |_	t|dk|_ jsvt
|tjrv||_ |d |_n| |_|_| |_|S )z8Initialize execution context for a string SQL statement.Tr   c                    s    g | ]  fd d D qS )c                    s    i | ]} |d   | qS )r   r[  )r   k)drv   r   rH   
<dictcomp>  s     zFDefaultExecutionContext._init_statement.<locals>.<listcomp>.<dictcomp>r   r  ru   )r  rH   rZ        z;DefaultExecutionContext._init_statement.<locals>.<listcomp>c                    s   g | ]}  |qS r   )r   )r   pru   r   rH   rZ    s    
r   )rI  rJ  rK  rv   rj  rO  rN  r,   r   r   r~   rP  r   r   r   r   r   rQ  rD   r   rR  ry   )rW   rv   rj   r   r   r   rF   r   ru   rH   _init_statement  s@   




z'DefaultExecutionContext._init_statementc                 C   s4   |  | }||_||_|j|_|j|_| |_|S )z;Initialize execution context for a ColumnDefault construct.)rI  rJ  rK  rv   rO  rN  rR  ry   )rW   rv   rj   r   rF   r   r   rH   _init_default  s   

z%DefaultExecutionContext._init_defaultc                 C      | j jS rJ   )rJ  r   rM   r   r   rH   r     rO   zDefaultExecutionContext.enginec                 C   r  rJ   )rL  	postfetchrM   r   r   rH   postfetch_cols  rO   z&DefaultExecutionContext.postfetch_colsc                 C   s    | j r| jjS | jr| jjS dS )Nr   )rf  rL  rr  rg  rs  rM   r   r   rH   prefetch_cols  s
   z%DefaultExecutionContext.prefetch_colsc                 C   s   | j j d S rJ   )rL  rp  rM   r   r   rH   returning_cols%  s   z&DefaultExecutionContext.returning_colsc                 C   s   | j ddS )Nno_parametersF)rN  getrM   r   r   rH   r  )  rZ   z%DefaultExecutionContext.no_parametersc                 C   s<   | j d| j r| jrtjpd}|tju r| | jS |S )N
autocommitF)rN  r  rL  r   r   PARSE_AUTOCOMMITshould_autocommit_textrQ  )rF   r  r   r   rH   should_autocommit-  s   
z)DefaultExecutionContext.should_autocommitc                 C   s   | j }t|tjr| jjs| j|d }| jjr| j }ni }|j	| j
||| d | j
 d }|durI|| j| j
jd d }|rI||S |S )a  Execute a string statement on the current cursor, returning a
        scalar result.

        Used to fire off sequences, default phrases, and "select lastrowid"
        types of statements individually or in the context of a parent INSERT
        or UPDATE statement.

        r   )r   Nr   )rJ  r~   r   r   rv   r   rD   r,   r   rz   ry   r{   _cached_result_processorr   )rF   stmttype_r   default_paramsrprocr   r   rH   _execute_scalar<  s$   

z'DefaultExecutionContext._execute_scalarc                 C   s
   | j  S rJ   )rJ  _branchrM   r   r   rH   rj   ]  r   z"DefaultExecutionContext.connectionc                 C   s
   t |S rJ   )AUTOCOMMIT_REGEXPmatch)rF   r   r   r   rH   r  a  s   
z.DefaultExecutionContext.should_autocommit_textc                 C   sx   | j jsdS | j jr3| jddo0| jrt| jjtj	p0| j p't| jjtj
o0| jo0t| j}|S | jdd}|S )NFstream_resultsT)rv   r-  server_side_cursorsrN  r  rL  r~   r   r   
Selectable
TextClauseSERVER_SIDE_CURSOR_REr  )rF   use_server_sider   r   rH   _use_server_side_cursord  s2   


z/DefaultExecutionContext._use_server_side_cursorc                 C   s&   |   rd| _|  S d| _| j S )NTF)r  _is_server_sidecreate_server_side_cursorrK  ry   rM   r   r   rH   rR    s
   
z%DefaultExecutionContext.create_cursorc                 C   s   t  rJ   )rf   rM   r   r   rH   r    s   z1DefaultExecutionContext.create_server_side_cursorc                 C   rr   rJ   r   rM   r   r   rH   pre_exec  r   z DefaultExecutionContext.pre_execc                 C   rr   rJ   r   rM   r   r   rH   	post_exec  r   z!DefaultExecutionContext.post_execc                 C   s   | | j|S )zReturn a 'result processor' for a given type as present in
        cursor.description.

        This has a default implementation that dialects can override
        for context-sensitive result type handling.

        )r  rv   )rF   r  colnamecoltyper   r   rH   get_result_processor  s   z,DefaultExecutionContext.get_result_processorc                 C   r  )a  return self.cursor.lastrowid, or equivalent, after an INSERT.

        This may involve calling special cursor functions,
        issuing a new SELECT on the cursor (or a new one),
        or returning a stored value that was
        calculated within post_exec().

        This function will only be called for dialects
        which support "implicit" primary key generation,
        keep preexecute_autoincrement_sequences set to False,
        and when no explicit id value was bound to the
        statement.

        The function is called once, directly after
        post_exec() and before the transaction is committed
        or ResultProxy is generated.   If the post_exec()
        method assigns a value to `self._lastrowid`, the
        value is used in place of calling get_lastrowid().

        Note that this method is *not* equivalent to the
        ``lastrowid`` method on ``ResultProxy``, which is a
        direct proxy to the DBAPI ``lastrowid`` accessor
        in all cases.

        )ry   	lastrowidrM   r   r   rH   get_lastrowid  s   z%DefaultExecutionContext.get_lastrowidc                 C   rr   rJ   r   )rF   r   r   r   rH   handle_dbapi_exception  r   z.DefaultExecutionContext.handle_dbapi_exceptionc                 C   s   | j rt| S t| S rJ   )r  r   BufferedRowResultProxyResultProxyrM   r   r   rH   get_result_proxy  s   

z(DefaultExecutionContext.get_result_proxyc                 C   r  rJ   )ry   rowcountrM   r   r   rH   r    rO   z DefaultExecutionContext.rowcountc                 C   r  rJ   )rv   rS   rM   r   r   rH   rS     r:  z.DefaultExecutionContext.supports_sane_rowcountc                 C   r  rJ   )rv   r(  rM   r   r   rH   r(    r:  z4DefaultExecutionContext.supports_sane_multi_rowcountc                 C   s   | j r| js| js| jjs| jjr|   n| js|   | 	 }| j rH| jr<|
 }|| _| | |  d |_|S | jsF|  d |_|S | jr^| jr^|
 }|| _|  d |_|S |jd u rj|j |  |S rJ   )rf  r   rq  rL  inlinerv   r  _setup_ins_pk_from_lastrowid_setup_ins_pk_from_emptyr  r{   returned_defaults%_setup_ins_pk_from_implicit_returning_soft_close	_metadataro  rg  r  )rF   r   r   r   r   rH   _setup_crud_result_proxy  sB   


z0DefaultExecutionContext._setup_crud_result_proxyc                    s   | j jd | j jj}| jd |  d ur?|j  d ur/ j| j	d }|d ur/| fdd|j
D | _d S fdd|j
D | _d S )Nr   r   c                    s(   g | ]}| u r
n |d qS rJ   r  r   cautoinc_colr^  
key_getterr  r   rH   rZ    s    zHDefaultExecutionContext._setup_ins_pk_from_lastrowid.<locals>.<listcomp>c                       g | ]
}  |d qS rJ   r  r  r^  r  r   rH   rZ    s    )rL  _key_getters_for_crud_columnr   r   rS  r  _autoincrement_columnr  r  rv   primary_keyinserted_primary_key)rF   r   r  r   r  rH   r    s$   

	z4DefaultExecutionContext._setup_ins_pk_from_lastrowidc                    s<   | j jd | j jj}| jd   fdd|jD | _d S )Nr   r   c                    r  rJ   r  r  r  r   rH   rZ    s    zDDefaultExecutionContext._setup_ins_pk_from_empty.<locals>.<listcomp>)rL  r  r   r   rS  r  r  )rF   r   r   r  rH   r    s   

z0DefaultExecutionContext._setup_ins_pk_from_emptyc                    s\   d u r	d | _ d S | jjd | jjj}| jd  fdd fdd|jD D | _ d S )Nr   r   c                    s$   g | ]\}}|d u r | n|qS rJ   r   )r   colr8  )r   r   rH   rZ  "  s    zQDefaultExecutionContext._setup_ins_pk_from_implicit_returning.<locals>.<listcomp>c                    s    g | ]}|  |d fqS rJ   r  )r   r  r  r   rH   rZ  $  r  )r  rL  r  r   r   rS  r  )rF   r   r   r   )r^  r  r   rH   r    s   


z=DefaultExecutionContext._setup_ins_pk_from_implicit_returningc                 C   s   | j s| jot| jjS rJ   )rf  rg  rm  rL  r  rM   r   r   rH   lastrow_has_defaults*  s   z,DefaultExecutionContext.lastrow_has_defaultsc              
      sB  t | jdsdS i }| jjD ]5}|j| j}t|}|| jj  dur?|r0 |vr?||vr?|r: |v s:||v r? ||< qd||< q| jjrV| jj	
|| j| j| j|  | jjrg }| jjD ]*}	| jj|	 }||d  dur|	| jv r| gt| j|	   q`|  q`z	| jj|  W dS  ty }
 z| j|
ddd|  W Y d}
~
dS d}
~
ww i }| jj D ];\}}	||d  dur|r||	|	}	| jjs| j|	d }	|	| jv r| fdd| j|	 D  q ||	< qz| jjdi | W dS  ty  }
 z| j|
ddd|  W Y d}
~
dS d}
~
ww )a&  Given a cursor and ClauseParameters, call the appropriate
        style of ``setinputsizes()`` on the cursor, using DB-API types
        from the bind parameter's ``TypeEngine`` objects.

        This method only called by those dialects which require it,
        currently cx_oracle.

        
bind_namesNr   c                 3   s    | ]}| fV  qd S rJ   r   )r   r  dbtyper   rH   r_  z  s
    
z:DefaultExecutionContext.set_input_sizes.<locals>.<genexpr>r   )hasattrrL  r  r  _unwrapped_dialect_implrv   get_dbapi_typer.   _has_eventsdispatchdo_setinputsizesry   r   r   r,   ry  r  r  r  r  r   r   setinputsizesBaseExceptionrJ  _handle_dbapi_exceptionitemsr  rD   r   )rF   	translateinclude_typesexclude_types
inputsizes	bindparamdialect_impldialect_impl_clspositional_inputsizesr]  r   keyword_inputsizesr   r  rH   set_input_sizes/  s   







z'DefaultExecutionContext.set_input_sizesc                 C   s|   |j r	| ||S |jr|| _|| S |jr;| j}|js%t	|j|}n|j}t
|gj|d}||di  S |jS )N)bindr   )is_sequencefire_sequenceis_callablecurrent_columnargis_clause_elementrj   _arg_is_typedr   type_coercerw   rx   _execute_compiledscalar)rF   columnr   r  r   default_argr  r   r   rH   _exec_default  s   
z%DefaultExecutionContext._exec_defaultTc                    s   z| j | j}W n ty   tdw |rS| jrS| jjjrS|j	r1|j
d  |jj|j i}n
|j|j i}d | jjjd  }| fdd|D  |S S )ai  Return a dictionary of parameters applied to the current row.

        This method can only be used in the context of a user-defined default
        generation function, e.g. as described at
        :ref:`context_default_functions`. When invoked, a dictionary is
        returned which includes entries for each column/value pair that is part
        of the INSERT or UPDATE statement. The keys of the dictionary will be
        the key value of each :class:`_schema.Column`,
        which is usually synonymous
        with the name.

        :param isolate_multiinsert_groups=True: indicates that multi-valued
         INSERT constructs created using :meth:`_expression.Insert.values`
         should be
         handled by returning only the subset of parameters that are local
         to the current column default invocation.   When ``False``, the
         raw parameters of the statement are returned including the
         naming convention used in the case of multi-valued INSERT.

        .. versionadded:: 1.2  added
           :meth:`.DefaultExecutionContext.get_current_parameters`
           which provides more functionality over the existing
           :attr:`.DefaultExecutionContext.current_parameters`
           attribute.

        .. seealso::

            :attr:`.DefaultExecutionContext.current_parameters`

            :ref:`context_default_functions`

        zdget_current_parameters() can only be invoked in the context of a Python side column default functionr   r   c                 3   s$    | ]}|d | f  fV  qdS )z%s_m%dNr   r\  indexr   r   rH   r_    s    
zADefaultExecutionContext.get_current_parameters.<locals>.<genexpr>)current_parametersr  AttributeErrorr   r  rf  rL  r   _has_multi_parameters_is_multiparam_columnr  originalr]  r   keysr   )rF   isolate_multiinsert_groupsr  r  r  r   r  rH   get_current_parameters  s2   !

z.DefaultExecutionContext.get_current_parametersc                 C       |j d u rd S | ||j |jS rJ   )r   r  r  rF   r  r   r   rH   get_insert_default     
z*DefaultExecutionContext.get_insert_defaultc                 C   r  rJ   )onupdater  r  r  r   r   rH   get_update_default  r  z*DefaultExecutionContext.get_update_defaultc                 C   s   | j jd }i }| j j}| j j}|D ]}|jr!|jjr!|jj||< q|D ]}|jr3|jjr3|jj||< q$| jD ]?}|| _	|D ]}||v rI|| }n| 
|}|d urX||||< q>|D ]}||v rf|| }n| |}|d uru||||< q[q7| `	d S )Nr   )rL  r  rr  rs  r   	is_scalarr  r  rS  r  r  r  )rF   r  scalar_defaultsrr  rs  r  rz  valr   r   rH   rt    s<   




z5DefaultExecutionContext._process_executemany_defaultsc                 C   s   | j jd }| jd  | _}| j jD ]!}|jr$|jjs$|jjr$|jj}n| 	|}|d ur3||||< q| j j
D ]}| |}|d urI||||< q8| `d S )Nr   r   )rL  r  rS  r  rr  r   r  r  r  r  rs  r  )rF   r  rS  r  r  r   r   rH   ru     s"   


z7DefaultExecutionContext._process_executesingle_defaults)NNN)T)>r  r^   r	  rf  rg  rh  rl  rj  rM  r   rL  r   re  r  rq  ro  _translate_colnamer   r   r  r6  rU  r{  rx  r  r  r4  r   r  r  r  r  r  r  r5  rj   r  r  rR  r  r  r  r  r  r  r  r  rS   r(  r  r  r  r  r  r  r  r  r  r  r  rt  ru  r   r   r   rH   rH    s    
 
un
/






!
 

'
X
<%rH  ))r
  rB   r   r  rK   r  r   r   r   r   r   r	   r
   r   r   r   sqlr   r   r   sql.elementsr   rx   IUNICODEr  r  Dialectr   objectr7  rE  r=  rF  r@  rG  rA  rB  ExecutionContextrH  execution_ctx_clsr   r   r   rH   <module>   sP       k      
