HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/__pycache__/compiler.cpython-310.pyc
o

���g2�@s	UdZddlmZddlZddlmZddlZddlm	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlZddlmZddlmZddlmZdd	lmZdd
lmZddlmZdd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*m<Z<dd0l*m=Z=dd1l.m>Z>dd2l0m?Z?dd3l@mAZAdd4lBmCZCdd5lBmDZDd6d7l&mEZEd6d&l&m1Z1d6d8l1mFZFd6d9lGmHZHd6d:lGmIZId6d;lGmJZJej$�rEdd<lKmLZLdd=l'mMZMdd>l'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^esfZthd_�Zue
�vd`e
jw�Zxe
�vdae
jw�Zydbdc�ezddd�D��{deg�Z|e
�vdfe
jw�Z}e
�vdfe
jw�Z~e
�vdge
jw�Ze
�vdhe
j��Z�e
�vdie
j��Z�djZ�e�dkdldmdndodp�Z�ie,j�dq�e,j�dr�e,j�ds�e,j�dt�e,j�du�e,j�dv�e,j�dw�e,j�dx�e,j�dy�e,j�dz�e,j�d{�e,j�d|�e,j�d}�e,j�d~�e,j�d�e,j�d��e,j�d��ie,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d��e,j�d���e,j�d�e,j�d�e,j�d�e,j�d�e,j�d�e,j�d�e,j�d�i�Z�e+j�d�e+j�d�e+j�d�e+j�d�e+j�d�e+j�d�e+j�d�e+j�d�e+j�d�e+j�d�e+j�d�e+j�d�e+j�d�e+j�d�iZ�d�e�d�<d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d��Z�e/j�j�d�e/j�j�d�e/j�j�d�e/j�j�d�e/j�j�d�e/j�j�d�iZ�Gd�d��d�e�Z�Gd�dÄd�eI�Z�dZ�d�e�d�<dZ�d�e�d�<d6Z�d�e�d�<d�Z�d�e�d�<Gd�d΄d�eJ�Z�Gd�dЄd�e�d�dҍZ�Gd�dԄd�e�Z�Gd�dքd�e�Z�Gd�d؄d�e�Z�Gd�dڄd�eF�Z�Gd�d܄d�e	�Z�Gd�dބd�e	�Z�e�eՃ\Z�Z�Z�Z�Gd�d�d�e��d�d�d�g��Z�Gd�d�d�Z�Gd�d�d�e1jރZ�Gd�d�d�e-j�ee*j�Z�Gd�d�d�e-j�ee*j�Z�Gd�d�d�e݃Z�Gd�d�d�e�Z�Gd�d�d�e݃Z�Gd�d�d�e߃Z�Gd�d�d�e�Z�Gd�d��d�eI�Z�Gd�d��d�eI�Z�Gd�d��d��Z�dS)�a]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)�util��is_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)�SchemaTranslateMapTyperN>^�as�do�in�is�on�or�to�all�and�any�asc�end�for�new�not�off�old�set�both�caser�desc�else�from�full�into�join�left�like�null�only�some�then�true�user�when�array�check�cross�false�grant�group�ilike�inner�limit�order�outer�right�table�union�using�where�binary�column�create�except�freeze�having�isnull�offset�select�unique�analyse�analyze�between�collate�default�foreign�leading�natural�notnull�placing�primary�similar�verbose�distinct�overlaps�trailing�	initially�	intersect�	localtime�	symmetric�
asymmetric�
constraint�
deferrable�
references�current_date�current_role�current_time�current_user�session_user�
authorization�localtimestamp�current_timestampz
^[A-Z0-9_$]+$z^[A-Z0-9_ $]+$cCsh|]}t|��qS�)�str)�.0�xr�r��B/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/compiler.py�	<setcomp>��r��
�$z5^(?:RESTRICT|CASCADE|SET NULL|NO ACTION|SET DEFAULT)$z^(?:DEFERRED|IMMEDIATE)$z%(?<![:\w\$\x5c]):([\w\$]+)(?![:\w\$])z\x5c(:[\w\$]*)(?![:\w\$])z
%%(%(name)s)s�?z%%sz:[_POSITION]z$[_POSITION]z	:%(name)s)�pyformat�qmark�format�numeric�numeric_dollar�namedz AND z OR z + z * z - � % �-z < z <= z != 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 >> �coalesce�CURRENT_DATE�CURRENT_TIME�CURRENT_TIMESTAMP�CURRENT_USER�	LOCALTIME�LOCALTIMESTAMP�random�sysdate�SESSION_USER�USER�CUBE�ROLLUPz
GROUPING SETSzDict[Type[Function[Any]], str]�	FUNCTIONS�month�day�year�second�hour�doy�minute�quarter�dow�week�epoch�milliseconds�microseconds�
timezone_hour�timezone_minute)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��UNIONz	UNION ALL�EXCEPTz
EXCEPT ALL�	INTERSECTz
INTERSECT ALLc@s8eZdZUdZded<	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.

    r��keyname�name�Tuple[Any, ...]�objects�TypeEngine[Any]�typeN��__name__�
__module__�__qualname__�__doc__�__annotations__r�r�r�r�r�[s
	r�c@seZdZd
d
d�ZdS)�_ResultMapAppenderr�r�r�r��
Sequence[Any]�type_r��return�NonecC�dS�Nr���selfr�r�r�rr�r�r��__call__{�z_ResultMapAppender.__call__N)
r�r�r�r�r�r�rr�rr�r�r�r�rr�r�r�r�r�z�r�z
Literal[0]�RM_RENDERED_NAMEz
Literal[1]�RM_NAMEz
Literal[2]�
RM_OBJECTS�z
Literal[3]�RM_TYPEc@s&eZdZUded<ded<ded<dS)�_BaseCompilerStackEntryzSet[FromClause]�asfrom_froms�correlate_fromsrPr#N�r�r�r�r�r�r�r�r�r�s
rc@s6eZdZUded<ded<ded<ded<ded	<d
S)�_CompilerStackEntryr>�
compile_state�bool�need_result_map_for_nested�need_result_map_for_compoundrP�select_0�Select[Any]�insert_from_selectNrr�r�r�r�r�s
rF)�totalc@s`eZdZUdZded<	ded<	ded<	ded	<	d
ed<	eddd��Zeddd��ZdS)�
ExpandedStatea�represents 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]]�
processors�Optional[Sequence[str]]�positiontupzMapping[str, List[str]]�parameter_expansionrr�cs,�jdur
t�d��t�fdd��jD��S)zrTuple of positional parameters, for statements that were compiled
        using a positional paramstyle.

        Nz.statement does not use a positional paramstylec3s�|]}�j|VqdSr�r�r��key�rr�r��	<genexpr>�s�z6ExpandedState.positional_parameters.<locals>.<genexpr>)r#r7�InvalidRequestError�tupler(r�r(r��positional_parameters�s

�z#ExpandedState.positional_parameterscC�|jS)z.synonym for :attr:`.ExpandedState.parameters`.r%r(r�r�r��additional_parameters�sz#ExpandedState.additional_parametersN)rr�)rrU)r�r�r�r�r��propertyr,r.r�r�r�r�r�s 
	rc@s�eZdZUdZded<	ded<	ded<	ded	<	d
Zded<	d
Zded<	d
Zded<	dZded<	d
Z	ded<	d
Z
ded<	d
Zded<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

    r�is_default_exprr��single_values_expr�List[crud._CrudParamElementStr]�insert_crud_params�int�num_positional_params_countedF�sort_by_parameter_order�includes_upsert_behaviorsN�Optional[Sequence[Column[Any]]]�sentinel_columnsr�num_sentinel_columnsr"�sentinel_param_keys�implicit_sentinel�embed_values_counter)r�r�r�r�r�r7r8r:r;r<r=r>r�r�r�r�r0�s0


r0c@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

    r��replaced_statementrV�replaced_parameters�#Optional[_GenericSetInputSizesType]�processed_setinputsizesz#Sequence[_DBAPISingleExecuteParams]�batchzSequence[Tuple[Any, ...]]�sentinel_valuesr5�current_batch_size�batchnum�
total_batchesr�rows_sorted�
is_downgradedNr�r�r�r�r�r?Ns
r?c@s<eZdZdZdZdZdZdZeeBeBZeeBZ	dZ
dZdS)	�InsertmanyvaluesSentinelOptszcbitflag enum indicating styles of PK defaults
    which can work as implicit sentinel columns

    rr6����@N)r�r�r�r��
NOT_SUPPORTED�
AUTOINCREMENT�IDENTITY�SEQUENCE�ANY_AUTOINCREMENT�_SUPPORTED_OR_NOT�USE_INSERT_FROM_SELECT�RENDER_SELECT_COL_CASTSr�r�r�r�rKgsrKc@seZdZdZ	dZ	dZdS)�
CompilerStaterrr6N)r�r�r��	COMPILING�STRING_APPLIED�NO_STATEMENTr�r�r�r�rXysrXc@s*eZdZdZdZ	dZ	dZ	eeBZdS)�Lintingz�represent preferences for the 'SQL linting' feature.

    this feature currently includes support for flagging cartesian products
    in SQL statements.

    rrr6N)r�r�r�r��
NO_LINTING�COLLECT_CARTESIAN_PRODUCTS�WARN_LINTING�FROM_LINTINGr�r�r�r�r\�sr\c@s$eZdZdZddd�Zd	dd�ZdS)
�
FromLinterzKrepresents current state for the "cartesian product" detection
    feature.Ncs�|j}|sdSt|j�}t|�}|dur|}|�|�n|��}t�|g�}|rQ|rQ|���|����fdd�|D�}|�	�fdd�|D��|�
|�|rQ|s*|rW||fSdS)N�NNcsh|]}�|vr|�qSr�r��r��edge��noder�r�r���z"FromLinter.lint.<locals>.<setcomp>c3s �|]}||���VqdSr)�indexrcrer�r�r)�s�z"FromLinter.lint.<locals>.<genexpr>)�fromsro�edges�remove�pop�collections�deque�popleft�discard�
extendleft�difference_update)r�startrirj�the_rest�
start_with�stack�	to_remover�rer��lint�s(


�zFromLinter.lint�SELECTcs`���\}}|r,|}|r.d}d��fdd�|D��}|j||�j|d�}t�|�dSdSdS)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.r�c3s"�|]}d�j|�d�VqdS)�"N)ri)r��from_r(r�r�r)�s�
�z"FromLinter.warn.<locals>.<genexpr>)�	stmt_typerirs)rxrwr�rir%�warn)rr|rtruri�template�	froms_str�messager�r(r�r}�s"����zFromLinter.warnr)ry)r�r�r�r�rxr}r�r�r�r�ra�s
%rarirjcs@eZdZUdZdZded<	dZded<	ded	<	d
Zd
ZdZ	ded<dZ
d
ed<dZded<ej
Zded<	ded<ej
Zded<dZded<	dZded<	dZded<	ded<	dd
e��fdEd$d%�ZdF�fd(d)�Zed*d+��Zd,d-�Zd.d/�Zed0d1��ZdGd6d7�ZdHd8d9�Z			:dIdJdAdB�ZedCdD��Z�Z S)K�CompiledaRepresent 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.
    N�Optional[ClauseElement]r�r��stringrX�stateFzOptional[CursorResultMetaData]�_cached_metadataz"Optional[List[ResultColumnsEntry]]�_result_columns� Optional[SchemaTranslateMapType]�schema_translate_maprY�execution_options�IdentifierPreparer�preparerr<�_annotationszOptional[CompileState]r�dml_compile_state�Optional[CacheKey]�	cache_key�float�	_gen_time�dialectr\�render_schema_translater�compile_kwargs�Mapping[str, Any]cCs�||_|jj|_|r||_|j�|�|_|durRtj|_||_|j	|_
|j|_|j
r7tr3t
|t�s3J�|j|_|j|jfi|��|_|rM|j�|j|�|_tj|_ntj|_t�|_dS)a�Construct 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)r��identifier_preparerr�r��_with_schema_translaterXrYr�r�supports_execution�can_executer�r�
isinstancer-�_execution_optionsr��processr��_render_schema_translatesrZr[rr��rr�rr�r�r�r�r�r��__init__;s0
��
zCompiled.__init__rrcs|��t���Sr)�_init_compiler_cls�super�__init_subclass__��cls��	__class__r�r�r�ss
zCompiled.__init_subclass__cCrrr�r�r�r�r�r�w�zCompiled._init_compiler_clscCs |jr
|�|||�St�|j��r)r��_execute_compiledr7�ObjectNotExecutableErrorr)r�
connection�distilled_paramsr�r�r�r��_execute_on_connection{s
�zCompiled._execute_on_connectioncKst�|t|��|�r�r7�UnsupportedCompilationErrorr��r�element�err�kwr�r�r��visit_unsupported_compilation��z&Compiled.visit_unsupported_compilationcC�t��)z�Return a Compiled that is capable of processing SQL expressions.

        If this compiler is one, it would likely just return 'self'.

        ��NotImplementedErrorr(r�r�r��sql_compiler�szCompiled.sql_compiler�objr5�kwargsrcKs|j|fi|��Sr��_compiler_dispatch)rr�r�r�r�r�r��r�zCompiled.processcCs|jtjur	|jSdS)z3Return the string text of the generated SQL or DDL.r�)r�rXrZr�r(r�r�r��__str__�szCompiled.__str__T�params�"Optional[_CoreSingleExecuteParams]�extracted_parameters�&Optional[Sequence[BindParameter[Any]]]�escape_names�)Optional[_MutableCoreSingleExecuteParams]cCr�)z�Return 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.
        r��rr�r�r�r�r�r��construct_params�s
zCompiled.construct_paramscCs|��S)z0Return the bind params for this compiled object.�r�r(r�r�r�r��szCompiled.params)
r�r\rr�r�r�r�rr�r�)rr)r�r5r�rrr�)rr��NNT�r�r�r�r�r�rrr�)!r�r�r�r�rr�r��is_sql�is_ddlr�r�r�r%�
EMPTY_DICTr�r�rr�r��
immutabledictr�r��classmethodr�r�r�r/r�r�r�r�r��
__classcell__r�r�r�r�r��sX
�8



	

�r�c@s2eZdZdZdZddd�Zdd
d�Zddd�ZdS)�TypeCompilerz2Produces DDL specification for TypeEngine objects.z	visit_\w+r�r\cCs
||_dSr)r�)rr�r�r�r�r���
zTypeCompiler.__init__rr�r�rrr�cKs4|jr|jj|jvr|j|jj}|j|fi|��Sr)�_variant_mappingr�r�r��rrr�r�r�r�r��s
�zTypeCompiler.processr�r��	ExceptionrcKst�||�|�r)r7r�r�r�r�r�r��sz*TypeCompiler.visit_unsupported_compilationN)r�r\)rr�r�rrr�)r�rr�r�r�rrr)r�r�r�r��ensure_kwargr�r�r�r�r�r�r�r��s

r�c@sBeZdZdZdZdZddd�Zedd��Zed	d
��Z	dd�Z
d
S)�
_CompileLabelz;lightweight label object which acts as an expression.Label.�label�r�r��
_alt_namesr�cCs||_||_|f||_dSrr�)r�colr��	alt_namesr�r�r�r��sz_CompileLabel.__init__cC�|jjSr�r��	proxy_setr(r�r�r�r���z_CompileLabel.proxy_setcCr�r�r�r�r(r�r�r�r��r�z_CompileLabel.typecK�|Srr��rr�r�r�r��
self_group��z_CompileLabel.self_groupN)r�)r�r�r�r��__visit_name__�	__slots__r�r/r�r�r�r�r�r�r�r��s


r�c@sHeZdZdZdZdZdd�Zedd��Zedd	��Z	d
d�Z
dd
�ZdS)�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

    �ilike_case_insensitive_operand�r��
comparatorcCs||_|j|_dSrr�)rr�r�r�r�r��szilike_case_insensitive.__init__cCr�rr�r(r�r�r�r��r�z ilike_case_insensitive.proxy_setcCr�rr�r(r�r�r�r��r�zilike_case_insensitive.typecKr�rr�r�r�r�r�r�r�z!ilike_case_insensitive.self_groupcCst|j�|��Sr)r�r��_with_binary_element_type)rrr�r�r�r�s
�z0ilike_case_insensitive._with_binary_element_typeN)r�r�r�r�r�r�r�r/r�r�r�r�r�r�r�r�r��s

r�c@seZdZUdZeZe�ddddddddd��Zde	d	<	d
e	d<de	d<d
Z
eZ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<e	d=<	e"�Z$d<e	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.�/dN�Z0e.�/dO�Z1e.�/e1j2�dPe0j2���Z3e4dQdR��Z5e4dSdT��Z6ddde7df�d
ddde�Z8e9�ddgdh��Z:ej;�ddidj��Z<e9dkdl��Z=e9dmdn��Z>e9dodp��Z?ej@�ddrds��ZAejB�ddudv��ZCeDjEdwdx��ZFdydz�ZGd{d|�ZHej@�dd~d��ZId�d��ZJe9d�d���ZK		
�d�dd�d��ZL			
		
	�d�dd�d��ZMejBd�d���ZNe9d�d���ZO	�d�dd�d��ZPe�Qd��d�d���ZRd�e	d�<ej@�dd�d���ZSej@e�Qd��d�d����ZTej@e�Qd��d�d����ZUd�d��ZVd�d��ZW�dd�d��ZXd�d��ZY	�dd�d��ZZ	�dd�d��Z[					�dd�d��Z\d�d��Z]d�d��Z^		
		�d�dd�dĄZ_d�dƄZ`d�dȄZad�dʄZbd�d̄Zcd�d΄Zdd�dЄZe�dd�d҄Zf	�dd�dԄZgd�dքZhd�d؄Zid�dڄZjd�d܄Zkd�dބZld�d�Zmd�d�Znd�d�Zod�d�Zpd�d�Zqd�d�Zrd�d�Zsd�d�Ztd�d�Zud�d�Zvd�d�Zwd�d��Zx	�d�dd�d��Zyd�d��Zzd�d��Z{d��d�Z|	�d �d�d�Z}�d�d�Z~�d�d�Z	�d!�d�d�Z��d	�d
�Z��d�d�Z��d
�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z�	�d�d�d�Z��d�d�Z�				�d"�d�d�Z��d�d �Z��d!�d"�Z��d#�d$�Z��d%�d&�Z��d'�d(�Z�	�d�d)�d*�Z��d+�d,�Z��d-�d.�Z�ej@�d/�d0��Z��d1�d2�Z��d3�d4�Z��d5�d6�Z��d7�d8�Z��d9�d:�Z��d;�d<�Z��d=�d>�Z��d?�d@�Z��dA�dB�Z��dC�dD�Z��dE�dF�Z��dG�dH�Z��dI�dJ�Z��dK�dL�Z��dM�dN�Z��dO�dP�Z��dQ�dR�Z��dS�dT�Z��dU�dV�Z��dW�dX�Z��dY�dZ�Z��d[�d\�Z�					�d#�d]�d^�Z��d_�d`�Z�e�df�da�db�Z��dc�dd�Z��de�df�Z��d$�dj�dk�Z��d%�dl�dm�Z�						�d&�d'�dw�dx�Z��dy�dz�Z�ddddde���d�f�d(�d��d��Z��d��d��Z��d��d��Z�								�d)�d��d��Z��d��d��Z��d��d��Z��d�d��d��Z��d��d��Z��d �d��d��Z��d��d��Z��d��d��Z��d*�d��d��Z�	�d�d��d��Z�				
			
�d+�d��d��ZĐd��d��ZŐd��d��ZƐd��d��Zǐd��d��ZȐd��d��Zɐd�e	�d�<e�jːs�e��d�e"�f�d�e"�fg�Z�	�d�d��d��Z�dZ�dce	�d�<								�d,�d��d��Zϐd-�d��d��ZАd��d��ZѐddÄZҐdĐdńZ�		�d�dƐdDŽZԐdȐdɄZՐdʐd˄Z֐d̐d̈́ZאdΐdτZؐdАdфZِd.�dאd؄ZڐdِdڄZ�			�d/�dېd܄Z�					
		�d0�dݐdބZݐd �dߐd�Zސd�d�Z�e�e�j�e�j�e�j�e�j�e�j�e�j�e�j�e�j�e�j�e�j�i�Z�e��e�j�e�j�i�Z�d1�d�d�Z�d2�d�d�Z�	�d3�d��d��Z�d��d��Z�d��d��Z�d��d��Z�d��d��Z�d�d��d�Z�d�d�Z�d�d�Z��d�d�d�Z��d�d�Z��d	�d
�Z��d�d�Z�dS(4�SQLCompilerz~Default implementation of :class:`.Compiled`.

    Compiles :class:`_expression.ClauseElement` objects into SQL strings.

    �P�A�Z�C�_)�%�(�)�:�.�[�]� zClassVar[Mapping[str, str]]�bindname_escape_characterszClassVar[Pattern[str]]�_bind_translate_re�_bind_translate_charsTFr�isdelete�isinsert�isupdatezOptional[List[Column[Any]]]�	postfetchr�zSequence[Column[Any]]�insert_prefetch�update_prefetchN�&Optional[Sequence[ColumnElement[Any]]]�implicit_returning�isplaintextzDict[str, BindParameter[Any]]�bindszDict[BindParameter[Any], str]�
bind_nameszList[_CompilerStackEntry]rv�returning_precedes_values�'render_table_with_column_in_update_from�ansi_bind_rulesr��bindtemplate�compilation_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_string�Optional[List[str]]�_pre_expanded_positiontupzOptional[_InsertManyValues]�_insertmanyvaluesz!Optional[crud._CrudParamSequence]�_insert_crud_paramszFrozenSet[BindParameter[Any]]�literal_execute_params�post_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_bindparam�inlinez"Optional[MutableMapping[CTE, str]]�cteszDict[Tuple[int, str], CTE]�ctes_by_level_namez/Dict[CTE, Tuple[int, str, selectable._CTEOpts]]�level_name_by_cte�ctes_recursivez"__\[POSTCOMPILE_(\S+?)(~~.+?~~)?\]z%\(([^)]+?)\)s�|cCs|��dSr)�_init_bind_translater�r�r�r�r�2szSQLCompiler._init_compiler_clscCs2t�d�|j��}t�d|�d��|_|j|_dS)Nr�r�r�)�re�escaperwr��compiler�r�)r��regr�r�r�r'6sz SQLCompiler._init_bind_translater�r\rr�r�r��column_keysr"�for_executemany�lintingr\�_supporting_against�Optional[SQLCompiler]r�rc
Ks�||_||_|rdd�|dD�}	dd�|dD�}
|
|	f|_||_||_i|_t��|_g|_	g|_
|j|_|jrS|j�
d�|_}|rO|jdkrLdnd|_t|_nt|j|_d	|_|jpa|j|_t�|_i|_i|_tj|||fi|��|js�|js�|jr�tr�t |t!�s�J�|js�|jr�tr�t |t"�s�J�|j#r�d
|_$n|jr�|jr�|j%j&r�|j'r�d
|_$t|j|_(|r�|j)�*dd�|j)�+�D��|j,t-j.ur�|jr�|jr�|�/�n|�0�|j1r�|j2dd
d
�}|j3|d
d�d	Sd	Sd	S)a�Construct 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|�qSr��r'�r��br�r�r��
<dictcomp>ar�z(SQLCompiler.__init__.<locals>.<dictcomp>rcSsi|]}||g�qSr�r�r2r�r�r�r4br�r�r�r�r�NTcSsi|]\}}|dvr||�qS)>r�r�r��
positionalrrrr��r��k�vr�r�r�r4�s��F�r��_no_postcompile)�_populate_self)4r,r�rr-r.rr%�column_dictrrvr�r5�
paramstyle�
startswithrr
�_pyformat_templater�BIND_TEMPLATESr"�label_length�max_identifier_lengthr4�anon_map�truncated_names�_truncated_countersr�r�r�r�r�rr�rBrC�_inliner!r��insert_executemany_returning�_return_defaultsr�__dict__�update�itemsr�rXrZ�_process_numeric�_process_positionalrr��#_process_parameters_for_postcompile)
rr�rr�r,r-r.r/r��cksm�ckbm�nbrr�r�r�r�<s� 

