U kfJ@sdZddlmZddlZddlZddlZddlZddlmZddl Z ddl m Z ddl m Z ddl m Z ddl m Z dd l mZdd l mZdd l mZdd l mZdd l mZddl mZddl mZddl mZddl mZddl mZddl mZddlZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddl&m'Z'ddl&m(Z(d d!lm)Z)d d"lm*Z*d d#lm+Z+d d$lm,Z,d d%l-m.Z.d d&l-m/Z/d d'l-m0Z0d d(l-m1Z1d d$l-m,Z2d d)l3m4Z4d d*l5m6Z6d d+l7m8Z8d d,l7m9Z9d d-l7m:Z:d d.l;mZ>d d0l=m?Z?e jrdd1l@mAZAdd2lmBZBdd3lmCZCdd4lmDZDdd5lmEZEdd6lmFZFdd7lmGZGdd8lmHZHdd9lmIZIdd:lmJZJdd;lmKZKddlOmPZPd d?l)mQZQd d@l+mRZRd dAl+mSZSd dBl-mTZTd dCl7mUZUd dDl7mVZVd dEl7mWZWd dFlXmYZYd dGlXmZZZd dHl;m[Z[d dIl\m]Z]d dJl^m_Z_d dKl^m`Z`d dLl^maZaebdMejcejdBZeefe!\ZgZhZiZjZkGdNdOdOe#ZlGdPdQdQelZmGdRdSdSe%Znenel_odS)TaDefault 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. ) annotationsN) perf_counter)Any)Callable)cast)Dict)List)Mapping)MutableMapping)MutableSequence)Optional)Sequence)Set)Tuple)Type) TYPE_CHECKING)Union)characteristics)cursor) interfaces) Connection) CacheStats) DBAPICursor)Dialect) ExecuteStyle)ExecutionContext) ObjectKind) ObjectScope)event)exc)pool)util)compiler)dml) expression)type_api) is_tuple_type)_NoArg) DDLCompiler)InsertmanyvaluesSentinelOpts) SQLCompiler) quoted_name)Final)Literal) ModuleType)Engine)ResultFetchStrategy)_CoreMultiExecuteParams)_CoreSingleExecuteParams)_DBAPICursorDescription)_DBAPIMultiExecuteParams)_ExecuteOptions)_MutableCoreSingleExecuteParams) _ParamStyle)DBAPIConnection)IsolationLevel)Row)URL)_ListenerFnType)Pool)PoolProxiedConnection) Executable)Compiled)Linting)ResultColumnsEntry)DMLState) UpdateBase) BindParameter)Column)_BindProcessorType)_ResultProcessorType) TypeEnginez \s*SELECTc@seZdZUdZejZejZej Z ej Z dZ dZdZdZdZdZejjZdZded<dZded<dZeZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2e34e56e57d Z8e34e3j9e3:d e3:d e3j9e3j9e3j9e3j;d ZdZ?dZ@ded<dZAded<dZBded<dZCded<dZDdZEiZFded<dZGdZHdZIdZJdZKdZLdZMded<dZNded<eOjPZQded<dZRd ed!<d"ZSdZTdZUdZVdZWdZXdZYded#<dZZdZ[dZ\d$Z]e3j^d%d&d'ddddddde_j`deaejbdf d(d)d*d+d,ddd-d,d.dd/d0 d1d2Zcede3ed3d4d5d6Zfe3jgd7d8Zhe3jgd9d:ZidZjdZke3jgd;d<d=d>Zle3jgd?d@ZmdAdBZne3jgdCdDZoe3jgdEdFZpeddGdHZqeddIdJZresdKdLdMdNdOZtdKdLdMdPdQZuesdRdSZvdTd<dUdVZwdWdXZxdYdZZyd[d\Zzd]d^Z{d_d`Z|ddadbZ}dcddd/ddedfdgZ~dhdiZdjdkZdldmZdnd dodpdqdrZdcd dodsdtduZdvdwZdxdyZdzd{Zd|d}Zd~dZddZddZe3jgddZdddddZdddddZddZddZddZddZddZdddZdddZdddZddZe3jddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZdS)DefaultDialectz!Default implementation of DialectTFNzOptional[Set[Any]]include_set_input_sizesexclude_set_input_sizesr)isolation_levelZ logging_tokendebug) pool_timeoutZechoZ echo_poolZ pool_recycleZ pool_sizeZ max_overflowfutureMapping[str, Any]engine_config_typesdefaulti' Optional[int]#_user_defined_max_identifier_lengthz Optional[str]rOmax_index_name_lengthmax_constraint_name_lengthz>)`` for public API use.) isinstancerr!rstype)rargrrr_ensure_has_table_connections   z+DefaultDialect._ensure_has_table_connectioncCs:|jjdd}|dkr2tjd|j|jfddt|S)Nsupports_statement_cacheaDialect %s:%s will not make use of SQL compilation caching as it does not set the 'supports_statement_cache' attribute to ``True``. This can have significant performance implications including some performance degradations in comparison to prior SQLAlchemy versions. Dialect maintainers should seek to set this attribute to True after appropriate development and testing for SQLAlchemy 1.4 caching support. Alternatively, this attribute may be set to False which will disable this warning.Zcprf)code) __class____dict__getr#warnnamedriverr])rZsscrrr_supports_statement_caches  z(DefaultDialect._supports_statement_cachecCstSr)weakrefWeakKeyDictionaryrrrr _type_memosszDefaultDialect._type_memoscCs|jd|jS)N+)rrrrrrdialect_descriptionsz"DefaultDialect.dialect_descriptioncCs|jS)zTrue if this dialect supports sane rowcount even if RETURNING is in use. For dialects that don't support RETURNING, this is synonymous with ``supports_sane_rowcount``. )supports_sane_rowcountrrrr supports_sane_rowcount_returnings z/DefaultDialect.supports_sane_rowcount_returningr=z Type[Pool])urlrcCst|dtjS)NZ poolclass)rtr"Z QueuePool)clsrrrrget_pool_classszDefaultDialect.get_pool_classcCs ||Sr)r)rrrrrget_dialect_pool_classsz%DefaultDialect.get_dialect_pool_classcCsDd|jddd}zt|dWntk r>YnXdS)N.rz .provision)join __module__split __import__ ImportError)rpackagerrrload_provisionings z DefaultDialect.load_provisioningzOptional[_ListenerFnType]cs"jdk rfdd}|SdSdS)Ncs|jdSr)_assert_and_set_isolation_levelr{) dbapi_connZconn_recrrrbuiltin_connectsz:DefaultDialect._builtin_onconnect..builtin_connect)r{)rrrrr_builtin_onconnects  z!DefaultDialect._builtin_onconnectcCsz|||_Wntk r*d|_YnXz|||_Wntk rVd|_YnXz||jj|_Wntk rd|_YnX|j s| |}|r||_ |j r|j |j krt d|j |j fdS)NzQLabel length of %d is greater than this dialect's maximum identifier length of %d)Z_get_server_version_infoserver_version_infoNotImplementedErrorZ_get_default_schema_namercget_default_isolation_level connectiondbapi_connectiondefault_isolation_levelrW_check_max_identifier_lengthrjrkr!rs)rrZmax_ident_lengthrrr initializes>         zDefaultDialect.initializecCsdSrrrrrr on_connect)szDefaultDialect.on_connectcCsdS)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 Nrrrrrrr-s z+DefaultDialect._check_max_identifier_lengthcCs ||S)aGiven a DBAPI connection, return its isolation level, or a default isolation level if one cannot be retrieved. May be overridden by subclasses in order to provide a "fallback" isolation level for databases that cannot reliably retrieve the actual isolation level. By default, calls the :meth:`_engine.Interfaces.get_isolation_level` method, propagating any exceptions raised. .. versionadded:: 1.3.22 )Zget_isolation_levelrrrrrr9sz*DefaultDialect.get_default_isolation_levelcCst||jS)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'Z adapt_typerZ)rZtypeobjrrrtype_descriptorIs zDefaultDialect.type_descriptorcKsP|j||fd|i|sdS|j||fd|i|D]}|d|kr4dSq4dS)NschemaFrT)Z has_table get_indexes)rrZ table_nameZ index_namerkwidxrrr has_indexTs  zDefaultDialect.has_indexrstr)r schema_namerrcKs||j|f|kSr)Zget_schema_names)rrrrrrr has_schema_szDefaultDialect.has_schemacCs&t||jkr"td||jfdS)Nz7Identifier '%s' exceeds maximum length of %d characters)lenrjr!ZIdentifierError)ridentrrrvalidate_identifierds z"DefaultDialect.validate_identifiercOs|jj||Sr)rconnect)rZcargsZcparamsrrrrkszDefaultDialect.connectcCs|}||jg|fSr)Ztranslate_connect_argsupdatequery)rroptsrrrcreate_connect_argsos z"DefaultDialect.create_connect_argsr1None)enginerrcsJtj}|rFtfdd|Dt|dfdd}dS)Nc3s|]}||fVqdSrr.0rrrr |sz>DefaultDialect.set_engine_execution_options..Zengine_connectcs|dSr)_set_connection_characteristics)r)rrrrset_connection_characteristicsszSDefaultDialect.set_engine_execution_options..set_connection_characteristics)setconnection_characteristics intersectionr# immutabledictr Z listens_for)rrrsupported_namesrr)rrrrset_engine_execution_optionsus  z+DefaultDialect.set_engine_execution_options)rrrcs<t|j}|r8tfdd|D}|||dS)Nc3s|]}||fVqdSrrrrrrrszBDefaultDialect.set_connection_execution_options..)rrrr#rr)rrrrrrrr set_connection_execution_optionss z/DefaultDialect.set_connection_execution_optionsc sfdd|D}|rNdd|D}|rNtdddd|D|jj}|D]\}}}||||qZ|jjj t j |dS)Ncs g|]\}}|j||fqSr)r)rrvaluerrr szBDefaultDialect._set_connection_characteristics..cSs g|]\}}}|jr||fqSr)Z transactional)rrobj_rrrrszThis connection has already initialized a SQLAlchemy Transaction() object via begin() or autobegin; %s may not be altered unless rollback() or commit() is called first., css|]\}}|VqdSrr)rrrrrrrszADefaultDialect._set_connection_characteristics..)itemsZin_transactionr!rrrrZset_connection_characteristicZ_connection_recordZfinalize_callbackappend functoolspartial_reset_characteristics) rrrZcharacteristic_valuesZ trans_objsrrcharacteristicrrrrrs0   z.DefaultDialect._set_connection_characteristicscCs$|D]}|j|}|||qdSr)rZreset_characteristic)rrrZcharacteristic_namerrrrrs z%DefaultDialect._reset_characteristicscCsdSrrrrrrrdo_beginszDefaultDialect.do_begincCs |dSr)rollbackrrrr do_rollbackszDefaultDialect.do_rollbackcCs |dSr)commitrrrr do_commitszDefaultDialect.do_commitcCs||dSr)do_closerrrr do_terminateszDefaultDialect.do_terminatecCs |dSr)closerrrrrszDefaultDialect.do_closecCsttdj|dS)Nrdialect)rr&selectcompilerrrr_dialect_specific_select_onesz+DefaultDialect._dialect_specific_select_oner:)rrc Csz ||WS|jjk r}zl|||d}|jrzztj|||dddWn*tjk rx}z |j }W5d}~XYnX|rWY dSW5d}~XYnXdS)NFT) is_disconnectZinvalidate_pool_on_disconnectZ is_pre_ping) do_pingrErrorr _has_eventsrZ$_handle_dbapi_exception_noconnectionr!ZStatementErrorZconnection_invalidated)rrerrrZnew_errrrr_do_ping_w_events$   zDefaultDialect._do_ping_w_eventcCs,d}|}z||jW5|XdS)NT)rrexecuter)rrrrrrrs  zDefaultDialect.do_pingcCsdtdddS)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_%032xrr)randomrandintrrrr create_xidszDefaultDialect.create_xidcCs|t|dSr)rr&ZSavepointClauserrrrrr do_savepointszDefaultDialect.do_savepointcCs|t|dSr)rr&ZRollbackToSavepointClauserrrrdo_rollback_to_savepointsz'DefaultDialect.do_rollback_to_savepointcCs|t|dSr)rr&ZReleaseSavepointClauserrrrdo_release_savepointsz#DefaultDialect.do_release_savepointc #stt|}tt|j}ddd}|j} |j} | dk s:tt|j} |j dj } |j rj|j di} nd} | rg}||_ | j}nd}d}|||| || || D]}|V| rz||}WnDtk r}z$|j|t|j|jd|ddW5d}~XYnX|dk st| jr|js| jdk}| jrZ|r@t|t|tdd q| jsft| jsrt| j|s|rfd d t | j|j! dDn| jd j"#|j!ddd}|rfd d|Dn(rfdd|Dndd|Dt$t$|j%krHt&'dt$|j%dt$dzfdd |j(D}Wn>t)k r}zt&'d|j*d d|W5d}~XYnX||q||qdS)NrFrbschema_translate_mapT)Z is_sub_execrr)keycs"g|]\}}|j|dqS)r)r_cached_result_processor)rcolZ cursor_descrrrr[s zDDefaultDialect._deliver_insertmanyvalues_batches..rcs0i|](}tddt| dD|qS)css"|]\}}|r||n|VqdSrr)rvalprocrrrrrszNDefaultDialect._deliver_insertmanyvalues_batches...N)tupleziprrow)_composite_sentinel_proc_nscrr qs zDDefaultDialect._deliver_insertmanyvalues_batches..csi|]}|d|qSrrr)_scalar_sentinel_procrrr{s cSsi|]}|d|qSrrrrrrrszASentinel-keyed result set did not produce correct number of rows z ; produced zP. Please ensure the sentinel column is fully unique and populated in all cases.csg|] }|qSrr)rZ sentinel_keys)rows_by_sentinelrrrszACan't match sentinel values in result set to parameter sets; key aT was not found. There may be a mismatch between the datatype passed to the DBAPI driver vs. that which it returns in a result row. Ensure the given Python value matches the expected result type *exactly*, taking care to not rely upon implicit conversions which may occur such as when using strings in place of UUID or integer values, etc. )+rDefaultExecutionContextr,compiledcompiled_parameters_insertmanyvaluesAssertionErrorr]effective_returningexecution_optionsrrbr _insertmanyvalues_rowssort_by_parameter_order!_deliver_insertmanyvalues_batchesfetchall_for_returning BaseExceptionZ_handle_dbapi_exceptionsql_utilZ_long_statementZreplaced_statementZreplaced_parametersnum_sentinel_columnsZ is_downgradedZimplicit_sentinelextendsortedoperator itemgetterZsentinel_param_keyssentinel_columnsr descriptionrr rbatchr!rZsentinel_valuesKeyErrorargs)rrr statement parametersZgeneric_setinputsizescontextrZ_sentinel_proc_initializedrimvZ is_returningZ batch_sizer resultr"Z imv_batchrowsbeZcomposite_sentinelZ ordered_rowsZker)rrrrrrr#s                      z0DefaultDialect._deliver_insertmanyvalues_batchescCs|||dSr) executemanyrrr1r2r3rrrdo_executemanyszDefaultDialect.do_executemanycCs|||dSrrr9rrr do_executeszDefaultDialect.do_executecCs||dSrr;)rrr1r3rrrdo_execute_no_paramssz#DefaultDialect.do_execute_no_paramscCsdS)NFr)rerrrrrrszDefaultDialect.is_disconnectcCspzt||}Wntk r(YdSXdd|D}||krdtd|jdtt||t|SdS)NcSsg|]}|ddqS)r )replaceupper)rlevelrrrrsz@DefaultDialect._gen_allowed_isolation_levels..rzi get_isolation_level_values() method should return names as UPPERCASE using spaces, not underscores; got ) listZget_isolation_level_valuesr ValueErrorrr)r differencer)rrZ raw_levelsZnormalized_levelsrrr_gen_allowed_isolation_levelssz,DefaultDialect._gen_allowed_isolation_levelsc CsZ|dd}||}|rJ||krJtd|d|jdd||||dS)Nrr?zInvalid value z1 for isolation_level. Valid isolation levels for z are r)r@rArFr!rsrrZset_isolation_level)rrrBZ_allowed_isolation_levelsrrrrsz.DefaultDialect._assert_and_set_isolation_levelcCsT|jdk r4|jdks$|j|jks$t|||jn|jdk sBt|||jdS)NZ AUTOCOMMIT)r{rrrrrrrreset_isolation_levels  z$DefaultDialect.reset_isolation_levelcCs\|dkr dS|}|}||kr(|S||kr@|j|s@|S||krTt|ddS|SdS)NT)quote)lowerrArz_requires_quotesr-rrZ name_lowerZ name_upperrrrnormalize_names zDefaultDialect.normalize_namecCsD|dkr dS|}|}||kr(|S||kr@|j|s@|}|Sr)rIrArzrJrKrrrdenormalize_nameszDefaultDialect.denormalize_namecCs|Srrrrrrget_driver_connectionsz$DefaultDialect.get_driver_connectioncCstt||jtt|jk Sr)rtr__code__rL)rmethodrrr_overrides_defaults z!DefaultDialect._overrides_defaultc ksg}g} tj|kr*||j| |jtj|krL||j| |jtj|krb||j | di} |r|t j kr|tj kr|} nrg} d|i|} g} t j |kr| |t j|kr| | | D]0}z| ||f| Wqtk rYqXq|r t|}| D]}|r$||kr||f}z ||||fd|i|fVWnNtjk r}z|| krt|| |<W5d}~XYntjk rYnXqdS)N unreflectabler)rZTABLErZget_table_namesZget_temp_table_namesZVIEWZget_view_namesZget_temp_view_namesZMATERIALIZED_VIEWZget_materialized_view_namespoprANYr\r( TEMPORARYrrr!ZUnreflectableTableErrorZNoSuchTableError)rZsingle_tbl_methodrkindrZ filter_namesscoperZ names_fnsZtemp_names_fnsrRnamesZname_kwZfnsfntabler rrrr_default_multi_reflectsf                  z%DefaultDialect._default_multi_reflectcKs|j|j|f|Sr)r[Zget_table_optionsrrrrrrget_multi_table_optionshs z&DefaultDialect.get_multi_table_optionscKs|j|j|f|Sr)r[Z get_columnsr\rrrget_multi_columnsmsz DefaultDialect.get_multi_columnscKs|j|j|f|Sr)r[Zget_pk_constraintr\rrrget_multi_pk_constraintps z&DefaultDialect.get_multi_pk_constraintcKs|j|j|f|Sr)r[Zget_foreign_keysr\rrrget_multi_foreign_keysus z%DefaultDialect.get_multi_foreign_keyscKs|j|j|f|Sr)r[rr\rrrget_multi_indexeszsz DefaultDialect.get_multi_indexescKs|j|j|f|Sr)r[Zget_unique_constraintsr\rrrget_multi_unique_constraints}s z+DefaultDialect.get_multi_unique_constraintscKs|j|j|f|Sr)r[Zget_check_constraintsr\rrrget_multi_check_constraintss z*DefaultDialect.get_multi_check_constraintscKs|j|j|f|Sr)r[Zget_table_commentr\rrrget_multi_table_comments z&DefaultDialect.get_multi_table_comment)N)N)N)N)__name__r __qualname____doc__r$r,statement_compilerr* ddl_compilerr|r}IdentifierPreparerryZsupports_alterZsupports_commentsZsupports_constraint_commentsZinline_commentsrZdiv_is_floordivrruNONErvrM__annotations__rNZdefault_sequence_baserexecute_sequence_formatZsupports_schemasZsupports_viewssupports_sequencessequences_optional"preexecute_autoincrement_sequencessupports_identity_columnspostfetch_lastrowidZfavor_returning_over_lastrowidZ#insert_null_pk_still_autoincrementsrrZupdate_returning_multifromZdelete_returning_multifromrZcte_follows_insertZsupports_native_enumriZsupports_native_uuidZreturns_native_bytesZ#non_native_boolean_check_constraintsupports_simple_order_by_labelZtuple_in_valuesr#rrZIsolationLevelCharacteristicZLoggingTokenCharacteristicrZasintZ bool_or_strZasboolrTZsupports_native_decimalrrjrWrOrXrYrsupports_sane_multi_rowcountrZrxZsupports_default_valuesZsupports_default_metavalueZdefault_metavalue_tokenZsupports_empty_insertsupports_multivalues_insertr^r_r+Z NOT_SUPPORTEDr`rbZinsertmanyvalues_max_parametersZsupports_is_distinct_fromrrreZsupports_for_update_ofrrcZrequires_name_normalizeZis_asyncZ has_terminateZ$_legacy_binary_type_literal_encodingZdeprecated_paramsr)r~raZ NO_LINTINGrproperty deprecatedrmemoized_propertyrrupdate_executemany_returningdelete_executemany_returningrrrrrrr classmethodrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r#r:r<r=rZmemoized_instancemethodrFrrGrLrMrNrQr[r]r^r_r`rarbrcrdrrrrrLssl               (R           $      -    IrLc@sPeZdZejZejZejZ ej Z dZ dZ dZdZdZdZdZdZdZdZdZdS)StrCompileDialectTFN)rerrfr$ZStrSQLCompilerrhr*riZStrSQLTypeCompilerr}rjryrrrrrqrnrorprirursrrrrr|sr|c @s8eZdZUdZdZdZdZdZdZe j Z de d<dZ de d<dZde d<dZd e d <ejZd e d <ejZdZd e d<dZdZdZdZdZdZde d<dZde d<eZde d<e Z!de d<de d<de d<de d<de d<de d <d!e d"<d#e d$<e"d%ejZ#dZ$d&e d'<d(Z%d)e d*<e&dddd d+d,d-d.d/Z'e&e(j)fdddd d0d1d2d#d3d,d4 d5d6Z*e&dddd dd!d,d7d8d9Z+e&dddd d,d:d;d<Z,dd=d>d?Z-e.d@dAZ/ej0dBdCZ1ej0dDdEZ2ej0dFd=dGdHZ3ej0dFd=dIdJZ4ej0dKdLZ5ddMdNZ6ej0dOdPZ7dQdRZ8dSdTZ9dUdVZ:dWdXZ;dYdZZd_d`Z?dadbZ@dcddZAdedfZBejCd)d=dgdhZDe.didjZEdkdlZFdmdnZGdodpZHdqdrZIdsdtZJej0dudvZKdwdxZLdydzZMd{d|ZNd}d~ZOdd=ddZPddZQddZRdZSde d<dddZTddZUddZVddZWdS)rFr execute_styleNzOptional[Compiled]rzAOptional[Tuple[List[ResultColumnsEntry], bool, bool, bool, bool]]result_column_structzOptional[Sequence[Row[Any]]]returned_default_rowsr7r zOptional[Executable]invoked_statementrV _rowcountzOptional[Callable[[str], str]]_translate_colnamezMapping[str, List[str]]_expanded_parametersrroot_connectionr@_dbapi_connectionrrrunicode_statementrrz%List[_MutableCoreSingleExecuteParams]rr6r2z&Optional[Sequence[BindParameter[Any]]]extracted_parametersrSzOptional[List[Tuple[Any, ...]]]r!rra_num_sentinel_colsr*r)rrrr  compiled_ddlrc Cs||}||_||_|j|_||_}d|_||_t||_|j rh|j di}|j j } | |j||_|j|_ ||_g|_|jr|g|_n |jg|_|S)zKInitialize execution context for an ExecutableDDLElement construct.Tr )__new__rrrrisddlr rrr rry_render_schema_translatesr1 create_cursorrrrwrmr2_empty_dict_params) rrrrr rrrr rstrrr _init_ddls2     z!DefaultExecutionContext._init_ddlr,r3rAr) rrrr rr2rr cache_hitrc s||} || _|| _|j| _| _|| _| _| | _|| _j j j j j f| _j| _} j| _} j| _} j| _| s| s| rȈjj}trt|tstd| _t|j| _}tj| _}|r|j rd| _!|r|rt|s|rȈj"r| r&| jj#s&t$%d| jj&dn| rV|j'rV| jj(sVt$%d| jj&dnr| rz| jj)rzj*szt$%dnN| r| jj+st$%d| jj&dn&| r| jj,st$%d| jj&d|sj-dd g| _.ndfd d t/|D| _.t0|d krF| jr>j*r>t1j2| _3j*}|j4d k rF|j5| _6nt1j7| _3j8| _9| :| _;| jj<sl| jj=rt| >j?}|j@sjAr| jBrt$%dC| j.d}|j| _9|jD| _EtF|G|jH|jI}njJr| jjI}nd }jKr| jLdi}jMjN}|| j9|| _9| j9| _jJrzg}|d k s@t| j.D]*fdd |D}|O|P|qF|| _QnZg}jR| j.D]BrfddD}nfddD}|O|q|| _Q| S)z6Initialize execution context for a Compiled construct.Trz] with current server capabilities does not support INSERT..RETURNING when executemany is usedz} with current server capabilities does not support INSERT..RETURNING with deterministic row ordering when executemany is usedznStatement does not have "insertmanyvalues" enabled, can't use INSERT..RETURNING with executemany in this case.z] with current server capabilities does not support UPDATE..RETURNING when executemany is usedz] with current server capabilities does not support DELETE..RETURNING when executemany is usedF)r escape_namescs"g|]\}}j|d|dqS)F)rZ _group_numberr)construct_params)rgrpm)rrrrrtsz:DefaultExecutionContext._init_compiled..rNzL'literal_execute' or 'expanding' parameters can't be used with executemany()rr cs,g|]$}|kr ||n|qSrrrr compiled_paramsflattened_processorsrrrscs6i|].}|||kr*||n|qSr)rr)r escaped_namesrrrrs  z:DefaultExecutionContext._init_compiled..cs.i|]&}||kr"||n|qSrrrrrrrs )Srrrrrrrrr Z_result_columnsZ_ordered_columnsZ_textual_ordered_columnsZ_ad_hoc_textualZ_loose_column_name_matchingr~isinsertisupdateisdeleteZ isplaintextis_text compile_stater1rrrFris_crudr]Z _returning_is_explicit_returningrh_is_implicit_returningZ_supplemental_returning_is_supplemental_returningZfor_executemanyrr!rrZ_sort_by_parameter_orderrr^rryrzrr enumeraterrINSERTMANYVALUESr}r,r'r EXECUTEMANYstringrrrinsert_prefetchupdate_prefetch_process_execute_defaults_bind_processorsliteral_execute_paramsZpost_compile_paramsr8Z#_process_parameters_for_postcompileZparameter_expansionrdictr processors positiontuprwr rryrrrmr2escaped_bind_names)rrrrr rr2rrrriiiuZid_Z dml_statementZierZiirr4rZexpanded_staterr rZcore_positional_parametersZl_paramZcore_dict_parametersZd_paramr)rrrrrr_init_compiled s                   z&DefaultExecutionContext._init_compiled)rrrr r1r2rcs||}||_||_|j|_d|_||_|sP|jjrDg|_q|j g|_nBt |djrh||_n*t |dt r~||_nfdd|D|_t |dkrt j|_||_|_||_|S)z8Initialize execution context for a string SQL statement.Trcsg|]}|qSr)rm)rprrrrsz;DefaultExecutionContext._init_statement..r)rrrrrr rwrmr2rrrrrrr}r1rrr)rrrrr r1r2rrrr_init_statements,      z'DefaultExecutionContext._init_statement)rrrr rcCs2||}||_||_|j|_||_||_|S)z;Initialize execution context for a ColumnDefault construct.)rrrrr rr)rrrrr rrrr _init_defaults  z%DefaultExecutionContext._init_defaultrcCs|jdkrdSt}|j}|jj}|dk s.t|tkrDd||fS|tkrZd||fS|tkrpd||fS|tkrd|j krd|j d||fSd||fSn&|t krd|j j |j j ||fSd SdS) Nzraw sqlz no key %.5fszcached since %.4gs agozgenerated in %.5fsZ_cache_disable_reasonzcaching disabled (%s) %.5fs zcaching disabled %.5fsz,dialect %s+%s does not support caching %.5fsunknown)rrrZ _gen_timer NO_CACHE_KEY CACHE_HIT CACHE_MISSCACHING_DISABLEDr NO_DIALECT_SUPPORTrrr)rnowchZgen_timerrr_get_cache_stats1s4   z(DefaultExecutionContext._get_cache_statscCs|jtjtjfkSr)r}rrrrrrrr8Ssz#DefaultExecutionContext.executemanycCs8|jr|jjSd|jkr,|jj|jdS|jjSdS)Nr )rryr rrzZ_with_schema_translaterrrrrzZs z+DefaultExecutionContext.identifier_preparercCs|jjSr)rrrrrrreszDefaultExecutionContext.enginezOptional[Sequence[Column[Any]]]cCstrt|jtst|jjSr)rrrr,r postfetchrrrrpostfetch_colsisz&DefaultExecutionContext.postfetch_colscCs8trt|jtst|jr"|jjS|jr0|jjSdSdS)Nr) rrrr,rrrrrrrrr prefetch_colsosz%DefaultExecutionContext.prefetch_colscCs|jddS)N no_parametersF)r rrrrrrzsz%DefaultExecutionContext.no_parametersc Cs|j}d|jkr0|jdi}|jj}|||}|sL|jjrH|j}ni}|j|j |||d|j }|dk r||d}nd}|dk r| |j|j j dd} | r| |S|S)aExecute 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 )r3Nrr) rr rrzrrrwrmZ_cursor_executerZfetchoner r-) rstmttype_r2connr rrrrrrr_execute_scalar~s2      z'DefaultExecutionContext._execute_scalarcCs|jSr)rrrrrrsz"DefaultExecutionContext.connectioncCsv|jjs dS|jjrd|jddo`|jr8t|jjtj p`|j sPt|jjtj o`|j o`t |j }n|jdd}|S)NFstream_resultsT)rrrrer rrrr1r&Z SelectableZ TextClauserSERVER_SIDE_CURSOR_REmatch)rZuse_server_siderrr_use_server_side_cursors2 z/DefaultExecutionContext._use_server_side_cursorcCsF|jjr4|jdds&|jjr4|r4d|_|Sd|_|SdS)NrFT) rrrr rrer_is_server_sidecreate_server_side_cursorcreate_default_cursorrrrrrs  z%DefaultExecutionContext.create_cursorcCs|Sr)Zfetchall)rrrrrr$sz.DefaultExecutionContext.fetchall_for_returningcCs |jSr)rrrrrrrsz-DefaultExecutionContext.create_default_cursorcCs tdSrrrrrrrsz1DefaultExecutionContext.create_server_side_cursorcCsdSrrrrrrpre_execsz DefaultExecutionContext.pre_execcCs tddS)Nz,This dialect does not support OUT parametersr)rrXrrrget_out_parameter_valuessz0DefaultExecutionContext.get_out_parameter_valuescCsdSrrrrrr post_execsz!DefaultExecutionContext.post_execcCs||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 r)rrZcolnameZcoltyperrrget_result_processorsz,DefaultExecutionContext.get_result_processorcCs|jjS)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 for an INSERT statement that would need to return the last inserted primary key for those dialects that make use of the lastrowid concept. In these cases, it is called directly after :meth:`.ExecutionContext.post_exec`. )r lastrowidrrrr get_lastrowidsz%DefaultExecutionContext.get_lastrowidcCsdSrr)rr>rrrhandle_dbapi_exception sz.DefaultExecutionContext.handle_dbapi_exceptioncCs|jdk r|jS|jjSdSr)rrrowcountrrrrrs z DefaultExecutionContext.rowcountcCs |jdk Sr)rrrrr _has_rowcountsz%DefaultExecutionContext._has_rowcountcCs|jjSr)rrrrrrrsz.DefaultExecutionContext.supports_sane_rowcountcCs|jjSr)rrtrrrrrtsz4DefaultExecutionContext.supports_sane_multi_rowcountcCs|j}|jdkr&|ddr&|jj|_|js2|jrD|}d}}nl|dd}|jp`|dd}|j }|r|t j krt |j|j}|j p|jj}|dkrt j}t |||}|j}|r|jstt|jr|||j|_|r||}|S)NZpreserve_rowcountF yield_perr)r rrrrrr_setup_dml_or_text_resultrcursor_fetch_strategy_cursor_DEFAULT_FETCHBufferedRowCursorFetchStrategyalternate_cursor_descriptionr-Z_NO_CURSOR_DQL CursorResultrrrr,Zhas_out_parameters_setup_out_parameters _soft_closedr)rZexec_optr5Zypsrstrategycursor_descriptionrrrr_setup_result_proxys@       z+DefaultExecutionContext._setup_result_proxyc Cstt|j}dd|jD}i}tdd|D|dd|DD]P\}}|j}||j }| |j j } | |j | } | dk r| |}|||j <qH||_dS)NcSsg|]\}}|jr||fqSr)Z isoutparamrparamrrrrrLszADefaultExecutionContext._setup_out_parameters..cSsg|] \}}|qSrrrrrrrTscSsg|] \}}|qSrrrrrrrVs)rr,r bind_namesrrrrZ dialect_implrZget_dbapi_typerresult_processorr out_parameters) rr5rZout_bindparamsr bindparamZ raw_valuerZ impl_typeZ dbapi_typerrrrrIs,      z-DefaultExecutionContext._setup_out_parameterscCstt|j}|j}|jrP|jtjkr@|jr@t j |j |j |j d}|jrP||_|jrp|t jkrpt |j |j}|t jkrd}n|j p|j j}|dkrt j}n&|jr|jtjkst|d|j }t |||}|jr<|jr*|}||_||||_|jjs t|j r |!|n|"n|j#s|"n|jr|}|rX||_t$||_%|j rv|!|n|"|jjstnP|jjs|j%dkr|j j&|_%|"n&|j's|j(r|j%dkr|j j&|_%|S)N)Zinitial_bufferZalternate_descriptionr))rr,rrrr}rrrrZ FullyBufferedCursorFetchStrategyrr!rrr_setup_ins_pk_from_lastrowidinserted_primary_key_rowsrrrr Z_NO_CURSOR_DMLr-rrrrallr%_setup_ins_pk_from_implicit_returning _metadataZ returns_rowsr_rewindZ _soft_closerrrrrr)rrrrr5r6rrrres                z1DefaultExecutionContext._setup_dml_or_text_resultcCs|Sr)_setup_ins_pk_from_emptyrrrrrsz1DefaultExecutionContext.inserted_primary_key_rowscCs(tt|jj}|}|||jdgS)Nr)rr,r+_inserted_primary_key_from_lastrowid_getterrr)rgetterrrrrrs z4DefaultExecutionContext._setup_ins_pk_from_lastrowidcs"tt|jjfdd|jDS)Ncsg|]}d|qSrr)rrrrrrszDDefaultExecutionContext._setup_ins_pk_from_empty..)rr,rrrrrrrrs z0DefaultExecutionContext._setup_ins_pk_from_emptycs4|sgStt|jj|j}fddt||DS)Ncsg|]\}}||qSrr)rrrrrrrszQDefaultExecutionContext._setup_ins_pk_from_implicit_returning..)rr,rZ+_inserted_primary_key_from_returning_getterrr)rr5r6rrrrrs z=DefaultExecutionContext._setup_ins_pk_from_implicit_returningcCs|js |jottt|jjSr)rrr]rr,rrrrrrlastrow_has_defaultss z,DefaultExecutionContext.lastrow_has_defaultsz0Optional[List[Tuple[str, Any, TypeEngine[Any]]]]cs|js |jrdStt|j}|dkr0dS|j}|jr^t|}|j ||j |j |j |jrljnd|jrfddjpdD}nddjD}g}|D]\}jkrq||jkrFtjrtjj||fddt|j|Dn.|d|fdd|j|Dq|ddk rh||n|}||jfq|S) aGiven a cursor and ClauseParameters, prepare arguments in order to 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 set the :attr:`.Dialect.bind_typing` attribute to :attr:`.BindTyping.SETINPUTSIZES`. cx_Oracle is the only DBAPI that requires setinputsizes(), pyodbc offers it as an option. Prior to SQLAlchemy 2.0, the setinputsizes() approach was also used for pg8000 and asyncpg, which has been changed to inline rendering of casts. Ncsg|]}|j|fqSr)Zbindsr)rrrr)szDDefaultExecutionContext._prepare_set_input_sizes..rcSsg|]\}}||fqSrr)rrr rrrr.sc3sD|]<\}}dk r||n||jj|fVqdSr)rrtypes)rr paramname)rdbtypesrnumrrr<s  zCDefaultExecutionContext._prepare_set_input_sizes..c3s.|]&}dk r||n|jfVqdSr)rr)rr)rdbtyperrrrLs )rrrr,rZ_get_set_input_sizes_lookuprrrdispatchZdo_setinputsizesrr1r2rrwrrrrrr(rrrr(rrr)rZ inputsizesrrZgeneric_inputsizesr Z escaped_namer)rrrrrrr_prepare_set_input_sizessh              z0DefaultExecutionContext._prepare_set_input_sizescCsF|jr|||S|jr(||_||S|jr<||||S|jSdSr)Z is_sequenceZ fire_sequence is_callablecurrent_columnrZis_clause_element_exec_default_clause_element)rcolumnrUrrrr _exec_defaultgs  z%DefaultExecutionContext._exec_defaultcs|jst|j|}n|j}t|j|jd}||j|j rh|j fdd|j p^dD}nfddD}|j t |||dS)Nrcs,g|]$}|kr ||n|qSrrrrrrrrszHDefaultExecutionContext._exec_default_clause_element..rcs.i|]&}||kr"||n|qSrrrrrrrs zHDefaultExecutionContext._exec_default_clause_element..)r2)Z _arg_is_typedr&Z type_coercerrrrrrrwrmrrr)rrrUrZ default_argrr2rrrrvs(  z4DefaultExecutionContext._exec_default_clause_elementz"Optional[_CoreSingleExecuteParams]current_parametersTcsz|j|j}Wntk r.tdYnX|dk s.)rrAttributeErrorr!rrrr,rrr%rZ_has_multi_parametersZ_is_multiparam_columnroriginalr Z_dict_parameterskeysr)rZisolate_multiinsert_groupsrrdr rrrget_current_parameterss@!        z.DefaultExecutionContext.get_current_parameterscCs$|jdkrdS|||j|jSdSr)rUrrrrrrrget_insert_defaults z*DefaultExecutionContext.get_insert_defaultcCs$|jdkrdS|||j|jSdSr)Zonupdaterrrrrrget_update_default s z*DefaultExecutionContext.get_update_defaultc sttj}|jd}|jr4fdd|jD}n"|jrRfdd|jD}ng}jD]x}|_|D]h\}}\}}} } } | r|||<|d7}qj|r|||<qj| r|_|||<qj| |} | dk rj| ||<qjq\`dS)Nrcs g|]}|||jjfqSr)Z_default_description_tuplerrcZ key_getterrrrr s zEDefaultExecutionContext._process_execute_defaults..cs g|]}|||jjfqSr)Z_onupdate_description_tuplerrrrrr s r) rr,rZ_within_exec_param_key_getterrrrrr) rrZsentinel_counterZ prefetch_recsrrZ param_keyrZ is_scalarrZ is_sentinelfallbackrrrrr s@          z1DefaultExecutionContext._process_execute_defaults)N)T)XrerrfrrrrrrrZEXECUTEr}rlrr~rr# EMPTY_DICTr rrrrrrrrrrrrrrrrrr!rr{rrrrrrrrvr8rxrzrrrrrrrrr$rrrrrrrrZnon_memoized_propertyrrrrtrrrrrrrrrrrrr rrrrrrrrs          , $f)"      )   *r  j'  Dr)prg __future__rrr*rretimertypingrrrrrr r r r r rrrrrrrrrrbaserrrrrrZ reflectionrrr r!r"r#sqlr$r%r&r'r&Z sql._typingr(Zsql.baser)Z sql.compilerr*r+r,Z sql.elementsr-Z util.typingr.r/rr0r1r2r3r4r5r6r7r8r9r:r;rr<rr=r>r?r@rArBrCrDZsql.dmlrErFrGZ sql.schemarHZ sql.type_apirIrJrKrIUNICODErrCrrrrrrLr|rZexecution_ctx_clsrrrr s                                                                          "!