U kf0^@sR UdZddlmZddlZddlmZddlZddlm Z ddl Z ddl Z ddl Z ddl Z ddlmZddlZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddl&m'Z'ddl&m(Z(ddl&m)Z)ddl&m*Z*dd l&m+Z+dd!l&m,Z,dd"l&m-Z-dd#l&m.Z.dd$l&m/Z/dd%l&m0Z0dd&l&m1Z2dd'l3m4Z4dd(l3m5Z5dd)l'm6Z6dd*l'm7Z7dd+l'm8Z8dd,l'm9Z9dd-l'm:Z:dd.l'm;Z;dd/l*mZ>dd2l0m?Z?dd3l@mAZAdd4lBmCZCdd5lBmDZDd6d7l&mEZEd6d&l&m1Z1d6d8l1mFZFd6d9lGmHZHd6d:lGmIZId6d;lGmJZJej$rddl'mNZNdd?lOmPZPdd@lQmRZRddAlSmTZTddBlSmUZUddClSmVZVddDl*mWZWddEl*mXZXddFl*mYZYddGl*mZZZddHl*m[Z[ddIl+m\Z\ddJl.m]Z]ddKl/m^Z^ddLl/m_Z_ddMl/m`Z`ddNl/maZaddOl/mbZbddPl/mcZcddQl/mdZdddRl/meZeddSl@mfZfd6dTlgmhZhd6dUlimjZjd6dVlimkZkd6dWlimlZld6dXlimmZmd6dYlimnZnd6dZlimoZod6d[limpZpd6d\limqZqd6d]limrZred^esfZtd_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddh^Zue vde jwZxe vde jwZyddezddD{dgZ|e vde jwZ}e vde jwZ~e vde jwZe vde jZe vde jZdZedddddd͜Ze,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jde,jdi)Ze+jde+jde+jde+jde+jde+jde+jde+jde+jde+jde+jde+jde+jde+jdiZded<ddd d d d d dddddddddZe/jjde/jjde/jjÐde/jjĐde/jjŐde/jjƐdiZGdddeZGdd d eIZdZʐd!ed"<dZːd#ed$<d6Z̐d%ed&<d'Z͐d(ed)<Gd*d+d+eJZGd,d-d-eΐd.d/ZGd0d1d1eZGd2d3d3eZGd4d5d5eZGd6d7d7eFZGd8d9d9e ZGd:d;d;e ZeeՃ\ZZZZGd<d=d=eېd=d>d?gZGd@dAdAZGdBdCdCe1jރZGdDdEdEe-jee*jZGdFdGdGe-jee*jZGdHdIdIe݃ZGdJdKdKeZGdLdMdMe݃ZGdNdOdOe߃ZGdPdQdQeZGdRdSdSeIZGdTdUdUeIZGdVdWdWZdS(Xa]Base SQL and DDL compiler implementations. Classes provided include: :class:`.compiler.SQLCompiler` - renders SQL strings :class:`.compiler.DDLCompiler` - renders DDL (data definition language) strings :class:`.compiler.GenericTypeCompiler` - renders type specification strings. To generate user-defined SQL strings, see :doc:`/ext/compiler`. ) annotationsN)IntEnum) perf_counter)Any)Callable)cast)ClassVar)Dict) FrozenSet)Iterable)Iterator)List)Mapping)MutableMapping) NamedTuple)NoReturn)Optional)Pattern)Sequence)Set)Tuple)Type) TYPE_CHECKING)Union)base) coercions)crud)elements) functions) operators)roles)schema) selectable)sqltypes)utilis_column_element)is_dml) _de_clone) _from_objects) _NONE_NAME) _SentinelDefaultCharacterization) Executable)NO_ARG) ClauseElement) quoted_name)Column) TupleType) TypeEngine)prefix_anon_map) Visitable)exc) FastIntFlag)Literal)Protocol) TypedDict)_AnnotationDict)_AmbiguousTableNameMap) CompileState)CacheKey)ExecutableDDLElement)Insert) UpdateBase) ValuesBase)_truncated_label) BindParameter) ColumnClause) ColumnElement)Label)Function)Table)AliasedReturnsRows)CompoundSelectState)CTE) FromClause)NamedFromClause) ReturnsRows)Select) SelectState)_BindProcessorType)CursorResultMetaData)_CoreSingleExecuteParams)_DBAPIAnyExecuteParams)_DBAPIMultiExecuteParams)_DBAPISingleExecuteParams)_ExecuteOptions)_GenericSetInputSizesType)_MutableCoreSingleExecuteParams)Dialect)SchemaTranslateMapTyperNallZanalyseZanalyzeandanyarrayasascZ asymmetric authorizationZbetweenbinaryZbothcasercheckcollatecolumn constraintcreatecross current_dateZ current_role current_timecurrent_timestamp current_userdefault deferrabledescZdistinctdoelseendexceptfalseforZforeignfreezefromfullZgrantgroupZhavingZilikein initiallyinnerZ intersectZintoisZisnulljoinleadingleftlikelimit localtimelocaltimestampZnaturalnewnotZnotnullnulloffoffsetoldononlyororderouteroverlapsZplacingprimaryZ referencesrightselect session_usersetZsimilarZsome symmetrictableZthentoZtrailingtrueunionuniqueuserusingverbosewhenwherez ^[A-Z0-9_$]+$z^[A-Z0-9_ $]+$cCsh|] }t|qS)str).0xrrG/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/sql/compiler.py sr $z5^(?:RESTRICT|CASCADE|SET NULL|NO ACTION|SET DEFAULT)$z^(?:DEFERRED|IMMEDIATE)$z%(? z >= z = z IS DISTINCT FROM z IS NOT DISTINCT FROM z || z MATCH z NOT MATCH z IN z NOT IN , z FROM  AS z IS z IS NOT z COLLATE zEXISTS DISTINCT zNOT zANY zALL z DESCz ASCz NULLS FIRSTz NULLS LASTz ^ z | z & ~z << z >> coalesceZ CURRENT_DATEZ CURRENT_TIMEZCURRENT_TIMESTAMPZ CURRENT_USERZ LOCALTIMEZLOCALTIMESTAMPrandomsysdateZ SESSION_USERUSERZCUBEZROLLUPz GROUPING SETSzDict[Type[Function[Any]], str] FUNCTIONSmonthdayyearsecondhourdoyminutequarterdowweekepoch milliseconds microseconds timezone_hourtimezone_minute)rrrrrrrrrrrrrrrUNIONz UNION ALLEXCEPTz EXCEPT ALL INTERSECTz INTERSECT ALLc@s2eZdZUdZded<ded<ded<ded<d S) ResultColumnsEntryaTracks a column expression that is expected to be represented in the result rows for this statement. This normally refers to the columns clause of a SELECT statement but may also refer to a RETURNING clause, as well as for dialect-specific emulations. rkeynamenameTuple[Any, ...]objectsTypeEngine[Any]typeN__name__ __module__ __qualname____doc____annotations__rrrrr[s  rc@s"eZdZddddddddZdS) _ResultMapAppenderrz Sequence[Any]rNonerrrtype_returncCsdSNrselfrrrrrrr__call__{sz_ResultMapAppender.__call__Nrrrrrrrrrzsrz Literal[0]RM_RENDERED_NAMEz Literal[1]RM_NAMEz Literal[2] RM_OBJECTSz Literal[3]RM_TYPEc@s&eZdZUded<ded<ded<dS)_BaseCompilerStackEntryzSet[FromClause] asfrom_fromscorrelate_fromsrPr#Nrrrrrrrrrs rc@s6eZdZUded<ded<ded<ded<ded <d S) _CompilerStackEntryr> compile_stateboolneed_result_map_for_nestedneed_result_map_for_compoundrPselect_0 Select[Any]insert_from_selectNrrrrrrs rF)totalc@s^eZdZUdZded<ded<ded<ded <d ed <ed d ddZedd ddZdS) ExpandedStatearepresents state to use when producing "expanded" and "post compile" bound parameters for a statement. "expanded" parameters are parameters that are generated at statement execution time to suit a number of parameters passed, the most prominent example being the individual elements inside of an IN expression. "post compile" parameters are parameters where the SQL literal value will be rendered into the SQL statement at execution time, rather than being passed as separate parameters to the driver. To create an :class:`.ExpandedState` instance, use the :meth:`.SQLCompiler.construct_expanded_state` method on any :class:`.SQLCompiler` instance. r statementrU parameters%Mapping[str, _BindProcessorType[Any]] processorsOptional[Sequence[str]] positiontupzMapping[str, List[str]]Zparameter_expansionrrcs,jdkrtdtfddjDS)zrTuple of positional parameters, for statements that were compiled using a positional paramstyle. Nz.statement does not use a positional paramstylec3s|]}j|VqdSrrrkeyrrr sz6ExpandedState.positional_parameters..)rr7InvalidRequestErrortuplerrrrpositional_parameterss  z#ExpandedState.positional_parameterscCs|jS)z.synonym for :attr:`.ExpandedState.parameters`.rrrrradditional_parameterssz#ExpandedState.additional_parametersN)rrrrrpropertyr r rrrrrs   rc@seZdZUdZded<ded<ded<ded <d Zded <d Zded <d Zded<dZded<d Z ded<d Z ded<d Z ded<d S)_InsertManyValuesarepresents state to use for executing an "insertmanyvalues" statement. The primary consumers of this object are the :meth:`.SQLCompiler._deliver_insertmanyvalues_batches` and :meth:`.DefaultDialect._deliver_insertmanyvalues_batches` methods. .. versionadded:: 2.0 ris_default_exprrsingle_values_exprList[crud._CrudParamElementStr]insert_crud_paramsintnum_positional_params_countedFsort_by_parameter_orderincludes_upsert_behaviorsNOptional[Sequence[Column[Any]]]sentinel_columnsrnum_sentinel_columnsrsentinel_param_keysimplicit_sentinelembed_values_counter) rrrrrrrrrrrrrrrrr s        r c@sbeZdZUdZded<ded<ded<ded <d ed <d ed <d ed<d ed<ded<ded<dS)_InsertManyValuesBatchasrepresents an individual batch SQL statement for insertmanyvalues. This is passed through the :meth:`.SQLCompiler._deliver_insertmanyvalues_batches` and :meth:`.DefaultDialect._deliver_insertmanyvalues_batches` methods out to the :class:`.Connection` within the :meth:`.Connection._exec_insertmany_context` method. .. versionadded:: 2.0.10 rreplaced_statementrVreplaced_parameters#Optional[_GenericSetInputSizesType]processed_setinputsizesz#Sequence[_DBAPISingleExecuteParams]batchzSequence[Tuple[Any, ...]]Zsentinel_valuesrcurrent_batch_sizebatchnum total_batchesrZ rows_sortedZ is_downgradedNrrrrrrNs  rc@s<eZdZdZdZdZdZdZeeBeBZeeBZ dZ dZ dS) InsertmanyvaluesSentinelOptszcbitflag enum indicating styles of PK defaults which can work as implicit sentinel columns rr6@N) rrrrZ NOT_SUPPORTED AUTOINCREMENTIDENTITYSEQUENCEANY_AUTOINCREMENT_SUPPORTED_OR_NOTUSE_INSERT_FROM_SELECTRENDER_SELECT_COL_CASTSrrrrr$gs r$c@seZdZdZdZdZdS) CompilerStaterrr6N)rrr COMPILINGSTRING_APPLIED NO_STATEMENTrrrrr0ysr0c@s$eZdZdZdZdZdZeeBZdS)Lintingzrepresent preferences for the 'SQL linting' feature. this feature currently includes support for flagging cartesian products in SQL statements. rrr6N)rrrr NO_LINTINGCOLLECT_CARTESIAN_PRODUCTS WARN_LINTING FROM_LINTINGrrrrr4s r4c@s$eZdZdZdddZd ddZdS) FromLinterzKrepresents current state for the "cartesian product" detection feature.Ncs|j}|sdSt|j}t|}|dk r8|}||n|}t|g}|r|r||fdd|D}| fdd|D| |qL|r||fSdSdS)N)NNcsh|]}|kr|qSrrredgenoderrrsz"FromLinter.lint..c3s|]}|| VqdSr)indexr:r<rrrsz"FromLinter.lint..) fromsredgesremovepop collectionsdequepopleftdiscard extendleftdifference_update)rstartr?r@the_rest start_withstackZ to_removerr<rlints&     zFromLinter.lintSELECTcsX\}}|rT|}|rTd}dfdd|D}|j||j|d}t|dS)Nz{stmt_type} statement has a cartesian product between FROM element(s) {froms} and FROM element "{start}". Apply join condition(s) between each element to resolve.rc3s |]}dj|dVqdS)"N)r?)rfrom_rrrrsz"FromLinter.warn..) stmt_typer?rI)rMrrr?r%warn)rrQrJrKr?templateZ froms_strmessagerrrrRs zFromLinter.warn)N)rN)rrrrrMrRrrrrr9s %r9r?r@csPeZdZUdZdZded<dZded<ded <d Zd ZdZ d ed <dZ d ed<dZ ded<e j Zded<ded<e j Zded<dZded<dZded<dZded<ded<dd e fddddd d!d"d#Zd$d%fd&d' Zed(d)Zd*d+Zd,d-Zed.d/Zd0d1dd2d3d4Zdd%d5d6Zd@d8d9dd:d;dd?ZZ S)ACompiledaRepresent a compiled SQL or DDL expression. The ``__str__`` method of the ``Compiled`` object should produce the actual text of the statement. ``Compiled`` objects are specific to their underlying database dialect, and also may or may not be specific to the columns referenced within a particular set of bind parameters. In no case should the ``Compiled`` object be dependent on the actual values of those bind parameters, even though it may reference those values as defaults. NOptional[ClauseElement]rrstringr0stateFzOptional[CursorResultMetaData]_cached_metadataz"Optional[List[ResultColumnsEntry]]_result_columns Optional[SchemaTranslateMapType]schema_translate_maprYexecution_optionsIdentifierPreparerpreparerr< _annotationszOptional[CompileState]rdml_compile_stateOptional[CacheKey] cache_keyfloat _gen_timer\rMapping[str, Any]dialectrr]render_schema_translatecompile_kwargscCs||_|jj|_|r(||_|j||_|dk rtj|_||_|j |_ |j |_ |j rnt rft |tsft|j|_|j|jf||_|r|j|j||_tj|_ntj|_t|_dS)aConstruct a new :class:`.Compiled` object. :param dialect: :class:`.Dialect` to compile against. :param statement: :class:`_expression.ClauseElement` to be compiled. :param schema_translate_map: dictionary of schema names to be translated when forming the resultant SQL .. seealso:: :ref:`schema_translating` :param compile_kwargs: additional kwargs that will be passed to the initial call to :meth:`.Compiled.process`. N)riidentifier_preparerr`r]_with_schema_translater0r1rYrZsupports_execution can_executerar isinstancer-AssertionErrorZ_execution_optionsr^processrX_render_schema_translatesr2r3rrfrrirr]rjrkrrr__init__;s2  zCompiled.__init__rrcs|tSr)_init_compiler_clssuper__init_subclass__cls __class__rrrwsszCompiled.__init_subclass__cCsdSrrrxrrrruwszCompiled._init_compiler_clscCs$|jr||||St|jdSr)rnZ_execute_compiledr7ZObjectNotExecutableErrorr)r connectionZdistilled_paramsr^rrr_execute_on_connection{szCompiled._execute_on_connectioncKst|t||dSrr7UnsupportedCompilationErrorrrelementerrkwrrrvisit_unsupported_compilationsz&Compiled.visit_unsupported_compilationcCs tdS)zReturn a Compiled that is capable of processing SQL expressions. If this compiler is one, it would likely just return 'self'. NNotImplementedErrorrrrr sql_compilerszCompiled.sql_compilerr5r)objkwargsrcKs|j|f|Sr_compiler_dispatch)rrrrrrrqszCompiled.processcCs|jtjkr|jSdSdS)z3Return the string text of the generated SQL or DDL.rWN)rYr0r2rXrrrr__str__s zCompiled.__str__T"Optional[_CoreSingleExecuteParams]&Optional[Sequence[BindParameter[Any]]])Optional[_MutableCoreSingleExecuteParams]paramsextracted_parameters escape_namesrcCs tdS)zReturn the bind params for this compiled object. :param params: a dict of string/object pairs whose values will override bind values compiled in to the statement. Nrrrrrrrrconstruct_paramss zCompiled.construct_paramscCs|S)z0Return the bind params for this compiled object.rrrrrrszCompiled.params)NNT)!rrrrrrrXis_sqlis_ddlrZr[r]r% EMPTY_DICTr^rarrbrd immutabledictrtrw classmethodrur}rr rrqrrr __classcell__rrrzrrUsF        8    rUc@sHeZdZdZdZddddZddd d d d Zdd dddddZdS) TypeCompilerz2Produces DDL specification for TypeEngine objects.z visit_\w+r\ricCs ||_dSrr)rrirrrrtszTypeCompiler.__init__rrr)rrrcKs0|jr"|jj|jkr"|j|jj}|j|f|Sr)Z_variant_mappingrirrrrrrrrrqs  zTypeCompiler.process Exceptionr)rrrrcKst|||dSr)r7rrrrrrsz*TypeCompiler.visit_unsupported_compilationN)rrrrZ ensure_kwargrtrqrrrrrrs rc@sBeZdZdZdZdZdddZeddZed d Z d d Z d S) _CompileLabelz;lightweight label object which acts as an expression.Label.labelrr _alt_namesrcCs||_||_|f||_dSrr)rcolr alt_namesrrrrtsz_CompileLabel.__init__cCs|jjSrr proxy_setrrrrrsz_CompileLabel.proxy_setcCs|jjSrrrrrrrrsz_CompileLabel.typecKs|Srrrrrrr self_groupsz_CompileLabel.self_groupN)r) rrrr__visit_name__ __slots__rtr rrrrrrrrs   rc@sHeZdZdZdZdZddZeddZedd Z d d Z d d Z dS)ilike_case_insensitiveaproduce a wrapping element for a case-insensitive portion of an ILIKE construct. The construct usually renders the ``lower()`` function, but on PostgreSQL will pass silently with the assumption that "ILIKE" is being used. .. versionadded:: 2.0 Zilike_case_insensitive_operandrZ comparatorcCs||_|j|_dSrr)rrrrrrtszilike_case_insensitive.__init__cCs|jjSrrrrrrrsz ilike_case_insensitive.proxy_setcCs|jjSrrrrrrrszilike_case_insensitive.typecKs|Srrrrrrrsz!ilike_case_insensitive.self_groupcCst|j|Sr)rr_with_binary_element_type)rrrrrrs z0ilike_case_insensitive._with_binary_element_typeN) rrrrrrrtr rrrrrrrrrs   rc @s eZdZUdZeZedddddddddZde d <d e d <de d <d Z e Z dZ de d<dZde d<dZde d<de d<dZde d<dZde d<dZde d<dZde d<de d<de d <d!e d"<dZde d#<dZde d$<dZde d%<d&e d'<d&e d(<d&e d)<d*e d+<dZde d,<dZde d-<d Zde d.<dZde d/<dZde d0<dZde d1<dZd2e d3<dZd4e d5<dZd6e d7<dZ d8e d9<dZ!d:e d;<e"Z#d<ej%Z&d?e d@<dZ'dZ(dZ)dAe dB<dZ*d6e dC<dZ+d6e dD<dZ,d6e dE<dZ-de dF<dGe dH<dIe dJ<dKe dL<de dM<e./dNZ0e./dOZ1e./e1j2dPe0j2Z3e4dQdRZ5e4dSdTZ6ddde7dfdUdVdWdXddYdZd[d\d]d^Z8e9d4d_d`daZ:ej;dd_dbdcZe9dhdiZ?ej@djd_dkdlZAejBdmd_dndoZCeDjEdpdqZFdrdsZGdtduZHej@dvd_dwdxZIdydzZJe9d{d|ZKdd}dd~dddZLdd}dddddddddZMejBddZNe9ddZOdddd~dddZPeQdddZRde d<ej@dd_ddZSej@eQdddZTej@eQdddZUddZVddZWdddZXddZYdddZZdddZ[dddZ\ddZ]ddZ^ddddddd[d&dddZ_ddZ`ddZaddZbddZcddZdddZeddd„ZfdddĄZgddƄZhddȄZiddʄZjdd̄Zkdd΄ZlddЄZmdd҄ZnddԄZoddքZpdd؄ZqddڄZrdd܄ZsddބZtddZuddZvddZwddZxdddd[d&dddZyddZzddZ{ddZ|dddZ}ddZ~ddZdddZddZddZddZddZddZddZddZddZdd d Zd d Zdd dZddZddZddZddZddZdddZddZddZej@dd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Zd=d>Zd?d@ZdAdBZdCdDZdEdFZdGdHZdIdJZdKdLZddMdNZdOdPZedfdQdRZdSdTZdUdVZd&dWd&dXdYdZZd&d&d[d\d]Zdd&ddd4d^d_d6d[d&d` dadbZdcddZdddddedfdedddfdgdhdid[d4dj dkdlZdmdnZdodpZddqdrZdsdtZdudvZddwdxZdydzZdd{d|Zd}d~ZddZd&d&ddddddZdddZÐdddZĐddZŐddZƐddZǐddZȐddZɐde d<ejː sede"fde"fgZ̐dddZdZd[e d<dddZϐdddddZАddZѐddZҐddZӐdddZԐddZՐddZ֐ddZאddZؐddZِdddd[d&dddZڐddZېdddZܐdddZݐdddZސdd„ZeejejejejejejejejejejiZeejejiZdÐdĐdŜdƐdDŽZd&dȐdɐdʐddd̐d͐dΜdϐdЄZddѐd҄ZdӐdԄZdՐdքZdאd؄ZddِdڄZdېd܄ZdݐdބZddߐdZddZddZddZdS( SQLCompilerz~Default implementation of :class:`.Compiled`. Compiles :class:`_expression.ClauseElement` objects into SQL strings. PAZC_)%():.[] zClassVar[Mapping[str, str]]bindname_escape_characterszClassVar[Pattern[str]]_bind_translate_re_bind_translate_charsTFrisdeleteisinsertisupdatezOptional[List[Column[Any]]]Z postfetchrzSequence[Column[Any]]insert_prefetchupdate_prefetchNz&Optional[Sequence[ColumnElement[Any]]]implicit_returning isplaintextzDict[str, BindParameter[Any]]bindszDict[BindParameter[Any], str] bind_nameszList[_CompilerStackEntry]rLreturning_precedes_values'render_table_with_column_in_update_fromansi_bind_rulesr bindtemplatecompilation_bindtemplate_numeric_binds_identifier_charzList[ResultColumnsEntry]r[_textual_ordered_columns_ad_hoc_textual_ordered_columns_loose_column_name_matching_numeric_binds_render_postcompilezOptional[ExpandedState]_post_compile_expanded_state Optional[str]_pre_expanded_stringzOptional[List[str]]_pre_expanded_positiontupzOptional[_InsertManyValues]_insertmanyvaluesz!Optional[crud._CrudParamSequence]_insert_crud_paramszFrozenSet[BindParameter[Any]]literal_execute_paramspost_compile_paramszutil.immutabledict[str, str]escaped_bind_nameszbOptional[Tuple[Dict[BindParameter[Any], List[BindParameter[Any]]], Dict[str, BindParameter[Any]]]]_cache_key_bind_matchr_values_bindparam_visited_bindparaminlinez"Optional[MutableMapping[CTE, str]]cteszDict[Tuple[int, str], CTE]ctes_by_level_namez/Dict[CTE, Tuple[int, str, selectable._CTEOpts]]level_name_by_ctectes_recursivez"__\[POSTCOMPILE_(\S+?)(~~.+?~~)?\]z%\(([^)]+?)\)s|cCs |dSr)_init_bind_translaterxrrrru2szSQLCompiler._init_compiler_clscCs2td|j}td|d|_|j|_dS)NrWrr)reescaperrcompilerr)ryregrrrr6sz SQLCompiler._init_bind_translater\rVrcrr4zOptional[SQLCompiler]r)rirrd column_keysfor_executemanylinting_supporting_againstrc Ks||_||_|r>dd|dD} dd|dD} | | f|_||_||_i|_t|_g|_ g|_ |j |_ |j r|j d|_} | r|j dkrdnd|_t|_n t|j |_d |_|jp|j|_t|_i|_i|_tj|||f||js|js|jrxtrt |t!st"|js*|jrxtr@t |t#s@t"|j$rPd |_%n(|jrx|jrr|j&j'rx|j(rxd |_%t|j |_)|r|j*+d d|j*,D|j-t.j/kr|j r|jr|0n|1|j2r|j3d d d } |j4| d dd S)aConstruct a new :class:`.SQLCompiler` object. :param dialect: :class:`.Dialect` to be used :param statement: :class:`_expression.ClauseElement` to be compiled :param column_keys: a list of column names to be compiled into an INSERT or UPDATE statement. :param for_executemany: whether INSERT / UPDATE statements should expect that they are to be invoked in an "executemany" style, which may impact how the statement will be expected to return the values of defaults and autoincrement / sequences and similar. Depending on the backend and driver in use, support for retrieving these values may be disabled which means SQL expressions may be rendered inline, RETURNING may not be rendered, etc. :param kwargs: additional keyword arguments to be consumed by the superclass. cSsi|] }|j|qSrrrbrrr asz(SQLCompiler.__init__..rcSsi|] }||gqSrrrrrrrbsrrrrNTcSsi|]\}}|dkr||qS)>rrY positionalr`rirrrrkvrrrrs Fr_no_postcompile)_populate_self)5rrdrrrrr%Z column_dictrrLr[r paramstyle startswithrr_pyformat_templaterBIND_TEMPLATESr label_lengthmax_identifier_lengthr4anon_maptruncated_names_truncated_countersrUrtrrrrrorBrprCZ_inlinerriZinsert_executemany_returningZ_return_defaultsr__dict__updateitemsrYr0r2_process_numeric_process_positionalrr#_process_parameters_for_postcompile) rrirrdrrrrrcksmckbmnbrrrrrt<s       zSQLCompiler.__init__rcCs|jdkrdS|jjSdS)aWhen an INSERT is compiled with a single set of parameters inside a VALUES expression, the string is assigned here, where it can be used for insert batching schemes to rewrite the VALUES expression. .. versionadded:: 1.3.8 .. versionchanged:: 2.0 This collection is no longer used by SQLAlchemy's built-in dialects, in favor of the currently internal ``_insertmanyvalues`` collection that is used only by :class:`.SQLCompiler`. N)rrrrrrinsert_single_values_exprs z%SQLCompiler.insert_single_values_exprcCs:|jr |jS|jdk r2t|jr2dd|jjDSdSdS)aThe effective "returning" columns for INSERT, UPDATE or DELETE. This is either the so-called "implicit returning" columns which are calculated by the compiler on the fly, or those present based on what's present in ``self.statement._returning`` (expanded into individual columns using the ``._all_selected_columns`` attribute) i.e. those set explicitly using the :meth:`.UpdateBase.returning` method. .. versionadded:: 2.0 NcSsg|]}t|r|qSrr&rcrrr sz3SQLCompiler.effective_returning..)rrr(_all_selected_columnsrrrreffective_returnings zSQLCompiler.effective_returningcCs|jS)zVbackwards compatibility; returns the effective_returning collection. )rrrrr returningszSQLCompiler.returningc CsBz|jddWStk r<}ztd|W5d}~XYnXdS)aReturn the current 'executable' that is being compiled. This is currently the :class:`_sql.Select`, :class:`_sql.Insert`, :class:`_sql.Update`, :class:`_sql.Delete`, :class:`_sql.CompoundSelect` object that is being compiled. Specifically it's assigned to the ``self.stack`` list of elements. When a statement like the above is being compiled, it normally is also assigned to the ``.statement`` attribute of the :class:`_sql.Compiler` object. However, all SQL constructs are ultimately nestable, and this attribute should never be consulted by a ``visit_`` method, as it is not guaranteed to be assigned nor guaranteed to correspond to the current statement being compiled. .. versionadded:: 1.3.21 For compatibility with previous versions, use the following recipe:: statement = getattr(self, "current_executable", False) if statement is False: statement = self.stack[-1]["selectable"] For versions 1.4 and above, ensure only .current_executable is used; the format of "self.stack" may change. r#z$Compiler does not have a stack entryN)rL IndexError)rZierrrcurrent_executableszSQLCompiler.current_executablecCst|jt|jSr)listrrrrrrprefetch%szSQLCompiler.prefetchzDict[Any, Any]cCsiSrrrrrr_global_attributes)szSQLCompiler._global_attributeszMutableMapping[CTE, str]cCs$t}||_i|_i|_d|_|S)zInitialize collections related to CTEs only if a CTE is located, to save on the overhead of these collections otherwise. F)r% OrderedDictrrrr)rrrrr_init_cte_state-s zSQLCompiler._init_cte_statec csp|j|j}}gd|_|_z0|jr8|jd}d|d<nd}|j|jfVW5|r\|d|||_|_XdS)z;special API to support the use case of 'nested result sets'FrrTN)r[rrBrL)rZresult_columnsZordered_columnsentryrrr_nested_resultEs   zSQLCompiler._nested_resultcsjr tjtjkstjr$tjjdkr6dnjjdksFtdgdddfdd t j j _ j rd d j Dtj tkstfd d D_n_jrgt j jj}fdd jjD}jj||d_dS)Nr%srrz re.Match[str]r)mrcs:|d}|r|S|d|dSdS)Nrr6r)r}append)r!Z normal_bind) placeholder positionsrr find_positionjs   z6SQLCompiler._process_positional..find_positioncSsi|]\}}||qSrrrrrrrysz3SQLCompiler._process_positional..csg|]}||qSrgetrr)reverse_escaperrr{sz3SQLCompiler._process_positional..c s4g|],}|d|dtj|d|dfqS)rrr6r)rsub_positional_patternrr)r%rrrrs rr)rrprYr0r2rrirrr*r+rXrrlenrrr_replace)rrrr)r%r#r$r)rrr ]sF        zSQLCompiler._process_positionalc s\js tjtjkstd}ijrZjdk rZtfddj Dj }n j }|D]T}|krvqhj |}|j ks|j krd|<qhj|}|d7}||<qh|_t_jrt}fddDt|kstjfddj_jrXjj}dd jjD}jj||d _dS) Nrc3s|]}|jkr|VqdSr)rr(rrrrs z/SQLCompiler._process_numeric..cs i|]\}}j|||qSr)rr')rrposrrrrs z0SQLCompiler._process_numeric..cs|dSNrr}r! param_posrrz.SQLCompiler._process_numeric..cSs$g|]}|d|dd|dfqS)rrr rrr,rrrrsz0SQLCompiler._process_numeric..r-)rrprYr0r2rr itertoolschainrvaluesrrrrnext_numeric_posrrrr.r_pyformat_patternr*rXrrr/) rnumr bind_namebindphZ len_beforerrr)r5rrr s`         zSQLCompiler._process_numericzVMutableMapping[str, Union[_BindProcessorType[Any], Sequence[_BindProcessorType[Any]]]]csddfddjDDS)NcSsi|]\}}|dk r||qSrrrrvaluerrrrsz0SQLCompiler._bind_processors..c3sN|]F}j||jjs$|jjntfddtt|jjDfVqdS)c3s|]}|jVqdSr)_cached_bind_processorri)rZ elem_typerrrrsz9SQLCompiler._bind_processors...N) rr_is_tuple_typerCrirrr2types)r bindparamrrrrs z/SQLCompiler._bind_processors..)rrrrr_bind_processorss  zSQLCompiler._bind_processorscCst|jdkSr1)r.rLrrrr is_subqueryszSQLCompiler.is_subquerycCs|SrrrrrrrszSQLCompiler.sql_compilerrr)rrrcCs|j||dd}||S)aRReturn a new :class:`.ExpandedState` for a given parameter set. For queries that use "expanding" or other late-rendered parameters, this method will provide for both the finalized SQL string as well as the parameters that would be used for a particular parameter set. .. versionadded:: 2.0.0rc1 Tr)rr )rrrrrrrconstruct_expanded_statesz$SQLCompiler.construct_expanded_staterz Optional[int]r[)rrr _group_number_checkrrcs2|jr2|s2|jdk st|s(t|jjStd|o>t|j}|r|j dkrZt dn |j d}|j } | dk svt| \} fddt ||D} nd} |ri} |j D]\} }|r|j||n|}| j|kr|| j| |<q||kr||| |<q|rD| jrD|r.tjd| j|fdd ntjd | jdd q| rX| | | }n| }| jrp|j| |<q|j| |<q| Si} |j D]\} }|r|j||n|}|r| jr|rtjd| j|fdd ntjd | jdd | r| | | }n| }| jr|j| |<n |j| |<q| SdS) z5return a dictionary of bind parameter keys and valuesNzcan't construct new parameters when render_postcompile is used; the statement is hard-linked to the original parameters. Use construct_expanded_state to generate a new statement and parameters.zcThis compiled object has no original cache key; can't pass extracted_parameters to construct_paramsrcs$i|]\}}|D] }||qqSrr)rrZ extractedr?r rrrGs  z0SQLCompiler.construct_params..z@A value is required for bind parameter %r, in parameter group %dZcd3x)codez)A value is required for bind parameter %r)rrrpdictrr7rrrrd CompileErrorrziprrr'rrequiredcallableeffective_valuerB)rrrrrJrKrZhas_escaped_namesZorig_extracted ckbm_tuplerZresolved_extractedpdrFr escaped_nameZ value_paramrrLrrs           zSQLCompiler.construct_paramscs|jjjjfddi}|j}|jD]F}||krHq:|jjrrfddtt |jj D||<q:|j||<q:|S)NcsD|}|dk r<dks(|kr<dks8|kr<|SdSdSr)_unwrapped_dialect_implZget_dbapi_type)typZdbtype)dbapiri exclude_types include_typesrr lookup_typesz.lookup_typecsg|] }|qSrr)rrX)r\rrrsz;SQLCompiler._get_set_input_sizes_lookup..) riZinclude_set_input_sizesZexclude_set_input_sizesrYrrrrDrr2rE)rZ inputsizesrrFr)rYrirZr[r\r_get_set_input_sizes_lookups     z'SQLCompiler._get_set_input_sizes_lookupcCs |jddS)zReturn the bind param dictionary embedded into this compiled object, for those values that are present. .. seealso:: :ref:`faq_sql_expression_string` - includes a usage example for debugging use cases. F)rKrrrrrrs zSQLCompiler.params)rrrcsi}j}|dkrj}jr8g}j}|dkr@j}nd}}j}td|td|i}ii} d} jr|dk r|} jrg} n j } j } | D]l| r| n} j }|j kr| krj||| d| <q|jkr| kr| | }d}n0|}| ||}|\}}|| | <|| <|js |||jjr|dk sjt|fddt|dDn|fdd|D| dk r| d d|Dn|dk r|d d|Dd d |D|<q|dk r|qfd d}tj||}| dk rz|dk s@tfddt| jDjfdd|}|| t|||||}|r|_|_|j _jrt!|jpdnd_|_"|S)ahandle special post compile parameters. These include: * "expanding" parameters -typically IN tuples that are rendered on a per-parameter basis for an otherwise fixed SQL statement string. * literal_binds compiled with the literal_execute flag. Used for things like SQL Server "TOP N" where the driver does not accommodate N as a bound parameter. Nrz/Mapping[str, Sequence[_BindProcessorType[Any]]]render_literal_valuec3s`|]X\}}t|dD]D\}}kr|ddk rd||f|dfVqqdS)rN%s_%s_%s enumerate)ri tuple_elementjr)rtuple_processorsrrr=s  zBSQLCompiler._process_parameters_for_postcompile..rc3s&|]\}}kr|fVqdSrr)rrr)rsingle_processorsrrrHscss|]\}}|VqdSrrrrrrrrrNscss|]\}}|VqdSrrrhrrrrUscSsg|] \}}|qSrr)rZ expand_keyrrrrrVszCSQLCompiler._process_parameters_for_postcompile..csb|d}|}|dr^|dd}|d|ddfdd|dD}|S)Nrr6~~rrc3s|]}d|fVqdSz%s%s%sNr)rexpbe_leftbe_rightrrresz]SQLCompiler._process_parameters_for_postcompile..process_expanding..)r}splitr)r!rexprtok)replacement_expressionsrlrprocess_expanding\s  zJSQLCompiler._process_parameters_for_postcompile..process_expandingcs i|]\}}|j|qSrr)rr=rrrrrqszCSQLCompiler._process_parameters_for_postcompile..cs|dSr1r2r3r4rrr6yr7zASQLCompiler._process_parameters_for_postcompile..r)#rrXrrrrGrrrr:rr'rrrender_literal_bindparamrBr$_literal_execute_expanding_parameterliteral_executerrrDrprbextendr"rr*_post_compile_patternr;r<rrrr)rrrZexpanded_parametersZpre_expanded_stringZnew_positiontupZpre_expanded_positiontuprZnew_processorsZto_update_setsZnumeric_positiontupnamesZebnrV parameter to_updater:Zleep_resreplacement_exprrsrZexpanded_stater)rr5rrrrgrfrr s                      z/SQLCompiler._process_parameters_for_postcompilezsqlalchemy.engine.cursorcCstjj}|j|jS)z(utility method used for unit tests only.)r% preloadedZ engine_cursorrTZ_create_description_match_mapr[)rcursorrrr_create_result_mapszSQLCompiler._create_result_map_BindNameForColProtocol_get_bind_name_for_colzCallable[[Any], str]cCs |j}|Sr)r)rgetterrrr_within_exec_param_key_gettersz)SQLCompiler._within_exec_param_key_getterzsqlalchemy.engine.resultcstjj}|j|jdk st|jj}tr6t|t s6t|j }fdd|j Dd|j dk rj |jd|jkrfdd}|nd|dd|j Dfdd}|S)Ncs"g|]}td|d|fqS)r'N)operator methodcallerrr)param_key_getterrrrszKSQLCompiler._inserted_primary_key_from_lastrowid_getter..cs ||}|dk r|S|SdSrr&) lastrowidrZ param_value) autoinc_keyrr_autoinc_getters zPSQLCompiler._inserted_primary_key_from_lastrowid_getter.._autoinc_gettercSsg|] }|jqSrrrrrrrscsNdk rdkr.fddDSfddDSdS)agiven cursor.lastrowid value and the parameters used for INSERT, return a "row" that represents the primary key, either by using the "lastrowid" or by extracting values from the parameters that were sent along with the INSERT. Nc3s|]\}}|VqdSrrrrrrrrrszWSQLCompiler._inserted_primary_key_from_lastrowid_getter..get..c3s8|]0\}}|kr(dk r$q.n|VqdSrrr) autoinc_colautoinc_getterrrrrrs  rrr)rrgetterslastrowid_processorrow_fnrrr's zDSQLCompiler._inserted_primary_key_from_lastrowid_getter..get)r%r~ engine_resultrrrprrrorAr primary_keyZ_autoincrement_columnrZ_cached_result_processorrir result_tuple)rresultrrrr'r)rrrrrrrr+_inserted_primary_key_from_lastrowid_getters2   z7SQLCompiler._inserted_primary_key_from_lastrowid_gettercstjrddlm}ntjj}|jdk s*t|jj }trDt |t sDt|j |j }|j}|dk sbtddt|Dtdfdd|jD|dd|jDfd d }|S) Nr6)rcSsi|]\}}||qSrr)ridxrrrrr szKSQLCompiler._inserted_primary_key_from_returning_getter..z'List[Tuple[Callable[[Any], Any], bool]]cs<g|]4}|kr"t|dfntd|ddfqS)Tr'NF)r itemgetterrr)rretrrr s zKSQLCompiler._inserted_primary_key_from_returning_getter..cSsg|] }|jqSrrrrrrr scsfddDS)Nc3s&|]\}}|r|n|VqdSrr)rrZuse_rowrrowrrr" szWSQLCompiler._inserted_primary_key_from_returning_getter..get..r)rr)rrrrr'! szDSQLCompiler._inserted_primary_key_from_returning_getter..get)typingrZenginerr%r~rrrprrorArrrrbrrr)rrrrrr'r)rrrrr+_inserted_primary_key_from_returning_getters*  z7SQLCompiler._inserted_primary_key_from_returning_gettercCsdS)zCalled when a SELECT statement has no froms, and no FROM clause is to be appended. Gives Oracle a chance to tack on a ``FROM DUAL`` to the string output. rWrrrrr default_from) szSQLCompiler.default_fromc Ks|jj|f|}|jD]}||jkr&q|j|}|j|j|jddd}|j|}||j|<|j|<||j|<|j|d||jkr|j|hO_||j kr|j |hO_ |j }|r|\} } |j D]&}|j| kr| |j} | |  |qq|S)aSQL compile the nested element of an _OverrideBinds with bindparams swapped out. The _OverrideBinds is not normally expected to be compiled; it is meant to be used when an already cached statement is to be used, the compilation was already performed, and only the bound params should be swapped in at execution time. However, there are test cases that exericise this object, and additionally the ORM subquery loader is known to feed in expressions which include this construct into new queries (discovered in #11173), so it has to do the right thing at compile time as well. TF)Z maintain_keyrQN) rr translaterZ _with_valuerrrBrrr _cloned_setr") rZoverride_bindsrsqltextrbpZnew_bprrTr r cbrrrvisit_override_binds2 s4           z SQLCompiler.visit_override_bindscKsd|jj|f|dSNrrrr)rgroupingasfromrrrrvisit_groupingr szSQLCompiler.visit_groupingcKsd|jj|f|dSrr)rrrrrrvisit_select_statement_groupingu sz+SQLCompiler.visit_select_statement_groupingc Ks|jr|jjrztd|jdd}Wn.tk rT}ztd|W5d}~XYnX|j\}}}|rl|} n|} |jj } | dk r| j | kr| | | j r|jj |d<|j |jfd|i|S)N'Union[SelectState, CompoundSelectState]rrECan't resolve label reference for ORDER BY / GROUP BY / DISTINCT etc.render_label_as_labelwithin_columns_clause) rLriZsupports_simple_order_by_labelrKeyErrorr7rO_label_resolve_dictrZ_order_by_label_elementrZshares_lineagerq) rrrrrke with_cols only_froms only_colsZ resolve_dictZ order_by_elemrrrvisit_label_referencex sL  z!SQLCompiler.visit_label_referencec Ks|js||jSztd|jdd}Wn8tk rb}ztj|jdtj |dW5d}~XYnX|j \}}}z|r||j} n ||j} Wn8tk r} ztj|jdtj | dW5d} ~ XYn X| |d<|j| fd|i|SdS)Nrrrr)extraZexc_clsrrr) rLrqZ _text_clauserrrZ_no_text_coercionrr7rOr) rrrrrrrrrrrrrrvisit_textual_label_reference sD     z)SQLCompiler.visit_textual_label_referencec Ks|o| }||k} | s|r>t|jtjr8|d|j} n|j} |r|dk rj|| |j|| f|j||j|jj|fddd|t t j |j || S| r|j || S|jj|fddi|SdS)NcolidentT)rwithin_label_clauserF)rorrrD_truncated_identifierrrrr OPERATORSr as_r` format_label) rradd_to_result_maprrrresult_map_targetsrZrender_label_with_asZrender_label_onlyZ labelnamerrr visit_label sJ  zSQLCompiler.visit_labelcCstddS)Nz:Cannot compile Column object until its 'name' is assigned.r7rOrrirrr_fallback_column_name sz!SQLCompiler._fallback_column_namecKs|j}|j|f|Sr)Z _resolvedrq)rrrZ sql_elementrrrvisit_lambda_element sz SQLCompiler.visit_lambda_elementColumnClause[Any]zOptional[_ResultMapAppender]rz Optional[_AmbiguousTableNameMap])rir include_tablerambiguous_table_name_maprrcKsB|j}}|dkr||}|j} | s>t|tjr>|d|}|dk rx|||jf|} |jrh| |jf7} |||| |j | r| |}n |j |}|j } | dks|r| js|S|j | } | r|j | d} nd} trt| tst| j}| s |r ||kr ||}t|tjr&|d|}| |j |d|SdS)NrrrWalias)rr is_literalrorrDrr _tq_labelrescape_literal_columnr`quoterZnamed_with_columnschema_for_object quote_schemarrOrp)rrirrrrrr orig_namertargetsreffective_schemaZ schema_prefixZ tablenamerrr visit_column sF        zSQLCompiler.visit_columncKs|j|jSr)r`format_collation collationrrrrrrvisit_collationI szSQLCompiler.visit_collationcKs|jSrr)rZ fromclauserrrrvisit_fromclauseL szSQLCompiler.visit_fromclausecKs|jSrr)rr>rrrr visit_indexO szSQLCompiler.visit_indexcKs&||d<|j|d<|jjj|jf|S)Ntype_expressionrl)r`ritype_compiler_instancerqr)r typeclauserrrrvisit_typeclauseR s zSQLCompiler.visit_typeclausecCs|jjr|dd}|SNr%%r`_double_percentsreplacertextrrrpost_process_textY s zSQLCompiler.post_process_textcCs|jjr|dd}|Srrrrrrr^ s z!SQLCompiler.escape_literal_columnc sRfdd}jsd_|r2|ddftjtddt|jS)Ncs:|d}|jkr(jj|fSj|fSdSr1)r}Z _bindparamsrqbindparam_string)r!rrr textclauserr do_bindparamd s  z2SQLCompiler.visit_textclause..do_bindparamTcSs |dSr1r2r3rrrr6v r7z.SQLCompiler.visit_textclause..) rLrr$NULLTYPEBIND_PARAMS_ESCr* BIND_PARAMSrr)rrrrrrrrvisit_textclausec s zSQLCompiler.visit_textclausec Ks|j }|r|jn|jd}tt|d}|j||jrJ||||pl|dkrb|ddpl|dd}|r|j|_|_ |j ot |j |_ |j D]} |j | d|jdq|j |jf|} |jr|st|jnd} |j| d | } |jd| S) Nrrrr#rrFrT)rr nesting_level)rL_default_stack_entryrr"_independent_ctes_dispatch_independent_ctesr'rrrrZ column_argsrrq_add_to_result_maprrr._render_cte_clauserB) rZtafcompound_indexrrtoplevelr new_entrypopulate_result_maprrrrrrvisit_textual_select| sB         z SQLCompiler.visit_textual_selectcKsdSNNULLrrrprrrr visit_null szSQLCompiler.visit_nullcKs|jjr dSdSdS)Nr1risupports_native_booleanrrrr visit_true szSQLCompiler.visit_truecKs|jjr dSdSdS)Nrx0rrrrr visit_false szSQLCompiler.visit_falsec s$|ddfdd|DDS)Ncss|]}|r|VqdSrrrsrrrr sz7SQLCompiler._generate_delimited_list..c3s|]}|jfVqdSrrrrrrrr sr)rr separatorrrrr_generate_delimited_list s z$SQLCompiler._generate_delimited_listc sltjtjtjjtjj|\}}|dkr:|djfSt tj}| ddfdd|DDSdS)Nrrcss|]}|r|VqdSrrrrrrr sz;SQLCompiler._generate_delimited_and_list..c3s|]}|jfVqdSrrrrrrr s) rZBooleanClauseListZ_process_clauses_for_booleanr and_ZTrue_Z _singletonZFalse_rrr)rclausesrZlccr rrr_generate_delimited_and_list s  z(SQLCompiler._generate_delimited_and_listcKsd|j|f|SN(%s))visit_clauselist)r clauselistrrrr visit_tuple szSQLCompiler.visit_tuplecKs0|j}|dkrd}n t|j}|j|j|f|SNr)rrr r )rrrseprrrr s  zSQLCompiler.visit_clauselistc Ks|j}||dd}|r&|||f|Sz t|}Wn0tk rb}zt|||W5d}~XYnXd|d<|j|j|f|SdS)NZexpression_clauselistT_in_operator_expression)r_get_operator_dispatchrrr7rr r )rrr operator_dispopstringrrrrvisit_expression_clauselist s&  z'SQLCompiler.visit_expression_clauselistcKsd}|jdk r&||jj|f|d7}|jD]4\}}|d|j|f|d|j|f|d7}q,|jdk r|d|jj|f|d7}|d7}|S)NzCASE rzWHEN z THEN zELSE END)rBrZwhensZelse_)rclauserrZcondrrrr visit_case s*    zSQLCompiler.visit_casecKs|jj|f|Sr)Ztyped_expressionr)rZ type_coercerrrrvisit_type_coerce szSQLCompiler.visit_type_coercecKsR|jj|f|}td|}d|jj|f||r:|dn||rJ|dndfS)Nz(.*)( COLLATE .*)zCAST(%s AS %s)%srr6rW)rrrmatchrr})rrrZ type_clauser rrr visit_cast s zSQLCompiler.visit_castc Ksd|dtjkrdn\|dtjkr&dnJ|ddkrTd|jtt|df|fnd|jt|df|f|dtjkrdn\|dtjkrdnJ|ddkrd|jtt|df|fnd|jt|df|ffS) Nz %s AND %srzUNBOUNDED PRECEDINGz CURRENT ROWz %s PRECEDINGz %s FOLLOWINGrzUNBOUNDED FOLLOWING)rZRANGE_UNBOUNDEDZ RANGE_CURRENTrqliteralabs)rrange_rrrr_format_frame_clause sD      z SQLCompiler._format_frame_clausec s|jjf}|jr,dj|jf}n |jrHdj|jf}nd}d|dfddd|jfd|jffD|r|gngfS) NzRANGE BETWEEN %szROWS BETWEEN %sz %s OVER (%s)rcs6g|].\}}|dk rt|rd||jffqS)Nz%s BY %s)r.r)rwordrrrrrrO s z*SQLCompiler.visit_over..Z PARTITIONZORDER)rrr$r%rowsrZ partition_byorder_by)rZoverrrr$rr'r visit_over? s4  zSQLCompiler.visit_overcKs$d|jj|f||jj|f|fS)Nz%s WITHIN GROUP (ORDER BY %s))rrr))rZ withingrouprrrrvisit_withingroup\ szSQLCompiler.visit_withingroupcKs$d|jj|f||jj|f|fS)Nz%s FILTER (WHERE %s))funcr criterion)rZ funcfilterrrrrvisit_funcfilterb szSQLCompiler.visit_funcfiltercKs*|j|j|j}d||jj|f|fS)NzEXTRACT(%s FROM %s)) extract_mapr'fieldrpr)rextractrr0rrr visit_extracth s zSQLCompiler.visit_extractcKs*|j|jf|}|j|f|}d||fS)Nz(%s).%s)visit_functionfnr)rrrZ compiled_fnZ compiled_colrrrvisit_scalar_function_columno sz(SQLCompiler.visit_scalar_function_columnz Function[Any])r,rrrc s|dk r ||j|j|jf|jtd|jd}|rH||f|}nt|jdrn|jrd7n6|jj st t j rj nddfdd|jDgdj|f|i}|jr|d7}|S)Nz visit_%s_funcz%(expr)srcs4g|],}j|s ttjr,j|n|qSr)r`_requires_quotes_illegal_charsrorr0r)rrqrrrrr s   z.SQLCompiler.visit_function..rpz WITH ORDINALITY)rrgetattrlowerrr'Z _deannotater{Z _has_argsr`r6rorr0rrZ packagenamesfunction_argspecZ_with_ordinality)rr,rrrrrr7rr3t s:       zSQLCompiler.visit_functioncKs ||jSr)visit_sequencesequence)rZ next_valuerrrrvisit_next_value_func sz!SQLCompiler.visit_next_value_funccKstd|jjdS)Nz2Dialect '%s' does not support sequence increments.rrirrr<rrrrr; s zSQLCompiler.visit_sequencecKs|jj|f|Sr)Z clause_exprr)rr,rrrrr: szSQLCompiler.function_argspecc  sbj }|j|f}|r(js(|_|j}|r8jnjd}|pV| oV|dd} |dkrh||d<j|d|d||| d|jr|j |j } d | d  fd d t |j D} dd <| j|ftfd i7} | j|f7} |jr$| j|f7} jrR|s.rrTrinclude_following_stack)rL_compile_state_factoryrrrr'r"rrcompound_keywordskeywordrrbZselectsgroup_by_clauserNorder_by_clause_has_row_limiting_clause_row_limit_clauserr.rrB) rcsrrrrrZ compound_stmtrZneed_result_maprErrrr@rvisit_compound_select sX         z!SQLCompiler.visit_compound_selectcKs*|jdk r|j|f|S|j|f|SdSr) _fetch_clause fetch_clause limit_clause)rrJrrrrrI s zSQLCompiler._row_limit_clausecCs(d|j||rd|ndf}t||dS)Nz visit_%s_%s%srrW)rr8)rrZ qualifier1Z qualifier2attrnamerrrr s z"SQLCompiler._get_operator_dispatchcKs|dk r"||f7}||d<||d<|jrt|jr8td||jdd}|r\|||jf|S|j|t|jf|SnL|jr||jdd}|r|||jf|S|j|t|jf|Sn tddS)NrrzFUnary expression does not support operator and modifier simultaneouslyunaryrmodifierz,Unary expression has no operator or modifier)rrQr7rOr _generate_generic_unary_operatorr _generate_generic_unary_modifier)rrPrrrrrrr visit_unary sN zSQLCompiler.visit_unarycKsx|jjrP|j|jf|d|jt|j|jjjt j kr>|jjnt f|S|j|jf|d|j|jf|SdS)N / ) ridiv_is_floordivrqrrZCastrr_type_affinityr$ZNumericrrerrrrrvisit_truediv_binary# s0  z SQLCompiler.visit_truediv_binarycKsh|jjr<|jjjtjkr<|j|jf|d|j|jf|Sd|j|jf|d|j|jf|SdS)NrUz FLOOR(%s)) rirVrrrWr$IntegerrqrrXrrrvisit_floordiv_binary> s"z!SQLCompiler.visit_floordiv_binarycKs6|js|jjr|j|jf|Sd|j|jf|SdS)Nz%s = 1Z_is_implicitly_booleanrirrqrrrrrrrrvisit_is_true_unary_operatorO s z(SQLCompiler.visit_is_true_unary_operatorcKs:|js|jjr"d|j|jf|Sd|j|jf|SdS)NNOT %sz%s = 0r\r]rrrvisit_is_false_unary_operatorX s z)SQLCompiler.visit_is_false_unary_operatorcKsd|j|tjdS)Nr_)override_operator) visit_binaryr match_oprXrrrvisit_not_match_op_binarya sz%SQLCompiler.visit_not_match_op_binarycKsd|j|t|f|Sr)_generate_generic_binaryrrXrrrvisit_not_in_op_binaryf s z"SQLCompiler.visit_not_in_op_binarycKsv|tjkr4t|dkr.dddd|DSdSn>|tjkrht|dkrbdddd|DSd Sn ||SdS) Nrz(%s)) OR (1 = 1rcss|] }dVqdSrNrrrrrrrr sz6SQLCompiler.visit_empty_set_op_expr..zNULL) OR (1 = 1z(%s)) AND (1 != 1css|] }dVqdSrgrrhrrrry szNULL) AND (1 != 1)r not_in_opr.rin_opvisit_empty_set_expr)rr expand_oprrrrvisit_empty_set_op_exprn s    z#SQLCompiler.visit_empty_set_op_exprcKstd|jjdS)Nz3Dialect '%s' does not support empty set expression.r>rZ element_typesrrrrrk s z SQLCompiler.visit_empty_set_exprc sLjj}|sP|jr<jjr$dndjjj}njgj}n|js~|jrt |dt j rt |dt t fs|jrtdjjrdnddfddt|D}n|r*j}||}|r|dstd |dd }|d |d dfd d|D}ndfdd|D}d|fS)NVALUES rWrz?bind_expression() on TupleType not supported with literal_bindsrc3s8|]0\}}ddfddt|jjDVqdS)rrc3s|]\}}||VqdSrr^)rrBZ param_typerrrr sz[SQLCompiler._literal_execute_expanding_parameter_literal_binds...N)rrPrrE)rrcrdr{rrrr s zQSQLCompiler._literal_execute_expanding_parameter_literal_binds..r6)unexpected format for expanding parameterrirrc3s&|]}d|jfVqdSrjr_rrrBrmrnr{rrrr s c3s|]}|jVqdSrrrrsrprrr sr)rrWrirDtuple_in_valuesrmrErl_isnullrocollections_abcrrbytes_has_bind_expressionrrrbrysearchr}rpro) rr{r:bind_expression_templatetyp_dialect_implreplacement_expressionZpost_compile_patternr!rqrrtr2_literal_execute_expanding_parameter_literal_binds s\   z>SQLCompiler._literal_execute_expanding_parameter_literal_bindscsXjr|Sj}j|jr2jnjjjrZj rZfddn fdd|sgj r jj j }n jgj }nj sЈjr t|dtjr t|dttfs jrtfddt|dD|jrdnd d fd d t|D}n0fd dt|dDd fdd D}|fS)Ncsjd|iSNr)render_bind_castrr) bind_templater{rr|rr_render_bindtemplate s  zNSQLCompiler._literal_execute_expanding_parameter.._render_bindtemplatecs d|iSrrr)rrrr srcs6g|].\}}t|dD]\}}d||f|fqqS)rr`ra)rrcrdrerBrrrr s zDSQLCompiler._literal_execute_expanding_parameter..rrorWrc3s8|]0\ddfddtDVqdS)rrc3s.|]&\}}t|dVqdS)rN)r.)rrerB)rrcr|rdrrr szMSQLCompiler._literal_execute_expanding_parameter...N)rrb)r)rr|)rcrdrr s  zCSQLCompiler._literal_execute_expanding_parameter..cs g|]\}}d|f|fqS)z%s_%sr)rrcrBrrrr sc3s|]\}}|VqdSrrrA)rrrr s)rwr~rirrWrrr_bind_typing_render_castsrrDrmrErlrvrorwrrrxZ _is_arrayrprbrur)rrr{r:rir}r)rrrr{rr|r|rrv sd       z0SQLCompiler._literal_execute_expanding_parameterc Ks(|rvt|jrv|dk rR|d}|jtt|jj |gt|j j |gn$|jtt|jj t|j j |j rt |jt jrt |j t jrd|d<|p|j}||dd} | r| ||f|Sz t|} Wn2tk r} zt||| W5d} ~ XYnX|j|| f||d|SdS)Nenclosing_lateralTrwre) from_linterlateral_from_linter)r Z is_comparisonrr@rr8productr)rr*rrrorrErrrr7rre) rreraeager_groupingrrrrrrrrrrrrb sV            zSQLCompiler.visit_binarycKs|j|jf|Sr)rqZ sql_functionr]rrr&visit_function_as_comparison_op_binaryW sz2SQLCompiler.visit_function_as_comparison_op_binarycKsT|jjr,|j|jf|d|j|jf|S|j|jf|d|j|jf|SdS)Nz %% r)r`rrqrrrXrrrvisit_mod_binaryZ szSQLCompiler.visit_mod_binarycKs*|j|d<|j|d||jdf|S)Nrr)rrerrr]rrrvisit_custom_op_binaryh s z"SQLCompiler.visit_custom_op_binarycKs|j|||jdf|Sr)rRrrr]rrrvisit_custom_op_unary_operatorp s z*SQLCompiler.visit_custom_op_unary_operatorcKs|j|d||jf|Sr)rSrrr]rrrvisit_custom_op_unary_modifieru s z*SQLCompiler.visit_custom_op_unary_modifiercKsf|dd}d|d<|j|d<|jj|fd|i|||jj|fd|i|}|rb|rbd|}|S)NrFT _binary_oprr)r'rrrr)rrerrrrrrrrrez s0   z$SQLCompiler._generate_generic_binarycKs||jj|f|SrrrrPrrrrrrR sz,SQLCompiler._generate_generic_unary_operatorcKs|jj|f||SrrrrrrrS sz,SQLCompiler._generate_generic_unary_modifiercCstjdtjdS)Nz'%')r)rZliteral_columnr$ STRINGTYPErrrr_like_percent_literal sz!SQLCompiler._like_percent_literalcKsd|jj|f|dS)Nzlower(rrrrrr$visit_ilike_case_insensitive_operand sz0SQLCompiler.visit_ilike_case_insensitive_operandcKs2|}|j}||j||_|j||f|Sr_clonerconcatrvisit_like_op_binaryrrerrpercentrrrvisit_contains_op_binary sz$SQLCompiler.visit_contains_op_binarycKs2|}|j}||j||_|j||f|Srrrrrvisit_not_like_op_binaryrrrrvisit_not_contains_op_binary sz(SQLCompiler.visit_not_contains_op_binarycKsB|}|j}t|j|_|t|j||_|j||f|Srrrrrrrvisit_ilike_op_binaryrrrrvisit_icontains_op_binary s z%SQLCompiler.visit_icontains_op_binarycKsB|}|j}t|j|_|t|j||_|j||f|Srrrrrrrvisit_not_ilike_op_binaryrrrrvisit_not_icontains_op_binary s z)SQLCompiler.visit_not_icontains_op_binarycKs,|}|j}||j|_|j||f|Sr)rr_rconcatrrrrrrvisit_startswith_op_binary sz&SQLCompiler.visit_startswith_op_binarycKs,|}|j}||j|_|j||f|Sr)rrrrrrrrrvisit_not_startswith_op_binary sz*SQLCompiler.visit_not_startswith_op_binarycKs<|}|j}t|j|_|t|j|_|j||f|Sr)rrrrrrrrrrrvisit_istartswith_op_binary s  z'SQLCompiler.visit_istartswith_op_binarycKs<|}|j}t|j|_|t|j|_|j||f|Sr)rrrrrrrrrrrvisit_not_istartswith_op_binary s  z+SQLCompiler.visit_not_istartswith_op_binarycKs,|}|j}||j|_|j||f|Srrrrrrvisit_endswith_op_binary sz$SQLCompiler.visit_endswith_op_binarycKs,|}|j}||j|_|j||f|Srrrrrrvisit_not_endswith_op_binary sz(SQLCompiler.visit_not_endswith_op_binarycKs<|}|j}t|j|_|t|j|_|j||f|Srrrrrrvisit_iendswith_op_binary s  z%SQLCompiler.visit_iendswith_op_binarycKs<|}|j}t|j|_|t|j|_|j||f|Srrrrrrvisit_not_iendswith_op_binary s  z)SQLCompiler.visit_not_iendswith_op_binarycKsP|jdd}d|jj|f||jj|f|f|dk rJd||tjndS)Nrz %s LIKE %s ESCAPE rW modifiersr'rrrr_r$rrrerrrrrrr sz SQLCompiler.visit_like_op_binarycKsP|jdd}d|jj|f||jj|f|f|dk rJd||tjndS)Nrz%s NOT LIKE %srrWrrrrrr sz$SQLCompiler.visit_not_like_op_binarycKs:|tjkr*|}t|j|_t|j|_|j||f|Sr)r Zilike_oprrrrrrXrrrrs    z!SQLCompiler.visit_ilike_op_binarycKs:|tjkr*|}t|j|_t|j|_|j||f|Sr)r Z not_ilike_oprrrrrrXrrrrs    z%SQLCompiler.visit_not_ilike_op_binarycKs&|jdd}|j||rdndf|S)NrFz BETWEEN SYMMETRIC z BETWEEN rr'rerrerrrrrrvisit_between_op_binarys z#SQLCompiler.visit_between_op_binarycKs&|jdd}|j||rdndf|S)NrFz NOT BETWEEN SYMMETRIC z NOT BETWEEN rrrrrvisit_not_between_op_binarys z'SQLCompiler.visit_not_between_op_binarycKstd|jjdSNz/%s dialect does not support regular expressionsr7rOrirrXrrrvisit_regexp_match_op_binary%s z(SQLCompiler.visit_regexp_match_op_binarycKstd|jjdSrrrXrrr visit_not_regexp_match_op_binary+s z,SQLCompiler.visit_not_regexp_match_op_binarycKstd|jjdS)Nz;%s dialect does not support regular expression replacementsrrXrrrvisit_regexp_replace_op_binary1s z*SQLCompiler.visit_regexp_replace_op_binarycKs|s|j|j}|jr||} |j| fd||o8|j ||d|} |jrtd| } | sft dd| d| d| df} |r|j |fd| d |} d | S| S|s|p|j p|o|j }|p|j} nd } |r|j |fd di|} |jrd | } | S||}||jkr|j|}||k r|js@|jrp|j|jsp|j|jsptd |nh|j|jkrtd|fnH|js|jr|jr|jrtdntd|jd|jd||j|j<|j|<|j}|r4|\}}|jD]*}|j|kr||j}|||q|jrBd|_| r||rTd|_|rl|j|hO_n|j|hO_|j|f| |j|jd|} |jrd | } | S)NT)skip_bind_expressionr literal_bindsrwrender_postcompilez&^(.*)\(__\[POSTCOMPILE_(\S+?)\]\)(.*)$rqz$(__[POSTCOMPILE_%s~~%s~~REPL~~%s~~])r6rr)rr{rFrzIBind parameter '%s' conflicts with unique bind parameter of the same nameaCan't reuse bound parameter name '%s' in both 'expanding' (e.g. within an IN expression) and non-expanding contexts. If this parameter is to receive a list/array value, set 'expanding=True' on it for expressions that aren't IN, otherwise use a different parameter name.a)Encountered unsupported case when compiling an INSERT or UPDATE statement. If this is a multi-table UPDATE statement, please provide string-named arguments to the values() method with distinct names; support for multi-table UPDATE statements that target multiple tables for UPDATE is very limitedzbindparam() name 'z' is reserved for automatic usage in the VALUES or SET clause of this insert/update statement. Please use a name other than column name when using bindparam() with insert() or update() (for example, 'b_z').) post_compile expandingbindparam_type) r dialect_implrirybind_expressionrqrrr rpr}rurwr_truncate_bindparamrrr intersectionrr7rOZ_is_crudrrr"Z isoutparamhas_out_parametersrrrr)rrFrrrrwrrimplrwrappedr!rrrexistingrTr r rrrrrvisit_bindparam7s                 zSQLCompiler.visit_bindparamcCs tdSrr)rrZ dbapi_typerrrrrszSQLCompiler.render_bind_castc Ks|tk r|}nZ|jdkrb|jdkrb|dd}|rR|tjtjfkrRtd|j f|j t j f|S|j }|jr|j}||||d\}} | S|||jSdS)NrzBound parameter '%s' rendering literal NULL in a SQL expression; comparisons to NULL should not use operators outside of 'is' or 'is not')r{)r.rBrRr'r is_is_notr%Z warn_limitedrrqr$rrSrr~r_r) rrFr_r{rrBopZleepr|r}rrrrus(  z$SQLCompiler.render_literal_bindparamc Cs|dkr|js|tjS||j}|r~z ||WStk rz}z$t dt |d|d|W5d}~XYqXnt dt |d|dS)aRender the value of a bind parameter as a quoted literal. This is used for statement sections that do not accept bind parameters on the target driver/database. This should be implemented by subclasses using the quoting services of the DBAPI. Nz Could not render literal value "z" with datatype z); see parent stack trace for more detail.z:No literal value renderer is available for literal value ") Zshould_evaluate_nonerqrZNullZ _instanceZ_cached_literal_processorrirr7rOsql_utilZ_repr_single_value)rrBr processorerrrr_s    z SQLCompiler.render_literal_valuecCs@||jkr|j|S|j}t|tjr2|d|}||j|<|S)NrF)rrrorrDr)rrFr>rrrr%s     zSQLCompiler._truncate_bindparamrD) ident_classrrcCs||f|jkr|j||fS||j}t||jdkr|j|d}|dt|jdddt|dd}|d|j|<n|}||j||f<|S)Nrrrr6) r apply_maprr.rrr'maxhex)rrrZanonnamecounterZ truncnamerrrr2s z!SQLCompiler._truncated_identifier)rrcCs ||jSrrrrrrr _anonymizeGszSQLCompiler._anonymizezOptional[TypeEngine[Any]]zOptional[Set[str]]) rrr escaped_fromraccumulate_bind_namesvisited_bindparamrrc  s |dk r|||dk r$|||sRj|rRjfdd|} |}| }|rhj||i_|rd|} |r|| S|dk r|j} | j r || | } | Sj t j krĈjd|i} njd|i} |dk rjjr|j} | j r || | } | S)Ncsj|dS)Nr)rr}r3rrrr6dr7z.SQLCompiler.bindparam_string..z__[POSTCOMPILE_%s]r)addr"rrzr*rrrWriZrender_literal_castrrYr0r1rrr) rrrrrrrrrnew_namerZ type_implrrrrJsL      zSQLCompiler.bindparam_stringcCsF|}|ddt|j|jD]\}}|j|fd|i|q"dS)Ncte_opts)copyrBrPrZ_independent_ctes_optsr)rstmtrZlocal_kwcteoptrrrrs  z&SQLCompiler._dispatch_independent_ctesrMzOptional[_FromHintsType]z Optional[CTE]zOptional[FromLinter]zselectable._CTEOpts) rrashint fromhints visiting_cterrrrc s} | jkst||d<|j} t| tjr<d| } d} d} |} |j pV|j }| j krj | \}}}|| ks~t|| f}j |}|j r|j rt d|| f}|rtjnd}|| f}}j |=|j |<||fj | <n6|rtjnd}|| f}|j kr"j |}nd}|dk r||k} ||jksN||krTd} nx||jkr| |=|}|| ks|t||kstj |=n8|jdk s|jdk r||rd} nt d| |s| sdS|jdk r|j}|jj}t|tjrd|}n|}d}| r\|j |<||fj | <|jkrTj|f||s\|| kr\|jrrd_j|| }|jr|j}dd |dD}|d d fd d |D7}|dddkstjs|jjfd|i|Sj||jf|}|jjfddi|}|d||f7}|j rT|dj||j f|7}|| |<|r|rv| |j!|"<| s| rj|| S|rЈj||}j#| rj$| } |%| 7}|Sj|| SdS)NrrTFz6CTE is stated as 'nest_here' in more than one locationrz5Multiple, unrelated CTEs found with the same name: %rcSs"g|]\}}}}}|s|p|qSrr)rr proxy_namefallback_label_namerrepeatedrrrrsz)SQLCompiler.visit_cte..rrc3s |]}jj|jdVqdS)rN)r`format_label_namer)ridentrrrr,s z(SQLCompiler.visit_cte..subqueryrz AS %s (%s)r)&rrrprrorrDr_get_reference_ctenestingrrr7rOr.rLZ _restatesZ _is_clone_ofcompareZ _cte_alias visit_cte recursiverr` format_aliasr_generate_columns_plus_namesrr'r_generate_prefixes _prefixes _suffixesr?r)_requires_quotesrget_render_as_alias_suffix)rrrrrrrrrZ self_ctescte_nameZ is_new_cteZembedded_in_current_named_cteZ_reference_cter cte_levelrZexisting_cte_optsZcte_level_nameZ existing_cteZold_level_nameZnew_level_nameZexisting_cte_reference_cteZ pre_alias_cteZcte_pre_alias_namerZ col_sourceZ recur_colsprefixesrrrrrs                         zSQLCompiler.visit_ctecKs4|jrd|d<|jr"|j|f|S|j|f|SdS)Nr)Zjoins_implicitly _is_lateral visit_lateral visit_aliasrrrrvisit_table_valued_alias`s z$SQLCompiler.visit_table_valued_aliascKs|j|f|Sr)rrrrrvisit_table_valued_columnhsz%SQLCompiler.visit_table_valued_columnc  s|r:dkrjstd<| r:dkr:dkr:| d<|dk r|jkrjjf|||||d} |r|sz|rd| f} | S}d<|s|rtjtjrdj} nj} |r҈j | S|r| r| | j <jjfd|d} |rd| f} |  j | } jrbjrb| dd fd d jD7} |r|kr| ||} | Sjjfd |iSdS) Nrr)rriscrudrlateralenclosing_aliasrrrT)rrrc3sB|]:}dj|jjr2djjj|jfndfVqdS)z%s%s %srWN)r`rrZ_render_derived_w_typesrirrqrrrrrrrrs  z*SQLCompiler.visit_alias..r)rrprrrorrrDrr`rr?r)rZ_supports_derived_columnsZ_render_derivedrrformat_from_hint_text)rrrrrrrrrrrrZ alias_namerrrrrks        zSQLCompiler.visit_aliascKsd|d<|j|f|S)NTrr)rrrrrrvisit_subqueryszSQLCompiler.visit_subquerycKsd|d<d|j|f|S)NTrz LATERAL %sr)rZlateral_rrrrrszSQLCompiler.visit_lateralcKsRd|j|fddi||j|f|f}|jdk rN|d|jj|f|7}|S)Nz%s TABLESAMPLE %srTz REPEATABLE (%s))rZ _get_methodrseed)rZ tablesamplerrrrrrvisit_tablesamples zSQLCompiler.visit_tablesamplec s6djdfddjD}d|S)Nrrc3s8|]0}|D]&}jtj|djifVq qdS)rEN)rqrrZ _column_typesr)rchunkelemrrrrrrsz-SQLCompiler._render_values..ro) setdefaultrr_data)rrrZtuplesrr r_render_valuess  zSQLCompiler._render_valuesc sj|f}|jrd}n$t|jtjr8d|j}n|j}|jrJd}nd}|r|rp|dk rb|nd|j| <|rdd<d|| j |d fd d |jDf}n d ||f}|S) Nr:zLATERAL rWz(unnamed VALUES element)Frz %s(%s)%s (%s)rc3s|]}|jfVqdSrrrrrrrsz+SQLCompiler.visit_values..z%s(%s))r Z_unnamedrorrrDrrr?r)rr`rrcolumns)rrrrrrrrrrr visit_valuess2  zSQLCompiler.visit_valuescKsd|j|f|dSr)r rrrrvisit_scalar_valuesszSQLCompiler.visit_scalar_valuescCsd|S)Nrr)rZalias_name_textrrrrsz&SQLCompiler.get_render_as_alias_suffixrrrcCsN|st|dks|dkr$d|_d|_|jr4td|jt||||dS)N*FTzxMost backends don't support SELECTing from a tuple() object. If this is an ORM query, consider using the Bundle object.) rprrrDr7rOr[r"rrrrrrs  zSQLCompiler._add_to_result_mapcKs"|jd||d|dkrin|f|S)aLRender a column with necessary labels inside of a RETURNING clause. This method is provided for individual dialects in place of calling the _label_select_column method directly, so that the two use cases of RETURNING vs. SELECT can be disambiguated going forward. .. versionadded:: 1.4.21 NF_label_select_column)rrrircolumn_clause_argsrrrr_label_returning_column7s z#SQLCompiler._label_returning_columnc sj|j} | jr(| s|r(| }n}|rh|j}| rL|fdd}ql|k rl|fdd}nd}| sxtdttj r|k rt |j j fd}n|}n|r|dk stdt |||j fd}n|k rd}n~ttjr |oj ojdk }nTttjr d }n@ttjr<jp8|}n$ttjs\jdkr\d}nd }|r|s|| rvtj}t|tjst|n|}t |||fd}n|}|j| || d |j|f|S) z.produce labeled columns present in a select().cs|||f|dSrrrrrr)rrrrrsz;SQLCompiler._label_select_column..add_to_result_mapcs||f||dSrrrrrirrrzs NzX_label_select_column is only relevant within the columns clause of a SELECT or RETURNING)rz*proxy_name is required if 'name' is passedTF)rrr)rrriZ_has_column_expressionZcolumn_expressionrrprorrHrrrrrFrrZ TextClauseZUnaryExpressionZwraps_column_expressionZ NamedColumnZ_non_anon_labelZ_anon_name_labelrDrr)rrrirrrrrrrcolumn_is_repeatedneed_column_expressionsrrZcol_exprrZ result_exprZrender_with_labelrrrrLs     z SQLCompiler._label_select_columncCs |||}|r|d|7}|Sr)get_from_hint_text)rrrhintrhinttextrrrrs  z!SQLCompiler.format_from_hint_textcCsdSrr)rZbyfromsrrrget_select_hint_textsz SQLCompiler.get_select_hint_textcCsdSrrrrrrrrrszSQLCompiler.get_from_hint_textcCsdSrrrrrrget_crud_hint_textszSQLCompiler.get_crud_hint_textcCs d|Srr )rZ hint_textsrrrget_statement_hint_textsz#SQLCompiler.get_statement_hint_textrrrrc Ksh|j }|r|jn|jd}|||}|d}|d} |rV|sV|j|| dd} n|j|| d} | S)NrrrrZexplicit_correlate_fromsZimplicit_correlate_froms)rLrrC_get_display_froms difference) r select_stmtrrrrrrrrr?rrr_display_froms_for_select s" z%SQLCompiler._display_froms_for_selecttranslate_select_structurec  s|dkstdd| d<jf| } | j| d<| jj } | rPjsP| _|dk pZ|} jrjfdi| } | k r| }}| jf| } | j| rjnjd}| p|ddp|dd|rdsd | kr| d = | |||}|  ddd d }j rJ \}}|rN||d 7}nd}jrb| jr|jjf| 7}|jf| 7}d dfdd| jDD}r|dk rttdd| jDdd|jDfddjD_|| |||| | }jrRfddjD}|rR|d |7}jr| rf| r| svtjnd}j|d|}jr|d jjf| 7}jd|S)NzpSQLAlchemy 1.4 requires use of the translate_select_structure hook for structural translations of SELECT objectsFrrrrrrr)rrzSELECT rcSsg|]}|dk r|qSrrrrrrrsz,SQLCompiler.visit_select..cs4g|],\}}}}}j|||||d qS))rrrrrrrrrrrir)rrrrr$rrrrs$ cSsg|]\}}}}}|qSrrrrrrrrrrrrscSsg|]\}}}}}|qSrrr(rrrrsc s4g|],\}}}}t||tfdd|D|qS)c3s|]}||VqdSrr&)rorrrrsz6SQLCompiler.visit_select...)rr)rrrrrr*rrrs cs$g|]\}}|djjfkr|qSrrir)r dialect_nameZhtrrrrsr)rprCZ_ambiguous_table_name_maprrLrr&rr'_setup_select_stackrr_hints_setup_select_hintsrrrrget_select_precolumnscolumns_plus_namesrNrPr[_compose_select_bodyZ_statement_hintsr rr.rrrB)rr$r insert_intorrZselect_wraps_forrrrrrZis_embedded_selectZnew_select_stmtZcompile_state_wraps_forrr?r hint_textbyfrom inner_columnsZ per_dialectrr)rrrrr$rrr visit_select-s             zSQLCompiler.visit_selectrzTuple[str, _FromHintsType])rrcs*fdd|jD}|}||fS)Nc s<i|]4\\}}}|djjfkr||d|jddiqS)rrT)rrirr)rrPrirrrrrs  z3SQLCompiler._setup_select_hints..)r/rr)rrr6r5rrrr0s   zSQLCompiler._setup_select_hintscCs|d}|d}|dkr"||d<nD|rf|d} t| j} t|j| krftdd| |dt|jf|r|s|j||dd} n|j||d} tt| } | |} | | ||d }|j || S) Nrrrrz}All selectables passed to CompoundSelect must have identical numbers of columns; select #%d has %d columns, select #%d has %drrr!)rrr#r) r.rr2r7rOr"r#rr*rrLr")rrrrrrrrrrZnumcolsr?Znew_correlate_fromsZall_correlate_fromsrrrrr.sJ      zSQLCompiler._setup_select_stackc s|d|7}jt@r:titjt@} |rB_ndd} |sN|}|r|d7}|jr|dfdd|D7}q|dfdd|D7}n | 7}|j rj |j fdi} | r|d| 7}| rdk st  |jr|j|f7}|jr<j |jf} | r<|d | 7}|jrV|j|f7}|jrp|j|f7}|jdk r|j|f7}|S) NrFz FROM cs&g|]}|jfddqS)T)rrrrrfr6rrrrrr_sz4SQLCompiler._compose_select_body..cs$g|]}|jfddqS)Trrrr:)rrrrrrlsrz WHERE z HAVING )rrr6r9rr7rrstripr/r_where_criteriarrprR_group_by_clausesrFZ_having_criteria_order_by_clausesrGrHrIZ_for_update_argfor_update_clause) rrrrr7r?r6rr warn_lintingtrr<rr3:sl           z SQLCompiler._compose_select_bodyc s*dfdd|D}|r&|d7}|S)Nrc3s4|],\}}|dks|jjkr|jfVqdS))NrNr9)rprefixr-rrrrs z1SQLCompiler._generate_prefixes..r )rrrrrrrrrs zSQLCompiler._generate_prefixesc Cs0|js dS|r|dkrt}t|jD]T}|j|\}}}|jpN|j}||kpf|of||dk} |r,| srq,|j|||<q,n|j}|sdStdd|D} | | d} | d dd| D7} | d7} |r,|dkr,t|D]8}|j|\}}}|j|=|j ||f=|j|=q| S) z include_following_stack Also render the nesting CTEs on the next stack. Useful for SQL structures like UNION or INSERT that can wrap SELECT statements containing nesting CTEs. rWrcSsg|] }|jqSr)r)rrrrrrsz2SQLCompiler._render_cte_clause..r, cSsg|]}|qSrr)rtxtrrrrsz ) rr%rrkeysrrrr`get_cte_preamblerr:r) rrrBrrrrrrZis_rendered_levelrZcte_textrrrrs>      zSQLCompiler._render_cte_clausecCs|rdSdSdS)NzWITH RECURSIVEZWITHr)rrrrrrIszSQLCompiler.get_cte_preamblecKs"|jrtjddd|jrdSdS)zcCalled when building a ``SELECT`` statement, position is just before column list. a DISTINCT ON is currently supported only by the PostgreSQL dialect. Use of DISTINCT ON for other backends is currently silently ignored, however this usage is deprecated, and will raise CompileError in a future release for all backends that do not support this syntax.z1.4versionrrW)Z _distinct_onr%warn_deprecatedZ _distinctrrrrrrr1s z!SQLCompiler.get_select_precolumnscKs,|j|jttjf|}|r$d|SdSdS)z5allow dialects to customize how GROUP BY is rendered.z GROUP BY rWN)r r@rr comma_op)rrrZgroup_byrrrrFszSQLCompiler.group_by_clausecKs,|j|jttjf|}|r$d|SdSdS)z5allow dialects to customize how ORDER BY is rendered.z ORDER BY rWN)r rArr rN)rrrr)rrrrGszSQLCompiler.order_by_clausecKsdS)Nz FOR UPDATErrMrrrrBszSQLCompiler.for_update_clauserBSequence[ColumnElement[Any]]rreturning_colsrrrc s6fddjdt|dD}dd|S)Nc s6g|].\}}}}}j|f||||dqS))rrrr)rr'rrrrrrrs$ z0SQLCompiler.returning_clause..T)cols RETURNING r)rr_select_iterablesrrrrQrrrrrRrreturning_clauseszSQLCompiler.returning_clausecKs^d}|jdk r&|d|j|jf|7}|jdk rZ|jdkrB|d7}|d|j|jf|7}|S)NrWz LIMIT z LIMIT -1z OFFSET )Z _limit_clauserq_offset_clause)rrrrrrrrN(s   zSQLCompiler.limit_clausec Ks|dkr|j}|j}n ddd}d}|jdk rf|j}|rJ||rJ|}|j|f|} |d| 7}n |rr|d7}|dk r|r||r|}|d|j|f||drdnd|d rd nd f7}|S) NF)r with_tiesrWz OFFSET %s ROWSz OFFSET 0 ROWSz FETCH FIRST %s%s ROWS %srz PERCENTrYz WITH TIESZONLY)rLZ_fetch_clause_optionsrXZ_simple_int_clauseZrender_literal_executerq) rrrMZrequire_offsetZ"use_literal_execute_for_simple_intrZfetch_clause_optionsrZ offset_clauseZ offset_strrrrrM2s8   zSQLCompiler.fetch_clausec Ks|r|j|j|<|s|r|j|} |rL| rL|j| d|j|j} nJ|j|j} | s|r|j|kr|d||j} | ||j d| } |r||kr| | ||||} | SdSdS)NrrrW) fullnamer?r`rrrrrrrr) rrrrrr use_schemarrrrrZ anon_namerrr visit_table[sD       zSQLCompiler.visit_tablecKs|r(|jtt|jjt|jj|jr4d}n|j r@d}nd}|jj |fd|d|||jj |fd|d|d|j j |fd|i|S)Nz FULL OUTER JOIN z LEFT OUTER JOIN z JOIN Tr=z ON r) r@rr8rr)rr*rr|ZisouterrZonclause)rrrrrZ join_typerrr visit_joinsT   zSQLCompiler.visit_joincsBfdd|jD}|j|kr:||j||jd}||fS)Ncs*i|]"\\}}}|djjfkr||qSr+r,)rrrir5rrrrs z1SQLCompiler._setup_crud_hints..T)r/rrr)rr table_text dialect_hintsrrr_setup_crud_hintss  zSQLCompiler._setup_crud_hintsrJr)rrcCs~|jj}|j}|j}|dkr dS|jr8|j|jd}n|j|jd}||@rT|S|j rzt d|dd|jj ddS)a)given a :class:`.Table`, return a usable sentinel column or columns for this dialect if any. Return None if no sentinel columns could be identified, or raise an error if a column was marked as a sentinel explicitly but isn't compatible with this dialect. NrzColumn z@ can't be explicitly marked as a sentinel column when using the a dialect, as the particular type of default generation on this column is not currently compatible with this dialect's specific INSERT..RETURNING syntax which can receive the server-generated value in a deterministic way. To remove this error, remove insert_sentinel=True from primary key autoincrement columns; these columns are automatically used as sentinels for supported dialects in any case.) ri"insertmanyvalues_implicit_sentinelZ _sentinel_column_characteristicsrZ is_autoinc_sentinel_col_autoinc_lookupr'Zdefault_characterization _sentinel_col_non_autoinc_lookupZ is_explicitr7rr)rrZ sentinel_optsZsentinel_characteristicsZ sent_colsZbitmaskrrr_get_sentinel_column_for_tables* z*SQLCompiler._get_sentinel_column_for_tablerWz%List[_MutableCoreSingleExecuteParams]rrr\z Iterator[_InsertManyValuesBatch])rrcompiled_parametersgeneric_setinputsizes batch_sizerr]rc1 #s j}|dk st|jsdn tj|jt } |jrJ jjsJd} d} n4 jj rl|rv j rv|j dksl|j rvd} d} nd} d} | rt tdt |dD]8\} \ } t|  gr| gngd| | || VqdS|rtj jj|d nd |j} r |}d|d}||d} jj}|rZt j}t|j}||}t||||}td t }td t|}d}d} | || |rdnd }|j}|dk st rć fd d |D}d  jsn jr jnit d } fd d|jrd}nd}dd fdd|D|d}|!fdd|D} fdd|"|D}dnd}t}i}|jrd|dn d|dt|jD]}#|dqr j$}|dk stfddt |D} t| t%| dt| kst j&rBt'( j)}!t'*|!dd|r|d |}"|d |}#g|d |<g|d |<|r|}$nt|"}$rdd fddt+|$DD} jr|j,}%|%t|"d krd }&}'|"}(n4|"d d}&|"d d}'fd!d|"D}(|jrBd fd"dt |"Ddd#})n|$dd#}) j&r|%d kr|'rntd}*|%|$|*}+t- fd$dt+|*|+D},|)|,})|d|)}-t-t.j/0|(}.|&|.|'}.n~g}/|1}.t |"D]V\ |d%t2}0|jr|0d&t2}0|/3|0|.# fd'd|Dq|dd |/}-t|-|.||"rpfd(d |#Dng|$| ||d V| d7} qBdS))NTFzKSequence[Tuple[_DBAPISingleExecuteParams, _MutableCoreSingleExecuteParams]]rr]rrZ__EXECMANY_TOKEN__zList[Sequence[Any]]rcs$g|]\}}}}||||fqSrr)rrrrpst)rstrrrs zASQLCompiler._deliver_insertmanyvalues_batches..cs@|D]6}||}|jd|ijd|di}q|S)NrZ__EXECMANY_INDEX__)r'rr)rH formattedr)rrrrapply_placeholderss   zISQLCompiler._deliver_insertmanyvalues_batches..apply_placeholdersz, _IMV_VALUES_COUNTERrWrc3s |]\}}}}||VqdSrr)rrrk bind_keys)rlrrrs z@SQLCompiler._deliver_insertmanyvalues_batches..c3s,|]$\}}}}|D]}||VqqdSrr&)rrrmr)rrrrs csi|]}|d|qS)rrrrrrrszASQLCompiler._deliver_insertmanyvalues_batches..z, _IMV_VALUES_COUNTER), z), rcsh|]\}}|kr|qSrr)rrr)all_names_we_will_expandrrrsz@SQLCompiler._deliver_insertmanyvalues_batches..z\d+r cSsg|]\}}}|||fqSrr)rZnew_keylen_rXrrrrsc3s2|]*}D] \}}}|d|||fVq qdS)rNr)rr>rrorX)rfrrrsrc3s|]}|VqdSrrr)expand_pos_lower_indexexpand_pos_upper_indexrrrsc3s"|]\}}dt|VqdS)_IMV_VALUES_COUNTERN)rrrrcr)executemany_values_w_commarrrs c3s|]}j|VqdSrrtrrcrrrr3sZEXECMANY_INDEX__rrcs i|]}|d|qS)__rr)rcparamrrrTs csg|] }|qSrr)rr)_sentinel_from_paramsrrrbs)4rrprrrr.r risupports_default_metavaluesupports_multivalues_insertr[rrrbrrPr functoolspartialr`rrrrZinsertmanyvalues_max_parametersrrminrrrrrrrr#rrrrrrrr*rangerrr8r9 from_iterablerrr")1rrrrerfrgrr]ZimvZ lenparamsZuse_row_at_a_timeZ downgradedr"Zcompiled_paramZimv_single_values_exprZexecutemany_valuesZ max_paramsZtotal_num_of_paramsZnum_params_per_batchZnum_params_outside_of_batchZbatchesZcompiled_batchesrr#rall_keysZimv_values_counterZformatted_values_clauseZkeys_to_replaceZbase_parametersr rZall_expand_positionsescapedr Zcompiled_batchr!Znum_ins_paramsZextra_params_leftZextra_params_rightZbatch_iteratorZexpanded_values_stringrIrvr$rrZreplaced_values_clausesZfmvr) ryrnrlrrtrprqrfrcrxrrjrr!_deliver_insertmanyvalues_batchess                               z-SQLCompiler._deliver_insertmanyvalues_batchesc s|j|f|}|j}|dk r,||d<d}nj }|rVd_jsJ|_jsV|_jtt|dd}d}jr|dkrg}t j |||fd|i|}jr|dk rt |}j rj dk rڈj |7_ n|_ |j} | sjjsjjsjjstdjj|jrljjsBtdjjn"jsR|jrd|jrdtd |j} n|j} j} jj} d } |jr| j||jf|7} | d 7} | |j} |j rΈ!|| \}} |j"r#||| | 7} | s| s| d d $dd| D7} |j%}d}d}d}jp0|j}|r|j&}|dk r|sRt'dd| D}g}|D]F}||krd}q(|}|||krd}q||qh|dkrjj)t*j+@rd}n|dj,rt'dt-|t-|}j.|||d}j/r| d|7} nd}|j0dk rj1jddfddi|}j2rjj3r|slt jnd}| dj4|dd|f7} n | d|7} n| s| r| d7} |r2t5djj6t7d| ||j|j8dk ||rt |nd|d _9n<|jr"| dd $dd |j:Df7} nd $d!dt7d| D}|r"|rЈjj)t*j;@r|j<sd}jj)t*j=@}d $d"d t>| D}|rd $fd#d t>| D}n|}| d$|d%|d&|d'7} nd}| d(|d)7} t5d|t7d| ||j|j8dk ||rt |nd|||d* _9n| d(|d)7} |j8dk r`j1|j8f|}|r`| d|7} |rzj/sz| d|7} j2rjj3s|st jnd}j4|dd| } j?d| S)+NrFTrrrzWThe '%s' dialect with current database version settings does not support empty inserts.zcThe '%s' dialect with current database version settings does not support in-place multirow inserts.zcRETURNING cannot be determinstically sorted when using an INSERT which includes multi-row values().zINSERT zINTO  (%s)rcSsg|]\}}}}|qSrr)rrrprrrrs z,SQLCompiler.visit_insert..cSsi|]\}}}}||qSrr)rrrZ param_namesrrrrs z,SQLCompiler.visit_insert..zTsentinel selection rules should have prevented us from getting here for this dialectrrrrr4z %s%srArz DEFAULT VALUESr)rrrrrz VALUES %scss&|]}dddd|DVqdS)rrcss|]\}}}}|VqdSrrrrrBrrrrfs z5SQLCompiler.visit_insert...Nr )rZcrud_param_setrrrrdsz+SQLCompiler.visit_insert..cSsg|]\}}}}|qSrrrrrrrls css|]\}}d|VqdSpNrrsrrrrsc3s6|].\}^}}|j|jjd|VqdSr)rrrWri)rrcrrrrrrs   z SELECT z FROM (VALUES (z)) AS imp_sen(z#, sen_counter) ORDER BY sen_counterz VALUES (r) r rrrrrrrrrr)@rCrrLrrbrr"rrr_get_crud_paramsr.rr single_paramsrisupports_default_valuesrzZsupports_empty_insertr7rOrZ_has_multi_parametersr{r _returningZ_sort_by_parameter_orderr`rr format_tablerr/r`rrruse_insertmanyvaluesZuse_sentinel_columnsrprrar$r,Z_insert_sentinelrrWrrrqrZcte_follows_insertrr Zdefault_metavalue_tokenrZ_post_values_clauserZall_multi_paramsr.Zis_default_metavalue_onlyr/rbrB) rZ insert_stmtrrrrrZcounted_bindparamcrud_params_structZcrud_params_singler`rrr^rrZnamed_sentinel_paramsZadd_sentinel_colsrrQZ_params_by_colZ_add_sentinel_col param_namerWZ select_textrrZembed_sentinel_valueZrender_bind_castsZcolnamesZcolnames_w_castZpost_values_clauserrr visit_insertns                           zSQLCompiler.visit_insertcCsdS)z3Provide a hook for MySQL to add LIMIT to the UPDATENr)r update_stmtrrrupdate_limit_clauseszSQLCompiler.update_limit_clausecKsd|d<|j|fddi|S)z|Provide a hook to override the initial table clause in an UPDATE statement. MySQL overrides this. Trrr)rr from_table extra_fromsrrrrupdate_tables_clausesz SQLCompiler.update_tables_clausecKs tddS)z~Provide a hook to override the generation of an UPDATE..FROM clause. MySQL and MSSQL override this. zCThis backend does not support multiple-table criteria within UPDATENrrrrr from_hintsrrrrupdate_from_clauses zSQLCompiler.update_from_clausec s|j||f|}|j}|dk r,||d<d}n|j }|rVd|_|jsJ||_|jsV||_|jt@rtit }|jt @}|r||_ nd}d}|j }t |} | rt t|jfdd|D} |} n g} |jh} |j| | |dd} |jr | |j||jf|7} |j||j| fd|i|} tj||||f|}|j}|jrZ||| \}} nd}|jrr|||| | 7} | d 7} | d d d td |D7} |js|jr|j r| d|j!||jp|j|d7} |r|j"||j| |fd|i|}|r| d|7} |j#rB|j$|j#fd|i|}|rB| d|7} |%|}|r^| d|7} |jsn|jr|j s| d|j!||jp|j|d7} |j&r|st'|jnd}|j(|d| } |r|dk st)|j*dd|j+d| S)NrFTcsg|]}|kr|qSrrr:Z main_fromsrrrsz,SQLCompiler.visit_update..rzUPDATE rz SET rcss"|]\}}}}|d|VqdS)=Nr)rrrprBrrrrNs z+SQLCompiler.visit_update..zList[Tuple[Any, str, str, Any]]rr WHERE rZUPDATErQr),rCrrLrrbrrr6r9rr7r _extra_fromsrr*rrr"rrrrrrr/r`rrrrrrrrWrr?rrrr.rrprRrB)rrrrrrrrCrZ is_multitableZrender_extra_fromsrrr^rZ crud_paramsr_extra_from_textrDrNrrrr visit_updates                    zSQLCompiler.visit_updatecKs tddS)zProvide a hook to override the generation of an DELETE..FROM clause. This can be used to implement DELETE..USING for example. MySQL and MSSQL override this. zCThis backend does not support multiple-table criteria within DELETENrrrrrdelete_extra_from_clauses z$SQLCompiler.delete_extra_from_clausecKs|j|fddd|S)NT)rrr)r delete_stmtrrrrrrdelete_table_clauseszSQLCompiler.delete_table_clausecKs|j||f|}|j}|dk r,||d<d}n|j }|rVd|_|jsJ||_|jsV||_|jt@rtit }|jt @}|r||_ nd}d}|j }|j h|} |j| | |dd} |jr| |j||jf|7} | d7} z|j||j ||d} Wn<tk r.|||j |} |r*|j|j |d} YnXtj||||f||jr^||| \} } nd} |jrv|||| | 7} |js|jr|jr| d|j||jp|j|d 7} |r|j||j || fd |i|}|r| d|7} |j r |j!|j fd |i|}|r | d |7} |js0|jrZ|jsZ| d|j||jpN|j|d 7} |j"r|srt#|jnd}|j$|d | } |r|dk st%|j&d d|j'd| S)NrFTrzDELETE FROM )rrrrrrDELETErr)(rCrrLrrbrrr6r9rr7rrrrr"rrr TypeErrorrqrrr/r`rrrrrrWrr?rrr.rrprRrB)rrrrrrrrCrrrr^rr_rrDrrrr visit_deletes              zSQLCompiler.visit_deletecKsd|j|S)Nz SAVEPOINT %sr`format_savepointrZsavepoint_stmtrrrrvisit_savepointszSQLCompiler.visit_savepointcKsd|j|S)NzROLLBACK TO SAVEPOINT %srrrrrvisit_rollback_to_savepoint sz'SQLCompiler.visit_rollback_to_savepointcKsd|j|S)NzRELEASE SAVEPOINT %srrrrrvisit_release_savepoint%sz#SQLCompiler.visit_release_savepoint)NT)NNTNTF)F)F)F)F)NFFNr)NTrN)N)NF)N)FN)Nr)N)NFNN)F)FFFFF)FFNNNN)FFFNFFNN)F)FN)N)NNNTFFT)F)FFNNNFN)NF)NFF)FFFNTNN)FN)NN)N)N)rrrr EXTRACT_MAPr/r%rrrrCOMPOUND_KEYWORDSrDrrrrrrrrrrrrrrrrrrrrr frozensetrrrrrZpostfetch_lastrowidrrrrrrrryr<patternr+rrurr5rtr rZro_memoized_propertyrrrrmemoized_propertyrZmemoized_instancemethodr contextlibcontextmanagerrr r rGrHrrIrr]rr preload_modulerrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrr!r%r*r+r.r2r5r3r=r;r:rKrIrrTrYr[r^r`rdrfrmrkr~rvrbrrrrrrerRrSrrrrrrrrrrrrrrrrrrrrrrrrrr.rur_rrrrrr#Z_CTEOptsrrrrrrrr rrrrrrrrrrr rrrr%r&r8r0r.r3rrrIr1rFrGrBrWrNrMr\r]r`r,Z CLIENTSIDEr$r-ZSENTINEL_DEFAULTNONEr*r+rcrr)rbrdrrrrrrrrrrrrrrrrr s   +                           "  ;I  & F  R . @  0 0 1;  4  *. A  &    J R8                       & ! % *C 0L  d   &   %       N 4 _ 5    ,0 >.^t      rcseZdZdZddZedfddZddZd d Z d d Z d dZ ddddddddZ ddZ ddZddZddZdd Zd!d"Zd#d$Zd%d&ZZS)'StrSQLCompileraA :class:`.SQLCompiler` subclass which allows a small selection of non-standard SQL features to render into a string value. The :class:`.StrSQLCompiler` is invoked whenever a Core expression element is directly stringified without calling upon the :meth:`_expression.ClauseElement.compile` method. It can render a limited set of non-standard SQL constructs to assist in basic stringification, however for more substantial custom or dialect-specific SQL constructs, it will be necessary to make use of :meth:`_expression.ClauseElement.compile` directly. .. seealso:: :ref:`faq_sql_expression_string` cCsdS)Nzrrrrrr?sz$StrSQLCompiler._fallback_column_namezsqlalchemy.engine.urlc s\|jdkrNtjj}|j|j}|j|d|d}t|t sN|j |f|St ||S)Nrq)r) Zstringify_dialectr%r~Z engine_urlURLrk get_dialectstatement_compilerrorrqrvr)rrrrurlricompilerrzrrrBs  z,StrSQLCompiler.visit_unsupported_compilationcKs$d|j|jf||j|jf|fS)Nz%s[%s])rqrrrXrrrvisit_getitem_binaryPsz#StrSQLCompiler.visit_getitem_binarycKs|j||f|SrrrXrrrvisit_json_getitem_op_binaryVsz+StrSQLCompiler.visit_json_getitem_op_binarycKs|j||f|SrrrXrrr!visit_json_path_getitem_op_binaryYsz0StrSQLCompiler.visit_json_path_getitem_op_binarycKsd|j|dS)Nz)r`format_sequencer?rrrr;\szStrSQLCompiler.visit_sequencerBrOrrrrPc s&fddt|D}dd|S)Nc sg|]}d|ddiqS)NTFrrrrrrisz3StrSQLCompiler.returning_clause..rTr)rrUrrVrrrrWas zStrSQLCompiler.returning_clausec s(dd<ddfdd|DS)NTrrrc3s$|]}|jfdiVqdSrNrrrDrrrrrrssz4StrSQLCompiler.update_from_clause..r rrrrrosz!StrSQLCompiler.update_from_clausec s(dd<ddfdd|DS)NTrrc3s$|]}|jfdiVqdSrrrrrrr|sz:StrSQLCompiler.delete_extra_from_clause..r rrrrrxsz'StrSQLCompiler.delete_extra_from_clausecKsdS)NzSELECT 1 WHERE 1!=1rrnrrrrksz#StrSQLCompiler.visit_empty_set_exprcCsd|S)Nz[%s]rrrrrrsz!StrSQLCompiler.get_from_hint_textcKs|j|df|S)Nz rerXrrrrsz+StrSQLCompiler.visit_regexp_match_op_binarycKs|j|df|S)Nz rrXrrrrsz/StrSQLCompiler.visit_not_regexp_match_op_binarycKs$d|jj|f||jj|f|fS)Nz(%s, %s))rrrrXrrrrsz-StrSQLCompiler.visit_regexp_replace_op_binarycKs$d|jj|f||jj|f|fS)NzTRY_CAST(%s AS %s))rrr)rrrrrrvisit_try_castszStrSQLCompiler.visit_try_cast)rrrrrr%rrrrrr;rWrrrkrrrrrrrrrzrr+s"   rc@seZdZdZer(diddddddd d Zejd d Zejd dZ djdddddddZ ddZ ddZ ddZ ddZdkdd Zdld!d"Zd#d$Zd%d&Zd'd(Zdmd)d*Zd+d,Zdnd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Zd=d>Zdod?d@ZdAdBZ dCdDZ!dEdFZ"dGdHZ#dIdJZ$dKdLZ%dMdNZ&dOdPZ'dQdRZ(dSdTZ)dUdVZ*dWdXZ+dYdZZ,d[d\Z-d]d^Z.d_d`Z/dadbZ0dcddZ1dedfZ2dgdhZ3dS)p DDLCompilerT.r\r@r\rrgrhcCsdSrrrsrrrrtszDDLCompiler.__init__cCs|jj|jd|jdS)Nrh)rirr]rrrrrs zDDLCompiler.sql_compilercCs|jjSr)rirrrrr type_compilerszDDLCompiler.type_compilerNrrrrcCsdSrrrrrrrszDDLCompiler.construct_paramscKs|j}t|jtjr|}|j}||j}t|dkrJ|dd}}n|d|d}}| d|| d|| d| |j|j |j |S)NrrrWrrr"rZ)contextrotargetr"rJrr`format_table_seqr.r rrrr)rddlrrr`pathrZschrrr visit_ddls    zDDLCompiler.visit_ddlcKs$d}|jr|d7}||j|jS)NzCREATE SCHEMA IF NOT EXISTS ) if_not_existsr` format_schemar)rrkrrrrrvisit_create_schemaszDDLCompiler.visit_create_schemacKs6d}|jr|d7}||j|j7}|jr2|d7}|S)Nz DROP SCHEMA IF EXISTS  CASCADE) if_existsr`rrcascaderdroprrrrrvisit_drop_schemaszDDLCompiler.visit_drop_schemac KsV|j}|j}d}|jr*|d|jd7}|d7}|jr@|d7}|||d7}||}|rl||d7}|d7}d}d}|jD]} | j} zD|j| | j o| d} | dk r||7}d }|d | 7}| j rd }Wqt j k r} z$t d |j | j | jd f| W5d} ~ XYqXq|j||jd} | r@||d | 7}|d||7}|S)Nz CREATE rzTABLE rr Ffirst_pkrF Tz (in table '%s', column '%s'): %sr) _include_foreign_key_constraintsz )%s )rr`rrrrcreate_table_suffixrrqrr7rO descriptionrargscreate_table_constraintsZinclude_foreign_key_constraintspost_create_table)rrkrrr`rrr rZ create_columnri processedZceconstrrrvisit_create_tablesX     zDDLCompiler.visit_create_tableFc sL|j}|jrdSj||d}dfdd|jD}|rH|d|7}|S)Nrrc3s|]}|VqdSr)rqrrjrrrrsz2DDLCompiler.visit_create_column..)rsystemget_column_specificationr constraints)rrkrrrirrrrrvisit_create_columns zDDLCompiler.visit_create_columnc stg}jr|jj}|dk r0||nt|fddjDdddfdd|DDS)Ncs"g|]}|jk r|kr|qSr)rr) omit_fkcsrrrr/s z8DDLCompiler.create_table_constraints..z, css|]}|dk r|VqdSrr)rrrrrr6s z7DDLCompiler.create_table_constraints..c3s6|].}|rjjr$t|dds|VqdS)Z use_alterFN)Z_should_create_for_compilerriZsupports_alterr8rqrrrrr8s   )rr"Zforeign_key_constraintsr#rrxZ_sorted_constraintsr)rrrrrZall_fkcsr)rrrrrs"     z$DDLCompiler.create_table_constraintscKs$d}|jr|d7}||j|jS)Nz DROP TABLE r)rr`rrrrrrvisit_drop_tableDszDDLCompiler.visit_drop_tablecKsd|j|jS)Nz DROP VIEW r`rrrrrrrrvisit_drop_viewJszDDLCompiler.visit_drop_viewcCs|jdkrtd|jdS)Nz,Index '%s' is not associated with any table.)rr7rOrrr>rrr_verify_index_tableMs zDDLCompiler._verify_index_tablec s|j}|j}d}|jr(|d7}|jdkr.) rrr`rrr7rOr_prepared_index_namerrrZ expressions)rrkrZinclude_table_schemarr>r`rrrrvisit_create_indexSs0    zDDLCompiler.visit_create_indexcKs>|j}|jdkrtdd}|jr,|d7}||j|ddS)Nz.DROP INDEX requires that the index have a namez DROP INDEX rTr)rrr7rOrr)rrrr>rrrrvisit_drop_indexss zDDLCompiler.visit_drop_indexcCsX|jdk r|j|j}nd}|r4|r4|j|}nd}|j|}|rT|d|}|SNr)rr`rr format_index)rr>rrZ schema_nameZ index_namerrrrs   z DDLCompiler._prepared_index_namecKs d|j|jj||jfS)NzALTER TABLE %s ADD %s)r`rrrrqrrkrrrrvisit_add_constraints z DDLCompiler.visit_add_constraintcKs(d|j|j|j|jjtfS)NzCOMMENT ON TABLE %s IS %s)r`rrrr_commentr$Stringrrrrvisit_set_table_comments z#DDLCompiler.visit_set_table_commentcKsd|j|jS)NzCOMMENT ON TABLE %s IS NULLrrrrrvisit_drop_table_commentsz$DDLCompiler.visit_drop_table_commentcKs.d|jj|jddd|j|jjtfS)NzCOMMENT ON COLUMN %s IS %sT) use_tabler[)r` format_columnrrr_rr$rrrrrvisit_set_column_commentsz$DDLCompiler.visit_set_column_commentcKsd|jj|jddS)NzCOMMENT ON COLUMN %s IS NULLT)r)r`rrrrrrvisit_drop_column_commentsz%DDLCompiler.visit_drop_column_commentcKst|t|dSrr~rrrrvisit_set_constraint_commentsz(DDLCompiler.visit_set_constraint_commentcKst|t|dSrr~rrrrvisit_drop_constraint_commentsz)DDLCompiler.visit_drop_constraint_commentcCsg}|jdk r|d|j|jdk r8|d|j|jdk rR|d|j|jdk rl|d|j|jdk r|d|jdk r|d|jdk r|d|j|jdk r||jrdnd d |S) NzINCREMENT BY %dz START WITH %dz MINVALUE %dz MAXVALUE %dz NO MINVALUEz NO MAXVALUEzCACHE %dZCYCLEzNO CYCLEr) incrementr"rIZminvalueZmaxvalueZ nominvalueZ nomaxvaluecachecycler)rZidentity_optionsrrrrget_identity_optionss$          z DDLCompiler.get_identity_optionscKsPd}|jr|d7}||j|j7}|r0||7}||j}|rL|d|7}|S)NzCREATE SEQUENCE rr)rr`rrr )rrkrErroptionsrrrvisit_create_sequences  z!DDLCompiler.visit_create_sequencecKs$d}|jr|d7}||j|jS)NzDROP SEQUENCE r)rr`rrrrrrvisit_drop_sequenceszDDLCompiler.visit_drop_sequencecKsj|j}|jdk r|j|}nd}|dkr:td|jd|j|jj|jrTdnd||j rbdndfS)Nzj|}|dk r>|d|7}|d7}|ddfdd|jrd|jn|jD7}||7}|S) NrrWrz PRIMARY KEY rrc3s|]}j|jVqdSrr`rrrrrrrHsz;DDLCompiler.visit_primary_key_constraint..) r.rr`rrZ_implicit_generatedZcolumns_autoinc_firstrr r!rrrvisit_primary_key_constraint?s     z(DDLCompiler.visit_primary_key_constraintc s|jd}|jdk r4|j|}|dk r4|d|7}t|jdjj}|ddfdd|jD|||dfdd|jDf7}|| |7}|| |7}|| |7}|S) NrWrrz"FOREIGN KEY(%s) REFERENCES %s (%s)rc3s|]}|jjVqdSr)rparentrr:r`rrr\sz;DDLCompiler.visit_foreign_key_constraint..c3s|]}|jjVqdSr)rrirr:r%rrrbs) r`rrrrrirrdefine_constraint_remote_tabledefine_constraint_matchdefine_constraint_cascadesr )rrjrrrZ remote_tablerr%rvisit_foreign_key_constraintSs0    z(DDLCompiler.visit_foreign_key_constraintcCs ||S)z=Format the remote table clause of a CREATE CONSTRAINT clause.)r)rrjrr`rrrr&ksz*DDLCompiler.define_constraint_remote_tablec s~t|dkrdSd}|jdk r>j|}|dk r>|d|7}|dj|f|dfdd|Df7}||7}|S)NrrWrz UNIQUE %s(%s)rc3s|]}j|jVqdSrr"rrrrrzsz6DDLCompiler.visit_unique_constraint..)r.rr`r!define_unique_constraint_distinctrr r!rrrvisit_unique_constraintps     z#DDLCompiler.visit_unique_constraintcKsdSrrrrrrr*sz-DDLCompiler.define_unique_constraint_distinctcCsLd}|jdk r&|d|j|jt7}|jdk rH|d|j|jt7}|S)NrWz ON DELETE %sz ON UPDATE %s)Zondeleter`validate_sql_phrase FK_ON_DELETEZonupdate FK_ON_UPDATErrjrrrrr(s    z&DDLCompiler.define_constraint_cascadescCsLd}|jdk r&|jr|d7}n|d7}|jdk rH|d|j|jt7}|S)NrWz DEFERRABLEz NOT DEFERRABLEz INITIALLY %s)rrrr`r, FK_INITIALLYr/rrrr s    z+DDLCompiler.define_constraint_deferrabilitycCs d}|jdk r|d|j7}|S)NrWz MATCH %s)r r/rrrr's z#DDLCompiler.define_constraint_matchcKsBd|jj|jddd}|jdkr,|d7}n|jdkr>|d7}|S)NzGENERATED ALWAYS AS (%s)FTrz STOREDz VIRTUAL)rrqrZ persisted)r generatedrrrrrvisit_computed_columns   z!DDLCompiler.visit_computed_columncKs2d|jr dndf}||}|r.|d|7}|S)NzGENERATED %s AS IDENTITYZALWAYSz BY DEFAULTr)alwaysr )rrrrr rrrvisit_identity_columns   z!DDLCompiler.visit_identity_column)...)NNT)F)N)FT)F)N)4rrrrrrtr%rrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrrrrrr#r)r&r+r*r(r r'r2r4rrrrrst    4  %         rc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZd`d d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zdd?Z!d@dAZ"dBdCZ#dDdEZ$dFdGZ%dHdIZ&dJdKZ'dLdMZ(dNdOZ)dPdQZ*dRdSZ+dTdUZ,dVdWZ-dXdYZ.dZd[Z/d\d]Z0d^d_Z1dS)aGenericTypeCompilercKsdS)NFLOATrrrrr visit_FLOATszGenericTypeCompiler.visit_FLOATcKsdS)NDOUBLErrrrr visit_DOUBLEsz GenericTypeCompiler.visit_DOUBLEcKsdS)NzDOUBLE PRECISIONrrrrrvisit_DOUBLE_PRECISIONsz*GenericTypeCompiler.visit_DOUBLE_PRECISIONcKsdS)NZREALrrrrr visit_REALszGenericTypeCompiler.visit_REALcKs<|jdkrdS|jdkr&dd|jiSd|j|jdSdS)NZNUMERICzNUMERIC(%(precision)s) precisionz!NUMERIC(%(precision)s, %(scale)s)r<scaler=rrrr visit_NUMERICs  z!GenericTypeCompiler.visit_NUMERICcKs<|jdkrdS|jdkr&dd|jiSd|j|jdSdS)NZDECIMALzDECIMAL(%(precision)s)r<z!DECIMAL(%(precision)s, %(scale)s)r=r=rrrr visit_DECIMALs  z!GenericTypeCompiler.visit_DECIMALcKsdS)NZINTEGERrrrrr visit_INTEGERsz!GenericTypeCompiler.visit_INTEGERcKsdS)NZSMALLINTrrrrrvisit_SMALLINTsz"GenericTypeCompiler.visit_SMALLINTcKsdS)NZBIGINTrrrrr visit_BIGINTsz GenericTypeCompiler.visit_BIGINTcKsdS)N TIMESTAMPrrrrrvisit_TIMESTAMPsz#GenericTypeCompiler.visit_TIMESTAMPcKsdS)NZDATETIMErrrrrvisit_DATETIMEsz"GenericTypeCompiler.visit_DATETIMEcKsdS)NZDATErrrrr visit_DATEszGenericTypeCompiler.visit_DATEcKsdS)NZTIMErrrrr visit_TIMEszGenericTypeCompiler.visit_TIMEcKsdS)NZCLOBrrrrr visit_CLOBszGenericTypeCompiler.visit_CLOBcKsdS)NZNCLOBrrrrr visit_NCLOBszGenericTypeCompiler.visit_NCLOBNcCsB|}|r|d|7}n|jr*|d|j7}|jr>|d|j7}|S)N(%d)z COLLATE "%s")lengthr)rrrlength_overriderrrr_render_string_typesz'GenericTypeCompiler._render_string_typecKs ||dS)NCHARrNrrrr visit_CHARszGenericTypeCompiler.visit_CHARcKs ||dS)NZNCHARrPrrrr visit_NCHARszGenericTypeCompiler.visit_NCHARcKs ||dS)NZVARCHARrPrrrr visit_VARCHARsz!GenericTypeCompiler.visit_VARCHARcKs ||dS)NZNVARCHARrPrrrrvisit_NVARCHARsz"GenericTypeCompiler.visit_NVARCHARcKs ||dS)NZTEXTrPrrrr visit_TEXT szGenericTypeCompiler.visit_TEXTcKsdS)NUUIDrrrrr visit_UUID szGenericTypeCompiler.visit_UUIDcKsdS)NZBLOBrrrrr visit_BLOBszGenericTypeCompiler.visit_BLOBcKsd|jrd|jpdS)NBINARYrKrWrLrrrr visit_BINARYsz GenericTypeCompiler.visit_BINARYcKsd|jrd|jpdS)NZ VARBINARYrKrWrZrrrrvisit_VARBINARYsz#GenericTypeCompiler.visit_VARBINARYcKsdS)NZBOOLEANrrrrr visit_BOOLEANsz!GenericTypeCompiler.visit_BOOLEANcKs0|jr|jjs|j|dddS|j|f|SdS)NrO )rM)Z native_uuidriZsupports_native_uuidrNrWrrrr visit_uuidszGenericTypeCompiler.visit_uuidcKs|j|f|Sr)rXrrrrvisit_large_binary!sz&GenericTypeCompiler.visit_large_binarycKs|j|f|Sr)r]rrrr visit_boolean$sz!GenericTypeCompiler.visit_booleancKs|j|f|Sr)rHrrrr visit_time'szGenericTypeCompiler.visit_timecKs|j|f|Sr)rFrrrrvisit_datetime*sz"GenericTypeCompiler.visit_datetimecKs|j|f|Sr)rGrrrr visit_date-szGenericTypeCompiler.visit_datecKs|j|f|Sr)rCrrrrvisit_big_integer0sz%GenericTypeCompiler.visit_big_integercKs|j|f|Sr)rBrrrrvisit_small_integer3sz'GenericTypeCompiler.visit_small_integercKs|j|f|Sr)rArrrr visit_integer6sz!GenericTypeCompiler.visit_integercKs|j|f|Sr)r;rrrr visit_real9szGenericTypeCompiler.visit_realcKs|j|f|Sr)r7rrrr visit_float<szGenericTypeCompiler.visit_floatcKs|j|f|Sr)r9rrrr visit_double?sz GenericTypeCompiler.visit_doublecKs|j|f|Sr)r?rrrr visit_numericBsz!GenericTypeCompiler.visit_numericcKs|j|f|SrrSrrrr visit_stringEsz GenericTypeCompiler.visit_stringcKs|j|f|Srrlrrrr visit_unicodeHsz!GenericTypeCompiler.visit_unicodecKs|j|f|SrrUrrrr visit_textKszGenericTypeCompiler.visit_textcKs|j|f|Srrorrrrvisit_unicode_textNsz&GenericTypeCompiler.visit_unicode_textcKs|j|f|Srrlrrrr visit_enumQszGenericTypeCompiler.visit_enumcKstd|dS)NzKCan't generate DDL for %r; did you forget to specify a type on this Column?rrrrrrTs zGenericTypeCompiler.visit_nullcKs|j||jf|Sr)rqZ type_enginerirrrrvisit_type_decorator[sz(GenericTypeCompiler.visit_type_decoratorcKs |jf|Sr) get_col_specrrrrvisit_user_defined^sz&GenericTypeCompiler.visit_user_defined)N)2rrrr7r9r:r;r?r@rArBrCrErFrGrHrIrJrNrQrRrSrTrUrWrXr[r\r]r_r`rarbrcrdrerfrgrhrirjrkrmrnrprqrrrrsrurrrrr5s^   r5c@s4eZdZddZddZddZddZd d Zd S) StrSQLTypeCompilercKs>z |j}Wn"tk r,|j|f|YSX||f|SdSr)rAttributeError_visit_unknown)rrrrrrrrqcs  zStrSQLTypeCompiler.processcCs|dr|jSt|dS)Nvisit_)rrxrw)rrrrr __getattr__ks zStrSQLTypeCompiler.__getattr__cKs(|jj|jjkr|jjSt|SdSr)r{rupperreprrrrrrxqsz!StrSQLTypeCompiler._visit_unknowncKsdSrrrrrrrwszStrSQLTypeCompiler.visit_nullcKs6z |j}Wntk r&t|YSX|f|SdSr)rtrwr|)rrrrtrrrruzs  z%StrSQLTypeCompiler.visit_user_definedN)rrrrqrzrxrrurrrrrvbs rvc@seZdZdddddZdS)_SchemaForObjectCallablerr)_SchemaForObjectCallable__objrcCsdSrr)rr~rrrrr7z!_SchemaForObjectCallable.__call__Nrrrrrr}sr}c@seZdZdddddZdS)rrr)rrcCsdSrr)rrrrrrr7z _BindNameForColProtocol.__call__Nrrrrrrsrc@seZdZUdZeZeZeZ de d<de d<de d<e dZ de d <d Zd e d <dRddZddZddZdddddZdddddZddZdddddZdd ddd Zd!d"ZdSdd#dd$d%d&ZdTdd#dd'd(d)Zd*d+ZdUd,d-ZdVd.d/dd0d1d2ZdWd3d/dd4d5d6ZdXd7d8Ze d9dYd:d;Z!dZdd?Z#d@dAZ$dBdCZ%d\dDdEZ&dFdGZ'd]dHdIZ(d^dJdKZ)d_dLdMZ*ej+dNdOZ,dPdQZ-dS)`r_z@Handle quoting and case-folding of identifiers based on options.r initial_quote final_quotezMutableMapping[str, str]_stringsr"r}rFr_includes_none_schema_translaterONTcCsN||_||_|p|j|_||_|jd|_||_||_i|_|jjdk|_ dS)asConstruct a new ``IdentifierPreparer`` object. initial_quote Character that begins a delimited identifier. final_quote Character that ends a delimited identifier. Defaults to `initial_quote`. omit_schema Prevent prepending schema name. Useful for databases that do not support schemae. r6)rrN) rirr escape_quoteescape_to_quote omit_schemaquote_case_sensitive_collationsrrr)rrirrrrrrrrrts  zIdentifierPreparer.__init__cs@|j|j}|j|jd|kfdd}||_|_|S)Ncs\|j}|jrR|dk srR|dk r>d|ks0d|kr>td|td|pHdddS|jSdS)NrrzJSquare bracket characters ([]) not supported in schema translate name '%s'z __[SCHEMA_%s]_noneFr)r"Z_use_schema_mapr7rOr0)rrZ includes_nonerr symbol_getters z@IdentifierPreparer._with_schema_translate..symbol_getter)r{__new__rrrr)rr]preprrrrrms z)IdentifierPreparer._with_schema_translatecsD|dkr(jstddd<fdd}td||S)Nzschema translate map which previously did not have `None` present as a key now has `None` present; compiled statement may lack adequate placeholders. Please use consistent keys in successive schema_translate_map dictionaries.rcsV|d}|kr|}n|dkr.td|}|sLjj}|sLtd|S)Nr6)Nrzschema translate map which previously had `None` present as a key now no longer has it present; don't know how to apply schema for compiled statement. Please use consistent keys in successive schema_translate_map dictionaries.zLDialect has no default schema name; can't use None as dynamic schema target.)r}r7rriZdefault_schema_namerOr)r!rrdrrrrs  z=IdentifierPreparer._render_schema_translates..replacez(__\[SCHEMA_([^\]]+)\]))rr7rrr*)rrr]rrrrrrs z,IdentifierPreparer._render_schema_translates)rBrcCs&||j|j}|jr"|dd}|S)zEscape an identifier. Subclasses should override this to provide database-dependent escaping behavior. rr)rrrrrrBrrr_escape_identifier s z%IdentifierPreparer._escape_identifiercCs||j|jS)zCanonicalize an escaped identifier. Subclasses should override this to provide database-dependent unescaping behavior that reverses _escape_identifier. )rrrrrrr_unescape_identifiersz'IdentifierPreparer._unescape_identifiercCs*|dk r&||s&td||jf|S)zkeyword sequence filter. a filter for elements that are intended to represent keyword sequences, such as "INITIALLY", "INITIALLY DEFERRED", etc. no special characters should be present. .. versionadded:: 1.3 Nz/Unexpected SQL phrase: %r (matching against %r))r r7rOr)rrrrrrr,!s z&IdentifierPreparer.validate_sql_phrasecCs|j|||jS)z~Quote an identifier. Subclasses should override this to provide database-dependent quoting behavior. )rrrrrrrquote_identifier3s z#IdentifierPreparer.quote_identifiercCs:|}||jkp8|d|jkp8|jt| p8||kS)z5Return True if the given identifier requires quoting.r)r9reserved_wordsillegal_initial_characterslegal_charactersr r)rrBZlc_valuerrrr@s  z#IdentifierPreparer._requires_quotescCs|jt| S)zjReturn True if the given identifier requires quoting, but not taking case convention into account.)rr rrrrrr6Jsz1IdentifierPreparer._requires_quotes_illegal_charsr)r"forcercCs |dk rtjddd||S)aConditionally quote a schema name. The name is quoted if it is a reserved word, contains quote-necessary characters, or is an instance of :class:`.quoted_name` which includes ``quote`` set to ``True``. Subclasses can override this to provide database-dependent quoting behavior for schema names. :param schema: string schema name :param force: unused .. deprecated:: 0.9 The :paramref:`.IdentifierPreparer.quote_schema.force` parameter is deprecated and will be removed in a future release. This flag has no effect on the behavior of the :meth:`.IdentifierPreparer.quote` method; please refer to :class:`.quoted_name`. NzThe IdentifierPreparer.quote_schema.force parameter is deprecated and will be removed in a future release. This flag has no effect on the behavior of the IdentifierPreparer.quote method; please refer to quoted_name().0.9rJ)r%rLr)rr"rrrrrOs  zIdentifierPreparer.quote_schema)rrrcCs|dk rtjdddt|dd}|dkrp||jkr>|j|S||rZ|||j|<n ||j|<|j|Sn|r~||S|SdS)aConditionally quote an identifier. The identifier is quoted if it is a reserved word, contains quote-necessary characters, or is an instance of :class:`.quoted_name` which includes ``quote`` set to ``True``. Subclasses can override this to provide database-dependent quoting behavior for identifier names. :param ident: string identifier :param force: unused .. deprecated:: 0.9 The :paramref:`.IdentifierPreparer.quote.force` parameter is deprecated and will be removed in a future release. This flag has no effect on the behavior of the :meth:`.IdentifierPreparer.quote` method; please refer to :class:`.quoted_name`. NzThe IdentifierPreparer.quote.force parameter is deprecated and will be removed in a future release. This flag has no effect on the behavior of the IdentifierPreparer.quote method; please refer to quoted_name().rrJr)r%rLr8rrr)rrrrrrrvs        zIdentifierPreparer.quotecCs|jr||S|SdSr)rr)rZcollation_namerrrrs z#IdentifierPreparer.format_collationcCs>||j}||}|js:|r:|dk r:||d|}|Sr)rrrrr)rr<r[rrrrrrs  z"IdentifierPreparer.format_sequencez Label[Any]r)rrrcCs||p |jSr)rr)rrrrrrrszIdentifierPreparer.format_labelzOptional[AliasedReturnsRows])rrrcCs.|dkr |dk st||jS||SdSr)rprr)rrrrrrrs  zIdentifierPreparer.format_aliascCs"|p|j}||r||}|Sr)rrr)rZ savepointrrrrrrs   z#IdentifierPreparer.format_savepointzsqlalchemy.sql.namingcCs^tjj}|jtkr.|||j}|dkr4dSn|j}|jdkrL|j||dS|j ||dSdS)Nr>)_alembic_quote) r%r~Z sql_namingrr+Z_constraint_name_for_tablerrtruncate_and_render_index_name#truncate_and_render_constraint_name)rrjrZnamingrrrrrs$  z$IdentifierPreparer.format_constraintcCs|jjp|jj}||||Sr)riZmax_index_name_lengthr _truncate_and_render_maxlen_namerrrmax_rrrrsz1IdentifierPreparer.truncate_and_render_index_namecCs|jjp|jj}||||Sr)riZmax_constraint_name_lengthrrrrrrrsz6IdentifierPreparer.truncate_and_render_constraint_namecCsbt|tjr@t||krL|d|ddt|dd}n |j||sT|S||SdS)Nrr&r) rorrDr.r%Zmd5_hexriZvalidate_identifierr)rrrrrrrrs  ( z3IdentifierPreparer._truncate_and_render_maxlen_namecCs ||Sr)rrrrrrszIdentifierPreparer.format_indexcCsF|dkr|j}||}||}|jsB|rB|rB||d|}|S)z'Prepare a quoted table and schema name.Nr)rrrrr)rrr[rrrrrrrs  zIdentifierPreparer.format_tablecCs ||S)zPrepare a quoted schema name.rrrrrr sz IdentifierPreparer.format_schemacCs(|dk rt|tjr||}||S)Prepare a quoted column name.N)rorrDrr)rrrrrrr%s   z$IdentifierPreparer.format_label_namecCs|dkr|j}|dk r,t|tjr,||}t|ddsh|r\|j|j||dd||S||Sn"|r|j|j||dd|S|SdS)rNrF)r[rr) rrorrDrr8rrr)rrirrZ table_namer[rrrrr3s@     z IdentifierPreparer.format_columncCsD||}|js0|r0|r0|||j|ddfS|j|ddfSdS)z(Format table name and schema as a tuple.FrN)rrrr)rrr[rrrrr`s   z#IdentifierPreparer.format_table_seqcCs@dd|j|j||jfD\}}}td|||d}|S)Ncss|]}t|VqdSr)rrrrrrrssz4IdentifierPreparer._r_identifiers..zM(?:(?:%(initial)s((?:%(escaped)s|[^%(final)s])+)%(final)s|([^\.]+))(?=\.|$))+)initialfinalr)rrrrr)rrrZ escaped_finalrrrr_r_identifiersqs   z!IdentifierPreparer._r_identifierscs(j}fdddd||DDS)z:Unpack 'schema.table.column'-like strings into components.csg|]}|qSr)rrvrrrrsz;IdentifierPreparer.unformat_identifiers..cSsg|]\}}|p|qSrr)rarrrrrs)rfindall)rZ identifiersrrrrunformat_identifierss z'IdentifierPreparer.unformat_identifiers)rONrOTF)N)N)T)N)N)N)T)T)T)TN)N)FNNFN)T).rrrrRESERVED_WORDSrLEGAL_CHARACTERSrILLEGAL_INITIAL_CHARACTERSrrr attrgetterrrrtrmrrrrr,rrr6rrrrrrrr%rrrrrrrrrrrrrrrrrrr_sh   $)    '4        -  r_)r __future__rrCcollections.abcabcrwrenumrr|r8rrtimerrrrrrr r r r r rrrrrrrrrrrrrWrrrrrr r!r"r#r$r%rZ_typingr'r(r)r*r+r,r-r.r/r0r1r2Ztype_apir3Zvisitorsr4r5r7r8Z util.typingr9r:r; annotationr<r=r>rdr?rr@ZdmlrArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSZ engine.cursorrTZengine.interfacesrUrVrWrXrYrZr[r\r]rZ_FromHintsTyperrIrZLEGAL_CHARACTERS_PLUS_SPACErrrr-r.r0UNICODErrrrr or_rmulr*modnegltlenegtgeeqZis_distinct_fromZis_not_distinct_fromZ concat_oprcZ not_match_oprjrirNrPrrrrhexistsZ distinct_opinvZany_opZall_opZdesc_opZasc_opZnulls_first_opZ nulls_last_opZbitwise_xor_opZ bitwise_or_opZbitwise_and_opZbitwise_not_opZbitwise_lshift_opZbitwise_rshift_oprrrmrnrorprrrrrrZcubeZrollupZ grouping_setsrrrZ_CompoundSelectKeywordrZ UNION_ALLrZ EXCEPT_ALLrZ INTERSECT_ALLrrrrrrrrrrr rr$r0r4rr5r6r7r8 namedtupler9rUZ EnsureKWArgrZBinaryElementRoleZCompilerColumnElementrrrrrr5rvr}rr_rrrr st                                                                                            a 1  =w (BL&Lo.!