�
������
�
��zSQLCompiler.__init__rcCs|jdurdS|jjS)a�When 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)rr2r(r�r�r��insert_single_values_expr�s
z%SQLCompiler.insert_single_values_exprcCs6|jr|jS|jdurt|j�rdd�|jjD�SdS)a�The 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|�qSr�r&�r��cr�r�r��
<listcomp>�s��z3SQLCompiler.effective_returning.<locals>.<listcomp>)rrr(�_all_selected_columnsr(r�r�r��effective_returning�s
�zSQLCompiler.effective_returningcCr-)zVbackwards compatibility; returns the
        effective_returning collection.

        )rWr(r�r�r��	returning�szSQLCompiler.returningc
Cs4z|jddWSty}ztd�|�d}~ww)a�Return 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)rv�
IndexError)r�ier�r�r��current_executables
��zSQLCompiler.current_executablecCst|j�t|j�Sr)�listrrr(r�r�r��prefetch%szSQLCompiler.prefetch�Dict[Any, Any]cCsiSrr�r(r�r�r��_global_attributes)r�zSQLCompiler._global_attributes�MutableMapping[CTE, str]cCs$t��}||_i|_i|_d|_|S)z�Initialize collections related to CTEs only if
        a CTE is located, to save on the overhead of
        these collections otherwise.

        F)r%�OrderedDictr"r#r$r%)rr"r�r�r��_init_cte_state-s	zSQLCompiler._init_cte_statec	cs��|j|j}}gd|_|_z'|jr|jd}d|d<nd}|j|jfVW|r.|�d�|||_|_dS|r>|�d�|||_|_w)z;special API to support the use case of 'nested result sets'FrYTrN)r�rrvrl)r�result_columns�ordered_columns�entryr�r�r��_nested_resultEs*��


��
�zSQLCompiler._nested_resultcs�jrJ��jtjus
J��jrJ��jjdkrd�n
�jjdks#J�d�g�d��fd	d
��t��j	��j
��_
�jr\dd��j��D��t
�j�t
��ksQJ��fd
d��D��_n��_�jr�g�t��j	��jj�}��fdd��jjD�}�jj||d��_dSdS)Nr��%sr�r��m�
re.Match[str]rr�cs6|�d�}|r��|��S��|�d��|�d�S)Nrr6r)r��append)ri�normal_bind)�placeholder�	positionsr�r��
find_positionjs


z6SQLCompiler._process_positional.<locals>.find_positioncS�i|]\}}||�qSr�r�r6r�r�r�r4y�z3SQLCompiler._process_positional.<locals>.<dictcomp>csg|]}��||��qSr���get�r�r�)�reverse_escaper�r�rU{s�z3SQLCompiler._process_positional.<locals>.<listcomp>c
s4g|]}|d|dt��j�|d�|df�qS)rrr6r)r(�sub�_positional_pattern�r�r8)rorr�r�rU�s����r2r4)rirjrr�)r#r�rXrZrr�r=r(rvrwr�rrK�lenrr2r4�_replace)rr2r4r�)rormrnrurr�rM]sD



�

���
��zSQLCompiler._process_positionalc	sZ�jsJ��jtjus
J�d}i��jr-�jdur-t��fdd��j�	�D��j�	��}n�j�	�}|D]*}|�vr;q4�j
|}|�jvsJ|�jvrOd�|<q4�j
�|��}|d7}|�|<q4|�_t���_�jr�t��}�fdd����D��t��|ks�J��j��fdd��j��_�jr��jj�}dd	��jjD�}�jj||d
��_dSdS)Nrc3s�|]
}|�jvr|VqdSr)rrtr(r�r�r)�s�
��z/SQLCompiler._process_numeric.<locals>.<genexpr>cs i|]\}}�j�||�|�qSr�)rrs)r�r��posr(r�r�r4����z0SQLCompiler._process_numeric.<locals>.<dictcomp>c��|�d�S�Nr�r��ri��	param_posr�r��<lambda>��z.SQLCompiler._process_numeric.<locals>.<lambda>cSs$g|]}|d|dd|df�qS)rrrhrr�rxr�r�r�rU�s��z0SQLCompiler._process_numeric.<locals>.<listcomp>ry)rr�rXrZrr�	itertools�chainr�valuesrrrr
�next_numeric_posr]r#rrzrK�_pyformat_patternrvr�r2r4r{)	r�numr��	bind_name�bind�ph�
len_beforer2r4r�)r�rr�rL�s\

��
	






�������zSQLCompiler._process_numeric�VMutableMapping[str, Union[_BindProcessorType[Any], Sequence[_BindProcessorType[Any]]]]csdd��fdd��jD�D�S)NcSsi|]\}}|dur||�qSrr��r�r'�valuer�r�r�r4�s
�z0SQLCompiler._bind_processors.<locals>.<dictcomp>c3sP�|]#}�j||jjs|j��j�nt�fdd�tt|j�jD��fVqdS)c3s�|]	}|��j�VqdSr)�_cached_bind_processorr�)r��	elem_typer(r�r�r)��
�
�
�z9SQLCompiler._bind_processors.<locals>.<genexpr>.<genexpr>N)	rr��_is_tuple_typer�r�r+rr2�types)r��	bindparamr(r�r�r)�s������
�z/SQLCompiler._bind_processors.<locals>.<genexpr>)rr(r�r(r��_bind_processors�s

��zSQLCompiler._bind_processorscCst|j�dkSr)rzrvr(r�r�r��is_subquery��zSQLCompiler.is_subquerycCr�rr�r(r�r�r�r�r�zSQLCompiler.sql_compilerr�r�r�rcCs|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

        Tr9)r�rN)rr�r�rr�r�r��construct_expanded_states��z$SQLCompiler.construct_expanded_stater�r��
_group_number�
Optional[int]�_checkr:r[cs
|jr|s|jdusJ�|st|jj�St�d��|ot|j�}|rK|jdur,t�	d��|jd}|j
}	|	dus:J�|	\�}
�fdd�t||�D�}nd}|r�i}|j�
�D]]\}
}|rc|j�||�n|}|
j|vrr||
j||<qV||vr}||||<qV|r�|
jr�|r�tjd|
j|fdd	��tjd
|
jdd	��|r�|�|
|
�}n|
}|
jr�|j||<qV|j||<qV|Si}|j�
�D]E\}
}|r�|j�||�n|}|r�|
jr�|r�tjd|
j|fdd	��tjd
|
jdd	��|r�|�|
|
�}n|
}|
jr�|j||<q�|j||<q�|S)z5return a dictionary of bind parameter keys and valuesNz�can'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]}||�q
qSr�r�)r�r3�	extractedr��rPr�r�r4Gs���z0SQLCompiler.construct_params.<locals>.<dictcomp>z@A value is required for bind parameter %r, in parameter group %d�cd3x)�codez)A value is required for bind parameter %r)rr�dictrr7r*rrr��CompileErrorr�ziprrKrsr'�required�callable�effective_valuer�)rr�r�r�r�r�r:�has_escaped_names�orig_extracted�
ckbm_tupler��resolved_extracted�pdr�r��escaped_name�value_paramr�r�r�r�s�
�
�

���

�������
����zSQLCompiler.construct_paramscs�|j��j��j��j�����fdd��i}|j}|jD]#}||vr$q|jjr9�fdd�tt	|j�j
D�||<q�|j�||<q|S)Ncs@|������}|dur�dus|�vr�dus|�vr|SdSr)�_unwrapped_dialect_impl�get_dbapi_type)�typ�dbtype)�dbapir��
exclude_types�
include_typesr�r��lookup_type�sz<SQLCompiler._get_set_input_sizes_lookup.<locals>.lookup_typec�g|]}�|��qSr�r�)r�r�)r�r�r�rU�s��z;SQLCompiler._get_set_input_sizes_lookup.<locals>.<listcomp>)r��include_set_input_sizes�exclude_set_input_sizesr�rrr�r�rr2r�)r�
inputsizesrr�r�)r�r�r�r�r�r��_get_set_input_sizes_lookup�s 

�z'SQLCompiler._get_set_input_sizes_lookupcCs|jdd�S)z�Return 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)r�r�r(r�r�r�r��szSQLCompiler.paramsrr;cs�i}�j}|dur�j}�jrg}�j}|dur�j}nd}}�j}td|��td|��i}i�i}	d}
�jrD|durD|}�jrCg}
n�j�	�}�j
}|D]��|rX|����n�}
�j�}|�j
vru|
�vrt�j||�|
�d��|
<qN|�jvr�|
�vr�|	|
}d}n|���}��|
||�}|\}}||	|
<|�|
<|js�|�|�|jjr�|dus�J�|���fdd�t|d�D��n
|���fdd�|D��|
dur�|
�d	d�|D��n|dur�|�d
d�|D��dd�|D�|�<qN|dur�|���qN�fd
d�}t��j||�}|
du�r5|du�sJ��fdd�t|
�j�D���j��fdd�|�}|�|
�t|||||�}|�r\|�_|�_|j�_�j�rVt |j�pTd�nd�_|�_!|S)a�handle 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.

        Nr z/Mapping[str, Sequence[_BindProcessorType[Any]]]��render_literal_valuec3sb�|],\}}t|d�D]"\}}��vr-��|ddurd�||f��|dfVqqdS)rN�%s_%s_%s��	enumerate)r��i�
tuple_element�jr�)r��tuple_processorsr�r�r)=s�����zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>rc3s(�|]\}}��vr|��fVqdSrr�)r�r'r�)r��single_processorsr�r�r)Hs�
��cs��|]\}}|VqdSrr��r�r�r�r�r�r�r)Ns�
�csr�rr�r�r�r�r�r)Us�cSsg|]\}}|�qSr�r�)r��
expand_keyr�r�r�r�rUVs�zCSQLCompiler._process_parameters_for_postcompile.<locals>.<listcomp>csb|�d�}�|}|�d�r/|�d��d�}|d|d��d���fdd�|�d�D��}|S)Nrr6�~~rr�c3s�|]
}d�|�fVqdS�z%s%s%sNr�)r��exp��be_left�be_rightr�r�r)e�
��
�z]SQLCompiler._process_parameters_for_postcompile.<locals>.process_expanding.<locals>.<genexpr>)r��splitrw)rir'�expr�tok)�replacement_expressionsr�r��process_expanding\s

�zJSQLCompiler._process_parameters_for_postcompile.<locals>.process_expandingcs i|]\}}|�j�|���qSr��r
)r�r�r'r(r�r�r4qr}zCSQLCompiler._process_parameters_for_postcompile.<locals>.<dictcomp>cr~rr�r�r�r�r�r�yr�zASQLCompiler._process_parameters_for_postcompile.<locals>.<lambda>r�)"rr�r5rr#r�rrrr�rrsrr�render_literal_bindparamrlr�$_literal_execute_expanding_parameter�literal_executerJr�r�r��extendrkr(rv�_post_compile_patternr�r�rrr]r)rrr;�expanded_parameters�pre_expanded_string�new_positiontup�pre_expanded_positiontupr!�new_processors�to_update_sets�numeric_positiontup�names�ebnr��	parameter�	to_updater��leep_res�replacement_exprr�r�expanded_stater�)r�r�r�rr�r�r�rN�s����	�


��


�

��

�
��
��

���
���z/SQLCompiler._process_parameters_for_postcompilezsqlalchemy.engine.cursorcCstjj}|j�|j�S)z(utility method used for unit tests only.)r%�	preloaded�
engine_cursorrT�_create_description_match_mapr�)r�cursorr�r�r��_create_result_map�s�zSQLCompiler._create_result_map�_BindNameForColProtocol�_get_bind_name_for_col�Callable[[Any], str]cCs
|j}|Sr)r�)r�getterr�r�r��_within_exec_param_key_getter�sz)SQLCompiler._within_exec_param_key_getterzsqlalchemy.engine.resultcs�tjj}|j�|jdusJ�|jj}trt|t�sJ�|j	}�fdd�|j
D��d�|j��durK�j�
|jd�������|jvrJ�fdd�}|�nd�|�dd�|j
D��������fdd�}|S)Ncs"g|]
}t�d�|�d�|f�qS)rsN)�operator�methodcaller�r�r�)�param_key_getterr�r�rU�s��zKSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.<listcomp>cs|��|�}|dur|S|Srrr)�	lastrowidr�param_value)�autoinc_keyr�r��_autoinc_getter�szPSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>._autoinc_gettercS�g|]}|j�qSr�r1r�r�r�r�rU��csJ�dur�����dur��fdd��D��S�����fdd��D��S)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�|]	\}}|��VqdSrr��r�r�r�r%r�r�r)���zWSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get.<locals>.<genexpr>c3s:�|]\}}|�ur�dur����n�n|��VqdSrr�r�)�autoinc_col�autoinc_getterr�rr�r�r)�s�
��
�
�r��r�r)rr�getters�lastrowid_processor�row_fnrr�rs�s
�zDSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get)r%r��
engine_resultr�rrrr�rAr��primary_key�_autoincrement_columnr��_cached_result_processorr�r�result_tuple)r�resultrr�r�rsr�)rrr�rrr�rr��+_inserted_primary_key_from_lastrowid_getter�s2
��

�z7SQLCompiler._inserted_primary_key_from_lastrowid_gettercs�tjr
ddlm}ntjj}|jdusJ�|jj}tr"t	|t
�s"J�|j�|j}|j
}|dus1J�dd�t|�D��td��fdd�|jD���|�dd�|jD�����fd	d
�}|S)Nr6)rcSrpr�r�)r��idxr�r�r�r�r4	rqzKSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.<dictcomp>z'List[Tuple[Callable[[Any], Any], bool]]cs<g|]}|�vrt��|�dfn
t�d�|�d�df�qS)TrsNF)r��
itemgetterr�r�)r��retr�r�rU	s��
���zKSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.<listcomp>cSr�r�r1r�r�r�r�rU	r�cs���fdd��D��S)Nc3s(�|]\}}|r|��n|��VqdSrr�)r�r��use_row�r�rowr�r�r)"	s
��
�zWSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.get.<locals>.<genexpr>r�)rr)rrrr�rs!	s�zDSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.get)�typingr�enginerr%r�rrrr�rAr�r�rr�rrr)rrrr�rXrsr�)rr�rrr��+_inserted_primary_key_from_returning_getter�s*��z7SQLCompiler._inserted_primary_key_from_returning_gettercC�dS)z�Called when a SELECT statement has no froms, and no FROM clause is
        to be appended.

        Gives Oracle Database a chance to tack on a ``FROM DUAL`` to the string
        output.

        r�r�r(r�r�r��default_from)	szSQLCompiler.default_fromcKs�|jj|fi|��}|jD]n}||jvrq
|j|}|j|j|jddd�}|j|}||j|<|j|<||j|<|j�|d�||jvrN|j|hO_||j	vr[|j	|hO_	|j
}|r{|\}	}
|jD]}|j|
vrz|
|j}|	|�|�qgq
|S)a�SQL 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)�maintain_keyr�N)
r�r��	translater�_with_valuer'rrlrrr�_cloned_setrk)r�override_bindsr��sqltextr7�bp�new_bpr�r�rPrO�cbr�r�r��visit_override_binds3	s6
	

	
�






�z SQLCompiler.visit_override_bindscKsd|jj|fi|��dS�Nr�r��r�r�)r�grouping�asfromr�r�r�r��visit_groupings	�zSQLCompiler.visit_groupingcKsd|jj|fi|��dSr#r$)rr%r�r�r�r��visit_select_statement_groupingv	r(z+SQLCompiler.visit_select_statement_groupingc
Ks�|jrN|jjrNztd|jdd�}Wnty%}zt�d�|�d}~ww|j\}}}|r1|}	n|}	|jj	}
|
durN|
j
|	vrN|
�|	|
j
�rN|jj	|d<|j|jfd|i|��S)N�'Union[SelectState, CompoundSelectState]rYr�ECan't resolve label reference for ORDER BY / GROUP BY / DISTINCT etc.�render_label_as_label�within_columns_clause)
rvr��supports_simple_order_by_labelr�KeyErrorr7r��_label_resolve_dictr��_order_by_label_elementr��shares_lineager�)rr�r-r�r�ke�	with_cols�
only_froms�	only_cols�resolve_dict�
order_by_elemr�r�r��visit_label_referencey	sL�����
�
������z!SQLCompiler.visit_label_referencec
Ks�|js	|�|j�Sztd|jdd�}Wnty2}ztj|jdtj	|d�WYd}~nd}~ww|j
\}}}z|rB||j}	n||j}	Wntyf}
ztj|jdtj	|
d�WYd}
~
dSd}
~
ww|	|d<|j|	fd|i|��S)Nr*rYrr+)�extra�exc_clsr�r,r-)rvr��_text_clauserr/r�_no_text_coercionr�r7r�r0)rr�r-r�rr3r4r5r6r�r�r�r�r��visit_textual_label_reference�	sN����
�������z)SQLCompiler.visit_textual_label_referencecKs�|o|}||u}	|	s
|rt|jtj�r|�d|j�}
n|j}
|rN|dur5||
|j||
f|j||j�|jj|fddd�|��t	t
j|j�
||
�S|	rW|j�
||
�S|jj|fddi|��S)N�colidentT)r-�within_label_clauser-F)r�r�rrD�_truncated_identifierr�r�r�r��	OPERATORSr �as_r��format_label)rr��add_to_result_mapr@r-r,�result_map_targetsr��render_label_with_as�render_label_only�	labelnamer�r�r��visit_label�	sJ��������
���zSQLCompiler.visit_labelcCs
t�d��)Nz:Cannot compile Column object until its 'name' is assigned.�r7r��rr�r�r�r��_fallback_column_name
s�z!SQLCompiler._fallback_column_namecKs|j}|j|fi|��Sr)�	_resolvedr�)rr�r��sql_elementr�r�r��visit_lambda_element
sz SQLCompiler.visit_lambda_elementr��ColumnClause[Any]rE�Optional[_ResultMapAppender]�
include_tablerFr��ambiguous_table_name_map� Optional[_AmbiguousTableNameMap]cKs6|j}}|dur|�|�}|j}	|	st|tj�r|�d|�}|dur<|||jf|}
|jr4|
|jf7}
||||
|j	�|	rD|�
|�}n|j�|�}|j
}|dusV|rV|jsX|S|j�|�}|ri|j�|�d}
nd}
trtt|t�stJ�|j}|s�|r�||vr�||}t|tj�r�|�d|�}|
|j�|�d|S)Nr?r�r��alias)r�rM�
is_literalr�rrDrAr'�	_tq_labelr��escape_literal_columnr��quoter��named_with_column�schema_for_object�quote_schemarrO)rr�rErSrFrTr�r��	orig_namerW�targetsr��effective_schema�
schema_prefix�	tablenamer�r�r��visit_column
sD
	
���zSQLCompiler.visit_columncKs|j�|j�Sr)r��format_collation�	collation�rr�r�r�r�r��visit_collationJ
r�zSQLCompiler.visit_collationcK�|jSr�r�)r�
fromclauser�r�r�r��visit_fromclauseM
�zSQLCompiler.visit_fromclausecKrhrri)rrhr�r�r�r��visit_indexP
rlzSQLCompiler.visit_indexcKs*||d<|j|d<|jjj|jfi|��S)N�type_expressionr�)r�r��type_compiler_instancer�r�)r�
typeclauser�r�r�r��visit_typeclauseS
s
��zSQLCompiler.visit_typeclausecC�|jjr
|�dd�}|S�Nr��%%�r��_double_percents�replace�r�textr�r�r��post_process_textZ
�zSQLCompiler.post_process_textcCrrrsrurxr�r�r�rY_
r{z!SQLCompiler.escape_literal_columnc	sR���fdd�}�jsd�_|r|dd�ftj�t�dd�t�|���j���S)Ncs>|�d�}|�jvr�j�j|fi���S�j|fi���Sr)r��_bindparamsr��bindparam_string)rir��r�r�
textclauser�r��do_bindparame
s

z2SQLCompiler.visit_textclause.<locals>.do_bindparamTcSs
|�d�Srr�r�r�r�r�r�w
s
z.SQLCompiler.visit_textclause.<locals>.<lambda>)	rvrr$�NULLTYPE�BIND_PARAMS_ESCrv�BIND_PARAMSrzry)rrrEr�r�r�r~r��visit_textclaused
s��zSQLCompiler.visit_textclausecKs�|j}|r	|jn|jd}t�t�|d�}|j�|�|jr%|�||�|p6|dko0|�dd�p6|�dd�}|rY|j|_|_	|joHt
|j�|_|jD]}	|j
|	d|jd�qM|j
|jfi|��}
|jrw|smt|j�nd}|j|d	�|
}
|j�d�|
S)
NrY�rrr#rrFrT)r-rE��
nesting_level)rv�_default_stack_entryrork�_independent_ctes�_dispatch_independent_ctesrsr5rrr�column_argsrr��_add_to_result_mapr�r"rz�_render_cte_clauserl)r�taf�compound_indexr&r��toplevelrf�	new_entry�populate_result_maprTryr�r�r�r��visit_textual_select}
sB�
�
�	
�
�
�z SQLCompiler.visit_textual_selectcKr�N�NULLr��rr�r�r�r�r��
visit_null�
r�zSQLCompiler.visit_nullcK�|jjrdSdS)Nr~�1�r��supports_native_booleanr�r�r�r��
visit_true�
�zSQLCompiler.visit_truecKr�)Nr��0r�r�r�r�r��visit_false�
r�zSQLCompiler.visit_falsecs$|�dd���fdd�|D�D��S)Ncs��|]}|r|VqdSrr��r��sr�r�r�r)�
���
�z7SQLCompiler._generate_delimited_list.<locals>.<genexpr>c3�"�|]}|j�fi���VqdSrr�rS�r�rr�r�r)�
�� �rw)rr�	separatorr�r�r�r��_generate_delimited_list�
s
�z$SQLCompiler._generate_delimited_listcsltj�tjtjjtjj|�\}}|dkr|dj�fi���St	tj}|�
dd���fdd�|D�D��S)Nrrcsr�rr�r�r�r�r�r)�
r�z;SQLCompiler._generate_delimited_and_list.<locals>.<genexpr>c3r�rr�rSr�r�r�r)�
r�)r�BooleanClauseList�_process_clauses_for_booleanr �and_�True_�
_singleton�False_r�rBrw)r�clausesr��lccr�r�r�r��_generate_delimited_and_list�
s�

�z(SQLCompiler._generate_delimited_and_listcKsd|j|fi|��S�N�(%s))�visit_clauselist)r�
clauselistr�r�r�r��visit_tuple�
szSQLCompiler.visit_tuplecKs4|j}|dur
d}nt|j}|j|j|fi|��S�Nr�)r�rBr�r�)rr�r��sepr�r�r�r��
s

zSQLCompiler.visit_clauselistc
Ks||j}|�|dd�}|r|||fi|��Szt|}Wnty.}zt�||�|�d}~wwd|d<|j|j|fi|��S)N�expression_clauselistT�_in_operator_expression)r��_get_operator_dispatchrBr/r7r�r�r�)rr�r��	operator_�disp�opstringr�r�r�r��visit_expression_clauselist�
s$�����z'SQLCompiler.visit_expression_clauselistcKs�d}|jdur||jj|fi|��d7}|jD]\}}|d|j|fi|��d|j|fi|��d7}q|jdurL|d|jj|fi|��d7}|d7}|S)NzCASE r�zWHEN z THEN zELSE �END)r�r��whens�else_)r�clauser�r��condrr�r�r��
visit_case�
s*
�����
�zSQLCompiler.visit_casecK�|jj|fi|��Sr)�typed_expressionr�)r�type_coercer�r�r�r��visit_type_coerce
�zSQLCompiler.visit_type_coercecKs^|jj|fi|��}t�d|�}d|jj|fi|��|r!|�d�n||r+|�d�fSdfS)Nz(.*)( COLLATE .*)zCAST(%s AS %s)%srr6r�)rpr�r(�matchr�r�)rrr��type_clauser�r�r�r��
visit_cast
s��zSQLCompiler.visit_castc	Ksd|dtjur
dn2|dtjurdn)|ddkr,d|jt�t|d��fi|��fnd|jt�|d�fi|��f|dtjurGdfS|dtjurRdfS|ddkrmd|jt�t|d��fi|��ffSd|jt�|d�fi|��ffS)	Nz	%s AND %srzUNBOUNDED PRECEDINGzCURRENT ROWz%s PRECEDINGz%s FOLLOWINGrzUNBOUNDED FOLLOWING)r�RANGE_UNBOUNDED�
RANGE_CURRENTr��literal�abs)r�range_r�r�r�r��_format_frame_clausesJ��	����������!������"��z SQLCompiler._format_frame_clausecs�|jj�fi���}|jrd�j|jfi���}n|jr*d�j|jfi���}nd}d|d���fdd�d|jfd|jffD�|rF|gng�fS)	NzRANGE BETWEEN %szROWS BETWEEN %sz%s OVER (%s)r�cs:g|]\}}|durt|�rd||j�fi���f�qS)Nz%s BY %s)rzr�)r��wordr��r�rr�r�rUPs��z*SQLCompiler.visit_over.<locals>.<listcomp>�	PARTITION�ORDER)r�r�r�r��rowsrw�partition_by�order_by)r�overr�ryr�r�r�r��
visit_over@s4�
��
���	���zSQLCompiler.visit_overcK�,d|jj|fi|��|jj|fi|��fS)Nz%s WITHIN GROUP (ORDER BY %s))r�r�r�)r�withingroupr�r�r�r��visit_withingroup]��zSQLCompiler.visit_withingroupcKr�)Nz%s FILTER (WHERE %s))�funcr��	criterion)r�
funcfilterr�r�r�r��visit_funcfiltercr�zSQLCompiler.visit_funcfiltercKs.|j�|j|j�}d||jj|fi|��fS)NzEXTRACT(%s FROM %s))�extract_maprs�fieldr�r�)r�extractr�r�r�r�r��
visit_extractis
�zSQLCompiler.visit_extractcKs2|j|jfi|��}|j|fi|��}d||fS)Nz(%s).%s)�visit_function�fnrc)rr�r��compiled_fn�compiled_colr�r�r��visit_scalar_function_columnpsz(SQLCompiler.visit_scalar_function_columnr��
Function[Any]cs�|dur||j|j|jf|j�t�d|j��d�}|r&||fi|��}nJt�|��jd���r9|jr8�d7�n|j��j	�
��sHt�tj
�rN�j	���n���d�d���fdd�|jD��g�d�j|fi|��i}|jrw|d7}|S)Nz
visit_%s_funcz%(expr)sr�cs4g|]}�j�|�st�tj�r�j�|�n|�qSr�)r��_requires_quotes_illegal_charsr�rr0rZ)r�r��r�rr�r�rU�s
��
��z.SQLCompiler.visit_function.<locals>.<listcomp>r�z WITH ORDINALITY)r�r��getattr�lowerr�rs�_deannotater��	_has_argsr�r�r�rr0rZrw�packagenames�function_argspec�_with_ordinality)rr�rEr�r�ryr�r�r�r�us<�
�
���	���
zSQLCompiler.visit_functioncKs|�|j�Sr)�visit_sequence�sequence)r�
next_valuer�r�r�r��visit_next_value_func��z!SQLCompiler.visit_next_value_funccK�td|jj��)Nz2Dialect '%s' does not support sequence increments.�r�r�r��rr�r�r�r�r�r���
��zSQLCompiler.visit_sequencecKr�r)�clause_exprr�)rr�r�r�r�r�r��r�zSQLCompiler.function_argspecc
sl�j}|j|�fi���}|r�js|�_|j}|r�jn�jd}|p-|o-|�dd�}	|dkr6||d<�j�|d|d|||	d��|jrO��|���j	|j
}
d	|
d	����fd
d�t|j
�D��}d�d<|�j|fitdd
�i�����7}|�j|fi���7}|jr�|�j|fi���7}�jr�|s�t�j�nd}�j|dd�|}�j�d�|S)NrYrFrrrr)rrr#rrr�c3s,�|]\}}|j�f�|d����VqdS))r&r�Nr�)r�r�rT�r&r�rr�r�r)�s�����
�z4SQLCompiler.visit_compound_select.<locals>.<genexpr>rSr&T�r��include_following_stackr�)rv�_compile_state_factoryrrr�rsrkr�r��compound_keywords�keywordrwr��selects�group_by_clauser��order_by_clause�_has_row_limiting_clause�_row_limit_clauser"rzr�rl)
r�csr&r�r�r�r�
compound_stmtrf�need_result_maprryr�r�rr��visit_compound_select�sX

���
��	$���z!SQLCompiler.visit_compound_selectcKs.|jdur|j|fi|��S|j|fi|��Sr)�
_fetch_clause�fetch_clause�limit_clause)rrr�r�r�r�r
�s
zSQLCompiler._row_limit_clausecCs(d|j||r
d|ndf}t||d�S)Nz
visit_%s_%s%sr�r�)r�r�)rr��
qualifier1�
qualifier2�attrnamer�r�r�r��s�z"SQLCompiler._get_operator_dispatchcKs�|dur||f7}||d<||d<|jr=|jrt�d��|�|jdd�}|r0|||jfi|��S|j|t|jfi|��S|jra|�|jdd�}|rT|||jfi|��S|j|t|jfi|��St�d��)NrErFzFUnary expression does not support operator and modifier simultaneously�unaryr��modifierz,Unary expression has no operator or modifier)r�rr7r�r�� _generate_generic_unary_operatorrB� _generate_generic_unary_modifier)rrrErFr�r�r�r�r��visit_unary�sB
��
���
���zSQLCompiler.visit_unarycKs�|jjr,|j|jfi|��d|jt�|j|jjjt	j
ur!|jjnt	�
��fi|��S|j|jfi|��d|j|jfi|��S)N� / )r��div_is_floordivr�rxr�Castr�r��_type_affinityr$�Numeric�rr�r�r�r�r�r��visit_truediv_binary$s0�����
������z SQLCompiler.visit_truediv_binarycKst|jjr"|jjjtjur"|j|jfi|��d|j|jfi|��Sd|j|jfi|��d|j|jfi|��S)Nrz	FLOOR(%s))	r�rr�r�r r$�Integerr�rxr"r�r�r��visit_floordiv_binary?s �������z!SQLCompiler.visit_floordiv_binarycKs:|js|jjr|j|jfi|��Sd|j|jfi|��S)Nz%s = 1��_is_implicitly_booleanr�r�r�r��rr�r�r�r�r�r��visit_is_true_unary_operatorPs��z(SQLCompiler.visit_is_true_unary_operatorcKs>|js|jjrd|j|jfi|��Sd|j|jfi|��S)N�NOT %sz%s = 0r&r(r�r�r��visit_is_false_unary_operatorYs��z)SQLCompiler.visit_is_false_unary_operatorcKsd|j|tjd�S)Nr*)�override_operator)�visit_binaryr �match_opr"r�r�r��visit_not_match_op_binarybs�z%SQLCompiler.visit_not_match_op_binarycKsd|j|t|fi|��Sr�)�_generate_generic_binaryrBr"r�r�r��visit_not_in_op_binarygs
��z"SQLCompiler.visit_not_in_op_binarycKsn|tjurt|�dkrdd�dd�|D��SdS|tjur2t|�dkr0dd�dd�|D��Sd	S|�|�S)
Nrz(%s)) OR (1 = 1r�cs��|]}dVqdS�r�Nr��r�r�r�r�r�r)s��z6SQLCompiler.visit_empty_set_op_expr.<locals>.<genexpr>zNULL) OR (1 = 1z(%s)) AND (1 != 1csr2r3r�r4r�r�r�r)zr5zNULL) AND (1 != 1)r �	not_in_oprzrw�in_op�visit_empty_set_expr)rr�	expand_opr�r�r�r��visit_empty_set_op_expros
�
�
z#SQLCompiler.visit_empty_set_op_exprcKr�)Nz3Dialect '%s' does not support empty set expression.r��r�
element_typesr�r�r�r�r8�rz SQLCompiler.visit_empty_set_exprc	sb�j��j�}|s.|jr!�jjrdnd���jj�j�}d|fS���jg�j�}d|fS|jsE|jrgt	|dt
j�rgt	|dtt
f�sg|jrLtd���jjrRdndd���fdd�t|�D��}d|fS|r��j}|�|�}|rx|�d�s|Jd	��|�d��d
�}|d|d��d�����fd
d�|D��}d|fSd���fdd�|D��}d|fS)N�VALUES r�rz?bind_expression() on TupleType not supported with literal_bindsr�c3s:�|]\}}dd��fdd�t|�jj�D��VqdS)r�r�c3s �|]\}}��||�VqdSrr�)r�r��
param_typer(r�r�r)�s
�
�
�z[SQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>.<genexpr>N)rwr�r�r�)r�r�r��r�rr�r�r)�s�
����
�zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>r6�)unexpected format for expanding parameterr�rrc3s(�|]}d���|�j��fVqdSr��r�r��r�r��r�r�r�rr�r�r)�s����
�c3s�|]
}��|�j�VqdSrrArBr?r�r�r)�r�r�)r�r�r�r��tuple_in_valuesr:r�r9�_isnullr��collections_abcrr��bytes�_has_bind_expressionr�rwr�r��searchr�r�)	rr�r��bind_expression_template�typ_dialect_impl�replacement_expression�post_compile_patternrir�r�rCr��2_literal_execute_expanding_parameter_literal_binds�s`
��=�
�6�����
��'�
�����z>SQLCompiler._literal_execute_expanding_parameter_literal_bindscsd�jr	���|�S�j}�j�|���jr�j�n�j��jjr-�j	r-����fdd��n�fdd��|sTg��j
rG���jj�j
�}�|fS���jg�j
�}�|fS�j
sk�jr�t|dtj�r�t|dttf�s��jrpJ��fdd�t|d�D��|jr�dnd	d
���fdd�t|�D��}�|fS�fd
d�t|d�D��d
��fdd��D��}�|fS)Ncs���j��d|i�S�Nr�)�render_bind_castr�ri)�
bind_templater�rrKr�r��_render_bindtemplate�s

�zNSQLCompiler._literal_execute_expanding_parameter.<locals>._render_bindtemplatecs�d|iSrOr�ri)rQr�r�rR�r�rcs6g|]\}}t|d�D]
\}}d�||f|f�qqS)rr�r�)r�r�r�r�r�rir�r�rU
s���zDSQLCompiler._literal_execute_expanding_parameter.<locals>.<listcomp>rr=r�r�c3s:�|]\��dd�����fdd�t��D��VqdS)r�r�c3s0�|]\}}���t��|d�VqdS)rN)rz)r�r�r�)rRr�r�r�r�r�r)
s���
�zMSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>.<genexpr>N)rwr�)r�)rRr�)r�r�r�r)	
s�
���
�zCSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>cs g|]\}}d�|f|f�qS)z%s_%sr�)r�r�r�rir�r�rU
r}c3s�|]	\}}�|�VqdSrr�r�)rRr�r�r)
s�
�)r�rNr�r�r�rrr�_bind_typing_render_castsrPr�r:r�r9rEr�rFrr�rG�	_is_arrayr�rDrw)rr�r�r�r�rLr�)rRrQr�r�rr�rKr�r��sd���	
�+�
�'����

�
��
���z0SQLCompiler._literal_execute_expanding_parameterc
Ks|r;t�|j�r;|dur)|d}|j�t�t|jj	|g�t|j
j	|g���n|j�t�t|jj	�t|j
j	���|jrPt|jt
j�rPt|j
t
j�rPd|d<|pT|j}|�|dd�}	|	rg|	||fi|��Szt|}
Wnty�}zt�||�|�d}~ww|j||
f||d�|��S)N�enclosing_lateralTr�r�)�from_linter�lateral_from_linter)r �
is_comparisonr�rjrJr��productr)rxr*r�r
r�rrEr�rBr/r7r�r0)rr�r,�eager_groupingrVrWr�rUr�r�r�r�r�r�r�r- 
sZ	����

��	���
�����zSQLCompiler.visit_binarycKs|j|jfi|��Sr)r��sql_functionr(r�r�r��&visit_function_as_comparison_op_binaryX
r�z2SQLCompiler.visit_function_as_comparison_op_binarycKs`|jjr|j|jfi|��d|j|jfi|��S|j|jfi|��d|j|jfi|��S)Nz %% r�)r�rvr�rxr�r"r�r�r��visit_mod_binary[
s������zSQLCompiler.visit_mod_binarycKs.|j|d<|j|d|�|j�dfi|��S)NrZr�)rZr0rYr�r(r�r�r��visit_custom_op_binaryi
s
��z"SQLCompiler.visit_custom_op_binarycKs |j||�|j�dfi|��Sr�)rrYr�r(r�r�r��visit_custom_op_unary_operatorq
�
��z*SQLCompiler.visit_custom_op_unary_operatorcKs |j|d|�|j�fi|��Sr�)rrYr�r(r�r�r��visit_custom_op_unary_modifierv
r`z*SQLCompiler.visit_custom_op_unary_modifiercKsf|�dd�}d|d<|j|d<|jj|fd|i|��||jj|fd|i|��}|r1|r1d|}|S)Nr�FT�
_binary_oprZr�)rsr�rxr�r�)rr�r�rZr�r�ryr�r�r�r0{
s0
���������
z$SQLCompiler._generate_generic_binarycKs||jj|fi|��Srr$�rrr�r�r�r�r�r�
�z,SQLCompiler._generate_generic_unary_operatorcKs|jj|fi|��|Srr$rcr�r�r�r�
rdz,SQLCompiler._generate_generic_unary_modifiercCstjdtjd�S)Nz'%')r)r�literal_columnr$�
STRINGTYPEr(r�r�r��_like_percent_literal�
sz!SQLCompiler._like_percent_literalcKsd|jj|fi|���d�S)Nzlower(r�r$rfr�r�r��$visit_ilike_case_insensitive_operand�
r(z0SQLCompiler.visit_ilike_case_insensitive_operandcK�6|��}|j}|�|j��|�|_|j||fi|��Sr��_clonerg�concatr��visit_like_op_binary�rr�r�r��percentr�r�r��visit_contains_op_binary�
�z$SQLCompiler.visit_contains_op_binarycKrir�rkrgrlr��visit_not_like_op_binaryrnr�r�r��visit_not_contains_op_binary�
rqz(SQLCompiler.visit_not_contains_op_binarycK�F|��}|j}t|j�|_|�t|j���|�|_|j||fi|��Sr�rkrgr�rxrlr��visit_ilike_op_binaryrnr�r�r��visit_icontains_op_binary�
���z%SQLCompiler.visit_icontains_op_binarycKrur�rkrgr�rxrlr��visit_not_ilike_op_binaryrnr�r�r��visit_not_icontains_op_binary�
ryz)SQLCompiler.visit_not_icontains_op_binarycK�0|��}|j}|�|j�|_|j||fi|��Sr)rkrg�_rconcatr�rmrnr�r�r��visit_startswith_op_binary�
�z&SQLCompiler.visit_startswith_op_binarycKr}r)rkrgr~r�rsrnr�r�r��visit_not_startswith_op_binary�
r�z*SQLCompiler.visit_not_startswith_op_binarycK�@|��}|j}t|j�|_|�t|j��|_|j||fi|��Sr)rkrgr�rxr~r�rwrnr�r�r��visit_istartswith_op_binary�
�
z'SQLCompiler.visit_istartswith_op_binarycKr�r)rkrgr�rxr~r�r{rnr�r�r��visit_not_istartswith_op_binary�
r�z+SQLCompiler.visit_not_istartswith_op_binarycKr}rrjrnr�r�r��visit_endswith_op_binary�
r�z$SQLCompiler.visit_endswith_op_binarycKr}rrrrnr�r�r��visit_not_endswith_op_binary�
r�z(SQLCompiler.visit_not_endswith_op_binarycKr�rrvrnr�r�r��visit_iendswith_op_binary�
r�z%SQLCompiler.visit_iendswith_op_binarycKr�rrzrnr�r�r��visit_not_iendswith_op_binary�
r�z)SQLCompiler.visit_not_iendswith_op_binarycK�Z|j�dd�}d|jj|fi|��|jj|fi|��f|dur*d|�|tj�SdS)Nr)z
%s LIKE %s� ESCAPE r���	modifiersrsrxr�r�r�r$rf�rr�r�r�r)r�r�r�rm�
s����z SQLCompiler.visit_like_op_binarycKr�)Nr)z%s NOT LIKE %sr�r�r�r�r�r�r�rs�
s����z$SQLCompiler.visit_not_like_op_binarycK�>|tjur|��}t|j�|_t|j�|_|j||fi|��Sr)r �ilike_oprkr�rxr�rmr"r�r�r�rw�

z!SQLCompiler.visit_ilike_op_binarycKr�r)r �not_ilike_oprkr�rxr�rsr"r�r�r�r{r�z%SQLCompiler.visit_not_ilike_op_binarycK�*|j�dd�}|j||rdndfi|��S)Nr�Fz BETWEEN SYMMETRIC z	 BETWEEN �r�rsr0�rr�r�r�r�r�r�r��visit_between_op_binarys��z#SQLCompiler.visit_between_op_binarycKr�)Nr�Fz NOT BETWEEN SYMMETRIC z
 NOT BETWEEN r�r�r�r�r��visit_not_between_op_binarys
��z'SQLCompiler.visit_not_between_op_binarycK�t�d|jj���Nz/%s dialect does not support regular expressions�r7r�r�r�r"r�r�r��visit_regexp_match_op_binary&�
��z(SQLCompiler.visit_regexp_match_op_binarycKr�r�r�r"r�r�r�� visit_not_regexp_match_op_binary,r�z,SQLCompiler.visit_not_regexp_match_op_binarycKr�)Nz;%s dialect does not support regular expression replacementsr�r"r�r�r��visit_regexp_replace_op_binary2r�z*SQLCompiler.visit_regexp_replace_op_binarycKs�|sW|j�|j�}|jrW|�|�}	|j|	fd||o|j||d�|��}
|jrUt�d|
�}|s3Jd��d|�	d�|�	d�|�	d�f}
|rU|j
|fd|
d	�|��}d
|S|
S|si|pb|jpb|ob|j}|pg|j}
nd}
|r�|j
|fddi|��}|jrd
|}|S|�
|�}||jvr�|j|}||ur�|js�|jr�|j�|j�s�|j�|j�s�t�d
|��|j|jkr�t�d|f��|js�|jr�|jr�|jr�t�d��t�d|j�d|j�d���||j|j<|j|<|j}|�r	|\}}|jD]}|j|v�r||j}||�|�q�|j�rd|_|
�r-|�rd|_|�r%|j|hO_n|j|hO_|j|f|
|j|jd�|��}|j�rDd
|}|S)NT)�skip_bind_expressionr-�
literal_bindsr��render_postcompilez&^(.*)\(__\[POSTCOMPILE_(\S+?)\]\)(.*)$r@z$(__[POSTCOMPILE_%s~~%s~~REPL~~%s~~])r6rr)r-rJr�Fr-zIBind 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�	expanding�bindparam_type)r��dialect_implr�rH�bind_expressionr�r�r(r�r�r�r�r
�_truncate_bindparamrr�r��intersectionrr7r��_is_crudr'rrk�
isoutparam�has_out_parametersrrrr})rr�r-r�r�r�r�r��implr��wrappedrirr�r��existingr�rPrOrr!r�r�r��visit_bindparam8s�
�
��	����������


������	�����
��


����zSQLCompiler.visit_bindparamcCr�rr�)rr�
dbapi_typerr�r�r�rP�rlzSQLCompiler.render_bind_castc
Ks�|tur|}n/|jdur3|jdur3|�dd�}|r)|tjtjfvr)t�d|j	f�|j
tjfi|��S|j
}|jrG|j}||||d�\}}	|	S|�||j�S)Nrbz�Bound parameter '%s' rendering literal NULL in a SQL expression; comparisons to NULL should not use operators outside of 'is' or 'is not')rJ)r.r�r�rsr �is_�is_notr%�warn_limitedr'r�r$r�r�r�rNr�r�)
rr�r�rJr�r��op�leepr�r�r�r�r�r��s(�
�z$SQLCompiler.render_literal_bindparamc
Cs�|dur|js|�tj���S|�|j�}|r9z||�WSty8}zt�	dt
�|��d|�d��|�d}~wwt�	dt
�|��d|����)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 ")�should_evaluate_noner�r�Null�	_instance�_cached_literal_processorr�r�r7r��sql_util�_repr_single_value)rr�r�	processor�er�r�r�r�s2
������
���z SQLCompiler.render_literal_valuecCs@||jvr
|j|S|j}t|tj�r|�d|�}||j|<|S)Nr�)rr'r�rrDrA)rr�r�r�r�r�r�&s


zSQLCompiler._truncate_bindparam�ident_classr�rDcCs�||f|jvr|j||fS|�|j�}t|�|jdkrB|j�|d�}|dt|jdd��dt|�dd�}|d|j|<n|}||j||f<|S)N�rrr�r6)	rD�	apply_maprCrzrArErs�max�hex)rr�r��anonname�counter�	truncnamer�r�r�rA3s���z!SQLCompiler._truncated_identifiercCs
||jSr�rC�rr�r�r�r��
_anonymizeHr�zSQLCompiler._anonymizer�r��escaped_fromr��Optional[TypeEngine[Any]]�accumulate_bind_names�Optional[Set[str]]�visited_bindparamr�cs|dur	|�|�|dur|�|�|s)�j�|�r)�j��fdd�|�}	|}|	}|r4�j�||i��_|rTd|}
|r>|
S|durR|��j�}|j	rR��
|||
�}
|
S�jtj
urb�jd|i}
n�jd|i}
|dur��jjr�|��j�}|j
r���
|||
�}
|
S)Ncs�j|�d�S)Nr)r�r�r�r(r�r�r�e�z.SQLCompiler.bindparam_string.<locals>.<lambda>z__[POSTCOMPILE_%s]r�)�addrkr�rIrvrr�r�r��render_literal_castrPr�rXrYrrrS)rr�r�r�r�r�r�r�r��new_namer�	type_implr�r(r�r}KsJ


����zSQLCompiler.bindparam_stringcCsF|��}|�dd�t|j|j�D]\}}|j|fd|i|��qdS)N�cte_opts)�copyrlr�r��_independent_ctes_optsr�)r�stmtr��local_kw�cte�optr�r�r�r��s��z&SQLCompiler._dispatch_independent_ctesr�rMr&�ashint�	fromhints�Optional[_FromHintsType]�visiting_cte�
Optional[CTE]rV�Optional[FromLinter]r��selectable._CTEOptscs����}	|	�jusJ�||d<|j}
t|
tj�r��d|
�}
d}d}|��}
|jp+|j}|
�j	vrx�j	|
\}}}||
ks?J�||
f}�j
|}|jrw|jrSt�d��||
f}|r^t
�j�nd}||
f}}�j
|=|�j
|<||f�j	|
<n|rt
�j�nd}||
f}|�j
vr��j
|}nd}|dur�||u}||jus�||ur�d}n6||jur�|	|=|��}||
us�J�||us�J��j	|=n|jdus�|jdur�|�|�r�d}nt�d|
��|s�|s�dS|jdur�|j}|jj}t|tj�r���d|�}n|}d}|�r�|�j
|<||f�j	|
<|�jv�r�j|fi|��|�s�||	v�r�|j�r-d�_�j�||
�}|j�rU|j}dd	�|�d�D�}|d
d��fdd
�|D��7}|�dd�du�s`J��j�sp|jj�fd|i|��S�j||jfi|��}|jj�fddi|��}|d||f7}|j�r�|d�j||jfi|��7}||	|<|�r�|�r�|
|j |�!�<|�s�|�r��j�||
�S|�r�j�||�}�j�"|
��r׈j�#|
�}
|��$|
�7}|S�j�||
�SdS)Nr�rVTFz6CTE is stated as 'nest_here' in more than one locationrz5Multiple, unrelated CTEs found with the same name: %rcSs"g|]
\}}}}}|s|p|�qSr�r�)r�r��
proxy_name�fallback_label_namerT�repeatedr�r�r�rUs��z)SQLCompiler.visit_cte.<locals>.<listcomp>r�r�c3s"�|]}�jj|�jd�VqdS)r�N)r��format_label_namerC)r��identr(r�r�r)-����
�z(SQLCompiler.visit_cte.<locals>.<genexpr>�subqueryr&z AS %s
(%s)r�)%rcr"r�r�rrDrA�_get_reference_cte�nestingr$r#r7r�rzrv�	_restates�_is_clone_of�compare�
_cte_alias�	visit_cte�	recursiver%r��format_aliasr��_generate_columns_plus_namesrwrsr��_generate_prefixes�	_prefixes�	_suffixesrir)�_requires_quotesrZ�get_render_as_alias_suffix)rr�r&r�r�r�rVr�r��	self_ctes�cte_name�
is_new_cte�embedded_in_current_named_cte�_reference_cter��	cte_levelr��existing_cte_opts�cte_level_name�existing_cte�old_level_name�new_level_name�existing_cte_reference_cte�
pre_alias_cte�cte_pre_alias_namery�
col_source�
recur_cols�prefixesr�r�r(r�r��s

�
�
��




���
��
����	���������
�zSQLCompiler.visit_ctecKs8|jrd|d<|jr|j|fi|��S|j|fi|��S)NrV)�joins_implicitly�_is_lateral�
visit_lateral�visit_aliasrfr�r�r��visit_table_valued_aliasas
z$SQLCompiler.visit_table_valued_aliascK�|j|fi|��Sr)rcrfr�r�r��visit_table_valued_columnir�z%SQLCompiler.visit_table_valued_columnc
	s�|rd�vr�jsJ���d<|	rd�vrd�vr|	�d<|durD|j�urD�jj�f|||||�d����}|rB|s=|rBd|f}|S�}�d<|sN|r`t�jtj�r]��d�j�}n�j}|ri�j�	�|�S|r�|	rt||	j
���<�jj�fd|d����}|r�d|f}|���j�	�|��}
�j
r��jr�|
dd	����fd
d��jD��7}
|r��|vr���|
�|�|�}
|
S�jj�fd|i���S)
NrUrW)r&r��iscrudr��lateral�enclosing_aliasr�rrVT)r&rr�c3sH�|]}d�j�|j��jrd�jjj|jfi���ndfVqdS)z%s%s� %sr�N)r�rZr��_render_derived_w_typesr�ror�r�r��rVr�rr�r�r)�s"�
�������
�z*SQLCompiler.visit_alias.<locals>.<genexpr>r)r	r�r�r�r�rrDrAr�r�rir)r��_supports_derived_columns�_render_derivedrwrT�format_from_hint_text)rrVr&r�rr�r�rrrVr�r��
alias_namerr�rr�rls�

����

���
�
������zSQLCompiler.visit_aliascKsd|d<|j|fi|��S)NTr��r)rr�r�r�r�r��visit_subquery�szSQLCompiler.visit_subquerycKsd|d<d|j|fi|��S)NTrz
LATERAL %sr)r�lateral_r�r�r�r�r
�szSQLCompiler.visit_lateralcKsZd|j|fddi|��|��j|fi|��f}|jdur+|d|jj|fi|��7}|S)Nz%s TABLESAMPLE %sr&Tz REPEATABLE (%s))r�_get_methodr��seed)r�tablesampler&r�ryr�r�r��visit_tablesample�s�
�zSQLCompiler.visit_tablesamplecs6��d�j�d����fdd��jD��}d|��S)Nr�r�c3s>�|]}|D]}�jtj|d�ji���fi���VqqdS)r�N)r�rr�
_column_typesr�)r��chunk�elem�r�r�rr�r�r)�s"��������z-SQLCompiler._render_values.<locals>.<genexpr>r=)�
setdefaultr�rw�_data)rr�r��tuplesr�r#r��_render_values�s
�

zSQLCompiler._render_valuesc	s��j|fi���}|jrd}nt|jtj�r��d|j�}n|j}|jr'd}nd}|rc|r:|dur3|nd|j|�	�<|r]d�d<d||��
�j�|��d�
��fd	d
�|jD��f}|Sd||f}|S)Nr�zLATERAL r�z(unnamed VALUES element)FrSz
%s(%s)%s (%s)r�c3r�rr�rSr�r�r�r)s
��
�z+SQLCompiler.visit_values.<locals>.<genexpr>z%s(%s))r'�_unnamedr�r�rrDrAr	rir)r�r�rZrw�columns)rr�r&rVr�r8r�rr�r�r��visit_values�s4���
�zSQLCompiler.visit_valuescKsd|j|fi|���d�Sr#)r'rfr�r�r��visit_scalar_values�zSQLCompiler.visit_scalar_valuescCsd|S)Nr�r�)r�alias_name_textr�r�r�r��z&SQLCompiler.get_render_as_alias_suffixr�r�rr�rcCsN|sJ�|dus|dkrd|_d|_|jrt�d��|j�t||||��dS)N�*FTzxMost backends don't support SELECTing from a tuple() object.  If this is an ORM query, consider using the Bundle object.)rrr�r7r�r�rkr�rr�r�r�r�s
��zSQLCompiler._add_to_result_mapcKs&|jd||d|durin|fi|��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)rr�r�r��column_clause_argsr�r�r�r��_label_returning_column8s��z#SQLCompiler._label_returning_columnc
s��j�|j�}
|
jr|s|r|
���}n�}|r4|j}|
r&|��fdd�}n|�ur3|���fdd�}nd}|	s<Jd��t�tj�rT|�urQt	|�j
�jfd�}ny|}nv|ri|dus^Jd��t	|||�jfd�}na|�urpd}n7t�tj
�r�|o��jo��jdu}n%t�tj�r�d	}nt�tj�r��jp�|}nt�tj�s��jdur�d}nd	}|r�|s�|
r�J��j}t|tj�s�t�|�n|}t	|||fd�}n|}|j|	||d
�|j|fi|��S)z.produce labeled columns present in a select().cs�|||f|�dSrr��r�r�r�r)r�r�r�rEsr�z;SQLCompiler._label_select_column.<locals>.add_to_result_mapcs�||�f||�dSrr�r4�r�r�r�r�rE{s�NzX_label_select_column is only relevant within the columns clause of a SELECT or RETURNING)r�z*proxy_name is required if 'name' is passedTF)r-rErS)r�r�r��_has_column_expression�column_expressionr�r�rrHr�r�r�rXrFrWr��
TextClause�UnaryExpression�wraps_column_expression�NamedColumn�_non_anon_label�_anon_name_labelrDrJr�)rr�r�r�r&r2r�r�r�r-�column_is_repeated�need_column_expressionsrSr��col_exprrE�result_expr�render_with_labelr�r5r�r1Ms������
�����
�
�����z SQLCompiler._label_select_columncCs |�||�}|r|d|7}|Sr�)�get_from_hint_text)rrr��hintr�hinttextr�r�r�r�sz!SQLCompiler.format_from_hint_textcCrrr�)r�byfromsr�r�r��get_select_hint_text�r�z SQLCompiler.get_select_hint_textcCrrr��rr�ryr�r�r�rC�r�zSQLCompiler.get_from_hint_textcCrrr�rHr�r�r��get_crud_hint_text�r�zSQLCompiler.get_crud_hint_textcCs
d�|�Sr�r�)r�
hint_textsr�r�r��get_statement_hint_textr�z#SQLCompiler.get_statement_hint_textrr�rrcKsj|j}|r	|jn|jd}|�||�}|d}|d}	|r,|s,|j|�|	�dd�}
|
S|j||	d�}
|
S)NrYrrr���explicit_correlate_froms�implicit_correlate_froms)rvr�r�_get_display_froms�
difference)r�select_stmtr&rr�r�rfrrrrir�r�r��_display_froms_for_select
s$����z%SQLCompiler._display_froms_for_select�translate_select_structurec	
s�|dusJd��d|	d<�j��fi|	��}
|
j|	d<|
j��j}|r*�js*|
�_|dup/|}�jrU�j�fd�i|	��}
|
�urU|
}�}|
��j��fi|	��}
|
j�|rZ�jn�jd}|pl|�dd�pl|�dd���|rsd��s|d	|	vr||	d	=���|
|�||�}|	�	����
ddd
��d}�jr�����\}}|r�||d7}nd}�j
r����|	��jr�|�j��jfi|	��7}|�j�fi|	��7}d
d�������fdd�|
jD�D�}��r|du�rttdd�|
jD�dd�|jD�����fdd��jD��_��|�|
|||||	�}�j�r-�fdd��jD�}|�r-|d��|�7}�j�rI|�r7|�rI|�s?t�j�nd}�j|d�|}�j�r\|d�j��jfi|	��7}�j�d�|S)NzpSQLAlchemy 1.4 requires use of the translate_select_structure hook for structural translations of SELECT objectsFr-rTr&rYrrrE)r@r-zSELECT r�cSsg|]}|dur|�qSrr�rSr�r�r�rU�s
�z,SQLCompiler.visit_select.<locals>.<listcomp>cs4g|]\}}}}}�j�|���||||�d�
�qS))r�r�r�r>r?r0�r�r�r�r�r�r�)r&r2r?r�rQrr�r�rU�s(
���cS�g|]	\}}}}}|�qSr�r��r�r'r�r�r�r�r�r�r�rU����cSrUr�r�rVr�r�r�rU�rWc	s4g|]\}}}}t||t�fdd�|D��|��qS)c3s�|]	}��||�VqdSrrr)r��o�rr�r�r)�rz6SQLCompiler.visit_select.<locals>.<listcomp>.<genexpr>)r�r+)r�r'r�r�rrYr�r�rU�s
���cs$g|]\}}|d�jjfvr|�qS�r/�r�r�)r��dialect_name�htr(r�r�rU�s
�r�)r�_ambiguous_table_name_maprrvrrSr�rs�_setup_select_stackr�rJ�_hints�_setup_select_hintsr�r�r�r��get_select_precolumns�columns_plus_namesr�r�r��_compose_select_body�_statement_hintsrKr"rzr�r�rl)rrQr&�insert_intor�r��select_wraps_forrrVr�rr��is_embedded_select�new_select_stmt�compile_state_wraps_forrfriry�	hint_text�byfrom�
inner_columns�per_dialectr�r�)r&r2r?r�rQrrr��visit_select.s�
����
�����
�
���������
���
��
��
�zSQLCompiler.visit_selectr�r�Tuple[str, _FromHintsType]cs*�fdd�|j��D�}��|�}||fS)Nc	s<i|]\\}}}|d�jjfvr||d|j�dd�i�qS)r/r�T)r��r�r�r�)r�r{r�rEr(r�r�r4�s
��z3SQLCompiler._setup_select_hints.<locals>.<dictcomp>)r`rKrG)rr�rlrkr�r(r�ra�s

�
zSQLCompiler._setup_select_hintscCs�|d}|d}|dkr||d<n"|r3|d}	t|	j�}
t|j�|
kr3t�dd|
|dt|j�f��|rB|sB|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 %drr�rL)rrr#r)rzrVrcr7r�rOrPror*r�rvrk)rr�rrfr&rr�rrr�numcolsri�new_correlate_froms�all_correlate_fromsr�r�r�r�r_sJ

���
���
�zSQLCompiler._setup_select_stackc	s�|d�|�7}�jt@rtit����jt@}	|r��_nd�d}	|s'|��}|rS|d7}|jrB|d�����fdd�|D��7}n|d����fdd�|D��7}n|��	�7}|j
rp�j|j
fd�i���}
|
rp|d|
7}|	r|�dusxJ����|j
r�|�j|fi���7}|jr��j|jfi���}
|
r�|d	|
7}|jr�|�j|fi���7}|jr�|�j|fi���7}|jdur�|�j|fi���7}|S)
Nr�Fz 
FROM cs&g|]}|j�fd��d�����qS)T)r&r�rVr��r��f�rlrVr�rr�r�rU`s�����z4SQLCompiler._compose_select_body.<locals>.<listcomp>cs$g|]}|j�fd�d�����qS)T�r&rVr�ru)rVr�rr�r�rUms�����rVz 
WHERE z	 
HAVING )rwr.r^raror_rV�rstripr`r�_where_criteriar�r}�_group_by_clausesr
�_having_criteria�_order_by_clausesrrr
�_for_update_arg�for_update_clause)rryr�rrmrirlr�r��warn_linting�tr�rwr�rd;sn

�	��
�������
z SQLCompiler._compose_select_bodycs*d���fdd�|D��}|r|d7}|S)Nr�c3s:�|]\}}|dvs|�jjkr|j�fi���VqdS))Nr/Nrq)r��prefixr\r�r�r�r)�s���z1SQLCompiler._generate_prefixes.<locals>.<genexpr>r�)rr�rr�r�r�r�r�r��s�zSQLCompiler._generate_prefixescCs,|jsdS|rB|dkrBt��}t|j���D]*}|j|��\}}}|jp'|j}||kp3|o3||dk}	|r8|	s9q|j|||<qn|j}|sIdStdd�|D��}
|�	|
�d}|d�
dd�|��D��7}|d7}|r�|dkr�t|���D]}|j|��\}}}|j|=|j||f=|j|��=qw|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.
        r�rcSr�r�)r�)r�r�r�r�r�rU�r�z2SQLCompiler._render_cte_clause.<locals>.<listcomp>r��, 
cSsg|]}|�qSr�r�)r��txtr�r�r�rU�r�z
 )
r"r%rbr]�keysr$r�r�rg�get_cte_preamblerwr�r#)rr�rr"r�r�r�r�r��is_rendered_levelr%�cte_textr�r�r�r��s@
���
�zSQLCompiler._render_cte_clausecCs|rdSdS)NzWITH RECURSIVE�WITHr�)rr�r�r�r�r��szSQLCompiler.get_cte_preamblecKs"|jr
tjddd�|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.4��versionr�r�)�_distinct_onr%�warn_deprecated�	_distinct�rr�r�r�r�r�rb�s�z!SQLCompiler.get_select_precolumnscK�,|j|jttjfi|��}|rd|SdS)z5allow dialects to customize how GROUP BY is rendered.z
 GROUP BY r�)r�r{rBr �comma_op)rr�r��group_byr�r�r�r
�s��zSQLCompiler.group_by_clausecKr�)z5allow dialects to customize how ORDER BY is rendered.z
 ORDER BY r�)r�r}rBr r�)rr�r�r�r�r�r�r�s��zSQLCompiler.order_by_clausecKr)Nz FOR UPDATEr�r�r�r�r�rr�zSQLCompiler.for_update_clauser�rB�returning_cols�Sequence[ColumnElement[Any]]r�cs6����fdd��jdt�|�d�D�}dd�|�S)Nc	s6g|]\}}}}}�j�|�f||||d�����qS))r�r>r�r�)r3rT�r�r�rr�r�r�rUs(�����z0SQLCompiler.returning_clause.<locals>.<listcomp>T)�cols�
RETURNING r�)r�r�_select_iterablesrw�rr�r�r�r�r)r�r�r��returning_clause	s
��zSQLCompiler.returning_clausecKsfd}|jdur|d|j|jfi|��7}|jdur1|jdur#|d7}|d|j|jfi|��7}|S)Nr�z
 LIMIT z

 LIMIT -1z OFFSET )�
_limit_clauser��_offset_clause)rr�r�ryr�r�r�r)s


zSQLCompiler.limit_clausec
Ks�|dur|j}|j}nddd�}d}|jdur5|j}|r%|�|�r%|��}|j|fi|��}	|d|	7}n|r;|d7}|durf|rJ|�|�rJ|��}|d|j|fi|��|drZdnd|d	rad
ndf7}|S)NF)ro�	with_tiesr�z
 OFFSET %s ROWSz
 OFFSET 0 ROWSz
 FETCH FIRST %s%s ROWS %sroz PERCENTr�z	WITH TIES�ONLY)r�_fetch_clause_optionsr��_simple_int_clause�render_literal_executer�)
rr�r�require_offset�"use_literal_execute_for_simple_intr��fetch_clause_optionsry�
offset_clause�
offset_strr�r�r�r3s8

�����zSQLCompiler.fetch_clausec	
Ks�|r|j|j|<|s|r]|j�|�}
|r&|
r&|j�|
�d|j�|j�}n%|j�|j�}|
sK|rK|j|vrK|�d||j�}||�|j�	d|��}|r[||vr[|�
|||||�}|SdS)Nr�rVr�)�fullnamerir�r\r]rZr�rAr�r�r)
rr�r&rr�r��
use_schemarVrTr�r`r�	anon_namer�r�r��visit_table\s:
�����

���zSQLCompiler.visit_tablecKs�|r|j�t�t|jj�t|jj���|jrd}n|j	r d}nd}|jj
|fd|d�|��||jj
|fd|d�|��d|jj
|fd|i|��S)Nz FULL OUTER JOIN z LEFT OUTER JOIN z JOIN Trxz ON rV)rjrJr�rYr)rxr*r�ru�isouterr��onclause)rrwr&rVr��	join_typer�r�r��
visit_join�sP

�����������	�����zSQLCompiler.visit_joincsB�fdd�|j��D�}|j|vr��||j||jd�}||fS)Ncs*i|]\\}}}|d�jjfvr||�qSrZr[)r�r�r�rkr(r�r�r4�s

�z1SQLCompiler._setup_crud_hints.<locals>.<dictcomp>T)r`rKr�r)rr��
table_text�
dialect_hintsr�r(r��_setup_crud_hints�s
�
�zSQLCompiler._setup_crud_hintsr�rJr9cCs~|jj}|j}|j}|durdS|jr|j�|jd�}n|j�|jd�}||@r*|S|j	r=t
�d|d�d|jj�d���dS)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.)
r��"insertmanyvalues_implicit_sentinel� _sentinel_column_characteristicsr)�
is_autoinc�_sentinel_col_autoinc_lookuprs�default_characterization� _sentinel_col_non_autoinc_lookup�is_explicitr7r*r�)rr��
sentinel_opts�sentinel_characteristics�	sent_cols�bitmaskr�r�r��_get_sentinel_column_for_table�s*����z*SQLCompiler._get_sentinel_column_for_tablerW�compiled_parameters�%List[_MutableCoreSingleExecuteParams]�generic_setinputsizesrB�
batch_sizer5r7r�r�� Iterator[_InsertManyValuesBatch]c1#s���j}|dus
J�|jsd�ntj|j��t�
�}	|jr&�jjs&d}
d}n�jjr7|r<�j	r<|j
dus7|jr<d}
d}nd}
d}|
rltt
dt�
|��d�D]\}\�	}
t|�	��	g�r`�|
�gngd||	||�
VqMdS|rxtj�jj|d��nd�|j}�r��|�}d|�d�}|�|d�}�jj}|r�t�j�}t|j�}||}t||||�}t
d	t�
��}t
d	t|��}d}d}|	||	|r�dnd
}|j}|dus�J��rއfdd�|D�}d
���j�s2�jr�j�ni�t�
d
�}��fd
d��|j�rd}nd}dd��fdd�|D���|�d�}|� �fdd�|D��}�
fdd�|�!|�D�}d�njd}t�}i}|j�rDd|�d��nd|�d��t��|jD]
}��"|d��qP��r��j#}|du�shJ��fdd�t|�D�} t| ��t$| �d�t| ���k�s�J��j%�r�t&�'�j(�}!t&�)|!�d�d���|�r�|d
|�}"|d
|�}#g|d
|�<g|d
|�<|�r�|}$nt|"�}$��r�dd��fdd�t*|$�D�D�}�j�rc|j+}%|%t|"d
�k�r�d }&}'|"}(n|"d
d��}&|"d
�d�}'��fd!d�|"D�}(|j�rd��fd"d�t|"�D��dd#�})n�|$dd#�})�j%�rN|%d
k�rN|'�r2J��d}*|%|$|*}+t,�fd$d�t*|*|+�D��},|)|,})|�d|)�}-t,t-j.�/|(��}.|&|.|'}.n?g}/|�0�}.t|"�D]+\��	|�d%t1���}0|j�r�|0�d&t1���}0|/�2|0�|.�"��	fd'd�|D���qm|�dd�|/��}-t|-|.||"��r��fd(d�|#D�ng|$|||d�
V|d7}|�s�dSdS))NTFzKSequence[Tuple[_DBAPISingleExecuteParams, _MutableCoreSingleExecuteParams]]r�r�r�r��__EXECMANY_TOKEN__zList[Sequence[Any]]rcs$g|]\}}}}||�|�|f�qSr�r�)r�r�r'r��st)�rstr�r�rU�s
��zASQLCompiler._deliver_insertmanyvalues_batches.<locals>.<listcomp>cs@|D]}��||�}|��jd|i�jd|�d�i�}q|S)Nr��__EXECMANY_INDEX__)rsrwr)r��	formattedr')rrr�r��apply_placeholders�s��zISQLCompiler._deliver_insertmanyvalues_batches.<locals>.apply_placeholdersz, _IMV_VALUES_COUNTERr�r�c3s"�|]\}}}}�||�VqdSrr�)r�r�r��	bind_keys)r�r�r�r)�s
�
�
�z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>c3s.�|]\}}}}|D]	}��||�Vq
qdSrrr)r�r�r�r')rr�r�r)�s�
�
��csi|]	}|�d|�qS)rr�r&r%r�r�r4�s��zASQLCompiler._deliver_insertmanyvalues_batches.<locals>.<dictcomp>z, _IMV_VALUES_COUNTER), z), rcsh|]
\}}|�vr|�qSr�r�)r�rr�)�all_names_we_will_expandr�r�r��s
�z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<setcomp>z\d+rhcSsg|]
\}}}|||f�qSr�r�)r��new_key�len_r�r�r�r�rU�s��c3s4�|]}�D]\}}}|�d|��||fVqqdS)r�Nr�)r�rhr'r�r�)r�r�r�r)�s����r�c3s�|]	}|���VqdSrr�r2)�expand_pos_lower_index�expand_pos_upper_indexr�r�r)r�c3s$�|]
\}}��dt|��VqdS)�_IMV_VALUES_COUNTERN)rwr��r�r�r�)�executemany_values_w_commar�r�r)s���
����c3s�|]
}�j�|��VqdSrr��r�r�r(r�r�r)4r��EXECMANY_INDEX__r�cs i|]}|�d����|�qS)�__r�r&)r��paramr�r�r4Us cr�r�r�)r�r!)�_sentinel_from_paramsr�r�rUcr�)3rr<r�rrzr1r��supports_default_metavalue�supports_multivalues_insertr�r:r8r�rr�r?�	functools�partialr�r�r2rw�insertmanyvalues_max_parametersrr4�minr]r5rror>rwr�rPrJr#r�rr(r)r
rv�ranger6r+r�r��
from_iterabler�r�rk)1rrrr�r�r�r7r��imv�	lenparams�use_row_at_a_time�
downgradedrG�compiled_param�imv_single_values_expr�executemany_values�
max_params�total_num_of_params�num_params_per_batch�num_params_outside_of_batch�batches�compiled_batchesrCrHr4�all_keys�imv_values_counter�formatted_values_clause�keys_to_replace�base_parametersr"r#�all_expand_positions�escapedrD�compiled_batchrF�num_ins_params�extra_params_left�extra_params_right�batch_iterator�expanded_values_stringrsrirnr@rA�replaced_values_clauses�fmvr�)
r�r�r�rr�r�r�r�r�r�rr�rr��!_deliver_insertmanyvalues_batchess��
�
�������

�����
�
���
�
�

�
��
��
���
�

��
�����
������z-SQLCompiler._deliver_insertmanyvalues_batchesc 
s�|j|�fi|��}|j}|dur||d<d}n�j}|r-d�_�js'|�_�js-|�_�j�t�t�|d��d}d}�jrF|durFg}t	j
�|||fd|i|��}�jrr|durrt|�}�jrr�j
duro�j
|7_
n|�_
|j}	|	s��jjs��jjs��jjs�t�d�jj��|jr��jjs�t�d�jj���js�|jr�|jr�t�d	��|j}	n|j}	�j}
�jj}d
}|jr�|�j||jfi|��7}|d7}|
�|j�}
|j r߈�!||
�\}}
|j"r��#||�||
7}|	s�|s�|dd
�$dd�|	D��7}|j%}d}d}d}�j�p
|j}|�r�|j&}|du�rm|�sJ�dd�|	D�}g}|D]!}||v�r4d}n��'|�}|||v�rDd}n|�|��q)|du�re�jj(t)j*@�r[d}n
|dj+�reJd��t,|�t,|�}�j-|||d�}�j.�r|d|7}nd}|j/du�r��j0�jddfddi|��}�j1�r��jj2�r�|�s�t�j�nd}|d�j3|dd�|f7}n�|d|7}n�|	�s�|�r�|d7}|�r�t4d�jj5t6d|	�||j|j7du||�r�t|�nd|d�	�_8n�|j�r|dd
�$dd �|j9D��f7}n�d
�$d!d�t6d|	�D��}|�r�|�rX�jj(t)j:@�rX|j;�sXd}�jj(t)j<@}d
�$d"d �t=|	�D��}|�rGd
�$�fd#d �t=|	�D��}n|}|d$|�d%|�d&|�d'�7}n
d}|d(|�d)�7}t4d|t6d|	�||j|j7du||�rxt|�nd|||d*��_8n|d(|�d)�7}|j7du�r��j0|j7fi|��}|�r�|d|7}|�r��j.�s�|d|7}�j1�rˈjj2�s�|�s�t�j�nd}�j3|dd�|}�j�>d�|S)+Nr�FTr�rr�zWThe '%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)r�cSsg|]\}}}}|�qSr�r�)r�r�r�r�r�r�rU�rgz,SQLCompiler.visit_insert.<locals>.<listcomp>cSsi|]	\}}}}||�qSr�r�)r�r�r��param_namesr�r�r�r4�s
��z,SQLCompiler.visit_insert.<locals>.<dictcomp>zTsentinel selection rules should have prevented us from getting here for this dialect�r�r�rYrrfz %s%srrz DEFAULT VALUESr3)r7r8r:r;r=z
 VALUES %scss(�|]}dd�dd�|D��VqdS)r�r�css�|]	\}}}}|VqdSrr��r�r�r�r�r�r�r)grz5SQLCompiler.visit_insert.<locals>.<genexpr>.<genexpr>Nr�)r��crud_param_setr�r�r�r)es���
�z+SQLCompiler.visit_insert.<locals>.<genexpr>cSsg|]\}}}}|�qSr�r�rr�r�r�rUms
��css�|]
\}}d|��VqdS��pNr�r�r�r�r�r)���
�c3s8�|]\}^}}��|j|j��j�d|���VqdSr)rPr�r�r�)r�r�r�r�r(r�r�r)�s�
��
�z SELECT z FROM (VALUES (z)) AS imp_sen(z#, sen_counter) ORDER BY sen_counterz	 VALUES (r�)r1r2r4r6r7r8r:r;r<r=r>)?rrrvr�r�rrkror5r�_get_crud_paramsrzrr�
single_paramsr��supports_default_valuesr��supports_empty_insertr7r�r��_has_multi_parametersr�r�
_returning�_sort_by_parameter_orderr�r�r��format_tabler�r`r�r�r�rw�use_insertmanyvalues�use_sentinel_columnsr�r�rKrT�_insert_sentinelr]r�rr�r�r"�cte_follows_insertr�r0�default_metavalue_tokenr�_post_values_clauser�all_multi_paramsrV�is_default_metavalue_onlyrWr�rl) r�insert_stmtr�r�r�rr��counted_bindparam�crud_params_struct�crud_params_singler�rryr�r�r�named_sentinel_params�add_sentinel_colsr=r��_params_by_col�_add_sentinel_col�
param_namer��select_textr�rR�embed_sentinel_value�render_bind_casts�colnames�colnames_w_cast�post_values_clauser�r(r��visit_insertos��������	
���������������

	�
�
���������
����
�
����
������
�
�	���	�
������zSQLCompiler.visit_insertcCr)z3Provide a hook for MySQL to add LIMIT to the UPDATENr�)r�update_stmtr�r�r��update_limit_clause�r�zSQLCompiler.update_limit_clausecCr)z3Provide a hook for MySQL to add LIMIT to the DELETENr�)r�delete_stmtr�r�r��delete_limit_clause�r�zSQLCompiler.delete_limit_clausecKsd|d<|j|fddi|��S)z|Provide a hook to override the initial table clause
        in an UPDATE statement.

        MySQL overrides this.

        Tr&rr�)rr&�
from_table�extra_fromsr�r�r�r��update_tables_clause�sz SQLCompiler.update_tables_clausecK�td��)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 UPDATEr��rr&r*r+�
from_hintsr�r�r�r��update_from_clause�s	�zSQLCompiler.update_from_clausecs�|j||fi|��}|j}|dur||d<d}n|j}|r-d|_|js'||_|js-||_|jt@rCtit	��}|jt
@}|rB||_nd}d}|j}t
|�}	|	rft	t|j����fdd�|D�}
��|�}ng}
|jh}|j�|||d��d}|jr�||j||jfi|��7}|j||j|
fd|i|��}
tj||||fi|��}|j}|jr�|�||
�\}}
nd}|jr�|�||�||
7}|d	7}|d
�dd�td
|�D��7}|js�|jr�|j r�|d|j!||jp�|j|d�7}|�r|j"||j|
|fd|i|��}|�r|d|7}|j#�r |j$|j#fd|i|��}|�r |d|7}|�%|�}|�r.|d|7}|j�s6|j�rK|j �sK|d|j!||j�pE|j|d�7}|j&�ra|�sWt'|j�nd}|j(|d�|}|�rq|du�skJ�|j)dd�|j�*d�|S)Nr�FTcsg|]}|�vr|�qSr�r�ru��
main_fromsr�r�rU#sz,SQLCompiler.visit_update.<locals>.<listcomp>r�zUPDATE rVz SET r�css$�|]
\}}}}|d|VqdS)�=Nr�)r�r�r�r�r�r�r�r)Ss
�

�
�z+SQLCompiler.visit_update.<locals>.<genexpr>zList[Tuple[Any, str, str, Any]]r�r� WHERE r��UPDATE�r|rY)+rrrvr�r�rr.r^raror_rV�_extra_fromsrr*r�r�rkr�r�r,rrrr`r�r�r�rwrrrrr�r0rzr�r'r"rzr�r}rl)rr&r�r�rr�rVr�r+�
is_multitable�render_extra_fromsrryr�r�crud_paramsr��extra_from_textr�rr�r�r1r��visit_updates��

�
����������
��
�

�������
���
�zSQLCompiler.visit_updatecKr-)z�Provide 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 DELETEr�r.r�r�r��delete_extra_from_clause�s�z$SQLCompiler.delete_extra_from_clausecKs|j|fddd�|��S)NT)r&rr�)rr(r*r+r�r�r�r��delete_table_clause�s���zSQLCompiler.delete_table_clausecKs�|j||fi|��}|j}|dur||d<d}n|j}|r-d|_|js'||_|js-||_|jt@rCtit	��}|jt
@}|rB||_nd}d}|j}|j
h�|�}	|j�|	|	|d��d}
|jrm|
|j||jfi|��7}
|
d7}
z|j||j
||d�}Wnty�|�||j
|�}|r�|j|j
|d�}Ynwtj||||fi|��|jr�|�||�\}
}nd}
|jr�|�||�|
|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}
|�"|�}|�r|
d|7}
|j�s!|j�r6|j�s6|
d|j||j�p0|j|d	�7}
|j#�rL|�sBt$|j�nd}|j%|d�|
}
|�r\|du�sVJ�|j&d
d�|j�'d�|
S)Nr�FTr�zDELETE �FROM )rVr�rrVr4r��DELETEr6rY)(rrrvr�r�rr.r^raror_rVr7r�r�rkr�r�r>�	TypeErrorr�rrr`r�r�r�rrrr�r=rzr�r)r"rzr�r}rl)rr(r�r�rr�rVr�r+rryr�r�r�r;r�rr�r�r�r��visit_delete�s���

�����
����	
����

�������
���
�zSQLCompiler.visit_deletecK�d|j�|�S)NzSAVEPOINT %s�r��format_savepoint�r�savepoint_stmtr�r�r�r��visit_savepoint&�zSQLCompiler.visit_savepointcKrC)NzROLLBACK TO SAVEPOINT %srDrFr�r�r��visit_rollback_to_savepoint)��z'SQLCompiler.visit_rollback_to_savepointcKrC)NzRELEASE SAVEPOINT %srDrFr�r�r��visit_release_savepoint.rKz#SQLCompiler.visit_release_savepoint)r�r\rr�r�r�r,r"r-rr.r\r/r0r�r)rr)rr)rr_)rra)rr�)NT)r�r�r�rrr)NNTNTF)r�r�r�r�r�rr�r�r�rr:rrr[�F)rr[r;rrr)rr�)NFFNr�)NTr�N)r�rQrErRrSrrFr�rTrUr�rrr�r)NF)r�r�rErRr�rrr�)FN�Nr�)NFNN)FFFFF)r�r�r�rDrr�)r�r�rr�)FFNNNN)r�r�r�rr�rr�rr�r�r�r�r�rr�rrr�)r�rMr&rr�rr�r�r�r�rVr�r�r�r�rrr)FFFNFFNN)
r�r�r�r�r�r�rr�rr)NNNTFFT)FFNNNFN)r�rrrp�
r�rBr�r�r�rr�rrr�)NFF)FFFNTNN)r�rJrr9)rr�rrWr�r�r�rBr�r5r7rr�r�rr�rb)�r�r�r�r��EXTRACT_MAPr�r%r�r�r�r��COMPOUND_KEYWORDSrr�r�r�rrrrrr	r
rrrrrrrrrrr�	frozensetrrr�rr��postfetch_lastrowidrr#rr r!r(r*r�r��patternrwr�r�r'r]r�r/rR�ro_memoized_propertyrWrXr\r^�memoized_propertyr`�memoized_instancemethodrc�
contextlib�contextmanagerrgrMrLr�r�r�r�r�r�r�rN�preload_moduler�r�r
rrr"r'r)r9r>rJrMrPrcrgrkrmrqrzrYr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
r�rr#r%r)r+r/r1r:r8rNr�r-r\r]r^r_rar0rrrgrhrprtrxr|rr�r�r�r�r�r�r�rmrsrwr{r�r�r�r�r�r�rPr.r�r�r�rAr�r}r�r#�_CTEOptsr�rrrrr
rr'r*r+r�r�r3r1rrGrCrIrKrrr�rRrSrorar_rdr�r�r�rbr
rrr�rrr�r�r�r,�
CLIENTSIDErKrU�SENTINEL_DEFAULT�NONErRrSr�r�rQr�r�r�r%r'r)r,r0r<r=r>rBrHrJrLr�r�r�r�r�	sH
��
�
	

�

�

	�

"

;I
��
&
�F
R.
@�0�0�1�;�4		*�.
�A	�&		�JR�8�					�&�!%
�C�L�d
&��%��	�N4_�5 
�,�0����>^�t
r�cs�eZdZdZdd�Ze�d��fdd��Zdd�Zd	d
�Z	dd�Z
d
d�Zd+dd�Zdd�Z
dd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Z�ZS),�StrSQLCompilera�A :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`

    cCr)Nz<name unknown>r�rLr�r�r�rMHr�z$StrSQLCompiler._fallback_column_namezsqlalchemy.engine.urlcs`|jdkr)tjj}|j�|j����}|j|d|d�}t|t	�s)|j
|fi|��St��||�S)Nr�)r/)
�stringify_dialectr%r��
engine_url�URLr��get_dialect�statement_compilerr�r_r�r�r�)rr�r�r��urlr��compilerr�r�r�r�Ks
�
z,StrSQLCompiler.visit_unsupported_compilationcKs,d|j|jfi|��|j|jfi|��fS)Nz%s[%s])r�rxr�r"r�r�r��visit_getitem_binaryYr�z#StrSQLCompiler.visit_getitem_binarycK�|j||fi|��Sr�rgr"r�r�r��visit_json_getitem_op_binary_r�z+StrSQLCompiler.visit_json_getitem_op_binarycKrhrrir"r�r�r��!visit_json_path_getitem_op_binarybr�z0StrSQLCompiler.visit_json_path_getitem_op_binarycKsd|j�|��d�S)Nz<next sequence value: �>)r��format_sequencerr�r�r�r�es�zStrSQLCompiler.visit_sequencer�rBr�r�r�rr�rrr�cs&�fdd�t�|�D�}dd�|�S)Nc	sg|]}��d|ddi��qS)NTFr0rSr(r�r�rUrs��z3StrSQLCompiler.returning_clause.<locals>.<listcomp>r�r�)rr�rwr�r�r(r�r�js
�zStrSQLCompiler.returning_clausecs(d�d<dd����fdd�|D��S)NTr&r?r�c3�&�|]}|j�fd�i���VqdS�r�Nr��r�r��r/r�rr�r�r)|�
��
�z4StrSQLCompiler.update_from_clause.<locals>.<genexpr>r�r.r�rqr�r0x�
�z!StrSQLCompiler.update_from_clausecs(d�d<dd����fdd�|D��S)NTr&r�c3rnror�rprqr�r�r)�rrz:StrSQLCompiler.delete_extra_from_clause.<locals>.<genexpr>r�r.r�rqr�r=�rsz'StrSQLCompiler.delete_extra_from_clausecKr)NzSELECT 1 WHERE 1!=1r�r;r�r�r�r8�r�z#StrSQLCompiler.visit_empty_set_exprcCsd|S)Nz[%s]r�rHr�r�r�rC�r.z!StrSQLCompiler.get_from_hint_textcK�|j|dfi|��S)Nz
 <regexp> �r0r"r�r�r�r��r�z+StrSQLCompiler.visit_regexp_match_op_binarycKrt)Nz <not regexp> rur"r�r�r�r��r�z/StrSQLCompiler.visit_not_regexp_match_op_binarycKs,d|jj|fi|��|jj|fi|��fS)Nz<regexp replace>(%s, %s))rxr�r�r"r�r�r�r��r�z-StrSQLCompiler.visit_regexp_replace_op_binarycKr�)NzTRY_CAST(%s AS %s))r�r�rp)rrr�r�r�r��visit_try_cast�r�zStrSQLCompiler.visit_try_castrO)r�r�r�r�rMr%rZr�rgrjrkr�r�r0r=r8rCr�r�r�rvr�r�r�r�r�r_4s$

		r_c@s�eZdZdZer			dpdqd
d�Zejdd��Zejdd��Z				drdsdd�Z
dd�Zdd �Zd!d"�Z
d#d$�Zdtd&d'�Z	dud(d)�Zd*d+�Zd,d-�Zd.d/�Z	dvd0d1�Zd2d3�Zdtd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Zd@dA�ZdBdC�ZdDdE�ZdudFdG�ZdHdI�Z dJdK�Z!dLdM�Z"dNdO�Z#dPdQ�Z$dRdS�Z%dTdU�Z&dVdW�Z'dXdY�Z(dZd[�Z)d\d]�Z*d^d_�Z+d`da�Z,dbdc�Z-ddde�Z.dfdg�Z/dhdi�Z0djdk�Z1dldm�Z2dndo�Z3dS)w�DDLCompilerT.r�r\rr@r�r�r�rr�r�cCrrr�r�r�r�r�r��szDDLCompiler.__init__cCs|jj|jd|jd�S)Nr�)r�rdr�r(r�r�r�r��s
�zDDLCompiler.sql_compilercCr�r)r�ror(r�r�r��
type_compiler�r�zDDLCompiler.type_compilerNr�r�r�r�r�rr�cCrrr�r�r�r�r�r��rzDDLCompiler.construct_paramscKs�|j}t|jtj�rD|��}|j}|�|j�}t|�dkr%|dd}}n	|d|d}}|�	d|�|�	d|�|�	d|�
|j��|j�|j
|�S)Nrrr�rYr�r"r�)�contextr��targetr"rJr�r��format_table_seqrzr$r
r�rzr)r�ddlr�ryr��pathr��schr�r�r��	visit_ddl�szDDLCompiler.visit_ddlcK�$d}|jr	|d7}||j�|j�S)NzCREATE SCHEMA �IF NOT EXISTS )�
if_not_existsr��
format_schemar�)rr�r�ryr�r�r��visit_create_schema��zDDLCompiler.visit_create_schemacKs6d}|jr	|d7}||j�|j�7}|jr|d7}|S)NzDROP SCHEMA �
IF EXISTS � CASCADE)�	if_existsr�r�r��cascade�r�dropr�ryr�r�r��visit_drop_schema�szDDLCompiler.visit_drop_schemacKsF|j}|j}d}|jr|d�|j�d7}|d7}|jr |d7}||�|�d7}|�|�}|r6||d7}|d7}d}d}|jD]D}	|	j}
z"|j|	|
j	oO|d�}|durb||7}d	}|d
|7}|
j	rgd}WqAt
jy�}zt
�d|j|
j
|jd
f�|�d}~ww|j||jd�}
|
r�||d
|
7}|d|�|�7}|S)Nz
CREATE r�zTABLE r�r��
F��first_pkr��	Tz (in table '%s', column '%s'): %sr)� _include_foreign_key_constraintsz
)%s

)r�r�r�rwr�r
�create_table_suffixr)r�rr7r��descriptionr��args�create_table_constraints�include_foreign_key_constraints�post_create_table)rr�r�r�r�ryr�r�r��
create_columnr��	processed�ce�constr�r�r��visit_create_table�s\

��������zDDLCompiler.visit_create_tableFcsL|j}|jrdS�j||d�}d��fdd�|jD��}|r$|d|7}|S)Nr�r�c3s�|]}��|�VqdSr)r��r�r�r(r�r�r) s�

�z2DDLCompiler.visit_create_column.<locals>.<genexpr>)r��system�get_column_specificationrw�constraints)rr�r�r�r�ryr�r�r(r��visit_create_columns�zDDLCompiler.visit_create_columncstg}�jr|��j��j}|dur|�|��nt��|���fdd��jD��d�dd��fdd�|D�D��S)Ncs"g|]
}|�jur|�vr|�qSr�)rrS)�	omit_fkcsr�r�r�rU8s
�z8DDLCompiler.create_table_constraints.<locals>.<listcomp>z, 
	css�|]	}|dur|VqdSrr�)r�rr�r�r�r)?s�	�
�z7DDLCompiler.create_table_constraints.<locals>.<genexpr>c3s8�|]}|���r�jjrt|dd�s��|�VqdS)�	use_alterFN)�_should_create_for_compilerr��supports_alterr�r�r�r(r�r�r)As���
�
�)rrk�foreign_key_constraintsrPror��_sorted_constraintsrw)rr�r�r�r��all_fkcsr�)r�rr�r�r�(s"��

��z$DDLCompiler.create_table_constraintscKr�)Nz
DROP TABLE r�)r�r�r
r�r�r�r�r��visit_drop_tableMr�zDDLCompiler.visit_drop_tablecKsd|j�|j�S)Nz
DROP VIEW �r�r
r��rr�r�r�r�r��visit_drop_viewSr�zDDLCompiler.visit_drop_viewcCs|jdur
t�d|j��dS)Nz,Index '%s' is not associated with any table.)r�r7r�r��rrhr�r�r��_verify_index_tableVs

��zDDLCompiler._verify_index_tablec	s�|j}��|��j}d}|jr|d7}|jdurt�d��|d7}|jr)|d7}|d�j||d�|j	|j
|d�d	��fd
d�|jD��f7}|S)NzCREATE zUNIQUE z0CREATE INDEX requires that the index have a namezINDEX r�z
%s ON %s (%s)��include_schema�r�r�c3s"�|]}�jj|ddd�VqdS)FT�rSr�N)r�r�)r�r�r(r�r�r)sr�z1DDLCompiler.visit_create_index.<locals>.<genexpr>)
r�r�r�r�r�r7r�r��_prepared_index_namer
r�rw�expressions)rr�r��include_table_schemar�rhr�ryr�r(r��visit_create_index\s.

����zDDLCompiler.visit_create_indexcKs>|j}|jdur
t�d��d}|jr|d7}||j|dd�S)Nz.DROP INDEX requires that the index have a namez
DROP INDEX r�Tr�)r�r�r7r�r�r�)rr�r�rhryr�r�r��visit_drop_index|s
�zDDLCompiler.visit_drop_indexcCsX|jdur
|j�|j�}nd}|r|r|j�|�}nd}|j�|�}|r*|d|}|S�Nr�)r�r�r\r]�format_index)rrhr�r`�schema_name�
index_namer�r�r�r��s
z DDLCompiler._prepared_index_namecKs d|j�|jj�|�|j�fS)NzALTER TABLE %s ADD %s)r�r
r�r�r��rr�r�r�r�r��visit_add_constraint�s
�z DDLCompiler.visit_add_constraintcKs(d|j�|j�|j�|jjt���fS)NzCOMMENT ON TABLE %s IS %s)r�r
r�r�r��commentr$�Stringr�r�r�r��visit_set_table_comment�s��z#DDLCompiler.visit_set_table_commentcKsd|j�|j�S)NzCOMMENT ON TABLE %s IS NULLr�r�r�r�r��visit_drop_table_comment�s�z$DDLCompiler.visit_drop_table_commentcKs.d|jj|jddd�|j�|jjt���fS)NzCOMMENT ON COLUMN %s IS %sT)�	use_tabler�)r��
format_columnr�r�r�r�r$r�r�r�r�r��visit_set_column_comment�s���z$DDLCompiler.visit_set_column_commentcKsd|jj|jdd�S)NzCOMMENT ON COLUMN %s IS NULLT)r�)r�r�r�r�r�r�r��visit_drop_column_comment�s�z%DDLCompiler.visit_drop_column_commentcK�t�|t|���rr�r�r�r�r��visit_set_constraint_comment�rIz(DDLCompiler.visit_set_constraint_commentcKr�rr�r�r�r�r��visit_drop_constraint_comment�rIz)DDLCompiler.visit_drop_constraint_commentcCs�g}|jdur|�d|j�|jdur|�d|j�|jdur)|�d|j�|jdur6|�d|j�|jdur@|�d�|jdurJ|�d�|jdurW|�d|j�|jdurf|�|jrcdnd	�d
�	|�S)NzINCREMENT BY %dz
START WITH %dzMINVALUE %dzMAXVALUE %dzNO MINVALUEzNO MAXVALUEzCACHE %d�CYCLEzNO CYCLEr�)
�	incrementrkrs�minvalue�maxvalue�
nominvalue�
nomaxvalue�cache�cyclerw)r�identity_optionsryr�r�r��get_identity_options�s$










z DDLCompiler.get_identity_optionscKsPd}|jr	|d7}||j�|j�7}|r||7}|�|j�}|r&|d|7}|S)NzCREATE SEQUENCE r�r�)r�r�rmr�r�)rr�r�r�ry�optionsr�r�r��visit_create_sequence�sz!DDLCompiler.visit_create_sequencecKr�)NzDROP SEQUENCE r�)r�r�rmr�r�r�r�r��visit_drop_sequence�r�zDDLCompiler.visit_drop_sequencecKsn|j}|jdur|j�|�}nd}|durt�d|j��d|j�|jj�|jr*dnd||j	r3dfSdfS)Nz<Can't emit DROP CONSTRAINT for constraint %r; it has no namez%ALTER TABLE %s DROP CONSTRAINT %s%s%sr�r�r�)
r�r�r��format_constraintr7r�r
r�r�r�)rr�r�r��formatted_namer�r�r��visit_drop_constraint�s$
����z!DDLCompiler.visit_drop_constraintcKs�|j�|�d|jjj|j|d�}|�|�}|dur!|d|7}|jdur0|d|�|j�7}|jdurC|jj	rC|d|�|j�7}|j
sQ|jrM|jj	sQ|d7}|S)Nr�)rnz	 DEFAULT z	 NOT NULL)r�r�r�ror�r��get_column_default_string�computed�identity�supports_identity_columns�nullable)rr�r��colspecr�r�r�r�r��s0
����


���z$DDLCompiler.get_column_specificationcCr�Nr�r��rr�r�r�r�r�r�zDDLCompiler.create_table_suffixcCrr�r�r�r�r�r�r�r�zDDLCompiler.post_create_tablecCs t|jtj�r|�|jj�SdSr)r��server_defaultr"�
DefaultClause�render_default_string�argrLr�r�r�r�sz%DDLCompiler.get_column_default_stringcCs*t|t�r
|j�|tj�S|jj|dd�S)NT)r�)r�r�r�r�r$rfr�)rr�r�r�r�r�"s

�z!DDLCompiler.render_default_stringcKs|jr|�|�S|�|�Sr)�is_column_level�visit_column_check_constraint�visit_check_constraint�rr�r�r�r�r��&visit_table_or_column_check_constraint*s

z2DDLCompiler.visit_table_or_column_check_constraintcK�\d}|jdur|j�|�}|dur|d|7}|d|jj|jddd�7}||�|�7}|S�Nr��CONSTRAINT %s z
CHECK (%s)FTr��r�r�r�r�r�r�define_constraint_deferrability�rr�r�ryr�r�r�r�r�0�


�z"DDLCompiler.visit_check_constraintcKr�r�r�r�r�r�r�r�<r�z)DDLCompiler.visit_column_check_constraintcs�t|�dkrdSd}|jdur�j�|�}|dur|d|7}|d7}|dd��fdd�|jr2|jn|jD��7}|��|�7}|S)	Nrr�r�zPRIMARY KEY r�r�c3��|]
}�j�|j�VqdSr�r�rZr�rSr(r�r�r)Qr�z;DDLCompiler.visit_primary_key_constraint.<locals>.<genexpr>)	rzr�r�r�rw�_implicit_generated�columns_autoinc_firstr)r�r�r�r(r��visit_primary_key_constraintHs
��z(DDLCompiler.visit_primary_key_constraintc	s�|j�d}|jdur|j�|�}|dur|d|7}t|j�djj}|dd��fdd�|jD��|�||��d��fdd�|jD��f7}||�	|�7}||�
|�7}||�|�7}|S)	Nr�r�rz"FOREIGN KEY(%s) REFERENCES %s (%s)r�c3��|]
}��|jj�VqdSr)rZ�parentr�ru�r�r�r�r)erz;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>c3r�r)rZr�r�rur�r�r�r)kr)r�r�r�r]rr�r�rw�define_constraint_remote_table�define_constraint_match�define_constraint_cascadesr�)rr�r�ryr��remote_tabler�r�r��visit_foreign_key_constraint\s,
����z(DDLCompiler.visit_foreign_key_constraintcCs
|�|�S)z=Format the remote table clause of a CREATE CONSTRAINT clause.)r
)rr�r�r�r�r�r�r�t�
z*DDLCompiler.define_constraint_remote_tablecs�t|�dkrdSd}|jdur�j�|�}|dur|d|7}|d�j|fi|��d��fdd�|D��f7}|��|�7}|S)Nrr�r�z
UNIQUE %s(%s)r�c3r�rr�rSr(r�r�r)�s�z6DDLCompiler.visit_unique_constraint.<locals>.<genexpr>)rzr�r�r��!define_unique_constraint_distinctrwr�r�r�r(r��visit_unique_constraintys
�z#DDLCompiler.visit_unique_constraintcKrr�r�r�r�r�r�r��r�z-DDLCompiler.define_unique_constraint_distinctcCsLd}|jdur|d|j�|jt�7}|jdur$|d|j�|jt�7}|S)Nr�z
 ON DELETE %sz
 ON UPDATE %s)�ondeleter��validate_sql_phrase�FK_ON_DELETE�onupdate�FK_ON_UPDATE�rr�ryr�r�r�r��s

�

�z&DDLCompiler.define_constraint_cascadescCsLd}|jdur|jr|d7}n|d7}|jdur$|d|j�|jt�7}|S)Nr�z DEFERRABLEz NOT DEFERRABLEz
 INITIALLY %s)r�r�r�r�FK_INITIALLYrr�r�r�r��s



�z+DDLCompiler.define_constraint_deferrabilitycCs d}|jdur|d|j7}|S)Nr�z	 MATCH %s)r�rr�r�r�r��s
z#DDLCompiler.define_constraint_matchcKsDd|jj|jddd�}|jdur|d7}|S|jdur |d7}|S)NzGENERATED ALWAYS AS (%s)FTr�z STOREDz VIRTUAL)r�r�r�	persisted)r�	generatedr�ryr�r�r��visit_computed_column�s�

�z!DDLCompiler.visit_computed_columncKs2d|jrdndf}|�|�}|r|d|7}|S)NzGENERATED %s AS IDENTITY�ALWAYSz
BY DEFAULTr�)�alwaysr�)rr�r�ryr�r�r�r��visit_identity_column�s�
z!DDLCompiler.visit_identity_column)...)
r�r\rr@r�r�r�rr�r�r�r�rMr)FT)4r�r�r�r�rr�r%rVr�rxr�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r
r
r�r�r�r�rw�st�	

�	
4
�%
� 






rwc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd`d d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,dVdW�Z-dXdY�Z.dZd[�Z/d\d]�Z0d^d_�Z1dS)a�GenericTypeCompilercKr)N�FLOATr�r�r�r�r��visit_FLOAT�r�zGenericTypeCompiler.visit_FLOATcKr)N�DOUBLEr�r�r�r�r��visit_DOUBLE�r�z GenericTypeCompiler.visit_DOUBLEcKr)NzDOUBLE PRECISIONr�r�r�r�r��visit_DOUBLE_PRECISION�r�z*GenericTypeCompiler.visit_DOUBLE_PRECISIONcKr)N�REALr�r�r�r�r��
visit_REAL�r�zGenericTypeCompiler.visit_REALcK�8|jdurdS|jdurdd|jiSd|j|jd�S)N�NUMERICzNUMERIC(%(precision)s)�	precisionz!NUMERIC(%(precision)s, %(scale)s)�r�scalerr�r�r�r��
visit_NUMERIC��

�z!GenericTypeCompiler.visit_NUMERICcKr)N�DECIMALzDECIMAL(%(precision)s)rz!DECIMAL(%(precision)s, %(scale)s)rrr�r�r�r��
visit_DECIMAL�rz!GenericTypeCompiler.visit_DECIMALcKr)N�INTEGERr�r�r�r�r��
visit_INTEGER�r�z!GenericTypeCompiler.visit_INTEGERcKr)N�SMALLINTr�r�r�r�r��visit_SMALLINT�r�z"GenericTypeCompiler.visit_SMALLINTcKr)N�BIGINTr�r�r�r�r��visit_BIGINT�r�z GenericTypeCompiler.visit_BIGINTcKr)N�	TIMESTAMPr�r�r�r�r��visit_TIMESTAMP�r�z#GenericTypeCompiler.visit_TIMESTAMPcKr)N�DATETIMEr�r�r�r�r��visit_DATETIME�r�z"GenericTypeCompiler.visit_DATETIMEcKr)N�DATEr�r�r�r�r��
visit_DATE�r�zGenericTypeCompiler.visit_DATEcKr)N�TIMEr�r�r�r�r��
visit_TIME�r�zGenericTypeCompiler.visit_TIMEcKr)N�CLOBr�r�r�r�r��
visit_CLOB�r�zGenericTypeCompiler.visit_CLOBcKr)N�NCLOBr�r�r�r�r��visit_NCLOB�r�zGenericTypeCompiler.visit_NCLOBNcCsB|}|r|d|7}n
|jr|d|j7}|jr|d|j7}|S)N�(%d)z
 COLLATE "%s")�lengthre)rrr��length_overrideryr�r�r��_render_string_type�sz'GenericTypeCompiler._render_string_typecK�|�|d�S)N�CHAR�r4r�r�r�r��
visit_CHARr�zGenericTypeCompiler.visit_CHARcKr5)N�NCHARr7r�r�r�r��visit_NCHAR	r�zGenericTypeCompiler.visit_NCHARcKr5)N�VARCHARr7r�r�r�r��
visit_VARCHARr�z!GenericTypeCompiler.visit_VARCHARcKr5)N�NVARCHARr7r�r�r�r��visit_NVARCHARr�z"GenericTypeCompiler.visit_NVARCHARcKr5)N�TEXTr7r�r�r�r��
visit_TEXTr�zGenericTypeCompiler.visit_TEXTcKr)N�UUIDr�r�r�r�r��
visit_UUIDr�zGenericTypeCompiler.visit_UUIDcKr)N�BLOBr�r�r�r�r��
visit_BLOBr�zGenericTypeCompiler.visit_BLOBcK�d|jr	d|jp
dS)N�BINARYr1r��r2r�r�r�r��visit_BINARYrdz GenericTypeCompiler.visit_BINARYcKrE)N�	VARBINARYr1r�rGr�r�r�r��visit_VARBINARYrdz#GenericTypeCompiler.visit_VARBINARYcKr)N�BOOLEANr�r�r�r�r��
visit_BOOLEAN!r�z!GenericTypeCompiler.visit_BOOLEANcKs0|jr|jjs|j|ddd�S|j|fi|��S)Nr6� )r3)�native_uuidr��supports_native_uuidr4rBr�r�r�r��
visit_uuid$szGenericTypeCompiler.visit_uuidcKr
r)rDr�r�r�r��visit_large_binary*r�z&GenericTypeCompiler.visit_large_binarycKr
r)rLr�r�r�r��
visit_boolean-r�z!GenericTypeCompiler.visit_booleancKr
r)r,r�r�r�r��
visit_time0r�zGenericTypeCompiler.visit_timecKr
r)r(r�r�r�r��visit_datetime3r�z"GenericTypeCompiler.visit_datetimecKr
r)r*r�r�r�r��
visit_date6r�zGenericTypeCompiler.visit_datecKr
r)r$r�r�r�r��visit_big_integer9r�z%GenericTypeCompiler.visit_big_integercKr
r)r"r�r�r�r��visit_small_integer<r�z'GenericTypeCompiler.visit_small_integercKr
r)r r�r�r�r��
visit_integer?r�z!GenericTypeCompiler.visit_integercKr
r)rr�r�r�r��
visit_realBr�zGenericTypeCompiler.visit_realcKr
r)rr�r�r�r��visit_floatEr�zGenericTypeCompiler.visit_floatcKr
r)rr�r�r�r��visit_doubleHr�z GenericTypeCompiler.visit_doublecKr
r)rr�r�r�r��
visit_numericKr�z!GenericTypeCompiler.visit_numericcKr
r�r<r�r�r�r��visit_stringNr�z GenericTypeCompiler.visit_stringcKr
rr]r�r�r�r��
visit_unicodeQr�z!GenericTypeCompiler.visit_unicodecKr
r�r@r�r�r�r��
visit_textTr�zGenericTypeCompiler.visit_textcKr
rr`r�r�r�r��visit_unicode_textWr�z&GenericTypeCompiler.visit_unicode_textcKr
rr]r�r�r�r��
visit_enumZr�zGenericTypeCompiler.visit_enumcKst�d|��)NzKCan't generate DDL for %r; did you forget to specify a type on this Column?rKr�r�r�r�r�]s
��zGenericTypeCompiler.visit_nullcKs|j|�|j�fi|��Sr)r��type_enginer�r�r�r�r��visit_type_decoratordr,z(GenericTypeCompiler.visit_type_decoratorcKs|jdi|��SrN)�get_col_specr�r�r�r��visit_user_definedgrIz&GenericTypeCompiler.visit_user_definedr)2r�r�r�rrrrrrr r"r$r&r(r*r,r.r0r4r8r:r<r>r@rBrDrHrJrLrPrQrRrSrTrUrVrWrXrYrZr[r\r^r_rarbrcr�rergr�r�r�r�r�s`

rc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�StrSQLTypeCompilercKs@z|j}Wnty|j|fi|��YSw||fi|��Sr)r��AttributeError�_visit_unknown)rrr�r�r�r�r�r�ls
�zStrSQLTypeCompiler.processcCs|�d�r|jSt|��)N�visit_)r>rjri)rr'r�r�r��__getattr__ts
zStrSQLTypeCompiler.__getattr__cKs$|jj|jj��kr|jjSt|�Sr)r�r��upper�reprr�r�r�r�rjzsz!StrSQLTypeCompiler._visit_unknowncKrr�r�r�r�r�r�r��r�zStrSQLTypeCompiler.visit_nullcKs4z|j}Wn
tyt|�YSw|di|��SrN)rfrirn)rrr�rfr�r�r�rg�s
�z%StrSQLTypeCompiler.visit_user_definedN)r�r�r�r�rlrjr�rgr�r�r�r�rhksrhc@�eZdZddd�ZdS)	�_SchemaForObjectCallable�_SchemaForObjectCallable__objrrr�cCrrr�)rrqr�r�r�r��z!_SchemaForObjectCallable.__call__N)rqrrr�r	r�r�r�r�rp�r
rpc@ro)	r�r�rQrr�cCrrr�)rr�r�r�r�r�rrz _BindNameForColProtocol.__call__N)r�rQrr�r	r�r�r�r�r��r
r�c@s�eZdZUdZeZeZeZ	de
d<de
d<de
d<e�d�Z
de
d	<	d
Zde
d<	
		
		
dTdd�Zdd�Zdd�ZdUdd�ZdUdd�Zdd�ZdUdd�ZdVd d!�Zd"d#�ZdWdXd&d'�ZdWdYd)d*�Zd+d,�ZdZd-d.�Z	dWd[d3d4�Z	dWd\d7d8�ZdWd9d:�Ze� d;�dZd<d=��Z!dZd>d?�Z"dZd@dA�Z#dBdC�Z$dDdE�Z%d]dFdG�Z&dHdI�Z'	dWdJdK�Z(	
			
	d^dLdM�Z)dZdNdO�Z*ej+dPdQ��Z,dRdS�Z-dS)_r�z@Handle quoting and case-folding of identifiers based on options.r��
initial_quote�final_quotezMutableMapping[str, str]�_stringsr"rpr\Fr�_includes_none_schema_translaterzNTcCsN||_||_|p
|j|_||_|jd|_||_||_i|_|jjdv|_	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)r�r�N)
r�rsrt�escape_quote�escape_to_quote�omit_schema�quote_case_sensitive_collationsrur=rv)rr�rsrtrwrzryr�r�r�r��szIdentifierPreparer.__init__cs@|j�|j�}|j�|j�d|v��fdd�}||_�|_|S)NcsX|j}|jr)|dus�r)|durd|vsd|vrt�d|��td|p$ddd�S|jS)Nr�r�zJSquare bracket characters ([]) not supported in schema translate name '%s'z
__[SCHEMA_%s]�_noneF�rZ)r"�_use_schema_mapr7r�r0)r�r���
includes_noner�r��
symbol_getter�s���z@IdentifierPreparer._with_schema_translate.<locals>.symbol_getter)r��__new__rIrJr\rv)rr��prepr�r�r~r�r��sz)IdentifierPreparer._with_schema_translatecsD|�d�vr�jst�d���d�d<��fdd�}t�d||�S)Nz�schema 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.r{csV|�d�}|�vr�|}n|dvrt�d��|}|s&�jj}|s&t�d����|�S)Nr6)Nr{z�schema 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�r7r*r��default_schema_namer�r])rir�r`��drr�r�rw�s

��
z=IdentifierPreparer._render_schema_translates.<locals>.replacez(__\[SCHEMA_([^\]]+)\]))rvr7r*r(rv)rrr�rwr�r�r�r��s�z,IdentifierPreparer._render_schema_translatesr�rcCs&|�|j|j�}|jr|�dd�}|S)z�Escape an identifier.

        Subclasses should override this to provide database-dependent
        escaping behavior.
        r�rt)rwrwrxrv�rr�r�r�r��_escape_identifiersz%IdentifierPreparer._escape_identifiercCs|�|j|j�S)z�Canonicalize an escaped identifier.

        Subclasses should override this to provide database-dependent
        unescaping behavior that reverses _escape_identifier.
        )rwrxrwr�r�r�r��_unescape_identifier!sz'IdentifierPreparer._unescape_identifiercCs*|dur|�|�st�d||jf��|S)z�keyword 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�r7r�rT)rr�r+r�r�r�r*s��z&IdentifierPreparer.validate_sql_phrasecCs|j|�|�|jS)z~Quote an identifier.

        Subclasses should override this to provide database-dependent
        quoting behavior.
        )rsr�rtr�r�r�r��quote_identifier<s���z#IdentifierPreparer.quote_identifiercCs:|��}||jvp|d|jvp|j�t|��p||kS)z5Return True if the given identifier requires quoting.r)r��reserved_words�illegal_initial_characters�legal_charactersr�r�)rr��lc_valuer�r�r�r�Is
���z#IdentifierPreparer._requires_quotescCs|j�t|��S)zjReturn True if the given identifier requires quoting, but
        not taking case convention into account.)r�r�r�r�r�r�r�r�Ssz1IdentifierPreparer._requires_quotes_illegal_chars�forcercCs |durtjddd�|�|�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`.

        Nz�The 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.9r�)r%r�rZ)rr"r�r�r�r�r]Xs�

zIdentifierPreparer.quote_schemar�cCs�|durtjddd�t|dd�}|dur7||jvr|j|S|�|�r-|�|�|j|<n||j|<|j|S|r>|�|�S|S)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`.

        Nz�The 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().r�r�rZ)r%r�r�rur�r�)rr�r�r�r�r�rZs �






zIdentifierPreparer.quotecCs|jr|�|�S|Sr)rzrZ)r�collation_namer�r�r�rd�s
z#IdentifierPreparer.format_collationcCs>|�|j�}|�|�}|js|r|dur|�|�d|}|Sr�)rZr�r\ryr])rr�r�r�r`r�r�r�rm�s
��z"IdentifierPreparer.format_sequencer��
Label[Any]r�rcCs|�|p|j�Sr�rZr�)rr�r�r�r�r�rD�szIdentifierPreparer.format_labelrV�Optional[AliasedReturnsRows]cCs*|dur|dus
J�|�|j�S|�|�Srr�)rrVr�r�r�r�r��s
zIdentifierPreparer.format_aliascCs"|p|j}|�|�r|�|�}|Sr)r�r�r�)r�	savepointr�r�r�r�r�rE�s


z#IdentifierPreparer.format_savepointzsqlalchemy.sql.namingcCsZtjj}|jtur|�||j�}|durdSn|j}|jdkr&|j||d�S|j	||d�S)Nrh)�_alembic_quote)
r%r��
sql_namingr�r+�_constraint_name_for_tabler�r��truncate_and_render_index_name�#truncate_and_render_constraint_name)rr�r��namingr�r�r�r�r��s 
��
��z$IdentifierPreparer.format_constraintcC�|jjp|jj}|�|||�Sr)r��max_index_name_lengthrB� _truncate_and_render_maxlen_name�rr�r��max_r�r�r�r�����z1IdentifierPreparer.truncate_and_render_index_namecCr�r)r��max_constraint_name_lengthrBr�r�r�r�r�r�r�z6IdentifierPreparer.truncate_and_render_constraint_namecCs^t|tj�r t|�|kr|d|d�dt�|�dd�}n|j�|�|s*|S|�|�S)NrrMr����)	r�rrDrzr%�md5_hexr��validate_identifierrZ)rr�r�r�r�r�r�r�s&�
z3IdentifierPreparer._truncate_and_render_maxlen_namecC�
|�|�Sr)r�r�r�r�r�r�r�zIdentifierPreparer.format_indexcCsF|dur|j}|�|�}|�|�}|js!|r!|r!|�|�d|}|S)z'Prepare a quoted table and schema name.Nr�)r�rZr\ryr])rr�r�r�rr`r�r�r�r
s

zIdentifierPreparer.format_tablecCr�)zPrepare a quoted schema name.r|r�r�r�r�r�)r�z IdentifierPreparer.format_schemacCs(|durt|tj�r|�|�}|�|�S)�Prepare a quoted column name.N)r�rrDr�rZ)rr�rCr�r�r�r�.s

�

z$IdentifierPreparer.format_label_namecCs�|dur|j}|durt|tj�r|�|�}t|dd�s3|r.|j|j||d�d|�|�S|�|�S|rB|j|j||d�d|S|S)r�NrWF)r�r�r�)	r�r�rrDr�r�r
r�rZ)rr�r�r��
table_namer�rCr�r�r�r�<s6
�
����
����z IdentifierPreparer.format_columncCs@|�|�}|js|r|r|�|�|j|dd�fS|j|dd�fS)z(Format table name and schema as a tuple.Fr�)r\ryr]r
)rr�r�r`r�r�r�r{is
�z#IdentifierPreparer.format_table_seqcCs@dd�|j|j|�|j�fD�\}}}t�d|||d��}|S)Ncss�|]}t�|�VqdSr)r(r)r�r�r�r�r)|s
��
�z4IdentifierPreparer._r_identifiers.<locals>.<genexpr>zM(?:(?:%(initial)s((?:%(escaped)s|[^%(final)s])+)%(final)s|([^\.]+))(?=\.|$))+)�initial�finalr�)rsrtr�r(r*)rr�r��
escaped_final�rr�r�r��_r_identifierszs
��
��z!IdentifierPreparer._r_identifierscs(�j}�fdd�dd�|�|�D�D�S)z:Unpack 'schema.table.column'-like strings into components.csg|]}��|��qSr�)r�r�r(r�r�rU�s��z;IdentifierPreparer.unformat_identifiers.<locals>.<listcomp>cSsg|]\}}|p	|�qSr�r�)r��ar3r�r�r�rU�rg)r��findall)r�identifiersr�r�r(r��unformat_identifiers�s
�z'IdentifierPreparer.unformat_identifiers)rzNrzTF)r�r�rr�)r�r�rrr)r"r�r�rrr�)r�r�r�rrr�)T)r�r�r�rrr�)rVr�r�rrr�)TN)FNNFN).r�r�r�r��RESERVED_WORDSr��LEGAL_CHARACTERSr��ILLEGAL_INITIAL_CHARACTERSr�r�r��
attrgetterr\rvr�r�r�r�r�rr�r�r�r]rZrdrmrDr�rEr%rZr�r�r�r�r�r
r�r�r�r{rVr�r�r�r�r�r�r��sl


�$
)
	



'4
��
		



�
�
-
r�)�r��
__future__rrm�collections.abc�abcrFrX�enumrr�r�r�r(�timerrrrrrr	r
rrr
rrrrrrrrrrrrr�rrrrrr r!r"r#r$r%r��_typingr'r(r)r*r+r,r-r.r/r0r1r2�type_apir3�visitorsr4r5r7r8�util.typingr9r:r;�
annotationr<r=r>r�r?r|r@�dmlrArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrS�
engine.cursorrT�engine.interfacesrUrVrWrXrYrZr[r\r]r��_FromHintsTyper�r*�Ir��LEGAL_CHARACTERS_PLUS_SPACEr�r�r�rrr�UNICODEr�r�r?r@r��or_r��mulrv�mod�neg�lt�le�ne�gt�ge�eq�is_distinct_from�is_not_distinct_from�	concat_opr.�not_match_opr7r6r�r{rCr�r�r��exists�distinct_op�inv�any_op�all_op�desc_op�asc_op�nulls_first_op�
nulls_last_op�bitwise_xor_op�
bitwise_or_op�bitwise_and_op�bitwise_not_op�bitwise_lshift_op�bitwise_rshift_oprBr�r�r�r�r�r�r�r�r�r�r�cube�rollup�
grouping_setsr�r�rP�_CompoundSelectKeywordr��	UNION_ALLr��
EXCEPT_ALLr��
INTERSECT_ALLrQr�r�rrr
rrrrr0r?rKrXr\r+r]r^r_r`�
namedtuplerar��EnsureKWArgr��BinaryElementRole�CompilerColumnElementr�r�r�r_rwrrhrpr�r�r�r�r�r��<module>s~a���
�������	�
���
������������������ �!�#�$�%�&�1���
=w�BL
�
�&Uo.!