
    g2                      U d Z ddlmZ ddlZddlmZ ddlZddlm	Z	 ddl
Z
ddlZddlZddlZddlmZ ddlZddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddlm#Z# ddlm$Z$ ddlm%Z% ddl&m'Z' ddl&m(Z( ddl&m)Z) ddl&m*Z* dd l&m+Z+ dd!l&m,Z, dd"l&m-Z- dd#l&m.Z. dd$l&m/Z/ dd%l&m0Z0 dd&l&m1Z2 dd'l3m4Z4 dd(l3m5Z5 dd)l'm6Z6 dd*l'm7Z7 dd+l'm8Z8 dd,l'm9Z9 dd-l'm:Z: dd.l'm;Z; dd/l*m<Z< dd0l*m=Z= dd1l.m>Z> dd2l0m?Z? dd3l@mAZA dd4lBmCZC dd5lBmDZD d6d7l&mEZE d6d&l&m1Z1 d6d8l1mFZF d6d9lGmHZH d6d:lGmIZI d6d;lGmJZJ ejH                  rdd<lKmLZL dd=l'mMZM dd>l'mNZN dd?lOmPZP dd@lQmRZR ddAlSmTZT ddBlSmUZU ddClSmVZV ddDl*mWZW ddEl*mXZX ddFl*mYZY ddGl*mZZZ ddHl*m[Z[ ddIl+m\Z\ ddJl.m]Z] ddKl/m^Z^ ddLl/m_Z_ ddMl/m`Z` ddNl/maZa ddOl/mbZb ddPl/mcZc ddQl/mdZd ddRl/meZe ddSl@mfZf d6dTlgmhZh d6dUlimjZj d6dVlimkZk d6dWlimlZl d6dXlimmZm d6dYlimnZn d6dZlimoZo d6d[limpZp d6d\limqZq d6d]limrZr ed^esf   Zth d_Zu ej                  d`ej                        Zx ej                  daej                        Zy ezddb      D  ch c]
  }  es|        c} j                  dcg      Z| ej                  ddej                        Z} ej                  ddej                        Z~ ej                  deej                        Z ej                  dfej                         Z ej                  dgej                         ZdhZedidjdkdldmdnZi e,j
                  doe,j                  dpe,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i e,j,                  de,j.                  de,j0                  de,j2                  de,j4                  de,j6                  de,j8                  de,j:                  de,j<                  de,j>                  de,j@                  de,jB                  de,jD                  de,jF                  de,jH                  de,jJ                  de,jL                  de,jN                  de,jP                  de,jR                  de,jT                  de,jV                  de,jX                  de,jZ                  diZe+j^                  de+j`                  de+jb                  de+jd                  de+jf                  de+jh                  de+jj                  de+jl                  de+jn                  de+jp                  de+jr                  de+jt                  de+jv                  de+jx                  diZded<   ddddddddddddddddZe/j                  j                  de/j                  j                  de/j                  j                  de/j                  j                  de/j                  j                  de/j                  j                  diZ G d de      Z G d deI      ZdZded<   dZded<   d6Zded<   dZded<    G d˄ deJ      Z G d̈́ dedϬЫ      Z G dф de      Z G dӄ de      Z G dՄ de      Z G dׄ deF      Z G dل de	      Z G dۄ de	      Z eeի      \  ZZZZ G d݄ d ej                  dddg            Z G d d      Z G d de1j                        Z G d de-j                  e   e*j                        Z G d de-j                  e   e*j                        Z G d deݫ      Z G d de      Z G d deݫ      Z G d de߫      Z G d de      Z G d deI      Z G d deI      Z G d d      Zyc c} w )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_ $]+$
   $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named 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 ,  FROM  AS  IS z IS NOT z	 COLLATE zEXISTS 	DISTINCT zNOT zANY zALL 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 SETSzDict[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                  @    e Zd ZU dZded<   	 ded<   	 ded<   	 ded<   y	)
ResultColumnsEntrya  Tracks 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.

    strkeynamenameTuple[Any, ...]objectsTypeEngine[Any]typeN__name__
__module____qualname____doc____annotations__     V/var/www/html/AdoubleTech/venv/lib/python3.12/site-packages/sqlalchemy/sql/compiler.pyr   r   [  s1     L;
I% r   r   c                  (    e Zd Z	 	 	 	 	 	 	 	 	 	 ddZy)_ResultMapAppenderc                     y Nr   selfr   r   r   type_s        r   __call__z_ResultMapAppender.__call__{  s     r   N)
r   r   r   r   r   zSequence[Any]r  r   returnNoner   r   r   r  r   r   r   r   r   z  s7      	
  
r   r   z
Literal[0]RM_RENDERED_NAMEz
Literal[1]RM_NAMEz
Literal[2]
RM_OBJECTS   z
Literal[3]RM_TYPEc                  ,    e Zd ZU ded<   ded<   ded<   y)_BaseCompilerStackEntryzSet[FromClause]asfrom_fromscorrelate_fromsrP   r$   Nr   r   r   r   r   r   r   r  r    s    !!$$r   r  c                  @    e Zd ZU ded<   ded<   ded<   ded<   ded	<   y
)_CompilerStackEntryr>   compile_stateboolneed_result_map_for_nestedneed_result_map_for_compoundrP   select_0Select[Any]insert_from_selectNr  r   r   r   r  r    s      $$"&&##r   r  F)totalc                  r    e Zd ZU dZded<   	 ded<   	 ded<   	 ded	<   	 d
ed<   	 edd       Zedd       Zy)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]]positiontupzMapping[str, List[str]]parameter_expansionc                      j                   t        j                  d      t         fd j                   D              S )zrTuple of positional parameters, for statements that were compiled
        using a positional paramstyle.

        z.statement does not use a positional paramstylec              3  <   K   | ]  }j                   |     y wr  r!  ).0keyr  s     r   	<genexpr>z6ExpandedState.positional_parameters.<locals>.<genexpr>  s     FcT__S)Fs   )r%  r7   InvalidRequestErrortupler  s   `r   positional_parametersz#ExpandedState.positional_parameters  s@     #))@  FT5E5EFFFr   c                    | j                   S )z.synonym for :attr:`.ExpandedState.parameters`.r)  r/  s    r   additional_parametersz#ExpandedState.additional_parameters  s     r   N)r  r   )r  rU   )r   r   r   r   r   propertyr0  r2  r   r   r   r  r    si    " N=(( 65+(( 10 	G 	G  r   r  c                      e Zd ZU dZded<   	 ded<   	 ded<   	 ded	<   	 d
Zded<   	 d
Zded<   	 dZded<   	 dZded<   	 dZ	ded<   	 d
Z
ded<   	 d
Zded<   y)_InsertManyValuesa  represents 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   r<  r=  r?  r@  rA  rB  rC  r   r   r   r5  r5    s     
  87M#&&
 %*T) ',t+ 9=5< !"#! 4807  $t#	 "'$&	r   r5  c                  v    e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<   ded<   ded<   y)_InsertManyValuesBatchas  represents 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]batchzSequence[Tuple[Any, ...]]sentinel_valuesr:  current_batch_sizebatchnumtotal_batchesr  rows_sortedis_downgradedNr   r   r   r   rE  rE  N  sD    
 //@@....Mr   rE  c                  B    e Zd ZdZdZdZdZdZeez  ez  Zeez  Z	dZ
dZy)	InsertmanyvaluesSentinelOptszcbitflag enum indicating styles of PK defaults
    which can work as implicit sentinel columns

    r   r6            @   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   rR  rR  g  sE    
 MMHH%08;%(99 r   rR  c                      e Zd ZdZ	 dZ	 dZy)CompilerStater   r   r6   N)r   r   r   	COMPILINGSTRING_APPLIEDNO_STATEMENTr   r   r   r`  r`  y  s     I=N Lr   r`  c                  ,    e Zd ZdZdZ	 dZ	 dZ	 eez  Zy)Lintingzrepresent preferences for the 'SQL linting' feature.

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

    r   r   r6   N)r   r   r   r   
NO_LINTINGCOLLECT_CARTESIAN_PRODUCTSWARN_LINTINGFROM_LINTINGr   r   r   re  re    s5     J!" L2-<Lr   re  c                       e Zd ZdZddZddZy)
FromLinterzKrepresents current state for the "cartesian product" detection
    feature.Nc                  	 | j                   }|syt        | j                        }t        |      }||}|j                  |       n|j	                         }t        j                  |g      }|rg|re|j                         	|j                  	       |D ch c]	  }	|v s| }}|j                  	fd|D               |j                  |       |r|re|r||fS yc c}w )NNNc              3  H   K   | ]  }||j                              y wr  )index)r*  edgenodes     r   r,  z"FromLinter.lint.<locals>.<genexpr>  s"     NDTdjj&6"67N   ")fromsro   edgesremovepopcollectionsdequepopleftdiscard
extendleftdifference_update)
r  startrs  rt  the_rest
start_withstackrp  	to_removerq  s
            @r   lintzFromLinter.lint  s    

DJJu:JOOJ'!J!!:,/==?DT" +0@$44<@I@ NINN##I.   Z'' As   	C Cc                      j                         \  }}|rX|}|rSd}dj                   fd|D              }|j                  || j                  |         }t	        j
                  |       y y y )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   c              3  D   K   | ]  }d j                   |    d   yw)"N)rs  )r*  from_r  s     r   r,  z"FromLinter.warn.<locals>.<genexpr>  s)      &16a

5)*!,&    )	stmt_typers  r}  )r  rw   r   rs  r&   warn)r  r  r~  r  rs  template	froms_strmessages   `       r   r  zFromLinter.warn  s    #yy{* E7  !II &:?& 	 #//'#**Z0 *  		'"!  r   r  )SELECT)r   r   r   r   r  r  r   r   r   rk  rk    s    #J#r   rk  rs  rt  c                      e Zd ZU dZdZded<   	 dZded<   	 ded	<   	 d
Zd
ZdZ	ded<   dZ
ded<   dZded<   ej                  Zded<   	 ded<   ej                  Zded<   dZded<   	 dZded<   	 dZded<   	 ded<   	 dd
 ej&                         f	 	 	 	 	 	 	 	 	 d(dZd) fdZed         Zd! Zd" Zed#        Zd*d$Zd+d%Z	 	 	 d,	 	 	 	 	 	 	 d-d&Zed'        Z xZ S ).Compileda  Represent 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   stringr`  stateFzOptional[CursorResultMetaData]_cached_metadataz"Optional[List[ResultColumnsEntry]]_result_columns Optional[SchemaTranslateMapType]schema_translate_maprY   execution_optionsIdentifierPreparerpreparerr<   _annotationszOptional[CompileState]r  dml_compile_stateOptional[CacheKey]	cache_keyfloat	_gen_timec                   || _         | j                   j                  | _        |r'|| _        | j                  j	                  |      | _        |t
        j                  | _        || _        |j                  | _
        |j                  | _        | j                  r)t        rt        |t              sJ |j                  | _         | j"                  | j                  fi || _        |r+| j                  j'                  | j$                  |      | _        t
        j(                  | _        nt
        j*                  | _        t-               | _        y)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)dialectidentifier_preparerr  r  _with_schema_translater`  ra  r  r   supports_executioncan_executer  r   
isinstancer-   _execution_optionsr  processr  _render_schema_translatesrb  rc  r   r  r  r  r   r  render_schema_translatecompile_kwargss         r   __init__zCompiled.__init__;  s   4 88(<D% MM@@$DM  &00DJ&DN(;;D ) 6 6D %i<<<)2)E)E&&$,,t~~HHDK&"mmEEKK!5 '55DJ&33DJ%r   c                @    | j                          t        | 	         S r  )_init_compiler_clssuper__init_subclass__)cls	__class__s    r   r  zCompiled.__init_subclass__s  s     w(**r   c                     y r  r   r  s    r   r  zCompiled._init_compiler_clsw  s    r   c                ~    | j                   r|j                  | ||      S t        j                  | j                        r  )r  _execute_compiledr7   ObjectNotExecutableErrorr   )r  
connectiondistilled_paramsr  s       r   _execute_on_connectionzCompiled._execute_on_connection{  s@     //&(9  ..t~~>>r   c                B    t        j                  | t        |            |r  r7   UnsupportedCompilationErrorr   r  elementerrkws       r   visit_unsupported_compilationz&Compiled.visit_unsupported_compilation  s    --dDMBKr   c                    t               )zReturn a Compiled that is capable of processing SQL expressions.

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

        NotImplementedErrorr/  s    r   sql_compilerzCompiled.sql_compiler  s     "##r   c                (     |j                   | fi |S r  _compiler_dispatch)r  objkwargss      r   r  zCompiled.process  s    %s%%d5f55r   c                T    | j                   t        j                  u r| j                  S y)z3Return the string text of the generated SQL or DDL.r  )r  r`  rb  r  r/  s    r   __str__zCompiled.__str__  s#     ::555;;r   c                    t               )zReturn the bind params for this compiled object.

        :param params: a dict of string/object pairs whose values will
                       override bind values compiled in to the
                       statement.
        r  r  paramsextracted_parametersescape_namess       r   construct_paramszCompiled.construct_params  s     "##r   c                "    | j                         S )z0Return the bind params for this compiled object.r  r/  s    r   r  zCompiled.params  s     $$&&r   )
r  r\   r   r  r  r  r  r  r  Mapping[str, Any])r  r  )r  r5   r  r   r  r   )r  r   NNTr  "Optional[_CoreSingleExecuteParams]r  &Optional[Sequence[BindParameter[Any]]]r  r  r  z)Optional[_MutableCoreSingleExecuteParams])!r   r   r   r   r   r   r  is_sqlis_ddlr  r  r  r&   
EMPTY_DICTr  r  r  r  r  immutabledictr  r  classmethodr  r  r  r3  r  r  r  r  r  __classcell__r  s   @r   r  r    s   
 *.I&-FC4-FF7;4;:>O7>=A:A)-8
 ! $(OOL/3,0M)0 15-4	 %)I!(	  BF(-,>D,>,>,@6(6( +6( ?	6(
 "&6( *6(p+  ?L $ $6 6:GK!	$2$ E$ 	$
 
3$ ' 'r   r  c                  <    e Zd ZdZdZddZddZ	 	 	 	 	 	 	 	 d	dZy)
TypeCompilerz2Produces DDL specification for TypeEngine objects.z	visit_\w+c                    || _         y r  )r  )r  r  s     r   r  zTypeCompiler.__init__  s	    r   c                    |j                   rE| j                  j                  |j                   v r#|j                   | j                  j                     } |j                  | fi |S r  )_variant_mappingr  r   r  r  r  r  s      r   r  zTypeCompiler.process  sU    ""!!U%;%;;**4<<+<+<=E'u''333r   c                0    t        j                  | |      |r  )r7   r  r  s       r   r  z*TypeCompiler.visit_unsupported_compilation  s     --dG<#Er   N)r  r\   )r  r   r  r   r  r   )r  r   r  	Exceptionr  r   r  r   )r   r   r   r   ensure_kwargr  r  r  r   r   r   r  r    s>    <L4FF!*F25F	Fr   r  c                  F    e Zd ZdZdZdZd	dZed        Zed        Z	d Z
y)
_CompileLabelz;lightweight label object which acts as an expression.Label.labelr  r   
_alt_namesc                6    || _         || _        |f|z   | _        y r  r  )r  colr   	alt_namess       r   r  z_CompileLabel.__init__  s    	&9,r   c                .    | j                   j                  S r  r  	proxy_setr/  s    r   r  z_CompileLabel.proxy_set      ||%%%r   c                .    | j                   j                  S r  r  r   r/  s    r   r   z_CompileLabel.type      ||   r   c                    | S r  r   r  r  s     r   
self_groupz_CompileLabel.self_group      r   N)r   )r   r   r   r   __visit_name__	__slots__r  r3  r  r   r  r   r   r   r  r    sD     FN/I-
 & & ! !r   r  c                  J    e Zd ZdZdZdZd Zed        Zed        Z	d Z
d Zy	)
ilike_case_insensitivea  produce 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  
comparatorc                4    || _         |j                  | _        y r  r  )r  r  s     r   r  zilike_case_insensitive.__init__  s    !,,r   c                .    | j                   j                  S r  r  r/  s    r   r  z ilike_case_insensitive.proxy_set  r  r   c                .    | j                   j                  S r  r  r/  s    r   r   zilike_case_insensitive.type  r  r   c                    | S r  r   r  s     r   r  z!ilike_case_insensitive.self_group   r  r   c                J    t        | j                  j                  |            S r  )r  r  _with_binary_element_type)r  r  s     r   r  z0ilike_case_insensitive._with_binary_element_type  s!    %LL2259
 	
r   N)r   r   r   r   r   r  r  r3  r  r   r  r  r   r   r   r  r    sJ    	 6N'I- & & ! !
r   r  c                  H   e Zd ZU dZeZ ej                  ddddddddd      Zde	d	<   	 d
e	d<   de	d<   dZ
eZdZde	d<   dZde	d<   dZde	d<   	 de	d<   	 dZde	d<   	 dZde	d<   	 dZde	d<   	 dZde	d<   de	d<   	 de	d <   	 d!e	d"<   	 dZde	d#<   	 dZde	d$<   	 dZde	d%<   	 d&e	d'<   	 d&e	d(<   	 d&e	d)<   	 d*e	d+<   	 dZde	d,<   	 dZde	d-<   	 dZde	d.<   	 dZde	d/<   	 dZde	d0<   	 dZde	d1<   	 dZd2e	d3<   	 dZd4e	d5<   	 dZd6e	d7<   dZ d8e	d9<   dZ!d:e	d;<    e"       Z#d<e	d=<   	  e"       Z$d<e	d><   	 ejJ                  Z&d?e	d@<   	 dZ'	 dZ(	 dZ)dAe	dB<   	 dZ*d6e	dC<   	 dZ+d6e	dD<   dZ,d6e	dE<   dZ-de	dF<   dGe	dH<   dIe	dJ<   dKe	dL<   de	dM<    e.j^                  dN      Z0 e.j^                  dO      Z1 e.j^                  e1jd                   dPe0jd                         Z3e4dQ        Z5e4dR        Z6ddde7df	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddTZ8e9ddU       Z:ejv                  ddV       Z<e9dW        Z=e9dX        Z>e9dY        Z?ej                  ddZ       ZAej                  d	d[       ZCeDj                  d\        ZFd] ZGd^ ZHej                  	 	 d
d_       ZId` ZJe9da        ZK	 	 d	 	 	 	 	 ddbZL	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddcZMej                  dd        ZNe9de        ZO	 d	 	 	 	 	 ddfZP ej                  dg      dh        ZRdie	dj<   ej                  ddk       ZSej                   ej                  dl      dm               ZTej                   ej                  dl      dn               ZUdo ZVdp ZWddqZXdr ZY	 ddsZZ	 ddtZ[	 	 	 	 	 dduZ\dv Z]dw Z^	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddxZ_dy Z`dz Zad{ Zbd| Zcd} Zdd~ ZeddZf	 ddZgd Zhd Zid Zjd Zkd Zld Zmd Znd Zod Zpd Zqd Zrd Zsd Ztd Zud Zvd Zwd Zx	 d	 	 	 	 	 	 	 ddZyd Zzd Z{d Z|	 ddZ}d Z~d Z	 ddZd Zd Zd Zd Zd Zd Zd Zd Z	 ddZd Z	 	 	 	 ddZd Zd Zd Zd Zd Z	 ddZd Zd Zej                  d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdÄ Z	 	 	 	 	 ddĄZdń ZedfdƄZdǄ ZdȄ Z	 	 	 	 	 	 ddɄZddʄZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd˄Zd̄ Zddddd ejl                  d      f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d d̈́Zd΄ Zdτ Z	 	 	 	 	 	 	 	 d!dЄZdф Zd҄ ZddӄZdԄ ZddՄZdք Zdׄ Z	 	 	 	 	 	 	 	 	 	 d"d؄Z	 ddلZ	 	 	 	 	 	 	 d#dڄZdۄ Zd܄ Zd݄ Zdބ Zd߄ Zde	d<   eʐj                  s" ej                  d e"       fd e"       fg      Z	 ddZdZdSe	d<   	 	 	 	 	 	 	 	 d$dZ	 	 	 	 d%dZd Zd Zd Z	 	 ddZd Zd Zd Zd Zd Z	 	 	 	 	 	 	 	 	 	 d&dZd Z	 	 	 d'dZ	 	 	 	 	 	 	 d(dZݐddZd Z ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  i      Zej                  ej                  ej                  i      Z	 	 	 	 d)dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*dZ	 d+dZd Zd Zd Zd ZddZd Zd  ZddZd Zd Zd Zy(,  SQLCompilerz~Default implementation of :class:`.Compiled`.

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

    PAZC_)%():.[] zClassVar[Mapping[str, str]]bindname_escape_characterszClassVar[Pattern[str]]_bind_translate_re_bind_translate_charsTFr  isdeleteisinsertisupdatezOptional[List[Column[Any]]]	postfetchr   zSequence[Column[Any]]insert_prefetchupdate_prefetchN&Optional[Sequence[ColumnElement[Any]]]implicit_returningisplaintextzDict[str, BindParameter[Any]]bindszDict[BindParameter[Any], str]
bind_nameszList[_CompilerStackEntry]r  returning_precedes_values'render_table_with_column_in_update_fromansi_bind_rulesr   bindtemplatecompilation_bindtemplate_numeric_binds_identifier_charzList[ResultColumnsEntry]r  _textual_ordered_columns_ad_hoc_textual_ordered_columns_loose_column_name_matching_numeric_binds_render_postcompilezOptional[ExpandedState]_post_compile_expanded_stateOptional[str]_pre_expanded_stringOptional[List[str]]_pre_expanded_positiontupzOptional[_InsertManyValues]_insertmanyvaluesz!Optional[crud._CrudParamSequence]_insert_crud_paramszFrozenSet[BindParameter[Any]]literal_execute_paramspost_compile_paramszutil.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]]cteszDict[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|c                $    | j                          y r  )_init_bind_translater  s    r   r  zSQLCompiler._init_compiler_cls2  s      "r   c                    t        j                  dj                  | j                              }t        j                  d| d      | _        | j                  | _        y )Nr  r  r  )reescaperw   r  compiler  r  )r  regs     r   rJ  z SQLCompiler._init_bind_translate6  sF    ii > >?@!#auAJ!7$'$B$B!r   r   c                >   || _         || _        |r:|d   D 	ci c]  }	|	j                  |	 }
}	|d   D 	ci c]  }	|	|	g }}	||
f| _        || _        || _        i | _        t        j                         | _	        g | _
        g | _        |j                  | _        | j                  rH|j                  j                  d      x| _        }|r|j                  dk(  rdnd| _        t"        | _        nt&        |j                     | _        d| _        |j*                  xs |j,                  | _        t/               | _        i | _        i | _        t7        j8                  | ||fi | | j:                  s| j<                  s| j>                  rt@        rtC        |tD              sJ | j:                  s| j<                  rmt@        rtC        |tF              sJ |jH                  rd| _%        nA| j                  r5| j:                  r"| jL                  jN                  r|jP                  rd| _%        t&        |j                     | _)        |rK| jT                  jW                  |jT                  jY                         D ci c]  \  }}|dvr|| c}}       | jZ                  t\        j^                  u rm| j                  r-| j                  r| ja                          n| jc                          | jd                  r'| jg                  d	d
      }| ji                  |d       yyyc c}	w c c}	w c c}}w )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.

        r   r   r   r   r  NT>   r  r  r  
positionalr-  r4  r.  Fr  _no_postcompile)_populate_self)5column_keysr  r+  r@  for_executemanylintingr(  r&   column_dictr)  r  r  rQ  
paramstyle
startswithr4  r/  _pyformat_templater.  BIND_TEMPLATESrD  label_lengthmax_identifier_lengthr4   anon_maptruncated_names_truncated_countersr  r  r   r!  r  r   r  rB   rC   _inlinerC  r  insert_executemany_returning_return_defaultsr-  __dict__updateitemsr  r`  rb  _process_numeric_process_positionalr5  r  #_process_parameters_for_postcompile)r  r  r   r  rU  rV  rW  _supporting_againstr  bcksmckbmnbkvr!  s                   r   r  zSQLCompiler.__init__<  s   @ '"&/l3AEE1H3D3$-aL1qAsF1D1*.D&
  / 
 **, 
! ",,??'.'9'9'D'DY'OOD""--1AACs 3 -?D),:7;M;M,ND)	   AG$A$A 	 () <>35 $=f===DMMT]]!)Z888}} %i<<<$$"&DK))AA%66 #'DK*7+=+=>MM   !4 < < B B D1	 qD" ::555&&))+,,.''!22!&$( 3 

 88t 9  ( 6y 41Vs   LL,L
c                H    | j                   y| j                   j                  S )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)r;  r7  r/  s    r   insert_single_values_exprz%SQLCompiler.insert_single_values_expr  s%     !!)))<<<r   c                    | j                   r| j                   S | j                  Dt        | j                        r/| j                  j                  D cg c]  }t	        |      r| c}S yc c}w )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

        N)r&  r   r(   _all_selected_columnsr'   )r  cs     r   effective_returningzSQLCompiler.effective_returning  sg     ""***^^'F4>>,B ==$Q'   s   A*c                    | j                   S )zVbackwards compatibility; returns the
        effective_returning collection.

        )rw  r/  s    r   	returningzSQLCompiler.returning  s     '''r   c                b    	 | j                   d   d   S # t        $ r}t        d      |d}~ww xY w)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)r  
IndexError)r  ies     r   current_executablezSQLCompiler.current_executable  s;    <	M::b>,// 	MCD"L	Ms    	.).c                X    t        | j                        t        | j                        z   S r  )listr#  r$  r/  s    r   prefetchzSQLCompiler.prefetch%  s#    D(()D1E1E,FFFr   c                    i S r  r   r/  s    r   _global_attributeszSQLCompiler._global_attributes)  s    	r   c                f    t        j                         }|| _        i | _        i | _        d| _        |S )zInitialize collections related to CTEs only if
        a CTE is located, to save on the overhead of
        these collections otherwise.

        F)r&   OrderedDictrD  rE  rF  rG  )r  rD  s     r   _init_cte_statezSQLCompiler._init_cte_state-  s:     *.)9)9);	 #% "$#r   c              #  h  K   | j                   | j                  }}g dc| _         | _        	 | j                  r| j                  d   }d|d<   nd}| j                   | j                  f |r|j                  d       ||c| _         | _        y# r|j                  d       ||c| _         | _        w xY ww)z;special API to support the use case of 'nested result sets'Fr{  Tr  N)r  r2  r  rv  )r  result_columnsordered_columnsentrys       r   _nested_resultzSQLCompiler._nested_resultE  s        !! ( 79%3d3	zz

26:23&&(=(===		67 8D $"7 		67 8D $"7s   (B2=B (#B2$B//B2c                  	 | j                   rJ | j                  t        j                  u sJ | j                  rJ | j
                  j                  dk(  rdn| j
                  j                  dk(  sJ dg 	d	fd}t        j                  | j                  || j                        | _
        | j                  rv| j                  j                         D ci c]  \  }}||
 }}}t        | j                        t        |      k(  sJ 	D cg c]  }|j                  ||       c}| _         n	| _         | j                  rg 	t        j                  | j                  || j                  j                         }| j                  j"                  D cg c]3  }|d   |d   t        j                  | j                  ||d         |d	   f5 }}| j                  j%                  ||
      | _        y y c c}}w c c}w c c}w )Nr   %sr   r   c                    | j                  d      }|rj                  |       S j                  | j                  d             | j                  d      S )Nr   r6   r   )r   append)mnormal_bindplaceholder	positionss     r   find_positionz6SQLCompiler._process_positional.<locals>.find_positionj  sM    ''!*K  -""   ,wwqz!r   r   r   r6   r  r7  r9  )r  zre.Match[str]r  r   )r%  r  r`  rb  r4  r  rY  rL  sub_positional_patternr  r?  rg  lengetr;  r7  r9  _replace)
r  r  rp  rq  reverse_escaper   r7  r9  r  r  s
           @@r   ri  zSQLCompiler._process_positional]  s   ####zz]99999&&&&<<""h.K<<**g555K		" ff$$mT[[
 ""/3/F/F/L/L/NOtq!adONOt../3~3FFFF;D 37""4. D  )D!!I!#((&&99" //BB"  aDaDFF433]AaDIaD	" " &*%;%;%D%D#5#5 &E &D"% " P "s   G1G78G<c                t     j                   sJ  j                  t        j                  u sJ d}i  j                  r\ j
                  Pt        j                   fd j                  j                         D         j                  j                               }n j                  j                         }|D ]R  }|v r j                  |   }| j                  v s| j                  v rd |<   9 j                   | }|dz  }||<   T | _        t               _         j"                  rYt%              }j'                         D ci c]"  \  }} j"                  j)                  ||      |$ c}}t%              |k(  sJ  j*                  j-                  fd j.                         _         j                  rl j                  j0                  z  }	 j                  j2                  D 
cg c]  }
|
d   |
d   d|
d   f }}
 j                  j5                  |	|       _        y y c c}}w c c}
w )Nr   c              3  >   K   | ]  }|j                   vr|  y wr  )rA  )r*  r   r  s     r   r,  z/SQLCompiler._process_numeric.<locals>.<genexpr>  s'      4#9#99    c                ,    | j                  d         S Nr   r   r  	param_poss    r   <lambda>z.SQLCompiler._process_numeric.<locals>.<lambda>  s    i
+ r   r   r  r  r  )r4  r  r`  rb  r;  rA  	itertoolschainr)  valuesr(  r>  r=  r/  next_numeric_posr  r%  r?  r  rg  r  _pyformat_patternr  r  r7  r9  r  )r  numr   	bind_namebindph
len_beforer   posr7  rq  r9  r  s   `           @r   rh  zSQLCompiler._process_numeric  sL   """"zz]99999$&	!!d&<&<&H OO $ 6 6 8
 &&(E OO**,E 	*II%::i(D0004666 (,	)$;;<SEBq')	)$	*  !$	?""YJ "+!2D# ''++D$7<I y>Z/// ,,00+T[[
 !! &&99  //BB" 1qtT1Q4(" "
 &*%;%;%D%D#5#5	 &E &D" "$"s   'H/3H5c                f      fd j                   D        D ci c]
  \  }}||| c}}S c c}}w )Nc           	   3    K   | ]  }j                   |   |j                  j                  s%|j                  j                  j                        n5t        fd t        t        |j                        j                  D              f  yw)c              3  T   K   | ]  }|j                  j                         ! y wr  )_cached_bind_processorr  )r*  	elem_typer  s     r   r,  z9SQLCompiler._bind_processors.<locals>.<genexpr>.<genexpr>  s(      # ) &<<T\\J#s   %(N)	r)  r   _is_tuple_typer  r  r.  r   r2   types)r*  	bindparamr  s     r   r,  z/SQLCompiler._bind_processors.<locals>.<genexpr>  sx        OOI.  )~~<< "==dllK" #-1 )9>>.#e	# s   B
B)r)  )r  r+  values   `  r   _bind_processorszSQLCompiler._bind_processors  sC     "&
U   # J
 	
 
s   -c                2    t        | j                        dkD  S r  )r  r  r/  s    r   is_subqueryzSQLCompiler.is_subquery  s    4::""r   c                    | S r  r   r/  s    r   r  zSQLCompiler.sql_compiler  s    r   c                L    | j                  ||d      }| j                  |      S )aR  Return 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

        TrR  )r  rj  )r  r  r  r!  s       r   construct_expanded_statez$SQLCompiler.construct_expanded_state  s:     **%  + 


 77
 	
r   c                   | j                   rF|sD| j                  J |st        | j                  j                        S t	        j
                  d      |xr t        | j                        }|rq| j                  t	        j                  d      | j                  d   }| j                  }	|	J |	\  }
}t        ||      D ci c]  \  }}|
|   D ]  }||  }}}}nd}|ri }| j                  j                         D ]  \  }}|r| j                  j                  ||      n|}|j                  |v r||j                     ||<   G||v r	||   ||<   T|rX|j                   rL|r&t	        j
                  d|j                  |fz  d      t	        j
                  d|j                  z  d      |r|j                  ||      }n|}|j"                  r|j$                  ||<   |j&                  ||<    |S i }| j                  j                         D ]  \  }}|r| j                  j                  ||      n|}|rX|j                   rL|r&t	        j
                  d|j                  |fz  d      t	        j
                  d|j                  z  d      |r|j                  ||      }n|}|j"                  r|j$                  ||<   |j&                  ||<    |S c c}}}w )	z5return a dictionary of bind parameter keys and valuesNzcan't construct new parameters when render_postcompile is used; the statement is hard-linked to the original parameters.  Use construct_expanded_state to generate a new statement and parameters.zcThis compiled object has no original cache key; can't pass extracted_parameters to construct_paramsr   z@A value is required for bind parameter %r, in parameter group %dcd3x)codez)A value is required for bind parameter %r)r5  r6  dictr!  r7   r-  r  r?  r  CompileErrorr@  zipr)  rg  r  r+  requiredcallableeffective_valuer  )r  r  r  r  _group_number_checkrS  has_escaped_namesorig_extracted
ckbm_tuplern  r  rl  	extractedr  resolved_extractedpdr  r   escaped_namevalue_params                        r   r  zSQLCompiler.construct_params  sT    ##O44@@@D==HHII--4  )JT$2I2I-J ~~%&&J 
 "&!233J))) GD! %(8L$M" " Ay G"  i"" " "&B#'??#8#8#: %=	4 ) ++//d;  ==F*'-imm'<B|$V^'-d|B|$	 2 2$!554(}}m<= "(	  "55G'mm,!'  *&8&<&<%y' '0 ))+6+F+F<(+6+<+<<(K%=L IB#'??#8#8#: 9	4 ) ++//d;  i00$!554(}}m<= "(	  "55G'mm,!'  &"4"8"8I"NK"+K%%'2'B'BB|$'2'8'8B|$=9@ Ig"s   Kc                  	 | j                   j                  	j                  j                  	fd}i }| j                  }| j
                  D ]n  }||v r|j                  j                  r<t        t        |j                        j                  D cg c]
  } ||       c}||<   Z ||j                        ||<   p |S c c}w )Nc                f    | j                        j                        }||vr|v r|S y r  )_unwrapped_dialect_implget_dbapi_type)typdbtypedbapir  exclude_typesinclude_typess     r   lookup_typez<SQLCompiler._get_set_input_sizes_lookup.<locals>.lookup_type  sH    009HHOF ""*fM.I"*f.Er   )r  include_set_input_sizesexclude_set_input_sizesr  r=  r)  r   r  r   r2   r  )
r  r  
inputsizesr=  r  r  r  r  r  r  s
         @@@@r   _get_set_input_sizes_lookupz'SQLCompiler._get_set_input_sizes_lookup  s    ,,7777
	 
!%!<!< 
	DI22~~,,  $Iy~~>DD)  $)
9%
 )4INN(C
9%
	D )s   C
c                &    | j                  d      S )zReturn the bind param dictionary embedded into this
        compiled object, for those values that are present.

        .. seealso::

            :ref:`faq_sql_expression_string` - includes a usage example for
            debugging use cases.

        F)r  r  r/  s    r   r  zSQLCompiler.params  s     $$E$22r   c                   i }| j                   }|| j                  }| j                  rg }| j                  }|| j                  }ndx}}| j
                  }t        d|      t        d|      i }i i }	d}
| j                  r||}| j                  rg }
n| j                  j                         }| j                  }|D ]  |r|j                        n}| j                     }|| j                  v r*|vr%| j                  ||j                  |            |<   a|| j                   v r|v r|	|   }d}n3|j                        }| j#                  |||      }|\  }}||	|<   ||<   |j$                  r|j'                  |       |j(                  j*                  r*|J |j'                  fdt-        |d      D               n|j'                  fd|D               |
|
j/                  d |D               n||j/                  d	 |D               |D cg c]  \  }}|	 c}}|<   w|{|j1                          fd
}t3        j4                  | j6                  ||      }|
l|J t-        |
| j8                        D ci c]  \  }}|| j:                   |  c}}| j<                  j5                  fd|      }|j/                  |
       t?        |||||      }|rR|| _         || _        |j@                  | _        | j                  rtC        |j                  xs d      nd| _        || _"        |S c c}}w c c}}w )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_valuec              3     K   | ]?  \  }}t        |d       D ]+  \  }}v r"   |d z
     d|d|   |d z
     f - A yw)r   Nr  )	enumerate)r*  ituple_elementjr  r   tuple_processorss        r   r,  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>=  s{      	.
 !1=(1-(C	. !%1#'77 0 6q1u = I /3Aq 9 0 6q1u =	.	.s   AAr   c              3  :   K   | ]  \  }}v r	|   f  y wr  r   )r*  r+  r  r   single_processorss      r   r,  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>H  s1      . &Q#'88 !"3D"9:.   c              3  &   K   | ]	  \  }}|  y wr  r   r*  r   r  s      r   r,  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>N  s      3%,T1D3   c              3  &   K   | ]	  \  }}|  y wr  r   r  s      r   r,  zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>U  s     .Mat.Mr  c                   | j                  d      }|   }| j                  d      rU| j                  d      j                  d      }|d   |d   cdj                  fd|j                  d      D              }|S )Nr   r6   ~~r  r   c              3  .   K   | ]  }|  y wr  r   )r*  expbe_leftbe_rights     r   r,  z]SQLCompiler._process_parameters_for_postcompile.<locals>.process_expanding.<locals>.<genexpr>e  s       ! !(h7!s   )r   splitrw   )r  r+  exprtokr  r  replacement_expressionss       @@r   process_expandingzJSQLCompiler._process_parameters_for_postcompile.<locals>.process_expanding\  s~    ''!*C*3/D wwqzggaj&&t,$'FCF!yy !#zz$/!  Kr   c                ,    | j                  d         S r  r  r  s    r   r  zASQLCompiler._process_parameters_for_postcompile.<locals>.<lambda>y  s    )AGGAJ/ r   r   )#r8  r  rQ  r:  r%  r  r   r4  r)  r  r?  r  r(  r=  render_literal_bindparamrv  r>  $_literal_execute_expanding_parameterliteral_executerf  r   r  r  extendr  rL  r  _post_compile_patternr  r/  r  r  r   r  r6  )r  r!  rT  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_expr
expand_keyr  r  r   r  r+  expanded_stater   r  r  r  r  s                             @@@@@r   rj  z/SQLCompiler._process_parameters_for_postcompile  s   $ ! #77&"&++?? O'+'E'E$'/+/+;+;( :>=O6**
 3Z
  =z
 >@24)+ 48??7C#;E""&(#OO**,E%% I	-D253774.4L

4(ID777'>>55%1;1M 6  ,L9 D444#:: .| <I!F (^^D1F#HH$i H 5=1Y 03<N<0<L+L9 00%%i0 ~~44%111&-- 	.
 5>fa4H	. 	 '-- .*3. 
 +6+22 3093  )4 (...M9.MM8A1'4z1
1'- !,&&t,SI	-V	 FF&&(9;N
	 *"... !*')>)>!C ;;<SEBBI ..22/I ""#67&
  )<D%-ED*(22DK ?? ^//526 
 1?D-{16s   $M
Mzsqlalchemy.engine.cursorc                    t         j                  j                  }|j                  j	                  | j
                        S )z(utility method used for unit tests only.)r&   	preloadedengine_cursorrT   _create_description_match_mapr  )r  cursors     r   _create_result_mapzSQLCompiler._create_result_map  s5     --**HH  
 	
r   _BindNameForColProtocol_get_bind_name_for_colc                    | j                   }|S r  )r  )r  getters     r   _within_exec_param_key_getterz)SQLCompiler._within_exec_param_key_getter  s    ,,r   zsqlalchemy.engine.resultc           	       	
 t         j                  j                  }| j                  }| j                  J | j                  j
                  }t        rt        |t              sJ |j                  }|j                  D cg c]!  }t        j                  d ||      d       |f# c}d 	|j                  Dj                  j                  | j                   d        |      

| j"                  v r

fd}|	nd |j%                  |j                  D cg c]  }|j&                   c}      	fd}|S c c}w c c}w )Nr  c                4    |j                  |       }||S | S r  r  )	lastrowidr!  param_valueautoinc_keys      r   _autoinc_getterzPSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>._autoinc_getter  s)    ",..i"HK".
  +*  )(r   c                j                fdD              S   fdD              S )a  given 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.

            c              3  4   K   | ]  \  }} |        y wr  r   )r*  r  r  r!  s      r   r,  zWSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get.<locals>.<genexpr>  s     L[VSfZ0L   c              3  V   K   | ]   \  }}|u r	       n	n |       " y wr  r   )r*  r  r  autoinc_colautoinc_getterr  r!  s      r   r,  zWSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get.<locals>.<genexpr>  sJ       $ +-  .9 +9jA!* $J/0   &)r   )r  r!  r'  r(  getterslastrowid_processorrow_fns   ``r   r  zDSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get  sH     #./	:	 LGLLL  (/  r   )r&   r  engine_resultr  r  r   r   r  rA   r   primary_keyoperatormethodcaller_autoincrement_columnr   _cached_result_processorr  r(  result_tupler+  )r  resultparam_key_getterr   r   r  r"  r  r'  r(  r!  r*  r+  r,  s           @@@@@@r   +_inserted_primary_key_from_lastrowid_getterz7SQLCompiler._inserted_primary_key_from_lastrowid_getter  sB    --==!!---&&00	i000 ((
 ""5*:3*?FL

 11""-"2"2"K"Kd# +;7K djj(
) "1 #'$$9J9J%K#cgg%KL	 	4 
G
N &Ls   &E Ec                  
 t         j                  rddlm} nt        j
                  j                  }| j                  J | j                  j                  }t        rt        |t              sJ | j                  }|j                  }| j                  }|J t        |      D ci c]  \  }}||
 }}}t        d|j                   D cg c]?  }||v rt#        j$                  ||         dfnt#        j&                  d ||      d       dfA c}      
|j)                  |j                   D cg c]  }|j*                   c}      
fd}	|	S c c}}w c c}w c c}w )Nr6   )r4  z'List[Tuple[Callable[[Any], Any], bool]]Tr  Fc                ,       fdD              S )Nc              3  H   K   | ]  \  }}|r |      n |        y wr  r   )r*  r  use_rowr!  rows      r   r,  zWSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.get.<locals>.<genexpr>"	  s-      #FG  'sF:,>>rr  r   )r;  r!  r*  r,  s   ``r   r  zDSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.get!	  s     '.  r   )typingr   enginer4  r&   r  r-  r  r   r  rA   r  r   r&  r  r   r.  r/  
itemgetterr0  r3  r+  )r  r4  r   r5  r   ry  idxr  retr  r*  r,  s             @@r   +_inserted_primary_key_from_returning_getterz7SQLCompiler._inserted_primary_key_from_returning_getter  s[    '^^11F!!---&&00	i000==++	$$$(1)(<=HCsCx==5 !,,  cz ((S2D9 !--!#3C#8$ 	
" $$9J9J%K#cgg%KL	 
7 > &Ls   &E
AE
.Ec                     y)zCalled 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/  s    r   default_fromzSQLCompiler.default_from)	  s     r   c                    |j                   j                  | fi |}|j                  D ]C  }|| j                  vr| j                  |   }|j	                  |j                  |j
                     dd      }| j                  |   }|x| j                  |<   | j                  |<   || j                  |<   | j                  j                  |d       || j                  v r| xj                  |hz  c_        || j                  v r| xj                  |hz  c_	        | j                  }|s|\  }	}
|j                  D ]4  }|j
                  |
v s|
|j
                     }|	|   j                  |       6 F |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+  r)  rv  r>  r=  r@  _cloned_setr  )r  override_bindsr  sqltextrp  bpnew_bpr   r  rn  rm  cbs               r   visit_override_bindsz SQLCompiler.visit_override_binds3	  sj   " <.((;;DGBG  )) "	0A

"AB ^^((0! $ F ??2&D/55DJJqMDJJt,&*DOOF#OOD)T---((VH4(T000++x7+33J'
d.. 0Bvv~!"&&\R/0?"	0H r   c                H    d |j                   j                  | fi |z   dz   S Nr  r  r  r  )r  groupingasfromr  s       r   visit_groupingzSQLCompiler.visit_groupings	  +    8X%%88HHH3NNr   c                H    d |j                   j                  | fi |z   dz   S rP  rQ  )r  rR  r  s      r   visit_select_statement_groupingz+SQLCompiler.visit_select_statement_groupingv	  rU  r   c                   | j                   r| j                  j                  r	 t        d| j                   d   d         }|j                  \  }}}|r|}	n|}	|j                  j                  }
|
E|
j                  |	v r7|
j                  |	|
j                           r|j                  j                  |d<    | j                  |j                  fd|i|S # t        $ r}t        j                  d      |d }~ww xY w)N'Union[SelectState, CompoundSelectState]r{  r  ECan't resolve label reference for ORDER BY / GROUP BY / DISTINCT etc.render_label_as_labelwithin_columns_clause)r  r  supports_simple_order_by_labelr   KeyErrorr7   r  _label_resolve_dictr  _order_by_label_elementr   shares_lineager  )r  r  r\  r  r  ke	with_cols
only_froms	only_colsresolve_dictorder_by_elems              r   visit_label_referencez!SQLCompiler.visit_label_referencey	  s    ::$,,EE	 $=JJrN?3! 11	$)( $OOCCM )!&&,6!00 !3!34
 OO;; ./ t||OO
"7
 
 	
A  &&/ s   C 	C7C22C7c                >   | j                   s| j                  |j                        S 	 t        d| j                   d   d         }j                  \  }}}	 |r||j                     }	n||j                     }	|	|d<    | j                  |	fd|i|S # t        $ r;}t        j                  |j                  dt        j                  |       Y d }~d }~ww xY w# t        $ r;}
t        j                  |j                  dt        j                  |
       Y d }
~
y d }
~
ww xY w)NrY  r{  r  rZ  )extraexc_clsr  r[  r\  )r  r  _text_clauser   r^  r   _no_text_coercionr  r7   r  r_  )r  r  r\  r  r  rb  rc  rd  re  r  r  s              r   visit_textual_label_referencez)SQLCompiler.visit_textual_label_reference	  s*    zz<< 4 455	 9

2/M ,9+L+L(	:y	$ 10 /2F*+4<<+@DJ ;  		''/ (( 		"  		''/ (( 		s/   B !C 	C1CC	D!1DDc                H   |xr | }||u }	|	s|rMt        |j                  t        j                        r| j	                  d|j                        }
n|j                  }
|r|1 |
|j                  ||
f|j
                  z   |z   |j                          |j                  j                  | fddd|t        t        j                     z   | j                  j                  |
      z   S |	r| j                  j                  |
      S  |j                  j                  | fddi|S )NcolidentT)r\  within_label_clauser\  F)r  r   r   rD   _truncated_identifierr  r   r  r  	OPERATORSr!   as_r  format_label)r  r  add_to_result_maprq  r\  r[  result_map_targetsr  render_label_with_asrender_label_only	labelnames              r   visit_labelzSQLCompiler.visit_label	  s?    "=*=&= 	 2U: 4%**h&?&?@ 66z5::N	!JJ	 ,!JJI&)9)99<NNJJ	 100*.(, 	 IMM*+ --,,UI>?	 ==--eY??35==33,157 r   c                ,    t        j                  d      )Nz:Cannot compile Column object until its 'name' is assigned.r7   r  r  r   s     r   _fallback_column_namez!SQLCompiler._fallback_column_name
  s    H
 	
r   c                @    |j                   } | j                  |fi |S r  )	_resolvedr  )r  r  r  sql_elements       r   visit_lambda_elementz SQLCompiler.visit_lambda_element
  s#    ''t||K.2..r   c                Z   |j                   x}}|| j                  |      }|j                  }	|	s,t        |t        j
                        r| j                  d|      }|C|||j                  f|z   }
|j                  r|
|j                  fz  }
 ||||
|j                         |	r| j                  |      }n| j                  j                  |      }|j                  }||r|j                  s|S | j                  j                  |      }|r| j                  j!                  |      dz   }nd}t"        rt        |t$              sJ |j                   }|s|r	||v r||   }t        |t        j
                        r| j                  d|      }|| j                  j                  |      z   dz   |z   S )Nrp  r  r  alias)r   r  
is_literalr  r   rD   rr  r+  	_tq_labelr   escape_literal_columnr  quoter   named_with_columnschema_for_objectquote_schemar   rO   )r  r   rv  include_tablerw  ambiguous_table_name_mapr  r   	orig_namer  targetsr   effective_schemaschema_prefix	tablenames                  r   visit_columnzSQLCompiler.visit_column
  s    ";;&y<--f5D&&
jx/H/HI--j$?D(tVZZ03EEGF,,..dIwD --d3D==&&t,D=U5L5LK#}}>>uEMM../?@3F  !#!%999

I %,!994Y?	)X%>%>? 66w	J	 4==#6#6y#AACG$NNr   c                L    | j                   j                  |j                        S r  )r  format_collation	collationr  r  r  s      r   visit_collationzSQLCompiler.visit_collationJ
  s    }}--g.?.?@@r   c                    |j                   S r  r   )r  
fromclauser  s      r   visit_fromclausezSQLCompiler.visit_fromclauseM
  s    r   c                    |j                   S r  r  )r  ro  r  s      r   visit_indexzSQLCompiler.visit_indexP
  s    zzr   c                    ||d<   | j                   |d<    | j                  j                  j                  |j                  fi |S )Ntype_expressionr  )r  r  type_compiler_instancer  r   )r  
typeclauser  s      r   visit_typeclausezSQLCompiler.visit_typeclauseS
  sJ     *$(MM !:t||22::OO
!
 	
r   c                V    | j                   j                  r|j                  dd      }|S Nr  %%r  _double_percentsreplacer  texts     r   post_process_textzSQLCompiler.post_process_textZ
  $    ==))<<T*Dr   c                V    | j                   j                  r|j                  dd      }|S r  r  r  s     r   r  z!SQLCompiler.escape_literal_column_
  r  r   c           	           fd} j                   sd _        |r |d d ft        j                         t        j                  d t        j                  | j                  j                                    S )Nc                    | j                  d      }|j                  v r  j                  j                  |   fi S  j                  |fi S r  )r   _bindparamsr  bindparam_string)r  r   r  r  
textclauses     r   do_bindparamz2SQLCompiler.visit_textclause.<locals>.do_bindparame
  sW    771:Dz---#t||J$:$:4$@GBGG,t,,T8R88r   Tc                $    | j                  d      S r  r  )r  s    r   r  z.SQLCompiler.visit_textclause.<locals>.<lambda>w
  s    aggaj r   )	r  r'  r%   NULLTYPEBIND_PARAMS_ESCr  BIND_PARAMSr  r  )r  r  rv  r  r  s   `` ` r   visit_textclausezSQLCompiler.visit_textclaused
  sl    	9 zz#D dD:-9J9JK "" OOd44Z__E
 	
r   c                "   | j                    }|r| j                  n| j                   d   }t               t               |d}| j                   j                  |       |j                  r| j                  ||       |xs- |dk(  xr |j                  dd      xs |j                  dd      }|rp|j                  x| _        | _	        |j                   xr t        |j                        | _        |j                  D ]   }	| j                  |	d| j                         "  | j                  |j                  fi |}
| j                   r.|st#        | j                         nd }| j%                  |	      |
z   }
| j                   j'                  d       |
S )
Nr{  r  r  r$   r   r  Fr  T)r\  rv  nesting_level)r  _default_stack_entryro   r  _independent_ctes_dispatch_independent_ctesr  rQ  r2  r0  r  column_argsr3  r  _add_to_result_mapr  rD  r  _render_cte_clauserv  )r  tafcompound_indexrS  r  toplevelr  	new_entrypopulate_result_maprv  r  r  s               r   visit_textual_selectz SQLCompiler.visit_textual_select}
  s    zz>-5))4::b>  #uE*
	
 	

)$  ++C4  >!# EII<eD>
 yy5u= 	 D!D$A 47>>/A 0dGD, __ *.&*&=&=   t||CKK.2.993;C

OM***G$ND

rr   c                     yNNULLr   r  r  r  s      r   
visit_nullzSQLCompiler.visit_null
      r   c                2    | j                   j                  ryy)Nr~   1r  supports_native_booleanr  s      r   
visit_truezSQLCompiler.visit_true
  s    <<//r   c                2    | j                   j                  ryy)Nr   0r  r  s      r   visit_falsezSQLCompiler.visit_false
  s    <<//r   c                J     |j                  d  fd|D        D              S )Nc              3  $   K   | ]  }|r| 
 y wr  r   r*  ss     r   r,  z7SQLCompiler._generate_delimited_list.<locals>.<genexpr>
  s      
 
   c              3  D   K   | ]  } |j                   fi   y wr  r  r*  rv  r  r  s     r   r,  z7SQLCompiler._generate_delimited_list.<locals>.<genexpr>
  s$     I1*a**4626Ir  rw   )r  r   	separatorr  s   `  `r   _generate_delimited_listz$SQLCompiler._generate_delimited_list
  s&    ~~ 
II
 
 	
r   c                t    t         j                  j                  t        j                  t         j
                  j                  t         j                  j                  |      \  }}|dk(  r |d   j                   fi S t        t        j                     }|j                  d  fd|D        D              S )Nr   r   c              3  $   K   | ]  }|r| 
 y wr  r   r  s     r   r,  z;SQLCompiler._generate_delimited_and_list.<locals>.<genexpr>
  s      " "r  c              3  D   K   | ]  } |j                   fi   y wr  r  r  s     r   r,  z;SQLCompiler._generate_delimited_and_list.<locals>.<genexpr>
  s$     Lq.!..t:r:Lr  )r   BooleanClauseList_process_clauses_for_booleanr!   and_True_
_singletonFalse_r  rs  rw   )r  clausesr  lccr  s   ` `  r   _generate_delimited_and_listz(SQLCompiler._generate_delimited_and_list
  s    11NNNNNN%%OO&&	
W !8071:00<<<!)..1I>> "LGL"  r   c                .    d | j                   |fi |z  S N(%s))visit_clauselist)r  
clauselistr  s      r   visit_tuplezSQLCompiler.visit_tuple
  s     ---j?B???r   c                    |j                   }|d}nt        |j                      } | j                  |j                  |fi |S Nr  )r/  rs  r  r  )r  r  r  seps       r   r  zSQLCompiler.visit_clauselist
  sG    !!;CJ//0C,t,,Z-?-?KKKr   c                   |j                   }| j                  |dd       }|r
 |||fi |S 	 t        |   }d|d<    | j                  |j                  |fi |S # t
        $ r}t        j                  | |      |d }~ww xY w)Nexpression_clauselistT_in_operator_expression)r/  _get_operator_dispatchrs  r  r  r^  r7   r  )r  r  r  	operator_dispopstringr  s          r   visit_expression_clauselistz'SQLCompiler.visit_expression_clauselist
  s    ''	**.
 
I444	 +H -1B()0400""H02 	  	L11$	BK	Ls   	A 	A>"A99A>c                d   d}|j                   #| |j                   j                  | fi |dz   z  }|j                  D ]8  \  }}|d |j                  | fi |z   dz    |j                  | fi |z   dz   z  }: |j                  &|d |j                  j                  | fi |z   dz   z  }|dz  }|S )NzCASE r  zWHEN z THEN zELSE END)r  r  whenselse_)r  clauser  xcondr4  s         r   
visit_casezSQLCompiler.visit_case
  s    <<#000@@3FFA"LL 	LD&)$))$9&9: ,&++D;F;< 	A	 <<#9&,,99$I&IICOA 	
U
r   c                <     |j                   j                  | fi |S r  )typed_expressionr  )r  type_coercer  s      r   visit_type_coercezSQLCompiler.visit_type_coerce
  s     >{++>>tJrJJr   c                    |j                   j                  | fi |}t        j                  d|      }d |j                  j                  | fi |d|r|j                  d      n|d|r|j                  d      S dS )Nz(.*)( COLLATE .*)zCAST(r   r   r  r6   r  )r  r  rL  matchr  r   )r  r   r  type_clauser  s        r   
visit_castzSQLCompiler.visit_cast  s    8doo88HH,k:*DKK**4:6:#EKKN4#EKKN+
 	
 *,+
 	
r   c           
     p   |d   t         j                  u rdn|d   t         j                  u rdnh|d   dk  r5 | j                  t        j                  t        |d               fi |dn+ | j                  t        j                  |d         fi |dd|d   t         j                  u rdS |d   t         j                  u rdS |d   dk  r7 | j                  t        j                  t        |d               fi |dS  | j                  t        j                  |d         fi |dS )	Nr   zUNBOUNDED PRECEDINGzCURRENT ROWz
 PRECEDINGz
 FOLLOWINGr   r   zUNBOUNDED FOLLOWING)r   RANGE_UNBOUNDEDRANGE_CURRENTr  literalabs)r  range_r  s      r   _format_frame_clausez SQLCompiler._format_frame_clause  s}    !9 8 88 & ayH$:$:: " "!9q=	 )DLL ( 0 0VAY @DF (4<<(8(8(CJrJM( !9 8 88 & +'
 '	
2 ayH$:$:: "+'
 '	
B "!9q=	 )DLL ( 0 0VAY @DF+'
 '	
F (4<<(8(8(CJrJM+'
 '	
r   c                    |j                   j                  | fi |}|j                  r!d | j                  |j                  fi |z  }n/|j                  r!d | j                  |j                  fi |z  }nd }|ddj                  d|j                  fd|j                  ffD cg c]*  \  }}|#t        |      r|d |j                  | fi |, c}}|r|gng z         dS c c}}w )	NzRANGE BETWEEN %szROWS BETWEEN %sz OVER (r  	PARTITIONORDERz BY r  )	r  r  r  r  rowsrw   partition_byorder_byr  )r  overr  r  r  wordr  s          r   
visit_overzSQLCompiler.visit_over@  s   .t||..t>v>;;'*C$*C*C+%+ F YY&)B)B)B		*#* F F HH
 %d&7&78 $--0) %f )c&k 6V66tFvFH  &F82	/
 	
s   '/C)c                ~     |j                   j                  | fi |d |j                  j                  | fi |dS )Nz WITHIN GROUP (ORDER BY r  )r  r  r  )r  withingroupr  s      r   visit_withingroupzSQLCompiler.visit_withingroup]  sB    2K224B6B3K  33DCFC
 	
r   c                ~     |j                   j                  | fi |d |j                  j                  | fi |dS )Nz FILTER (WHERE r  )funcr  	criterion)r  
funcfilterr  s      r   visit_funcfilterzSQLCompiler.visit_funcfilterc  s@    .JOO..t>v>3J  33DCFC
 	
r   c                    | j                   j                  |j                  |j                        }d|d |j                  j                  | fi |dS )NzEXTRACT(r   r  )extract_mapr  fieldr  r  )r  extractr  r*  s       r   visit_extractzSQLCompiler.visit_extracti  sH      $$W]]GMMB+GLL++D;F;
 	
r   c                r     | j                   |j                  fi |} | j                  |fi |}d|d|S )Nr  z).)visit_functionfnr  )r  r  r  compiled_fncompiled_cols        r   visit_scalar_function_columnz(SQLCompiler.visit_scalar_function_columnp  s?    )d))'**;;(t((7B7'66r   c           	     x   |4 ||j                   |j                   |j                   f|j                         t        | d|j                   j                         z  d       }|r ||fi |}n8t        j                  |j                         j                  d       }|r|j                  ri|dz  }nc|j                   }| j                  j                  |      st        |t        j                        r| j                  j                  |      n|}|dz   }dj                  |j                   D cg c]T  }| j                  j                  |      st        |t        j                        r| j                  j                  |      n|V c}|gz         d | j"                  |fi |iz  }|j$                  r|dz  }|S c c}w )Nzvisit_%s_funcz%(expr)sr  r  z WITH ORDINALITY)r   r   getattrlowerr   r  _deannotater  	_has_argsr  _requires_quotes_illegal_charsr  r   r0   r  rw   packagenamesfunction_argspec_with_ordinality)r  r$  rv  r  r  r  r   r  s           r   r.  zSQLCompiler.visit_functionu  s    (diiTYYL$))Lt_tyy/@@$G ''D==!1!1!3!=!=tDD>>J&Dyy }}CCDI!$(<(<= MM''- 	  j(88  $00 	  ==GGL%dH,@,@A ++C0 !! &	 ...t>v>?@D   &&Ds   *AF7c                8    | j                  |j                        S r  )visit_sequencesequence)r  
next_valuer  s      r   visit_next_value_funcz!SQLCompiler.visit_next_value_func  s    "":#6#677r   c                F    t        d| j                  j                  z        )Nz2Dialect '%s' does not support sequence increments.r  r  r   r  r>  r  s      r   r=  zSQLCompiler.visit_sequence  s$    !@ll 
 	
r   c                <     |j                   j                  | fi |S r  )clause_exprr  )r  r$  r  s      r   r:  zSQLCompiler.function_argspec  s     2t224B6BBr   c           
          j                    } |j                  | fi }|r j                  s| _        |j                  }|r j                  n j                   d   }|xs | xr |j                  dd      }	|dk(  r||d<    j                   j                  |d   |d   |||	d       |j                  r j                  |        j                  |j                     }
d	|
z   d	z   j                   fd
t        |j                        D              }dd<   |  j                  |fi t        ddiz  }|  j                   |fi z  }|j"                  r|  j$                  |fi z  } j&                  r/|st)         j                         nd } j+                  |d      |z   } j                   j-                  d       |S )Nr{  r  Fr   r  r  r  )r  r  r$   r  r  r  c              3  P   K   | ]  \  }} |j                   f|d   yw))rS  r  Nr  )r*  r  rv  rS  r  r  s      r   r,  z4SQLCompiler.visit_compound_select.<locals>.<genexpr>  sA       Aq %$$!'=Cs   #&r  rS  Tr  include_following_stackr   )r  _compile_state_factoryr  r   r  r  r  r  r  compound_keywordskeywordrw   r  selectsgroup_by_clauser  order_by_clause_has_row_limiting_clause_row_limit_clauserD  r  r  rv  )r  csrS  r  r  r  r  compound_stmtr  need_result_maprL  r  r  s   ` ` `        r   visit_compound_selectz!SQLCompiler.visit_compound_select  s    zz>111"dEfED..!.D%//-5))4::b>" 
 A		8%@ 	 Q "E*

#():#; %n 5 !.0?	
 **++M6B((4g#)) &bjj1	
 #($$$RI4+Hv+H+HII$$$R2622&&*D**2888D993;C

OM''"/,0 (  	  	

rr   c                f    |j                    | j                  |fi |S  | j                  |fi |S r  )_fetch_clausefetch_clauselimit_clause)r  rR  r  s      r   rQ  zSQLCompiler._row_limit_clause  s>    '$4$$R2622$4$$R2622r   c                R    d|j                   d||rd|z   nd}t        | |d       S )Nvisit_r  r  )r   r4  )r  r  
qualifier1
qualifier2attrnames        r   r  z"SQLCompiler._get_operator_dispatch  s5     *C*2

 tXt,,r   c                "   |||fz  }||d<   ||d<   |j                   ry|j                  rt        j                  d      | j	                  |j                   dd      }|r |||j                   fi |S  | j
                  |t        |j                      fi |S |j                  rX| j	                  |j                  dd      }|r |||j                  fi |S  | j                  |t        |j                     fi |S t        j                  d      )Nrv  rw  zFUnary expression does not support operator and modifier simultaneouslyunaryr/  modifierz,Unary expression has no operator or modifier)r/  ra  r7   r  r   _generate_generic_unary_operatorrs   _generate_generic_unary_modifier)r  r`  rv  rw  r  r  s         r   visit_unaryzSQLCompiler.visit_unary  s8    (5(*&7B"#'9B#$>>~~&&2  ..D E5>>8R88<t<<9U^^48:  ^^..D E5>>8R88<t<<9U^^48:  ""> r   c                   | j                   j                  r | j                  |j                  fi |dz    | j                  t	        j
                  |j                  |j                  j                  j                  t        j                  u r|j                  j                  nt        j                               fi |z   S  | j                  |j                  fi |dz    | j                  |j                  fi |z   S )N / )r  div_is_floordivr  rx   r   Castr   r   _type_affinityr%   Numericr  r   r/  r  s       r   visit_truediv_binaryz SQLCompiler.visit_truediv_binary$  s    <<''V[[/B/ $,,MM  &||00??'// 0 #LL-- "*!1!1!3 	( V[[/B/$,,v||2r23r   c                   | j                   j                  rn|j                  j                  j                  t
        j                  u r> | j                  |j                  fi |dz    | j                  |j                  fi |z   S d | j                  |j                  fi |dz    | j                  |j                  fi |z   z  S )Nrf  z	FLOOR(%s))	r  rg  r   r   ri  r%   Integerr  rx   rk  s       r   visit_floordiv_binaryz!SQLCompiler.visit_floordiv_binary?  s    LL((!!00H4D4DD V[[/B/$,,v||2r23 V[[/B/$,,v||2r23 r   c                    |j                   s| j                  j                  r | j                  |j                  fi |S d | j                  |j                  fi |z  S )Nz%s = 1_is_implicitly_booleanr  r  r  r  r  r  r/  r  s       r   visit_is_true_unary_operatorz(SQLCompiler.visit_is_true_unary_operatorP  sQ    **||334<<6266ldll7??AbAAAr   c                    |j                   s| j                  j                  r d | j                  |j                  fi |z  S d | j                  |j                  fi |z  S )NNOT %sz%s = 0rq  rs  s       r   visit_is_false_unary_operatorz)SQLCompiler.visit_is_false_unary_operatorY  sV    **||33ldll7??AbAAAldll7??AbAAAr   c                J    d| j                  |t        j                        z  S )Nrv  )override_operator)visit_binaryr!   match_oprk  s       r   visit_not_match_op_binaryz%SQLCompiler.visit_not_match_op_binaryb  s,    $++i&8&8 , 
 
 	
r   c                >    d | j                   |t        |   fi |z  S r  )_generate_generic_binaryrs  rk  s       r   visit_not_in_op_binaryz"SQLCompiler.visit_not_in_op_binaryg  s3     555Ih'
+-
 
 	
r   c                   |t         j                  u r*t        |      dkD  rddj                  d |D              z  S y|t         j                  u r*t        |      dkD  rddj                  d |D              z  S y| j                  |      S )	Nr   z(%s)) OR (1 = 1r   c              3      K   | ]  }d   ywr  Nr   r*  r  s     r   r,  z6SQLCompiler.visit_empty_set_op_expr.<locals>.<genexpr>s       :f:   zNULL) OR (1 = 1z(%s)) AND (1 != 1c              3      K   | ]  }d   ywr  r   r  s     r   r,  z6SQLCompiler.visit_empty_set_op_expr.<locals>.<genexpr>z  r  r  zNULL) AND (1 != 1)r!   	not_in_opr  rw   in_opvisit_empty_set_expr)r  r  	expand_opr  s       r   visit_empty_set_op_exprz#SQLCompiler.visit_empty_set_op_expro  s    	+++5zA~(II:E::  ))//)5zA~*II:E::  +,,U33r   c                F    t        d| j                  j                  z        )Nz3Dialect '%s' does not support empty set expression.rB  r  element_typesr  s      r   r  z SQLCompiler.visit_empty_set_expr  s$    !All 
 	
r   c                   	
 j                   j                   j                        }|s|j                  rO j                  j                  rdnd j                  j                   j                  j                        z   }d|fS  j                  j                   gj                        }d|fS |j                  sB|j                  rt        |d   t        j                        rst        |d   t        t        f      sZ|j                  rt        d       j                  j                  rdnddj!                   fdt#        |      D              z   }d|fS |r j$                  }|j'                  |      }|r|j)                  d      sJ d       |j)                  d      j+                  d	      }|d
   |d   c	
dj!                  	
 fd|D              }d|fS dj!                   fd|D              }d|fS )NVALUES r  r   z?bind_expression() on TupleType not supported with literal_bindsr   c           	   3     K   | ]B  \  }}d dj                  fdt        |j                  j                        D              z   D yw)r  r   c              3  H   K   | ]  \  }}j                  ||        y wr  r  )r*  r  
param_typer  s      r   r,  z[SQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>.<genexpr>  s*      -E: 11%Drr  N)rw   r  r   r  )r*  r  r  r  r  s      r   r,  zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>  sQ       %A} II 14)9>>+?+?2 s   AAr6   )unexpected format for expanding parameterr  r   r  c              3  b   K   | ]&  }j                  |j                         ( y wr  r  r   )r*  r  r  r  r  r  s     r   r,  zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>  s7      3 	  11%H 	3s   ,/c              3  V   K   | ]   }j                  |j                         " y wr  r  )r*  r  r  r  s     r   r,  zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>  s*      3 --eY^^D3r)  r   )r   r  r  r  tuple_in_valuesr  r  r  _isnullr  collections_abcr   r   bytes_has_bind_expressionr  rw   r  r  searchr   r  )r  r  r  bind_expression_templatetyp_dialect_implreplacement_expressionpost_compile_patternr  r  r  r  s   ``       @@r   2_literal_execute_expanding_parameter_literal_bindsz>SQLCompiler._literal_execute_expanding_parameter_literal_binds  s    %>>AA$,,O
  ..!%!=!=I200NN(()*=*=*&z )))m *.)E)E^^$i&9&9*&l )))e ,,$$6!9o&>&>?vay3,744)$  "\\99	r		  )2&(9 &"N )))1 ('+'A'A$(//0HIQWW ?>?  ggaj&&t,$'FCF!)- 3 "(3 *& ))) *. 3!'3 *&
 )))r   c                p   
 j                   r j                  |      S  j                  }j                  j	                  |       j
                  r j                  n j                   j                  j                  rj                  r	 fd
nfd
|smg j                  r4 j                  j                  j                  j                        }|fS  j                  j                  gj                        }|fS j                  sBj                  rt        |d   t         j"                        rt        |d   t$        t&        f      sj(                  rJ t+        |d      D 	cg c]%  \  }}t+        |d      D ]  \  }}	|d|d||	f ' c}	}}}|j,                  rdnddj/                  
fd	t+        |      D              z   }|fS t+        |d      D 	cg c]  \  }}	|d||	f c}	}dj/                  
fd
D              }|fS c c}	}}}w c c}	}w )Nc                H    j                  j                  d| iz        S Nr   )render_bind_castr   )r   bind_templater  r  r  s    r   _render_bindtemplatezNSQLCompiler._literal_execute_expanding_parameter.<locals>._render_bindtemplate  s,    ,,NN$!VTN2 r   c                    d| iz  S r  r   )r   r  s    r   r  zNSQLCompiler._literal_execute_expanding_parameter.<locals>._render_bindtemplate  s    $~55r   r   r   r  r  r  r   c              3  z   K   | ]0  \  d dj                  fdt              D              z   2 yw)r  r   c              3  ^   K   | ]$  \  }} t              z  |z      d           & yw)r   N)r  )r*  r  r  r  r  r  r  s      r   r,  zMSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>.<genexpr>  s@       %Au -%a#m*<&<q&@A!Ds   *-N)rw   r  )r*  r  r  r  r  s    @@r   r,  zCSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>	  sD       %A} II  )2-(@	 s   6;c              3  4   K   | ]  \  }} |        y wr  r   )r*  r+  r  r  s      r   r,  zCSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>  s       /.8c5$S)/r%  )r  r  r  r   r  r4  r.  r-  _bind_typing_render_castsr  r  r  r  r  r  r  r  r   r   r  	_is_arrayr  r  rw   )r  r   r  r  r  r  r  r  r  r  r  r  r  r  s   ` `       @@@@r   r  z0SQLCompiler._literal_execute_expanding_parameter  sQ   $$JJ6  ,,$>>AA'J 99M --M LL22 11 6 I..)-)E)ENN(()*=*=*&V 000O *.)E)E^^$i&9&9*&N 000G ,,$$6!9o&>&>?vay3,7'1111 )2&!(< $A} )- ; Au  $Q*E22I %44	"		  )2&(9 &". 000 !*&! 4Au !!$e,I &*YY /<E/ &" 000;*s   =*H*
5H2c           	        |rt        j                  |j                        r|w|d   }|j                  j	                  t        j                  t        |j                  j                  |gz         t        |j                  j                  |gz                      ni|j                  j	                  t        j                  t        |j                  j                        t        |j                  j                                     | j                  rMt        |j                  t        j                        r)t        |j                  t        j                        rd|d<   |xs |j                  }| j                  |dd       }	|	r
 |	||fi |S 	 t         |   }
 | j"                  ||
f||d|S # t$        $ r}t'        j(                  | |      |d }~ww xY w)Nenclosing_lateralTr  r   )from_linterlateral_from_linter)r!   is_comparisonr/  rt  rf  r  productr)   rx   r*   r   r,  r  r   rE   r  rs  r~  r^  r7   r  )r  r   ry  eager_groupingr  r  r  r  r  r  r  r  s               r   rz  zSQLCompiler.visit_binary   s    9226??C".$&':$;!#))00%%!"KK559J8KK ""LL66:K9LL		 !!((%%!&++";";<!&,,"<"<=   6;;(>(>?6<<)?)?@$(B !%8	**9hE	0R00$Y/ 5t44 !,(;	
    P55dIFCOPs   	F. .	G7GGc                <     | j                   |j                  fi |S r  )r  sql_functionrs  s       r   &visit_function_as_comparison_op_binaryz2SQLCompiler.visit_function_as_comparison_op_binaryX  s    t||G007B77r   c                &   | j                   j                  r> | j                  |j                  fi |dz    | j                  |j                  fi |z   S  | j                  |j                  fi |dz    | j                  |j                  fi |z   S )Nz %% r   )r  r  r  rx   r   rk  s       r   visit_mod_binaryzSQLCompiler.visit_mod_binary[  s    ==))V[[/B/$,,v||2r23 V[[/B/$,,v||2r23r   c                    |j                   |d<    | j                  |d| j                  |j                        z   dz   fi |S )Nr  r  )r  r~  r  r  rs  s       r   visit_custom_op_binaryz"SQLCompiler.visit_custom_op_binaryi  sS    '66,t,,$,,X->->??#E
 
 	
r   c                b     | j                   || j                  |j                        dz   fi |S r  )rb  r  r  rs  s       r   visit_custom_op_unary_operatorz*SQLCompiler.visit_custom_op_unary_operatorq  s:    4t44T//0A0ABSH
LN
 	
r   c                b     | j                   |d| j                  |j                        z   fi |S r  )rc  r  r  rs  s       r   visit_custom_op_unary_modifierz*SQLCompiler.visit_custom_op_unary_modifierv  s:    4t44S455h6G6GHH
LN
 	
r   c                    |j                  dd      }d|d<   |j                  |d<    |j                  j                  | fd|i||z    |j                  j                  | fd|i|z   }|r|rd|z  }|S )Nr  FT
_binary_opr  r  )r  r/  rx   r  r   )r  r   r  r  r  r  r  s          r   r~  z$SQLCompiler._generate_generic_binary{  s     #%&&)BE"J(,$%!??<*FKK**%379  .fll--%379	 	 #~D=Dr   c                B    | |j                   j                  | fi |z   S r  rQ  r  r`  r  r  s       r   rb  z,SQLCompiler._generate_generic_unary_operator  s$    :%--::4F2FFFr   c                B     |j                   j                  | fi ||z   S r  rQ  r  s       r   rc  z,SQLCompiler._generate_generic_unary_modifier  s#    /u}}//;;hFFr   c                L    t        j                  dt        j                        S )Nz'%')r  )r   literal_columnr%   
STRINGTYPEr/  s    r   _like_percent_literalz!SQLCompiler._like_percent_literal  s    &&uH4G4GHHr   c                D    d |j                   j                  | fi | dS )Nzlower(r  rQ  r  s      r   $visit_ilike_case_insensitive_operandz0SQLCompiler.visit_ilike_case_insensitive_operand  s)    :::4F2FGqIIr   c                    |j                         }| j                  }|j                  |j                        j                  |      |_         | j                  ||fi |S r  _cloner  concatr   visit_like_op_binaryr  r   r/  r  percents        r   visit_contains_op_binaryz$SQLCompiler.visit_contains_op_binary  sQ    ,,~~fll3::7C(t((@R@@r   c                    |j                         }| j                  }|j                  |j                        j                  |      |_         | j                  ||fi |S r  r  r  r  r   visit_not_like_op_binaryr  s        r   visit_not_contains_op_binaryz(SQLCompiler.visit_not_contains_op_binary  sQ    ,,~~fll3::7C,t,,VXDDDr   c                   |j                         }| j                  }t        |j                        |_        |j	                  t        |j
                              j	                  |      |_         | j                  ||fi |S r  r  r  r  rx   r  r   visit_ilike_op_binaryr  s        r   visit_icontains_op_binaryz%SQLCompiler.visit_icontains_op_binary  sl    ,,,V[[9~~"6<<0

&/ 	 *t))&(AbAAr   c                   |j                         }| j                  }t        |j                        |_        |j	                  t        |j
                              j	                  |      |_         | j                  ||fi |S r  r  r  r  rx   r  r   visit_not_ilike_op_binaryr  s        r   visit_not_icontains_op_binaryz)SQLCompiler.visit_not_icontains_op_binary  sl    ,,,V[[9~~"6<<0

&/ 	 .t--fhE"EEr   c                    |j                         }| j                  }|j                  |j                        |_         | j                  ||fi |S r  )r  r  _rconcatr   r  r  s        r   visit_startswith_op_binaryz&SQLCompiler.visit_startswith_op_binary  sH    ,,''5(t((@R@@r   c                    |j                         }| j                  }|j                  |j                        |_         | j                  ||fi |S r  )r  r  r  r   r  r  s        r   visit_not_startswith_op_binaryz*SQLCompiler.visit_not_startswith_op_binary  sH    ,,''5,t,,VXDDDr   c                    |j                         }| j                  }t        |j                        |_        |j	                  t        |j
                              |_         | j                  ||fi |S r  )r  r  r  rx   r  r   r  r  s        r   visit_istartswith_op_binaryz'SQLCompiler.visit_istartswith_op_binary  s^    ,,,V[[9''(>v||(LM)t))&(AbAAr   c                    |j                         }| j                  }t        |j                        |_        |j	                  t        |j
                              |_         | j                  ||fi |S r  )r  r  r  rx   r  r   r  r  s        r   visit_not_istartswith_op_binaryz+SQLCompiler.visit_not_istartswith_op_binary  s^    ,,,V[[9''(>v||(LM-t--fhE"EEr   c                    |j                         }| j                  }|j                  |j                        |_         | j                  ||fi |S r  r  r  s        r   visit_endswith_op_binaryz$SQLCompiler.visit_endswith_op_binary  sF    ,,~~fll3(t((@R@@r   c                    |j                         }| j                  }|j                  |j                        |_         | j                  ||fi |S r  r  r  s        r   visit_not_endswith_op_binaryz(SQLCompiler.visit_not_endswith_op_binary  sF    ,,~~fll3,t,,VXDDDr   c                    |j                         }| j                  }t        |j                        |_        |j	                  t        |j
                              |_         | j                  ||fi |S r  r  r  s        r   visit_iendswith_op_binaryz%SQLCompiler.visit_iendswith_op_binary  s\    ,,,V[[9~~&<V\\&JK)t))&(AbAAr   c                    |j                         }| j                  }t        |j                        |_        |j	                  t        |j
                              |_         | j                  ||fi |S r  r  r  s        r   visit_not_iendswith_op_binaryz)SQLCompiler.visit_not_iendswith_op_binary  s\    ,,,V[[9~~&<V\\&JK-t--fhE"EEr   c                   |j                   j                  dd       } |j                  j                  | fi |d |j                  j                  | fi ||%d| j                  |t        j                        z   z   S dz   S )NrM  z LIKE  ESCAPE r  	modifiersr  rx   r  r   r  r%   r  r  r   r/  r  rM  s        r   r  z SQLCompiler.visit_like_op_binary  s    !!%%h5 +FKK**4626+FLL++D7B7

 ! 2268;N;NOO	
 	
 
 	
r   c                   |j                   j                  dd       } |j                  j                  | fi |d |j                  j                  | fi ||%d| j                  |t        j                        z   z   S dz   S )NrM  z
 NOT LIKE r  r  r  r  s        r   r  z$SQLCompiler.visit_not_like_op_binary  s    !!%%h5*FKK**4626+FLL++D7B7

 ! 2268;N;NOO	
 	
 
 	
r   c                    |t         j                  u rD|j                         }t        |j                        |_        t        |j
                        |_         | j                  ||fi |S r  )r!   ilike_opr  r  rx   r   r  rk  s       r   r  z!SQLCompiler.visit_ilike_op_binary  sW    y)))]]_F0=FK1&,,?FL )t((@R@@r   c                    |t         j                  u rD|j                         }t        |j                        |_        t        |j
                        |_         | j                  ||fi |S r  )r!   not_ilike_opr  r  rx   r   r  rk  s       r   r  z%SQLCompiler.visit_not_ilike_op_binary  sW    y---]]_F0=FK1&,,?FL -t,,VXDDDr   c                j    |j                   j                  dd      } | j                  ||rdndfi |S )Nr   Fz BETWEEN SYMMETRIC z	 BETWEEN r  r  r~  r  r   r/  r  r   s        r   visit_between_op_binaryz#SQLCompiler.visit_between_op_binary  sA    $$((e<	,t,,Y)K
KM
 	
r   c                j    |j                   j                  dd      } | j                  ||rdndfi |S )Nr   Fz NOT BETWEEN SYMMETRIC z NOT BETWEEN r  r  s        r   visit_not_between_op_binaryz'SQLCompiler.visit_not_between_op_binary  sD    $$((e<	,t,,)2%
 
 	
r   c                Z    t        j                  d| j                  j                  z        Nz/%s dialect does not support regular expressionsr7   r  r  r   rk  s       r   visit_regexp_match_op_binaryz(SQLCompiler.visit_regexp_match_op_binary&  *    =ll 
 	
r   c                Z    t        j                  d| j                  j                  z        r  r  rk  s       r    visit_not_regexp_match_op_binaryz,SQLCompiler.visit_not_regexp_match_op_binary,  r  r   c                Z    t        j                  d| j                  j                  z        )Nz;%s dialect does not support regular expression replacementsr  rk  s       r   visit_regexp_replace_op_binaryz*SQLCompiler.visit_regexp_replace_op_binary2  s*    Ill 
 	
r   c           	     ^   |s|j                   j                  | j                        }|j                  r|j	                  |      }	 | j
                  |	fd||xr |j                   ||d|}
|j                  rut        j                  d|
      }|sJ d       d|j                  d      d|j                  d      d	|j                  d
      d}
|r | j                  |fd|
d|}d|z  S |
S |s3|xs |j                  xs |xr | j                  }|xs |j                  }nd}|r( | j                  |fddi|}|j                  rd|z  }|S | j                  |      }|| j                  v r5| j                  |   }||ur!|j                  s|j                  rb|j                   j#                  |j                         s=|j$                  j#                  |j$                        st'        j(                  d|z        |j                  |j                  k7  rt'        j(                  d|d      |j*                  s|j*                  r]|j*                  r!|j*                  rt'        j(                  d      t'        j(                  d|j,                   d|j,                   d      |x| j                  |j,                  <   | j                  |<   | j.                  }|rH|\  }}|j$                  D ]4  }|j,                  |v s||j,                     }||   j1                  |       6 |j2                  rd| _        |r8|rd| _        |r| xj8                  |hz  c_        n| xj:                  |hz  c_         | j<                  |f||j                  |j                   d|}|j                  rd|z  }|S )NT)skip_bind_expressionr\  literal_bindsr  render_postcompilez&^(.*)\(__\[POSTCOMPILE_(\S+?)\]\)(.*)$r  z(__[POSTCOMPILE_r6   r  r   z~~REPL~~r  z~~]))r\  r  r  Fr\  zIBind parameter '%s' conflicts with unique bind parameter of the same namez"Can't reuse bound parameter name 'z' 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 limitedzbindparam() 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  r  bind_expressionr  r  rL  r  r   r  r  r,  _truncate_bindparamr(  r   r  intersectionrH  r7   r  _is_crudr+  r@  r  
isoutparamhas_out_parametersr5  r=  r>  r  )r  r  r\  r  r  r  r  r  implr  wrappedr  r@  r  r   existingr  rn  rm  rK  rM  s                        r   visit_bindparamzSQLCompiler.visit_bindparam8  s    $>>..t||<D(("&"6"6y"A&$,,#)-*?"/"K	8K8K4K$3'9  && A7A III1


G %;d;;%265< %	  &|+ D,,D)Bd.B.B 
 +Ai.A.AL L/$//159?C ""slJ''	24::zz$'Hy(__	(8(8$..;;!++ %00==!-- **ACGH  ''9+>+>>** :>@  &&)*<*<((Y-?-? "..&
 
 "..0 @" #,--5	 	 8A@

9==!DJJt$4 //
#JD$++ /66T>bffBHOOI./
 &*D#!+/(++	{:+((YK7(#d##
%))$>>	

 
 3,C
r   c                    t               r  r  )r  r  
dbapi_typerJ  s       r   r  zSQLCompiler.render_bind_cast  s    !##r   c                   |t         ur|}n|j                  |j                  x|j                  dd       }|rC|t        j
                  t        j                  fvr!t        j                  d|j                  f        | j                  t        j                  fi |S |j                  }|j                  r| j                  } ||||      \  }}	|	S | j!                  ||j"                        S )Nr  zBound parameter '%s' rendering literal NULL in a SQL expression; comparisons to NULL should not use operators outside of 'is' or 'is not')r  )r.   r  r  r  r!   is_is_notr&   warn_limitedr+  r  r%   r  r  r  r  r  r   )
r  r  r  r  r  r  opleepr  r  s
             r   r  z$SQLCompiler.render_literal_bindparam  s      v-(E&9+=+=+EVVL$/"Y]]I4D4D$EE%%@ #(	 $t||H$5$5<<<--EJJD*.)A+'I'
 $#,,UINNCCr   c                   |9|j                   s-| j                  t        j                  j	                               S |j                  | j                        }|r		  ||      S t        j                  dt        j                  |       d|       # t        $ r5}t        j                  dt        j                  |       d| d      |d}~ww xY w)a  Render 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  r7   r  sql_util_repr_single_value)r  r  r  	processores        r   r  z SQLCompiler.render_literal_value  s     =!;!; << 7 7 9::33DLLA		 '' ""//67 8!!&)   && 33E:; <%g ## s   B 	C0C		Cc                    || j                   v r| j                   |   S |j                  }t        |t        j                        r| j                  d|      }|| j                   |<   |S )Nr  )r)  r+  r  r   rD   rr  )r  r  r  s      r   r  zSQLCompiler._truncate_bindparam&  s^    '??9--MM	i!:!:;22;	JI &/	"r   c                   ||f| j                   v r| j                   ||f   S |j                  | j                        }t        |      | j                  dz
  kD  r]| j
                  j                  |d      }|dt        | j                  dz
  d       dz   t        |      dd  z   }|dz   | j
                  |<   n|}|| j                   ||f<   |S )N   r   r   r  r6   )	r`  	apply_mapr_  r  r]  ra  r  maxhex)r  ident_classr   anonnamecounter	truncnames         r   rr  z!SQLCompiler._truncated_identifier3  s     $"6"66''d(;<<>>$--0x=4,,q00..22;BGS!2!2Q!6:;g,qr"# 
 5<aKD$$[1 I4=k401r   c                     || j                   z  S r  r_  r  r   s     r   
_anonymizezSQLCompiler._anonymizeH  s    dmm##r   c                    ||j                  |       ||j                  |       |s> j                  j                  |      r# j                  j	                   fd|      }	|}|	}|r" j
                  j                  ||i       _        |rGd|z  }
|r|
S |:|j                   j                        }|j                  r j                  |||
      }
|
S  j                  t        j                  u r j                  d|iz  }
n j                  d|iz  }
|P j                  j                   r:|j                   j                        }|j                  r j                  |||
      }
|
S )Nc                @    j                   | j                  d         S )Nr   )r  r   )r  r  s    r   r  z.SQLCompiler.bindparam_string.<locals>.<lambda>e  s    d88D r   z__[POSTCOMPILE_%s]r   )addr  r  r  r  r?  r   r  r  render_literal_castr  r  r`  ra  r.  r-  r  )r  r   r  r  escaped_fromr  accumulate_bind_namesvisited_bindparamr  new_namer@  	type_impls   `           r   r  zSQLCompiler.bindparam_stringK  ss    !,!%%d+($$T*&&--d3  2266D  $&*&=&=&C&Ct$'D# &-C 
 )*BBLL	 00//	3OCJZZ=222//64.@C##vtn4C &66&>>t||LI))++NIsK
r   c                    |j                         }|j                  dd        t        |j                  |j                        D ]  \  }} |j
                  | fd|i|  y )Ncte_opts)copyrv  r  r  _independent_ctes_optsr  )r  stmtr  local_kwcteopts         r   r  z&SQLCompiler._dispatch_independent_ctes  sb    779Z&""D$?$?
 	CHC #C""4B#BB	Cr   c                	     j                         }	|	 j                  u sJ ||d<   |j                  }
t        |
t        j
                        r j                  d|
      }
d}d}|j                         }|j                  xs |j                  }| j                  v r j                  |   \  }}}||
k(  sJ ||
f} j                  |   }|j                  r|j                  rt        j                  d      ||
f}|rt         j                        nd}||
fx}} j                  |= | j                  |<   ||fz    j                  |<   n=|rt         j                        nd}||
f}| j                  v r j                  |   }nd }|||u }||j                  u s||u rd}n||j                  u r-|	|= |j                         }||u sJ ||u sJ  j                  |= nD|j                   |j                   |j#                  |      rd}nt        j                  d|
z        |s|sy |j$                  O|j$                  }|j$                  j                  }t        |t        j
                        r j                  d|      }n|}d }|r| j                  |<   ||fz    j                  |<   | j                  vr  j&                  |fi | |s]||	vrX|j(                  rd _         j,                  j/                  ||
      }|j(                  r^|j0                  }|j3                  d      D cg c]  \  }}}}}|s|xs | }}}}}}|dd	j5                   fd
|D              z  z  }|j7                  dd      du sJ  j                  s |j0                  j8                   fd|i|S   j:                  ||j<                  fi |}  |j0                  j8                   fddi|}!|d| d|!dz  }|j>                  r$|d  j:                  ||j>                  fi |z   z  }||	|<   |r|r|
|j@                  |jC                         <   |s|r j,                  j/                  ||
      S |rh j,                  j/                  ||      } j,                  jE                  |
      r j,                  jG                  |
      }
| jI                  |
      z  }|S  j,                  j/                  ||
      S y c c}}}}}w )Nvisiting_cter  TFz6CTE is stated as 'nest_here' in more than one locationr   z5Multiple, unrelated CTEs found with the same name: %rr  r   c              3  l   K   | ]+  }j                   j                  |j                          - yw)r8  N)r  format_label_namer_  )r*  identr  s     r   r,  z(SQLCompiler.visit_cte.<locals>.<genexpr>-  s8      " !& !MM;; % < "s   14subqueryrS  r   z
(r  r  )%r  rD  r   r  r   rD   rr  _get_reference_ctenestingrF  rE  r7   r  r  r  	_restates_is_clone_ofcompare
_cte_alias	visit_cte	recursiverG  r  format_aliasr  _generate_columns_plus_namesrw   r  r  _generate_prefixes	_prefixes	_suffixesrs  r)   _requires_quotesr  get_render_as_alias_suffix)"r  rJ  rS  ashint	fromhintsrM  r  rE  r  	self_ctescte_name
is_new_cteembedded_in_current_named_cte_reference_cterS  	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_namer  
col_source
proxy_namefallback_label_namerv  repeated
recur_colsprefixesr   s"   `                                 r   rX  zSQLCompiler.visit_cte  s    ((*	DII%%%!$~88h 9 9:11'8DH
(-%//1++1!1!1 T333.2.D.D/+Iq+ = ='2N22>BL
 $,,**1 
 #,X!6/6C

OA	3<h2GG++N;:F''79GK :&&~6
 ,3DJJI'2N!8!88#66~F##,8L,H) l,,,|0C"
. l+-9-L-L-N*1^CCC1\AAA**+EF $$0#00<kk,/!&J**,.67 
 j>>%NNM!$!4!4,h.G.GH%)%?%?/&"  M!%69D##N35CG 6D"">2 DII-}77%#Y*>==*.D'}}11#x@==!$J" )EEdK" "&/$' ,9z9"J "  F		 " *4	"  D zz*e4===zz :3;;99%+/5   7t66S]] .4 H ;CKK::%)-3E h>>D==C"9$"9"9S]]#.4#  D "&	#5=!!#--/2"?}}11#x@@!}}11#7IJ==11(;#}}228<H77AA}}11#x@@G"s   /S1c                    |j                   rd |d<   |j                  r | j                  |fi |S  | j                  |fi |S )Nr  )joins_implicitly_is_lateralvisit_lateralvisit_aliasr  s      r   visit_table_valued_aliasz$SQLCompiler.visit_table_valued_aliasa  sN    ## $B}%4%%g444#4##G2r22r   c                (     | j                   |fi |S r  )r  r  s      r   visit_table_valued_columnz%SQLCompiler.visit_table_valued_columni  s     t  /B//r   c
           
        
 |r&d
vrj                   sJ 
d<   |	rd
vr	d
v r|	
d<   |@|j                  u r2 j                  j                   f|||||d
}|r
|s|rd|d}|S x}
d<   |s|rMt        j                  t
        j                        r j                  dj                        }nj                  }|r j                  j                        S |r|	r|	j                  j                         <    j                  j                   fd|d	
}|rd|d}| j                   j                  j                              z   }j                  r8j                  r,|d
dj                  
 fdj                   D              z  z  }|r|v r j#                  ||   |      }|S  j                  j                   fd|i
S )Nr  r  )rS  ra  iscrudrb  lateralenclosing_aliasr  r  r  r  T)rS  r  r  r   c              3     K   | ]m  }j                   j                  |j                        j                  r4d  j                  j
                  j                  |j                  fi z  nd o yw) %sr  N)r  r  r   _render_derived_w_typesr  r  r  r   )r*  r  r  r  r  s     r   r,  z*SQLCompiler.visit_alias.<locals>.<genexpr>  s{         !MM//9 $)#@#@	 !&"M$,,"E"E"M"M$'HH#"06#"!"
 &(!(	s   A3A6r  )ry  r  r  r  r   r   rD   rr  r  rZ  rs  r)   r`  _supports_derived_columns_render_derivedrw   rv  format_from_hint_text)r  r  rS  ra  r  rb  rQ  r  r  r  r  r   
alias_namer@  s   ``        `   r   r{  zSQLCompiler.visit_aliasl  s4    "&0 ((((.3*+
 )7'610;,-&?+B+Be+K4EMM44	# %	 	E Vw"')L:??Of%67V%**h&?&?@!77L
"ZZ
==--eZ@@7A!!%//"344EMM44!76<E "')$99**5*= C ..53H3HvII  $)77  $ Ui/00	% 0& J 45==33%)/ r   c                2    d|d<    | j                   |fi |S )NTrQ  r{  )r  rQ  r  s      r   visit_subqueryzSQLCompiler.visit_subquery  s#    :t/B//r   c                8    d|d<   d | j                   |fi |z  S )NTr  z
LATERAL %sr  )r  lateral_r  s      r   rz  zSQLCompiler.visit_lateral  s)    9.d..x>2>>>r   c                     | j                   |fddi|d |j                         j                  | fi |}|j                  #|d |j                  j                  | fi |z  z  }|S )NrS  Tz TABLESAMPLE z REPEATABLE (%s))r{  _get_methodr  seed)r  tablesamplerS  r  r  s        r   visit_tablesamplezSQLCompiler.visit_tablesample  s    D[<<<8K##%88DD

 '&3  33D?B? D r   c                     j                  dj                         dj                   fdj                  D              }d| S )Nr  r   c           	   3     K   | ]I  }|D ]B  } j                   t        j                  |d j                  ij	                         fi  D K yw)r  N)r  r   r   _column_typesr  )r*  chunkelemr  r  r  s      r   r,  z-SQLCompiler._render_values.<locals>.<genexpr>  sk      	
 	
  DLL26!//*, 		
	
   AAr  )
setdefaultr  rw   _data)r  r  r  tupless   ``` r   _render_valueszSQLCompiler._render_values  sG    
ow'<'<= 	
 !	
 	
 !!r   c           
     (      j                   |fi }|j                  rd }nMt        |j                  t        j
                        r j                  d|j                        }n|j                  }|j                  rd}nd}|r|r!||nd|j                  |j                         <   |r`dd<   |d|d j                   j                  j                  |            d	d
j                   fd|j                  D              d}|S |d|d}|S )Nr  zLATERAL r  z(unnamed VALUES element)Fr  r  r   (r   c              3  D   K   | ]  } |j                   fi   y wr  r  r  s     r   r,  z+SQLCompiler.visit_values.<locals>.<genexpr>  s+      " ! 1A00<<"r  )r  _unnamedr  r   r   rD   rr  ry  rs  r)   r`  r  r  rw   columns)r  r  rS  r  r  rq  r   r  s   `   `   r   visit_valueszSQLCompiler.visit_values  s   D.2.Dh&?&?@--hED<<D GG ,D2L !!'"3"3"56 &+?#33DMM4G4G4MN		 "%,__" 
  !(+r   c                0    d | j                   |fi | dS rP  )r  r  s      r   visit_scalar_valueszSQLCompiler.visit_scalar_values  s%    &4&&w5"56a88r   c                    d|z   S )Nr   r   )r  alias_name_texts     r   r`  z&SQLCompiler.get_render_as_alias_suffix  s    ''r   c                    |sJ ||dk(  rd| _         d| _        |j                  rt        j                  d      | j
                  j                  t        ||||             y )N*FTzxMost backends don't support SELECTing from a tuple() object.  If this is an ORM query, consider using the Bundle object.)r2  r1  r  r7   r  r  r  r   r  s        r   r  zSQLCompiler._add_to_result_map  sk     w?gn$)D!#'D ""4 
 	##wgu=	
r   c                8     | j                   d||d|i n|fi |S )aL  Render 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)r  rH  r   r  column_clause_argsr  s         r   _label_returning_columnz#SQLCompiler._label_returning_column8  s:     )t(($,B2D
 
 	
r   c                <   j                   j                  | j                        }|j                  r|s|r|j	                        }n}|r#| j
                  }|
r|fd}n|ur|fd}nd}|	sJ d       t        t        j                        r-|ur%t        |j                  j                  f      }n8|}n4|r%|J d       t        |||j                  f      }n|urd}nt        t        j                        r"|xr j                   xr j                  du}nst        t        j                         rd}nVt        t        j"                        rj$                  xs |}n+t        t        j&                        sj(                  d}nd}|rS|s|
rJ j*                  }t        |t        j,                        st        j,                  |      n|}t        |||f      }n|}|j/                  |	||	        |j0                  | fi |S )
z.produce labeled columns present in a select().c                     | || f|       y r  r   )r   r   r   r  r  s       r   rv  z;SQLCompiler._label_select_column.<locals>.add_to_result_maps  s    &wwj%Hr   c                $     | |f|z   |       y r  r   )r   r   r   r  r  r   s       r   rv  z;SQLCompiler._label_select_column.<locals>.add_to_result_map{  s    &y7':Er   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\  rv  r  )r   r  r  _has_column_expressioncolumn_expressionr  r  r   rH   r  r   r  r  rF   r  r   
TextClauseUnaryExpressionwraps_column_expressionNamedColumn_non_anon_label_anon_name_labelrD   rf  r  )r  r   r   r  rS  r  r   rr  rs  r\  column_is_repeatedneed_column_expressionsr  r  col_exprrv  result_exprrender_with_labelr  s     `               @r   r  z SQLCompiler._label_select_columnM  sf     {{''5&&#':--f5HH
 !% 7 7
 "%6"I
 '%6" !% % 	
:	
$ fhnn-v%+fkkfnn5F ' &<;<& ( $$K& v% %)!FH$9$9:  1"---1D0 "
 FH$7$78$)!FH$<$<=$*$B$B$Lf!
 vx';';< **2$(!$)! *
  211*0*A*A' &+X-F-F --.AB - $ ,1j] '!!"7/' 	" 	

 .{--dI6HIIr   c                >    | j                  ||      }|r|d|z   z  }|S r  )get_from_hint_text)r  rJ  r   hintr  hinttexts         r   r  z!SQLCompiler.format_from_hint_text  s*    **5$7sX~%Gr   c                     y r  r   )r  byfromss     r   get_select_hint_textz SQLCompiler.get_select_hint_text      r   c                     y r  r   r  r   r  s      r   r  zSQLCompiler.get_from_hint_text  r  r   c                     y r  r   r  s      r   get_crud_hint_textzSQLCompiler.get_crud_hint_text  r  r   c                $    dj                  |      S r  r  )r  
hint_textss     r   get_statement_hint_textz#SQLCompiler.get_statement_hint_text   s    xx
##r   r  r  r  r  c                   | j                    }|r| j                  n| j                   d   }|j                  ||       }|d   }|d   }	|r&|s$|j                  |j	                  |	      d      }
|
S |j                  ||	      }
|
S )Nr{  r  r  r   explicit_correlate_fromsimplicit_correlate_froms)r  r  rJ  _get_display_froms
difference)r  select_stmtrS  r  r  r  r  r  r  r  rs  s              r   _display_froms_for_selectz%SQLCompiler._display_froms_for_select
  s     zz>-5))4::b>#::;M 12^,'!44)8)C)C * *,	 5 E 	 "44)8)5 5 E r   translate_select_structurec	                  % |J d       d|	d<    |j                   || fi |	}
|
j                  |	d<   |
j                  }| j                   }|r| j                  s|
| _        |d uxs |}| j
                  r? | j
                  |fd|i|	}||ur&|
}|}|} |j                   || fi |	}
|
j                  }|r| j                  n| j                  d   }|xs& |j                  dd      xs |j                  dd      x}}|rd}|sd	|	v r|	d	= | j                  ||
||||      }|	j                         }|j                  ddd
       d}|j                  r| j                  |      \  }}|r||dz   z  }nd }|j                  r| j                  ||	       |j                  r!| | j                   ||j                  fi |	z  }| | j"                  |fi |	z  }|
j$                  D cg c]#  \  }}}}}| j'                  ||||||||||
      % c}}}}}D cg c]  }|| }}|r|t)        t+        |
j$                  D cg c]
  \  }}}}}| c}}}}}j$                  D cg c]
  \  }}}}}| c}}}}}            %| j,                  D  cg c]'  \  }}}} t/        ||t1        %fd|D              |       ) c} }}}| _        | j3                  |||
|||||	      }|j4                  rQ|j4                  D !"cg c]!  \  }!}"|!d| j6                  j8                  fv r|"# }#}!}"|#r|d| j;                  |#      z   z  }| j<                  r2|r|r.|st?        | j                        nd }$| jA                  |$      |z   }|jB                  r$|d | j                   ||jB                  fi |	z   z  }| j                  jE                  d       |S c c}}}}}w c c}w c c}}}}}w c c}}}}}w c c} }}}w c c}"}!w )NzpSQLAlchemy 1.4 requires use of the translate_select_structure hook for structural translations of SELECT objectsFr\  r  rS  r{  r  r  rv  )rq  r\  zSELECT r  )r   rr  rs  r  r  c              3  B   K   | ]  }j                  ||        y wr  r  )r*  orF  s     r   r,  z+SQLCompiler.visit_select.<locals>.<genexpr>  s     $FQY]]1a%8$Fs   r  r  )#rJ  _ambiguous_table_name_mapr   r  r  r  r  r  _setup_select_stackrF  rf  _hints_setup_select_hintsr  r  r]  r\  get_select_precolumnscolumns_plus_namesr  r  r  r  r   r.  _compose_select_body_statement_hintsr  r   r  rD  r  r  r^  rv  )&r  r  rS  insert_intorb  r  select_wraps_forr  r  r  r  r  is_embedded_selectnew_select_stmtcompile_state_wraps_forr  r  r  rs  r  r  	hint_textbyfromr   rr  rs  r   rt  rv  inner_columnsr+  r  r  dialect_namehtper_dialectr  rF  s&                                        @r   visit_selectzSQLCompiler.visit_select.  s     ' 	
-	
' +0&':::
!'
 33 	)* $--zz>D..!.D+47F;
 **=d==$*.4O k1*7'#. - B B B!)/! ,55-5))4::b>  >yy7?>yy5u=	
5 "'
 #':f'D*+((vw
 $[[]!!$)EJ	
  $ 8 8 EIv	C'F((++K@  +D++[226< D 	***;A&AA. #55' '# ))'&)(;'/,C * 
* }- 
 
4 #3#?  +==	 	&/ $ 	$ 5GG	 	&/ $ 	I: .2-A-A	$ $ *CsE #u$F#$FF$D  ((	
 '' +6*F*F&\2C):):#;; K 
 d::;GGG 990H3;C

OM***G$ND  C1$11[226<  D 	

ry
@		$&s$   &(OOO+O(,O1
&O9c                    |j                   j                         D ci c];  \  \  }}}|d| j                  j                  fv r||d|j	                  | d      iz  = }}}}| j                  |      }||fS c c}}}w )Nr  r   T)ra  )r  rg  r  r   r  r  )r  r   r  r  r  r  r  s          r   r  zSQLCompiler._setup_select_hints  s     /5mm.A.A.C
 
 + (3 1 122 8u//T/BCD D
 
 --f5	&  
s   A A8c           	        |d   }|d   }|dk(  r||d<   nf|rd|d   }	t        |	j                        }
t        |j                        |
k7  r2t        j                  dd|
|dz   t        |j                        fz        |r%|s#|j                  |j                  |      d      }n|j                  ||      }t        t        |       }|j                  |      }||||d	}| j                  j                  |       |S )
Nr  r  r   r  z}All selectables passed to CompoundSelect must have identical numbers of columns; select #%d has %d columns, select #%d has %dr   r   r  )r  r  r$   r  )r  ru  r  r7   r  r  r  ro   r*   r   r  r  )r  r   r  r  rS  r  r  r  r  r  numcolsrs  new_correlate_fromsall_correlate_fromsr  s                  r   r  zSQLCompiler._setup_select_stack  s;      12^,Q &E*Z(H(889G=334?&&!
 &*F889			  '!44)8)C)C * *,	 5 E "44)8)5 5 E
 "-"78177H 02 *	*
	 	

)$r   c	                ,   |dj                  |      z  }| j                  t        z  r1t        i t	                     }	| j                  t
        z  }
|r|	| _        nd }	d}
|s|j                         }|r|dz  }|j                  r8|dj                  |D cg c]  } |j                  | fd||	d| c}      z  }nJ|dj                  |D cg c]  } |j                  | fd|	d| c}      z  }n|| j                         z  }|j                  r) | j                  |j                  fd|	i|}|r|d|z   z  }|
r|	J |	j                          |j                  r| | j                  |fi |z  }|j                   r' | j                  |j                   fi |}|r|d	|z   z  }|j"                  r| | j$                  |fi |z  }|j&                  r| | j(                  |fi |z  }|j*                  | | j,                  |fi |z  }|S c c}w c c}w )
Nr   Fz 
FROM T)rS  rb  r  rS  r  r  z 
WHERE z	 
HAVING )rw   rW  rg  rk  ro   rh  r  rstripr  r  rC  _where_criteriar  r  _group_by_clausesrN  _having_criteria_order_by_clausesrO  rP  rQ  _for_update_argfor_update_clause)r  r  r   r  r  rs  r  r  r  r  warn_lintingfts                r   r  z SQLCompiler._compose_select_body;  s    			-((<<44$R/K<<,6L#. K L ;;=DJD}}		 "'	  -,, #'&,(3	
 %	  		 "'  -,, #'(3 %	
 
 D%%''D!!111&&4?CIA a'***##(D((:6::D""111''+1A q((##(D((:6::D***D**6<V<<D!!-*D**6<V<<Dq	s   H

H
c                N     dj                   fd|D              }|r|dz  }|S )Nr  c              3     K   | ]7  \  }}|d v s|j                   j                  k(  r |j                  fi  9 yw))Nr  N)r  r   r  )r*  prefixr  r  r  s      r   r,  z1SQLCompiler._generate_prefixes.<locals>.<genexpr>  sH      
${*ldll>O>O.O &F%%d1b1
s   =A r  )r  rH  rv  r  r  s   `  ` r   r\  zSQLCompiler._generate_prefixes  s1     
(0
 

 cMFr   c                v   | j                   sy|r|dkD  rt        j                         }t        | j                   j	                               D ]g  }| j
                  |j                            \  }}}|j                  xs |j                  }||k(  xs |xr ||dz   k(  }	|r|	sV| j                   |   ||<   i n| j                   }|syt        |D cg c]  }|j                   c}      }
| j                  |
      dz   }|dj                  |j                         D cg c]  }| c}      z  }|dz  }|r{|dkD  rvt        |j	                               D ]Z  }| j
                  |j                            \  }}}| j                   |= | j                  ||f= | j
                  |j                         = \ |S c c}w c c}w )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  r   r  , 
z
 )rD  r&   r  r  keysrF  rR  rS  rg   rY  get_cte_preamblerw   r  rE  )r  r  rI  rD  rJ  rh  rd  rE  rS  is_rendered_levelrG  cte_texttxts                r   r  zSQLCompiler._render_cte_clause  s    yy ]Q.##%DDIINN,- +040F0F**,1-	8X ++9)9)9$-$> %+N	]Q=N0N "  $5 IIcNS	+ 99Dt<cmm<=((83>FKK > >??E]Q.DIIK( E040F0F**,1-	8X IIcN++Y,AB**3+A+A+CDE  = !?s   F1	F6
c                
    |ryy)NzWITH RECURSIVEWITHr   )r  rY  s     r   r  zSQLCompiler.get_cte_preamble  s    #r   c                h    |j                   rt        j                  dd       |j                  rdS dS )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.z1.4versionr   r  )_distinct_onr&   warn_deprecated	_distinctr  r   r  s      r   r  z!SQLCompiler.get_select_precolumns  s:    
   3
  %..{6B6r   c                x     | j                   |j                  t        t        j                     fi |}|rd|z   S y)z5allow dialects to customize how GROUP BY is rendered.z
 GROUP BY r  )r  r  rs  r!   comma_op)r  r   r  group_bys       r   rN  zSQLCompiler.group_by_clause  sG     1400$$i	0B0B&C
GI
 (**r   c                x     | j                   |j                  t        t        j                     fi |}|rd|z   S y)z5allow dialects to customize how ORDER BY is rendered.z
 ORDER BY r  )r  r  rs  r!   r  )r  r   r  r  s       r   rO  zSQLCompiler.order_by_clause  sG     1400$$i	0B0B&C
GI
 (**r   c                     y)Nz FOR UPDATEr   r  s      r   r  zSQLCompiler.for_update_clause  s    r   c                   |j                  dt        j                  |            D 	cg c]"  \  }}}}}	 | j                  |||f||	||d|$ }
}}}}}	ddj	                  |
      z   S c c}	}}}}w )NT)cols)rs  r  r   rr  
RETURNING r   )r[  r   _select_iterablesr  rw   )r  rH  returning_colsr  r  r   rr  rs  r   rt  r  s              r   returning_clausezSQLCompiler.returning_clause	  s    2 22411.A 3 #
 
# )D((#	 %8#+%	 	
 
, dii000-
s   'A.c                    d}|j                   #|d | j                  |j                   fi |z   z  }|j                  4|j                   |dz  }|d | j                  |j                  fi |z   z  }|S )Nr  z
 LIMIT z

 LIMIT -1z OFFSET )_limit_clauser  _offset_clause)r  r   r  r  s       r   rY  zSQLCompiler.limit_clause)  s    +K,$,,v/C/C"Jr"JJJD  ,##+%Jf.C.C!Jr!JJJDr   c                   ||j                   }|j                  }nddd}d}|j                  K|j                  }|r!|j                  |      r|j	                         } | j
                  |fi |}	|d|	z  z  }n|r|dz  }|O|r!|j                  |      r|j	                         }|d | j
                  |fi ||d   rdndd	|d
   rdndz  }|S )NF)r  	with_tiesr  z
 OFFSET %s ROWSz
 OFFSET 0 ROWSz
 FETCH FIRST r  z PERCENTz ROWS r   z	WITH TIESONLY)rW  _fetch_clause_optionsr  _simple_int_clauserender_literal_executer  )
r  r   rX  require_offset"use_literal_execute_for_simple_intr  fetch_clause_optionsr  offset_clause
offset_strs
             r   rX  zSQLCompiler.fetch_clause3  s    !//L#)#?#? /45#I   ,"11M2--m< - D D F%m:r:J'*44D&&D#2--l;+BBD\0R029=
2E3K@fL D
 r   c	                R   |r|j                   |j                  |<   |s|r| j                  j                  |      }
|rG|
rE| j                  j	                  |
      dz   | j                  j                  |j                        z   }n| j                  j                  |j                        }|
s]|r[|j                  |v rM| j                  d||j                           }|| j                  | j                  j                  d |            z   }|r||v r| j                  ||||   |      }|S y)Nr  r  r  )fullnamers  r  r  r  r  r   rr  r`  rZ  r  )r  r   rS  r  ra  rb  
use_schemar  r  r  r  r@  	anon_names                r   visit_tablezSQLCompiler.visit_table\  s%    ',~~Ke$V#}}>>uE.MM../?@mm))%**56  mm))%**5 )0

&>> $ : :!9%**!E!I  ? ?224C! C Ui/00	% 0& Jr   c                   |ri|j                   j                  t        j                  t	        |j
                  j                        t	        |j                  j                                     |j                  rd}n|j                  rd}nd} |j
                  j                  | fd|d||z    |j                  j                  | fd|d|z   dz    |j                  j                  | fd|i|z   S )Nz FULL OUTER JOIN z LEFT OUTER JOIN z JOIN Tr   ON r  )rt  rf  r  r  r)   rx   r*   r   ru   isouterr  onclause)r  rw   rS  r  r  	join_types         r   
visit_joinzSQLCompiler.visit_join  s
   $$!!dii556djj667 99+I\\+I I(DII((!{>D  ,djj++!{>D	  /dmm.."-17	
r   c                "   |j                   j                         D ci c]%  \  \  }}}|d| j                  j                  fv r||' }}}}|j                  |v r+| j                  ||j                  ||j                     d      }||fS c c}}}w )Nr  T)r  rg  r  r   r   r  )r  rH  
table_textr   r  r  dialect_hintss          r   _setup_crud_hintszSQLCompiler._setup_crud_hints  s     04{{/@/@/B
 
+ )3 1 122 9
 

 ::&33DJJdjj(A4J j((
s   *B
c                   | j                   j                  }|j                  }|j                  }|y|j                  r'| j
                  j                  |j                  d      }n&| j                  j                  |j                  d      }||z  r|S |j                  r3t        j                  d|d    d| j                   j                   d      y)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.

        Nr   zColumn 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_lookupr  default_characterization _sentinel_col_non_autoinc_lookupis_explicitr7   r-  r   )r  r   sentinel_optssentinel_characteristics	sent_colsbitmasks         r   _get_sentinel_column_for_tablez*SQLCompiler._get_sentinel_column_for_table  s     GG#(#I#I ,44	#..77;;(AA1G ;;??(AA1G 7"#// )))A, (><<$$% &@
@  r   c              #     @ABCDK    j                   }|J |j                  sd }	nt        j                  |j                   }	t	        |      }
|j
                  r j                  j                  sd}d}nE j                  j                  r&|r) j                  r|j                  |j                  rd}d}nd}d}|rNt        t        dt        ||            d      D ]*  \  }\  }}t        |||g|	r	 |	|      gng d||
||
       , y |r,t!        j"                   j$                  j&                  |      }nd }|j(                  }|r ||      }d| d}|j+                  |d      } j                  j,                  }|rAt	         j.                        }t	        |j0                        }||z
  }t3        |||z
  |z        }t        d	t5        |            }t        d	t5        |            }d }d}|
|z  |
|z  rdnd
z   }|j0                  }|J |r$|D cg c]  \  }}}}|| ||      |f }}}}}d
xCD j6                  s j8                  r j8                  Ani At;        |d
         } A fd@|j<                  rd}!nd}!ddj?                  @fd|D               |! d}"| jA                  Afd|D              }#| jC                  |#      D ci c]  }||d
   |    }$}dBnd}"t;               }#i }$|j<                  rd| dBnd| dBt;               }%|j0                  D ]  }&|%jE                  |&d           |%r] jF                  }'|'J t        |'      D ()ch c]  \  }(})|)|%v r|( }*}(})t3        |*      CtI        |*      dz   Dt	        |*      DCz
  k(  sJ  jJ                  r9tM        jN                   jP                        }+tM        jR                  |+ ddB      B|r[|d
| },|d
| }-g |d
| g |d
| |r|}.nt	        |,      }.r,fdtU        |.      D        D /01cg c]  \  }/}0}1|/|0|1f }}0}/}1 j6                  r|jV                  }2|2t	        |,d
         k(  rdx}3}4|,}5n|,d
   d C }3|,d
   Dd  }4CDfd|,D        }5|j<                  r'dj?                  Bfdt        |,      D              d d }6nB|.z  d d }6 jJ                  r9|2d
kD  r4|4rJ Cdz   }7|2|.z  |7z   }8tY         fdtU        |7|8      D              }9|6|9z  }6|j+                  d|6      }:tY        tZ        j\                  j_                  |5            };|3|;z   |4z   };ng }<|$ja                         };t        |,      D ]  \  }=}|"j+                  dtc        |=            }>|j<                  r|>j+                  dtc        |=            }>|<je                  |>       |;jE                  |#D ci c]  }| d|= ||    c}        |j+                  ddj?                  |<            }:t        |:|;||,|	r|-D ?cg c]
  }? |	|?       c}?ng |.|||d
       |dz  }|rZy y c c}}}}w c c}w c c})}(w c c}1}0}/w c c}w c c}?w w)NTFzKSequence[Tuple[_DBAPISingleExecuteParams, _MutableCoreSingleExecuteParams]]r   r  r  r  __EXECMANY_TOKEN__zList[Sequence[Any]]r   c                    | D ]G  }j                  ||      }|j                  j                  d|iz  j                  d| diz        }I |S )Nr   __EXECMANY_INDEX__)r  r  r-  )r  	formattedr+  r?  r  s      r   apply_placeholderszISQLCompiler._deliver_insertmanyvalues_batches.<locals>.apply_placeholders  sl     C,00c:C ) 1 1))VSM9))!cU*<#=>?!I ! r   z, _IMV_VALUES_COUNTERr  r   c              3  :   K   | ]  \  }}}} ||        y wr  r   )r*  r  rK  	bind_keysrL  s       r   r,  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  s(      6.Aq)Y #9i86r  c              3  Z   K   | ]"  \  }}}}|D ]  }j                  ||        $ y wr  r  )r*  r  rN  r+  r?  s       r   r,  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  sC      4&Aq!Y$4  #&&sC0404   (+z, _IMV_VALUES_COUNTER), z), r  z\d+r  c              3  H   K   | ]  }D ]  \  }}}| d | ||f   yw)r  Nr   )r*  ro  r+  len_r  generic_setinputsizess        r   r,  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  sF      /!.C/ +Cs  5%)45/5/rr  r   c              3  (   K   | ]	  }|   y wr  r   )r*  rl  expand_pos_lower_indexexpand_pos_upper_indexs     r   r,  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  s"      & 01GH&s   c              3  Z   K   | ]"  \  }}j                  d t        |             $ yw)_IMV_VALUES_COUNTERN)r  r   )r*  r  r  executemany_values_w_commas      r   r,  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>  s3        !%1 7>> 5s1v rP  c              3  >   K   | ]  }j                    |   y wr  )r/  )r*  r  r  s     r   r,  z@SQLCompiler._deliver_insertmanyvalues_batches.<locals>.<genexpr>4  s)      &  >>?sC&r  EXECMANY_INDEX__rX  __)3r;  rA  r/  r>  r  r6  r  supports_default_metavaluesupports_multivalues_insertr  r?  r=  r  r   r  rE  	functoolspartialr  r  r7  r  insertmanyvalues_max_parametersr)  r9  minr  rQ  r?  ro   rC  rw   r  r  rf  r%  r1  r4  rL  rM  r/  r  ranger;  r.  r  r  from_iterablerF  r   r  )Er  r   r!  compiled_parametersrS  
batch_sizer<  r  imv_sentinel_from_params	lenparamsuse_row_at_a_time
downgradedrM  paramcompiled_paramrstimv_single_values_exprexecutemany_values
max_paramstotal_num_of_paramsnum_params_per_batchnum_params_outside_of_batchbatchescompiled_batchesrI  rN  r9  r  r+  r  stall_keysimv_values_counterformatted_values_clausekeys_to_replacebase_parametersall_names_we_will_expandr  r%  r?  r   all_expand_positionsescapedrJ  compiled_batchrL  new_keyrR  r  num_ins_paramsextra_params_leftextra_params_rightbatch_iteratorexpanded_values_stringr}  ri   r  rF  rG  replaced_values_clausesr  fmvrM  rL  r?  rY  rU  rV  sE   `   `                                                           @@@@@r   !_deliver_insertmanyvalues_batchesz-SQLCompiler._deliver_insertmanyvalues_batches  s      $$&&$(!$,$7$7((%! 
O	t||'N'N !%J99#$$%%-1N1N
 !%J %J5>a
$78 6 115. -)G 1 /~>?+ . ##77%9C
 C!$!7!7%()?%@" !7 8:%%&8:NO	 \\AA
"%doo"6#&s'='=#> #&:: ( "==+,J ,d:.>?!4(;#<
 HL!Z/Z'AQ
 !33!--- +=" "&CdB c3t9b)" " ;<;!7&&%)%<%<"%'":a=)H! ''%<"%'"*+DII 62D6 - , ""!''#
 '33 4*<4 O $..? Z]3''O  *,&&(#!eO O''.//GH + 011G0H-L*14$.. 9(//Q89 (".."... &/{%;(!T77 ($ (
 *--A)B&),-A)BQ)F&,--0FFGG ""))D$G$GH-/VVy$d,F.* Aj)E-a
;N$&GAj!-/Qz*%/"%(Z"$/%*+=%>/+ +*s dC(+' + !$!B!B "Sq]2=??%(:%*N(-a1H2H(I%).q2H2I)J&&!&&N
 ++   )2%(8	   r.* 46HHr.* &&>A+=  2112Q6E(,>?%GC !& &!&uc!2& !I .Di-O*%.%6%6(*@&" ',OO11.A'#
 &)*() $ +-'&5&:&:&<# )% 0 
HAu199*CFC //!kk*?QH+2237'..>MNsC51#c
2N
 &/%6%6(II56&"
 )"#' - :HH2*2.H"'   MHI o"P:(D+x O IsX   HY%Y
1B"Y%Y	#A;Y%Y.B5Y%#Y3FY%Y
9Y%Y &Y%?&Y%c                     |j                   | fi |}|j                  }|||d<   d}n j                   }|r-d _         j                  s| _         j
                  s| _         j                  j                  t               t               |d       d}d } j                  r|g }t        j                   |||fd|i|} j                  rB|@t        |      } j                  r) j                   xj                  |z  c_        n| _        |j                  }	|	sn j                  j                   sX j                  j"                  sB j                  j$                  s,t'        j(                  d j                  j*                  z        |j,                  r j                  j.                  s,t'        j(                  d j                  j*                  z         j0                  s|j2                  r!|j4                  rt'        j(                  d	      |j                  }	n|j                  }	 j6                  }
 j                  j                   }d
}|j8                  r!|  j:                  ||j8                  fi |z  }|dz  }|
j=                  |j>                        }|j@                  r jC                  ||      \  }}|jD                  r jG                  ||       ||z  }|	s|s,|ddjI                  |	D cg c]	  \  }}}}| c}}      z  z  }|jJ                  }d }d }d} j0                  xs |j2                  }|r|jL                  }||sJ |	D ci c]
  \  }}}}|| }}}}g }|D ]7  }||vrd } n/ jO                  |      }|||   vrd } n|j                  |       9 |@ j                  jP                  tR        jT                  z  rd}n|d   jV                  rJ d       tY        |      tY        |      z   } j[                  |||      } j\                  r|d|z   z  }nd }|j^                    j`                   j                  d   d   fddi|} jb                  rL j                  jd                  r6|st         j                        nd }|d jg                  |d      |z  }n|d|z  z  }n|	sf|rd|dz  }|rti        d j                  jj                  tm        d|	      ||j4                  |jn                  d u||rt        |      nd|	       _8        n}|j,                  r*|ddjI                  d |jr                  D              z  }nGdjI                  tm        d|	      D cg c]	  \  }}}}| c}}      }|r|r j                  jP                  tR        jt                  z  r|jv                  sd} j                  jP                  tR        jx                  z  } djI                  d t{        |	      D              }!| r$djI                   fdt{        |	      D              }"n|!}"|d|" d| d|! d z  }nd}|d!| d"z  }ti        d|tm        d|	      ||j4                  |jn                  d u||rt        |      nd|||#       _8        n	|d!| d"z  }|jn                  '  j`                  |jn                  fi |}#|#r|d|#z   z  }|r j\                  s|d|z   z  } jb                  rE j                  jd                  s/|st         j                        nd } jg                  |d      |z   } j                  j}                  d       |S c c}}w c c}}}w c c}}w )$NrM  FTr  r   rA  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().zINSERT zINTO  (%s)r   zTsentinel selection rules should have prevented us from getting here for this dialectr  r  r{  r  r  rH  r  z DEFAULT VALUESr8  )r<  r=  r?  r@  rB  z VALUES c              3  R   K   | ]  }d dj                  d |D              z   ! yw)r  r   c              3  *   K   | ]  \  }}}}|  y wr  r   )r*  r  r  s      r   r,  z5SQLCompiler.visit_insert.<locals>.<genexpr>.<genexpr>g  s      L>1a Ls   Nr  )r*  crud_param_sets     r   r,  z+SQLCompiler.visit_insert.<locals>.<genexpr>e  s2       ' yy L^ LLNs   %'c              3  ,   K   | ]  \  }}d |   ywpNr   )r*  r  r  s      r   r,  z+SQLCompiler.visit_insert.<locals>.<genexpr>  s      )$(Aq!A3)s   c              3     K   | ]L  \  }^}}j                  |j                  |j                  j                  j                        d |        N ywr  )r  r   r  r  )r*  r  r  r  r  s       r   r,  z+SQLCompiler.visit_insert.<locals>.<genexpr>  sT      4 !-9C! !11 # # @ @ N"#A34s   AAz SELECT z FROM (VALUES (z)) AS imp_sen(z#, sen_counter) ORDER BY sen_counterz	 VALUES (r  )r6  r7  r9  r;  r<  r=  r?  r@  rA  rB  rC  )?rJ  r   r  r   r  r  r  ro   rQ  r   _get_crud_paramsr  r4  rA  single_paramsr  supports_default_valuesr^  supports_empty_insertr7   r  r   _has_multi_parametersr_  r&  
_returning_sort_by_parameter_orderr  r]  r\  format_tabler   r  r8  r  r  rw   use_insertmanyvaluesuse_sentinel_columnsr  r:  rR  r[  _insert_sentinelr  r  r*  r   r  rD  cte_follows_insertr  r5  default_metavalue_tokenr   _post_values_clauser;  all_multi_paramsr]  is_default_metavalue_onlyr^  r  rv  )$r  insert_stmtrA  rM  r  r  r  counted_bindparamcrud_params_structcrud_params_singler  r  r  r6  r  r  r  named_sentinel_paramsadd_sentinel_colsrB  r  r  param_names_params_by_col_add_sentinel_col
param_namer  select_textr  r  rs  embed_sentinel_valuerender_bind_castscolnamescolnames_w_castpost_values_clauses$   `                                   r   visit_insertzSQLCompiler.visit_inserto  s~    ;::
!#
 $--#!-B~H::~H DM)))6&%%%2"

#&5 #)	
  ! ??|3
 !#!22	

 0
 
 ??0< #$5 6""))5**.??*->D*/== #LL88LL;;LL66""!\\../  ..<<;;&&137<<3D3DE  '';+A+A66&&I  "4!A!A!3!A!A=="&,,"F"F  +D++[2268 D 	**;+<+<=
 22;
KMAz((++K<
%<Gdii+=>-!T1a>  D  2FF9= !00JK4J4J 2 G G ,+++ 3E" ".Q; $" " )+%): 
=%(>04-!%!C!C)"J "8I)JJ04-)00<
= )0 GG6HHI -1) $5Q#7#H#H DH "&n!5=N8O!O#44$,  5   --...  $)&$,,

234BFJLK yyT\\<<7?DJJT++&304 ,     ++#(?%%D#):LL889;M &#<< $77tC%62C-.&7#*&& 00		  +=*M*M  D )-		 +/9*+&1eQ )% $%GG6MMN
 0II ,0( GG6NNO &
  $yy ),56H,I)  H ) +/)) 4 1::L0M4 + +3"?"3 4$$=#> ?&&.Z 0//D ,1(i(A'B!DDD):$)'@'+9*( 3D#<< $77tC%62C-.(=&7)=)*&0 )$=#>a@@**6!-//"35" "000D$B$BC***D99T\\<<3;C

OM''"/,0 (  	  	

rs ?0"^s   ;]]%;],
c                     y)z3Provide a hook for MySQL to add LIMIT to the UPDATENr   )r  update_stmts     r   update_limit_clausezSQLCompiler.update_limit_clause      r   c                     y)z3Provide a hook for MySQL to add LIMIT to the DELETENr   )r  delete_stmts     r   delete_limit_clausezSQLCompiler.delete_limit_clause  r  r   c                6    d|d<    |j                   | fddi|S )z|Provide a hook to override the initial table clause
        in an UPDATE statement.

        MySQL overrides this.

        TrS  r  r  )r  r  
from_tableextra_fromsr  s        r   update_tables_clausez SQLCompiler.update_tables_clause  s*     8,z,,TE$E"EEr   c                    t        d      )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  r  r  r  r  
from_hintsr  s         r   update_from_clausezSQLCompiler.update_from_clause  s     "%
 	
r   c                |    |j                   || fi |}|j                  }|||d<   d}n| j                   }|r-d| _        | j                  s|| _        | j
                  s|| _        | j                  t        z  r1t        i t                     }| j                  t        z  }|r|| _        nd }d}|j                  }t        |      }	|	rDt        t        |j                              }
|D cg c]	  }||
vs| }}|
j!                  |      }ng }|j                  h}| j                  j#                  |||d       d}|j$                  r!| | j&                  ||j$                  fi |z  } | j(                  ||j                  |fd|i|}t+        j,                  | |||fi |}|j.                  }|j0                  r| j3                  ||      \  }}nd }|j4                  r| j7                  ||       ||z  }|dz  }|dj9                  d	 t;        d
|      D              z  }| j<                  s|j>                  r>| j@                  r2|d| jC                  || j<                  xs |j>                  |      z   z  }|r, | jD                  ||j                  ||fd|i|}|r|d|z   z  }|jF                  r) | jH                  |jF                  fd|i|}|r|d|z   z  }| jK                  |      }|r|d|z   z  }| j<                  s|j>                  r>| j@                  s2|d| jC                  || j<                  xs |j>                  |      z   z  }| jL                  r.|stO        | j                        nd }| jQ                  |      |z   }|r|J |jS                  d       | j                  jU                  d       |S c c}w )NrM  FTr  zUPDATE r  z SET r   c              3  6   K   | ]  \  }}}}|d z   |z     yw)=Nr   )r*  r  r  r  s       r   r,  z+SQLCompiler.visit_update.<locals>.<genexpr>S  s)      
!4 3J
s   zList[Tuple[Any, str, str, Any]]r  r   WHERE r  UPDATEr  r{  )+rJ  r   r  r!  r  r  rW  rg  rk  ro   rh  r  _extra_fromsr  r*   r   r   r  r]  r\  r  r   r  r  r  r8  r  r  rw   r   r&  r  r*  r  r  r  r  r  rD  r  r  r  rv  )r  r  rM  r  r  r  r  r  r  is_multitable
main_fromsr  render_extra_fromsr  r  r6  r  crud_paramsr7  extra_from_textr  rY  r  s                          r   visit_updatezSQLCompiler.visit_update  sM   :::
!#
 $--#!-B~H::~H DM)))6&%%%2"<<44$R/K<<,6L#. K L#00[)];+<+<=>J&"!:*=" " )..{;O!#*001O

#2 /)	
   +D++[2268 D /T..
 $	

 

 "22+}h
:<
 )66(,(>(>Z)%M: !M((++K<
		 
%)1;&
 
 	
 ""k&<&<--d33++E{/E/E(0 4    5d55!!"	
 ( O o--&&111++9DHJA 	A%//<C,&&D ##{'='=00C$//''A;+A+A$, 0   D 993;C

OM***G$ND***x0

rS"s   *	N94N9c                    t        d      )zProvide a hook to override the generation of an
        DELETE..FROM clause.

        This can be used to implement DELETE..USING for example.

        MySQL and MSSQL override this.

        zCThis backend does not support multiple-table criteria within DELETEr  r  s         r   delete_extra_from_clausez$SQLCompiler.delete_extra_from_clause  s     "%
 	
r   c                .     |j                   | fddd|S )NT)rS  r  r  )r  r  r  r  r  s        r   delete_table_clausezSQLCompiler.delete_table_clause  s,    ,z,,
d
.0
 	
r   c                    |j                   || fi |}|j                  }|||d<   d}n| j                   }|r-d| _        | j                  s|| _        | j
                  s|| _        | j                  t        z  r1t        i t                     }| j                  t        z  }|r|| _        nd }d}|j                  }|j                  hj                  |      }	| j                  j                  |	|	|d       d}
|j                   r!|
 | j"                  ||j                   fi |z  }
|
dz  }
	 | j%                  ||j                  ||      }t+        j,                  | |||fi | |j.                  r| j1                  ||      \  }}nd }|j2                  r| j5                  ||       |
|z  }
| j6                  s|j8                  r>| j:                  r2|
d| j=                  || j6                  xs |j8                  |	      z   z  }
|r, | j>                  ||j                  ||fd
|i|}|r|
d|z   z  }
|j@                  r) | jB                  |j@                  fd
|i|}|r|
d|z   z  }
| jE                  |      }|r|
d|z   z  }
| j6                  s|j8                  r>| j:                  s2|
d| j=                  || j6                  xs |j8                  |	      z   z  }
| jF                  r.|stI        | j                        nd }| jK                  |      |
z   }
|r|J |jM                  d       | j                  jO                  d       |
S # t&        $ r@ | j%                  ||j                  |      }|r| j)                  |j                  |      }Y Aw xY w)NrM  FTr  zDELETE FROM )r  r  r  r  r  r  DELETEr  r{  )(rJ  r   r  r  r  r  rW  rg  rk  ro   rh  r  r  r   r   r  r]  r\  r  	TypeErrorr  r   r  r  r8  r  r  r&  r  r*  r  r  r  r  r  rD  r  r  r  rv  )r  r  rM  r  r  r  r  r  r  r  r  r6  r  r7  r  r  rY  r  s                     r   visit_deletezSQLCompiler.visit_delete  s   :::
!#
 $--#!-B~H::~H DM)))6&%%%2"<<44$R/K<<,6L#. K L#00&,,-33K@

#2 /)	
   +D++[2268 D 		M11!!'	 2 J 	dKOBO(,(>(>Z)%M: !M((++K<
 ##{'='=,,C$//''A;+A+A$, 0   D ;d;;!!	
 ( O o--&&111++9DHJA 	A%//<C,&&D ##{'='=00C$//''A;+A+A$, 0   D 993;C

OM***G$ND***x0

rU  	M 11[..J LL!2!2LL	Ms   +M ANNc                >    d| j                   j                  |      z  S )NzSAVEPOINT %sr  format_savepointr  savepoint_stmtr  s      r   visit_savepointzSQLCompiler.visit_savepoint&  s     > >~ NNNr   c                >    d| j                   j                  |      z  S )NzROLLBACK TO SAVEPOINT %sr  r  s      r   visit_rollback_to_savepointz'SQLCompiler.visit_rollback_to_savepoint)  s#    )DMM,J,J-
 
 	
r   c                >    d| j                   j                  |      z  S )NzRELEASE SAVEPOINT %sr  r  s      r   visit_release_savepointz#SQLCompiler.visit_release_savepoint.  s#    %(F(F)
 
 	
r   )r  r\   r   r  r  r  rU  r$  rV  r  rW  re  rk  zOptional[SQLCompiler]r  r   )r  r7  )r  r%  )r  zDict[Any, Any])r  zMutableMapping[CTE, str])r  zVMutableMapping[str, Union[_BindProcessorType[Any], Sequence[_BindProcessorType[Any]]]])NT)r  r  r  r  r  r  )NNTNTF)r  r  r  r  r  r  r  zOptional[int]r  r  rS  r  r  r[   F)r!  r[   rT  r  r  r  )r  zCallable[[Any], str])NFFNr   )NTr   N)r   ColumnClause[Any]rv  Optional[_ResultMapAppender]r  r  rw  r   r  z Optional[_AmbiguousTableNameMap]r  r   r  r   r  )NF)r$  zFunction[Any]rv  r  r  r   r  r   )FNNr   )NFNN)FFFFF)r3  r   r   rD   r  r   )r   r   r  r   )FFNNNN)r   r   r  r  r  r  r?  r7  r  zOptional[TypeEngine[Any]]r@  zOptional[Set[str]]rA  r9  r  r   r  r   )rJ  rM   rS  r  ra  r  rb  zOptional[_FromHintsType]rM  zOptional[CTE]r  zOptional[FromLinter]rE  zselectable._CTEOptsr  r   r  r7  )FFFNFFNN)
r   r   r   r   r   r   r  r   r  r  )NNNTFFT)FFNNNFN)r   r  r  zTuple[str, _FromHintsType]
rH  rB   r  zSequence[ColumnElement[Any]]r  r  r  r   r  r   )NFF)FFFNTNN)r   rJ   r  r>  )r   r   r!  rW   rf  z%List[_MutableCoreSingleExecuteParams]rS  rH  rg  r:  r<  r  r  r  r  z Iterator[_InsertManyValuesBatch]rm  )r   r   r   r   EXTRACT_MAPr)  r&   r  r  r   r  COMPOUND_KEYWORDSrK  r  r   r!  r#  r$  r&  r'  r*  r+  r,  r0  r1  r2  r3  r4  r5  r6  r8  r:  r;  r<  	frozensetr=  r>  r  r?  r  postfetch_lastrowidr@  r%  rA  rB  rC  rL  rN  r  r  patternr  r  r  rJ  rf  r  r3  rs  ro_memoized_propertyrw  ry  r~  r  memoized_propertyr  memoized_instancemethodr  
contextlibcontextmanagerr  ri  rh  r  r  r  r  r  r  r  rj  preload_moduler  r  r6  rA  rC  rN  rT  rW  rh  rn  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r'  r,  r2  r.  r@  r=  r:  rU  rQ  r  rd  rl  ro  rt  rw  r|  r  r  r  r  r  rz  r  r  r  r  r  r~  rb  rc  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$   _CTEOptsrX  r|  r~  r{  r  rz  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  rN  rO  r  r  rY  rX  r.  r4  r8  r,   
CLIENTSIDErR  r\  SENTINEL_DEFAULTNONErY  rZ  r?  r   rX  r=  rE  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r  r  	  s    K 			
  ; : /.66F)HdHdHd
 +*% .0O*/ .0O*/$ BF>E K((I--6 %$4 ',t+ 5:+T9
 "OT! B!! %('
 .-
 &+d* "OT! "d! ).- !ND  !&% =A "9@ +/-.
 6:295929=A:A<EK9G
 :C6D
 8<4F
   % 	    (,K$+ .2*1.2+2FD
,, 32 GF&BJJ'LM"

#45$"**$$
%Q'<'D'D&EF # # C C )-/3 %%59PP +P &	P
 -P P P 3P Pd = =$ 
 0 ( (  M  MD G G 
  
!! ".  .9vGR 



 
8#  
 6:!
2
 
 
	
2 6:GK!'+ %~2~ E~ 	~
 %~ ~ ~ 
)~@ 
!!$ "$L 
3 
3  %C3C C 
	CJ T34
 5
 43	  
T34P 5 Pd 
T34, 5 ,\>@OO .3-
` .3+` !#"/b

/ ;?".0EI9O!9O 89O 	9O
 ,9O #C9O 9O 
9OvA



4 052h
"@L&&K
(
T
:


7 ;?,, 8, 	,
 
,\8
C 04?B3- AC$L6"BB


4$
 ;?H*TM1d  6p8



 05*GG 
I IJAEBFAEBFAEBF

	
AE




 $" cJ$ $!%	DB#J&6	*$ #&*484815AA A 	A
 $A 2A  2A /A A 
AFC .2&*,0(;
(;(;E(BII I 	I
 ,I $I *I &I I 
IV30 bH0?"$L9(

 
 !	

 
 

4 EI
8  "  %bJH$ .-1t11-	/LM 

 ,1: '+* KZ
!!
!	#
!2h]~  %3j7 	
11 51
 "1 1 
1@ +0'X !%.`
<
)" (:t'9'9,77,>>,==,>>,11,>>,55,55,55,55	
($& $D#I#I,11,::	
$ <<	(<|YY -Y C	Y
  CY Y "&Y ?Y 
*Yx
 AEpdF
KZ
 

AFO


r   r  c                       e Zd ZdZd Z ej                  d       fd       Zd Zd Z	d Z
d Z	 	 	 	 	 	 	 	 	 	 dd	Zd
 Zd Zd Zd Zd Zd Zd Zd Z xZS )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`

    c                     y)Nz<name unknown>r   r~  s     r   r  z$StrSQLCompiler._fallback_column_nameH  s    r   zsqlalchemy.engine.urlc                T   |j                   dk7  rt        j                  j                  } |j                  j                  |j                         j                                }|j                  |d |       }t        |t              s |j                  |fi |S t        | 1  ||      S )Nr   )rk  )stringify_dialectr&   r  
engine_urlURLr   get_dialectstatement_compilerr  r  r  r  r  )r  r  r  r  urlr  compilerr  s          r   r  z,StrSQLCompiler.visit_unsupported_compilationK  s    $$	1..++CMcggnnW%>%>?KKMOG114 2 H h7'x''6266w4WcBBr   c                ~     | j                   |j                  fi |d | j                   |j                  fi |dS )Nr  r  )r  rx   r   rk  s       r   visit_getitem_binaryz#StrSQLCompiler.visit_getitem_binaryY  s:    DLL++DLL,,
 	
r   c                *     | j                   ||fi |S r  r  rk  s       r   visit_json_getitem_op_binaryz+StrSQLCompiler.visit_json_getitem_op_binary_      (t((@R@@r   c                *     | j                   ||fi |S r  r  rk  s       r   !visit_json_path_getitem_op_binaryz0StrSQLCompiler.visit_json_path_getitem_op_binaryb  r	  r   c                @    d| j                   j                  |       dS )Nz<next sequence value: >)r  format_sequencerC  s      r   r=  zStrSQLCompiler.visit_sequencee  s#    $T]]%B%B8%L$MQO	
r   c          
         t        j                  |      D cg c]  }| j                  d |ddi        }}ddj                  |      z   S c c}w )NTFr  r   )r   r  r  rw   )r  rH  r  r  r  rv  r  s          r   r  zStrSQLCompiler.returning_clausej  sZ     ++N;
 %%dAtUB?
 
 dii000	
s   A
c                P     dd<   ddj                   fd|D              z   S )NTrS  r  r   c              3  H   K   | ]  } |j                   fd i  ywrb  Nr  r*  r  r  r  r  s     r   r,  z4StrSQLCompiler.update_from_clause.<locals>.<genexpr>|  s0      #
 !A  BBrB#
rr  r  r  s   `   ``r   r  z!StrSQLCompiler.update_from_clausex  s3     8 #
 #
 
 
 	
r   c                P     dd<   ddj                   fd|D              z   S )NTrS  r   c              3  H   K   | ]  } |j                   fd i  ywr  r  r  s     r   r,  z:StrSQLCompiler.delete_extra_from_clause.<locals>.<genexpr>  s0       
 !A  BBrB 
rr  r  r  s   `   ``r   r  z'StrSQLCompiler.delete_extra_from_clause  s3     8dii  
  
 
 
 	
r   c                     y)NzSELECT 1 WHERE 1!=1r   r  s      r   r  z#StrSQLCompiler.visit_empty_set_expr  s    $r   c                    d|z  S )Nz[%s]r   r  s      r   r  z!StrSQLCompiler.get_from_hint_text  s    }r   c                *     | j                   |dfi |S )Nz
 <regexp> r~  rk  s       r   r  z+StrSQLCompiler.visit_regexp_match_op_binary  s    ,t,,V\HRHHr   c                *     | j                   |dfi |S )Nz <not regexp> r  rk  s       r   r  z/StrSQLCompiler.visit_not_regexp_match_op_binary  s    ,t,,V5ELLLr   c                    d |j                   j                  | fi |d |j                  j                  | fi |dS )Nz<regexp replace>(r   r  )rx   r  r   rk  s       r   r	  z-StrSQLCompiler.visit_regexp_replace_op_binary  s>    *FKK**4626+FLL++D7B7
 	
r   c                    d |j                   j                  | fi |d |j                  j                  | fi |dS )Nz	TRY_CAST(r   r  )r  r  r  )r  r   r  s      r   visit_try_castzStrSQLCompiler.visit_try_cast  s>    *DKK**4:6:.DOO..t>v>
 	
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  s   @r   r  r  4  s    &  T01C 2C
AA

11 51
 "1 1 
1

%IM

r   r  c                     e Zd ZdZer	 	 	 d0	 	 	 	 	 	 	 	 	 d1dZej                  d        Zej                  d        Z		 	 	 d2	 	 	 	 	 	 	 d3dZ
d Zd Zd	 Zd
 Zd4dZ	 d5dZd Zd Zd Z	 d6dZd Zd4dZd Zd Zd Zd Zd Zd Zd Zd Zd5dZd Z d Z!d Z"d Z#d  Z$d! Z%d" Z&d# Z'd$ Z(d% Z)d& Z*d' Z+d( Z,d) Z-d* Z.d+ Z/d, Z0d- Z1d. Z2d/ Z3y)7DDLCompilerTc                     y r  r   r  s         r   r  zDDLCompiler.__init__  s     r   c                f    | j                   j                  | j                   d | j                        S )NrG  )r  r  r  r/  s    r   r  zDDLCompiler.sql_compiler  s/    ||..LL$T5N5N / 
 	
r   c                .    | j                   j                  S r  )r  r  r/  s    r   type_compilerzDDLCompiler.type_compiler  s    ||222r   Nc                     y r  r   r  s       r   r  zDDLCompiler.construct_params  s     r   c                   |j                   }t        |j                  t        j                        r|j                         }| j                  }|j                  |j                        }t        |      dk(  r|d   d}}n
|d   |d   }}|j                  d|       |j                  d|       |j                  d|j                  |j                               | j                  j                  |j                  |z        S )Nr   r   r  r{  r   r#   r+  )contextr  targetr#   rJ   rF  r  format_table_seqr  r  r  r  r  r   )r  ddlr  r&  r  pathr   schs           r   	visit_ddlzDDLCompiler.visit_ddl  s    ++cjj&,,/llnG}}H,,SZZ8D4yA~!!Wbs!"XtAwsw.x-z8+@+@+LM  223==73JKKr   c                x    d}|j                   r|dz  }|| j                  j                  |j                        z   S )NzCREATE SCHEMA IF NOT EXISTS )if_not_existsr  format_schemar  )r  r   r  r  s       r   visit_create_schemazDDLCompiler.visit_create_schema  s9    $$Ddmm11&..AAAr   c                    d}|j                   r|dz  }|| j                  j                  |j                        z  }|j                  r|dz  }|S )NzDROP SCHEMA 
IF EXISTS  CASCADE)	if_existsr  r0  r  cascader  dropr  r  s       r   visit_drop_schemazDDLCompiler.visit_drop_schema  sK    >>L D++DLL99<<JDr   c                ,   |j                   }| j                  }d}|j                  r!|dj                  |j                        dz   z  }|dz  }|j                  r|dz  }||j                  |      dz   z  }| j                  |      }|r||dz   z  }|dz  }d}d}|j                  D ]P  }	|	j                   }
	 | j                  |	|
j                  xr |       }|||z  }d	}|d
|z   z  }|
j                  rd}R | j                  ||j                         }|r||d
z   |z   z  }|d| j#                  |      z  z  }|S # t        j                  $ rE}t        j                  d|j                  d|
j                  d|j                  d         |d }~ww xY w)Nz
CREATE r  zTABLE r.  r  
Ffirst_pkr  	Tz(in table 'z', column 'z'): r   ) _include_foreign_key_constraintsz
)%s

)r  r  r]  rw   r/  r  create_table_suffixr  r  r.  r7   r  descriptionr   argscreate_table_constraintsinclude_foreign_key_constraintspost_create_table)r  r   r  r   r  r  r@  r  r=  create_columnr   	processedceconsts                 r   visit_create_tablezDDLCompiler.visit_create_table  s   ==??CHHU__-33D$$D%%e,s22"66u='#--D	 #^^ 	M"**F LL!F,>,>,Ox< ) 	 (I%D &ID9,,D%%#H	$ ---3-S-S . 
 I$u,,Dd44U;;; ## &&((&++rwwqzC s   5AD;;FA FFc                     |j                   }|j                  ry  j                  ||      }dj                   fd|j                  D              }|r|d|z   z  }|S )Nr<  r  c              3  @   K   | ]  }j                  |        y wr  )r  r*  r   r  s     r   r,  z2DDLCompiler.visit_create_column.<locals>.<genexpr>   s      
)3DLL$
s   )r  systemget_column_specificationrw   constraints)r  r   r=  r  r   r  rI  s   `      r   visit_create_columnzDDLCompiler.visit_create_column  sd    ==,,Vh,G 
7=7I7I
 
 C%KDr   c                l    g }|j                   r|j                  |j                          |j                  }||j                  |      }n
t	               }|j                  |j                  D cg c]  }||j                   ur||vr| c}       dj                  d  fd|D        D              S c c}w )Nz, 
	c              3  $   K   | ]  }|| 
 y wr  r   )r*  r  s     r   r,  z7DDLCompiler.create_table_constraints.<locals>.<genexpr>?  s      
 } 
r  c              3     K   | ]I  }|j                        r6j                  j                  rt        |d d      sj	                  |       K yw)	use_alterFN)_should_create_for_compilerr  supports_alterr4  r  rM  s     r   r,  z7DDLCompiler.create_table_constraints.<locals>.<genexpr>A  sI      ::4@33":{EB Z(r  )r.  r  foreign_key_constraintsr  ro   r   _sorted_constraintsrw   )r  r   r?  r  rP  all_fkcs	omit_fkcsrv  s   `       r   rC  z$DDLCompiler.create_table_constraints(  s    
 u00100+7 ++,LMII 22E---!92D 	
 }} 
"-
 
 	
s   .B1c                x    d}|j                   r|dz  }|| j                  j                  |j                        z   S )Nz
DROP TABLE r3  )r5  r  r  r  r7  s       r   visit_drop_tablezDDLCompiler.visit_drop_tableM  s6    >>L Ddmm00>>>r   c                R    d| j                   j                  |j                        z   S )Nz
DROP VIEW r  r  r  r  r8  r  s      r   visit_drop_viewzDDLCompiler.visit_drop_viewS  s      : :4<< HHHr   c                `    |j                   "t        j                  d|j                  z        y )Nz,Index '%s' is not associated with any table.)r   r7   r  r   r  ro  s     r   _verify_index_tablezDDLCompiler._verify_index_tableV  s0    ;;"">K  r   c           	         |j                   } j                  |        j                  }d}|j                  r|dz  }|j                  t        j                  d      |dz  }|j                  r|dz  }| j                  ||      d|j                  |j                  |      d	d
j                   fd|j                  D              dz  }|S )NzCREATE UNIQUE z0CREATE INDEX requires that the index have a namezINDEX r.  include_schemar0  r,  r  r   c              3  Z   K   | ]"  }j                   j                  |d d       $ yw)FTr  r  N)r  r  )r*  r  r  s     r   r,  z1DDLCompiler.visit_create_index.<locals>.<genexpr>s  s8        !!))T * rP  r  )r  rd  r  r   r   r7   r  r/  _prepared_index_namer  r   rw   expressions)r  r   rh  include_table_schemar  ro  r  r  s   `       r   visit_create_indexzDDLCompiler.visit_create_index\  s       '==<<ID::""B  	$$D%%eN%K!!(< "  II  "--	 
 	
 r   c                    |j                   }|j                  t        j                  d      d}|j                  r|dz  }|| j                  |d      z   S )Nz.DROP INDEX requires that the index have a namez
DROP INDEX r3  Trg  )r  r   r7   r  r5  rl  )r  r8  r  ro  r  s        r   visit_drop_indexzDDLCompiler.visit_drop_index|  s^    ::""@  >>L Dd//d/KKKr   c                    |j                   &| j                  j                  |j                         }nd }|r|r| j                  j                  |      }nd }| j                  j	                  |      }|r|dz   |z   }|S Nr  )r   r  r  r  format_index)r  ro  rh  r  schema_name
index_names         r   rl  z DDLCompiler._prepared_index_name  sw    ;;"#}}>>u{{K#.--445EFKK]]//6
$s*Z7Jr   c                    d| j                   j                  |j                  j                        d| j	                  |j                        S )NALTER TABLE z ADD )r  r  r  r   r  r  r   r  s      r   visit_add_constraintz DDLCompiler.visit_add_constraint  s8    MM&&v~~';';<LL(
 	
r   c                    d| j                   j                  |j                        d| j                  j	                  |j                  j
                  t        j                               S )NzCOMMENT ON TABLE r   )r  r  r  r  r  commentr%   Stringry  s      r   visit_set_table_commentz#DDLCompiler.visit_set_table_comment  sL    MM&&v~~622&&(9
 	
r   c                R    d| j                   j                  |j                        z  S )NzCOMMENT ON TABLE %s IS NULLr_  r`  s      r   visit_drop_table_commentz$DDLCompiler.visit_drop_table_comment  s'    ,t}}/I/ILL0
 
 	
r   c                    d| j                   j                  |j                  dd      d| j                  j	                  |j                  j
                  t        j                               S )NzCOMMENT ON COLUMN T)	use_tabler,  r   )r  format_columnr  r  r  r|  r%   r}  ry  s      r   visit_set_column_commentz$DDLCompiler.visit_set_column_comment  sZ    MM''$4 (  22&&(9	
 	
r   c                V    d| j                   j                  |j                  d      z  S )NzCOMMENT ON COLUMN %s IS NULLT)r  )r  r  r  r`  s      r   visit_drop_column_commentz%DDLCompiler.visit_drop_column_comment  s/    -0K0KLLD 1L 1
 
 	
r   c                @    t        j                  | t        |            r  r  ry  s      r   visit_set_constraint_commentz(DDLCompiler.visit_set_constraint_comment  s    --dDLAAr   c                @    t        j                  | t        |            r  r  r`  s      r   visit_drop_constraint_commentz)DDLCompiler.visit_drop_constraint_comment  s    --dDJ??r   c                   g }|j                   |j                  d|j                   z         |j                  |j                  d|j                  z         |j                  |j                  d|j                  z         |j                  |j                  d|j                  z         |j
                  |j                  d       |j                  |j                  d       |j                  |j                  d|j                  z         |j                  |j                  |j                  rdnd	       d
j                  |      S )NzINCREMENT BY %dzSTART WITH %dzMINVALUE %dzMAXVALUE %dzNO MINVALUEzNO MAXVALUEzCACHE %dCYCLEzNO CYCLEr  )
	incrementr  r}  minvaluemaxvalue
nominvalue
nomaxvaluecachecyclerw   )r  identity_optionsr  s      r   get_identity_optionsz DDLCompiler.get_identity_options  s   %%1KK),<,F,FFG!!-KK*:*@*@@A$$0KK(8(A(AAB$$0KK(8(A(AAB&&2KK&&&2KK&!!-KK
%5%;%;;<!!-KK#3#9#9zJxx~r   c                    d}|j                   r|dz  }|| j                  j                  |j                        z  }|r||z  }| j	                  |j                        }|r|d|z   z  }|S )NzCREATE SEQUENCE r.  r  )r/  r  r  r  r  )r  r   r   r  r  optionss         r   visit_create_sequencez!DDLCompiler.visit_create_sequence  sn    !$$D--fnn==FND++FNN;C'M!Dr   c                x    d}|j                   r|dz  }|| j                  j                  |j                        z   S )NzDROP SEQUENCE r3  )r5  r  r  r  r7  s       r   visit_drop_sequencezDDLCompiler.visit_drop_sequence  s6    >>L Ddmm33DLLAAAr   c                d   |j                   }|j                  | j                  j                  |      }nd }|"t	        j
                  d|j                   z        d| j                  j                  |j                   j                        d|j                  rdnd||j                  rdS dS )Nz<Can't emit DROP CONSTRAINT for constraint %r; it has no namerx  z DROP CONSTRAINT r3  r  r4  )
r  r   r  format_constraintr7   r  r  r   r5  r6  )r  r8  r  r   formatted_names        r   visit_drop_constraintz!DDLCompiler.visit_drop_constraint  s    \\
??&!]]<<ZHN!N!""!#'<<0  " MM&&t||'9'9: NNL2,,J.	
 	
 -/.	
 	
r   c                "   | j                   j                  |      dz   | j                  j                  j	                  |j
                  |      z   }| j                  |      }||d|z   z  }|j                  !|d| j	                  |j                        z   z  }|j                  7| j                  j                  r!|d| j	                  |j                        z   z  }|j                  s'|j                  r| j                  j                  s|dz  }|S )Nr  )r  z	 DEFAULT z	 NOT NULL)r  r  r  r  r  r   get_column_default_stringcomputedidentitysupports_identity_columnsnullable)r  r   r  colspecr   s        r   rO  z$DDLCompiler.get_column_specification  s    MM''/ll1199V :  	 008{W,,G??&sT\\&//:::G OO'66sT\\&//:::Gt||'M'M{"Gr   c                     yNr  r   r  r   s     r   r@  zDDLCompiler.create_table_suffix      r   c                     yr  r   r  s     r   rE  zDDLCompiler.post_create_table  r  r   c                    t        |j                  t        j                        r%| j	                  |j                  j
                        S y r  )r  server_defaultr#   DefaultClauserender_default_stringargr~  s     r   r  z%DDLCompiler.get_column_default_string  s8    f++V-A-AB--f.C.C.G.GHHr   c                    t        |t              r*| j                  j                  |t        j
                        S | j                  j                  |d      S )NT)r  )r  r   r  r  r%   r  r  )r  r   s     r   r  z!DDLCompiler.render_default_string"  sN    gs#$$99,,  $$,,WD,IIr   c                ^    |j                   r| j                  |      S | j                  |      S r  )is_column_levelvisit_column_check_constraintvisit_check_constraintr  r   r  s      r   &visit_table_or_column_check_constraintz2DDLCompiler.visit_table_or_column_check_constraint*  s-    %%55jAA..z::r   c                    d}|j                   %| j                  j                  |      }||d|z  z  }|d| j                  j	                  |j
                  dd      z  z  }|| j                  |      z  }|S Nr  CONSTRAINT %s z
CHECK (%s)FTrk  r   r  r  r  r  rJ  define_constraint_deferrabilityr  r   r  r  r  s        r   r  z"DDLCompiler.visit_check_constraint0      ??&!]]<<ZHN)(>99t0088e4  9  
 
 	
 	44Z@@r   c                    d}|j                   %| j                  j                  |      }||d|z  z  }|d| j                  j	                  |j
                  dd      z  z  }|| j                  |      z  }|S r  r  r  s        r   r  z)DDLCompiler.visit_column_check_constraint<  r  r   c                B    t        |      dk(  ryd}|j                  % j                  j                  |      }||d|z  z  }|dz  }|ddj	                   fd|j
                  r|j                  n|j                  D              z  z  }| j                  |      z  }|S )Nr   r  r  zPRIMARY KEY r  r   c              3  h   K   | ])  }j                   j                  |j                         + y wr  r  r  r   r*  rv  r  s     r   r,  z;DDLCompiler.visit_primary_key_constraint.<locals>.<genexpr>Q  s,      #
 MM'#
   /2)	r  r   r  r  rw   _implicit_generatedcolumns_autoinc_firstr  r  r  s   `    r   visit_primary_key_constraintz(DDLCompiler.visit_primary_key_constraintH  s    z?a??&!]]<<ZHN)(>99 #
 11 00''#
 
 
 	
 	44Z@@r   c           
        | j                   d}|j                  %| j                   j                  |      }||d|z  z  }t        |j                        d   j
                  j                  }|ddj                  fd|j                  D              d| j                  ||      ddj                  fd	|j                  D              d
z  }|| j                  |      z  }|| j                  |      z  }|| j                  |      z  }|S )Nr  r  r   zFOREIGN KEY(r   c              3  h   K   | ])  }j                  |j                  j                         + y wr  )r  parentr   r*  r  r  s     r   r,  z;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>e  '      23qxx}}-r  z) REFERENCES r  c              3  h   K   | ])  }j                  |j                  j                         + y wr  )r  r   r   r  s     r   r,  z;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>k  r  r  r  )r  r   r  r  r   r   r   rw   define_constraint_remote_tabledefine_constraint_matchdefine_constraint_cascadesr  )r  r   r  r  r  remote_tabler  s         @r   visit_foreign_key_constraintz(DDLCompiler.visit_foreign_key_constraint\  s   ==??&!]]<<ZHN)(>99J//03::@@II 7A7J7J  //L( II 7A7J7J 

 
	
 	,,Z88//
;;44Z@@r   c                $    |j                  |      S )z=Format the remote table clause of a CREATE CONSTRAINT clause.)r  )r  r   r   r  s       r   r  z*DDLCompiler.define_constraint_remote_tablet  s     $$U++r   c                    t        |      dk(  ryd}|j                  % j                  j                  |      }||d|z  z  }|d  j                  |fi |ddj                   fd|D              dz  }| j                  |      z  }|S )	Nr   r  r  rf  r  r   c              3  h   K   | ])  }j                   j                  |j                         + y wr  r  r  s     r   r,  z6DDLCompiler.visit_unique_constraint.<locals>.<genexpr>  s$     Fadmm))!&&1Fr  r  )r  r   r  r  !define_unique_constraint_distinctrw   r  r  s   `    r   visit_unique_constraintz#DDLCompiler.visit_unique_constrainty  s    z?a??&!]]<<ZHN)(>992D22:DDIIF:FF
 	
 	44Z@@r   c                     yr  r   r  s      r   r  z-DDLCompiler.define_unique_constraint_distinct  r  r   c                    d}|j                   0|d| j                  j                  |j                   t              z  z  }|j                  0|d| j                  j                  |j                  t
              z  z  }|S )Nr  z ON DELETE %sz ON UPDATE %s)ondeleter  validate_sql_phraseFK_ON_DELETEonupdateFK_ON_UPDATEr  r   r  s      r   r  z&DDLCompiler.define_constraint_cascades  s    *Odmm&G&G##\'  D *Odmm&G&G##\'  D r   c                    d}|j                   |j                   r|dz  }n|dz  }|j                  0|d| j                  j                  |j                  t              z  z  }|S )Nr  z DEFERRABLEz NOT DEFERRABLEz INITIALLY %s)r   r   r  r  FK_INITIALLYr  s      r   r  z+DDLCompiler.define_constraint_deferrability  sq      ,$$%))+Odmm&G&G$$l'  D r   c                F    d}|j                   |d|j                   z  z  }|S )Nr  z	 MATCH %s)r  r  s      r   r  z#DDLCompiler.define_constraint_match  s-    'K*"2"222Dr   c                    d| j                   j                  |j                  dd      z  }|j                  du r|dz  }|S |j                  du r|dz  }|S )NzGENERATED ALWAYS AS (%s)FTrk  z STOREDz VIRTUAL)r  r  rJ  	persisted)r  	generatedr  r  s       r   visit_computed_columnz!DDLCompiler.visit_computed_column  sr    )D,=,=,E,EU$ -F -
 
 $&ID    E)JDr   c                d    d|j                   rdndd}| j                  |      }|r|d|z  z  }|S )Nz
GENERATED ALWAYSz
BY DEFAULTz AS IDENTITYr  )alwaysr  )r  r  r  r  r  s        r   visit_identity_columnz!DDLCompiler.visit_identity_column  s@     H\9
 ++H5Gg%%Dr   )...)
r  r\   r   r@   r  r  r  r  r  r  r  r  r  r  )FT)4r   r   r   r  r   r  r&   r  r  r#  r  r,  r1  r9  rJ  rQ  rC  r]  ra  rd  ro  rq  rl  rz  r~  r  r  r  r  r  r  r  r  r  rO  r@  rE  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r  r    s   F FI,/03		 ,	 #C		
 &*	 .	 

 

 
3 3
 6:GK!	2 E 	
 
3L&B2h  7;#
J?I BF@L 






B@(B
&6J;

(0,

r   r  c                  (   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd1dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(d( Z)d) Z*d* Z+d+ Z,d, Z-d- Z.d. Z/d/ Z0d0 Z1y)2GenericTypeCompilerc                     y)NFLOATr   r  s      r   visit_FLOATzGenericTypeCompiler.visit_FLOAT      r   c                     y)NDOUBLEr   r  s      r   visit_DOUBLEz GenericTypeCompiler.visit_DOUBLE      r   c                     y)NzDOUBLE PRECISIONr   r  s      r   visit_DOUBLE_PRECISIONz*GenericTypeCompiler.visit_DOUBLE_PRECISION  s    !r   c                     y)NREALr   r  s      r   
visit_REALzGenericTypeCompiler.visit_REAL  r  r   c                    |j                   y|j                  dd|j                   iz  S d|j                   |j                  dz  S )NNUMERICzNUMERIC(%(precision)s)	precisionz!NUMERIC(%(precision)s, %(scale)s)r  scaler  r  s      r   visit_NUMERICz!GenericTypeCompiler.visit_NUMERIC  M    ??"[[ +{EOO.LLL6"__:  r   c                    |j                   y|j                  dd|j                   iz  S d|j                   |j                  dz  S )NDECIMALzDECIMAL(%(precision)s)r  z!DECIMAL(%(precision)s, %(scale)s)r  r  r  s      r   visit_DECIMALz!GenericTypeCompiler.visit_DECIMAL  r  r   c                     y)NINTEGERr   r  s      r   visit_INTEGERz!GenericTypeCompiler.visit_INTEGER      r   c                     y)NSMALLINTr   r  s      r   visit_SMALLINTz"GenericTypeCompiler.visit_SMALLINT      r   c                     y)NBIGINTr   r  s      r   visit_BIGINTz GenericTypeCompiler.visit_BIGINT  r  r   c                     y)N	TIMESTAMPr   r  s      r   visit_TIMESTAMPz#GenericTypeCompiler.visit_TIMESTAMP  s    r   c                     y)NDATETIMEr   r  s      r   visit_DATETIMEz"GenericTypeCompiler.visit_DATETIME  r
  r   c                     y)NDATEr   r  s      r   
visit_DATEzGenericTypeCompiler.visit_DATE  r  r   c                     y)NTIMEr   r  s      r   
visit_TIMEzGenericTypeCompiler.visit_TIME  r  r   c                     y)NCLOBr   r  s      r   
visit_CLOBzGenericTypeCompiler.visit_CLOB  r  r   c                     y)NNCLOBr   r  s      r   visit_NCLOBzGenericTypeCompiler.visit_NCLOB  r  r   Nc                    |}|r	|d|z  z  }n|j                   r|d|j                   z  z  }|j                  r|d|j                  z  z  }|S )N(%d)z COLLATE "%s")lengthr  )r  r  r   length_overrider  s        r   _render_string_typez'GenericTypeCompiler._render_string_type  sR    F_,,D\\FU\\))D??Oeoo55Dr   c                &    | j                  |d      S )NCHARr$  r  s      r   
visit_CHARzGenericTypeCompiler.visit_CHAR      ''v66r   c                &    | j                  |d      S )NNCHARr'  r  s      r   visit_NCHARzGenericTypeCompiler.visit_NCHAR	  s    ''w77r   c                &    | j                  |d      S )NVARCHARr'  r  s      r   visit_VARCHARz!GenericTypeCompiler.visit_VARCHAR  s    ''y99r   c                &    | j                  |d      S )NNVARCHARr'  r  s      r   visit_NVARCHARz"GenericTypeCompiler.visit_NVARCHAR  s    ''z::r   c                &    | j                  |d      S )NTEXTr'  r  s      r   
visit_TEXTzGenericTypeCompiler.visit_TEXT  r)  r   c                     y)NUUIDr   r  s      r   
visit_UUIDzGenericTypeCompiler.visit_UUID  r  r   c                     y)NBLOBr   r  s      r   
visit_BLOBzGenericTypeCompiler.visit_BLOB  r  r   c                J    d|j                   xr d|j                   z  xs dz   S )NBINARYr!  r  r"  r  s      r   visit_BINARYz GenericTypeCompiler.visit_BINARY  s$    5<<AFU\\,AGRHHr   c                J    d|j                   xr d|j                   z  xs dz   S )N	VARBINARYr!  r  r>  r  s      r   visit_VARBINARYz#GenericTypeCompiler.visit_VARBINARY  s$    ellDv/DJKKr   c                     y)NBOOLEANr   r  s      r   visit_BOOLEANz!GenericTypeCompiler.visit_BOOLEAN!  r  r   c                    |j                   r| j                  j                  s| j                  |dd      S  | j                  |fi |S )Nr&      )r#  )native_uuidr  supports_native_uuidr$  r8  r  s      r   
visit_uuidzGenericTypeCompiler.visit_uuid$  sE      (I(I++E62+NN"4??5/B//r   c                (     | j                   |fi |S r  )r;  r  s      r   visit_large_binaryz&GenericTypeCompiler.visit_large_binary*      tu+++r   c                (     | j                   |fi |S r  )rE  r  s      r   visit_booleanz!GenericTypeCompiler.visit_boolean-      !t!!%.2..r   c                (     | j                   |fi |S r  )r  r  s      r   
visit_timezGenericTypeCompiler.visit_time0  rM  r   c                (     | j                   |fi |S r  )r  r  s      r   visit_datetimez"GenericTypeCompiler.visit_datetime3      "t""5/B//r   c                (     | j                   |fi |S r  )r  r  s      r   
visit_datezGenericTypeCompiler.visit_date6  rM  r   c                (     | j                   |fi |S r  )r  r  s      r   visit_big_integerz%GenericTypeCompiler.visit_big_integer9       t  -"--r   c                (     | j                   |fi |S r  )r	  r  s      r   visit_small_integerz'GenericTypeCompiler.visit_small_integer<  rU  r   c                (     | j                   |fi |S r  )r  r  s      r   visit_integerz!GenericTypeCompiler.visit_integer?  rP  r   c                (     | j                   |fi |S r  )r  r  s      r   
visit_realzGenericTypeCompiler.visit_realB  rM  r   c                (     | j                   |fi |S r  )r  r  s      r   visit_floatzGenericTypeCompiler.visit_floatE  s    t,,,r   c                (     | j                   |fi |S r  )r  r  s      r   visit_doublez GenericTypeCompiler.visit_doubleH  rZ  r   c                (     | j                   |fi |S r  )r  r  s      r   visit_numericz!GenericTypeCompiler.visit_numericK  rP  r   c                (     | j                   |fi |S r  r/  r  s      r   visit_stringz GenericTypeCompiler.visit_stringN  rP  r   c                (     | j                   |fi |S r  rh  r  s      r   visit_unicodez!GenericTypeCompiler.visit_unicodeQ  rP  r   c                (     | j                   |fi |S r  r5  r  s      r   
visit_textzGenericTypeCompiler.visit_textT  rM  r   c                (     | j                   |fi |S r  rm  r  s      r   visit_unicode_textz&GenericTypeCompiler.visit_unicode_textW  rM  r   c                (     | j                   |fi |S r  rh  r  s      r   
visit_enumzGenericTypeCompiler.visit_enumZ  rP  r   c                2    t        j                  d|z        )NzKCan't generate DDL for %r; did you forget to specify a type on this Column?r}  r  s      r   r  zGenericTypeCompiler.visit_null]  s"    #%*+
 	
r   c                Z     | j                   |j                  | j                        fi |S r  )r  type_enginer  r  s      r   visit_type_decoratorz(GenericTypeCompiler.visit_type_decoratord  s'    t||E--dll;BrBBr   c                &     |j                   di |S r  )get_col_specr  s      r   visit_user_definedz&GenericTypeCompiler.visit_user_definedg  s    !u!!'B''r   r  )2r   r   r   r  r  r  r  r  r  r  r	  r  r  r  r  r  r  r  r$  r(  r,  r/  r2  r5  r8  r;  r?  rB  rE  rJ  rL  rO  rR  rT  rW  rY  r\  r^  r`  rb  rd  rf  ri  rk  rn  rp  rr  r  rv  ry  r   r   r   r  r    s    "		78:;7IL0,/,0,.0/,-.///,,/
C(r   r  c                  *    e Zd Zd Zd Zd Zd Zd Zy)StrSQLTypeCompilerc                r    	 |j                   } || fi |S # t        $ r  | j                  |fi |cY S w xY wr  )r  AttributeError_visit_unknown)r  r  r  r  s       r   r  zStrSQLTypeCompiler.processl  sN    	2!&!9!9 &d1b11  	4&4&&u333	4s    66c                R    |j                  d      r| j                  S t        |      )Nr[  )rZ  r~  r}  )r  r+  s     r   __getattr__zStrSQLTypeCompiler.__getattr__t  s%    >>(#&&& %%r   c                    |j                   j                  |j                   j                  j                         k(  r|j                   j                  S t        |      S r  )r  r   upperreprr  s      r   r~  z!StrSQLTypeCompiler._visit_unknownz  sA    ??##u'?'?'E'E'GG??+++;r   c                     yr  r   r  s      r   r  zStrSQLTypeCompiler.visit_null  r  r   c                `    	 |j                   } |di |S # t        $ r t        |      cY S w xY wr  )rx  r}  r  )r  r  r  rx  s       r   ry  z%StrSQLTypeCompiler.visit_user_defined  s=    	& --L  %"%%  	;	s    --N)r   r   r   r  r  r~  r  ry  r   r   r   r{  r{  k  s    2&&r   r{  c                      e Zd ZddZy)_SchemaForObjectCallablec                     y r  r   )r  _SchemaForObjectCallable__objs     r   r  z!_SchemaForObjectCallable.__call__      r   N)r  r   r  r   r	  r   r   r   r  r    s    .r   r  c                      e Zd ZddZy)r  c                     y r  r   )r  r  s     r   r  z _BindNameForColProtocol.__call__  r  r   N)r  r  r  r   r	  r   r   r   r  r    s    :r   r  c                     e Zd ZU dZeZeZeZ	de
d<   de
d<   de
d<    ej                  d      Zde
d	<   	 d
Zde
d<   	 	 	 	 	 d+dZd Zd Zd,dZd,dZd Zd,dZd-dZd Zd.d/dZd.d0dZd Zd1dZ	 d.	 	 	 	 	 d2dZ	 d.	 	 	 	 	 d3dZd.dZ ej@                  d      d1d       Z!d1d Z"d1d!Z#d" Z$d# Z%d4d$Z&d% Z'	 d.d&Z(	 	 	 	 	 d5d'Z)d1d(Z*ejV                  d)        Z,d* Z-y)6r  z@Handle quoting and case-folding of identifiers based on options.r   initial_quotefinal_quotezMutableMapping[str, str]_stringsr#   r  r  Fr  _includes_none_schema_translateNc                    || _         || _        |xs | j                  | _        || _        | j                  dz  | _        || _        || _        i | _        | j                   j                  dv | _	        y)as  Construct 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  r  r  escape_quoteescape_to_quoteomit_schemaquote_case_sensitive_collationsr  rY  r  )r  r  r  r  r  r  r  s          r   r  zIdentifierPreparer.__init__  st    . *&<$*<*<(#0014&/N, $ 7 7 <
 !
r   c                    | j                   j                  | j                         }|j                  j                  | j                         d |v fd}||_        |_        |S )Nc                    | j                   }| j                  r:|r6| d|v sd|v rt        j                  d|z        t	        d|xs dz  d      S | j                   S )Nr  r  zJSquare bracket characters ([]) not supported in schema translate name '%s'z__[SCHEMA_%s]_noneFr  )r#   _use_schema_mapr7   r  r0   )r  r   includes_nones     r   symbol_getterz@IdentifierPreparer._with_schema_translate.<locals>.symbol_getter  sw    ::D""(8M#t**8:>?  ##tw7u  zz!r   )r  __new__re  rf  r  r  )r  r  prepr  r  s       @r   r  z)IdentifierPreparer._with_schema_translate  sX    ~~%%dnn5T]]+ 44	" "//<,r   c                     |d v r) j                   st        j                  d      d    d<    fd}t        j                  d||      S )Nzschema translate map which previously did not have `None` present as a key now has `None` present; compiled statement may lack adequate placeholders.  Please use consistent keys in successive schema_translate_map dictionaries.r  c                    | j                  d      }|v r|   }n|dv rt        j                  d      |}|s-j                  j                  }|st        j
                  d      j                  |      S )Nr6   )Nr  zschema 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   r7   r-  r  default_schema_namer  r  )r  r   r  dr  s      r   r  z=IdentifierPreparer._render_schema_translates.<locals>.replace  s    771:Dqy#$T7 ?*11=  $( ##'<<#C#C '**=  $$%566r   z(__\[SCHEMA_([^\]]+)\]))r  r7   r-  rL  r  )r  r   r  r  r  s   `   @r   r  z,IdentifierPreparer._render_schema_translates  sZ     1977--9  4AgJ	72 vv0'9EEr   c                    |j                  | j                  | j                        }| j                  r|j                  dd      }|S )zEscape an identifier.

        Subclasses should override this to provide database-dependent
        escaping behavior.
        r  r  )r  r  r  r  r  r  s     r   _escape_identifierz%IdentifierPreparer._escape_identifier  s>     d//1E1EF  MM#t,Er   c                N    |j                  | j                  | j                        S )zCanonicalize an escaped identifier.

        Subclasses should override this to provide database-dependent
        unescaping behavior that reverses _escape_identifier.
        )r  r  r  r  s     r   _unescape_identifierz'IdentifierPreparer._unescape_identifier!  s!     }}T1143D3DEEr   c                x    |7|j                  |      s&t        j                  d|d|j                  d      |S )zkeyword sequence filter.

        a filter for elements that are intended to represent keyword sequences,
        such as "INITIALLY", "INITIALLY DEFERRED", etc.   no special characters
        should be present.

        .. versionadded:: 1.3

        zUnexpected SQL phrase: z (matching against r  )r  r7   r  r  )r  r  rO  s      r   r  z&IdentifierPreparer.validate_sql_phrase*  s=     syy'9""CKK)  r   c                X    | j                   | j                  |      z   | j                  z   S )z~Quote an identifier.

        Subclasses should override this to provide database-dependent
        quoting behavior.
        )r  r  r  r  s     r   quote_identifierz#IdentifierPreparer.quote_identifier<  s3     %%e,-	
r   c                    |j                         }|| j                  v xs? |d   | j                  v xs, | j                  j	                  t        |             xs ||k7  S )z5Return True if the given identifier requires quoting.r   )r5  reserved_wordsillegal_initial_characterslegal_charactersr  r   )r  r  lc_values      r   r_  z#IdentifierPreparer._requires_quotesI  sf    ;;=+++ #Qx4:::#((..s5z::# E!		
r   c                L    | j                   j                  t        |             S )zjReturn True if the given identifier requires quoting, but
        not taking case convention into account.)r  r  r   r  s     r   r8  z1IdentifierPreparer._requires_quotes_illegal_charsS  s"     ((..s5z:::r   c                V    |t        j                  dd       | j                  |      S )a  Conditionally 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`.

        zThe 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  r  )r  r#   forces      r   r  zIdentifierPreparer.quote_schemaX  s5    .    !  zz&!!r   c                R   |t        j                  dd       t        |dd      }|k|| j                  v r| j                  |   S | j	                  |      r| j                  |      | j                  |<   n|| j                  |<   | j                  |   S |r| j                  |      S |S )a  Conditionally quote an identifier.

        The identifier is quoted if it is a reserved word, contains
        quote-necessary characters, or is an instance of
        :class:`.quoted_name` which includes ``quote`` set to ``True``.

        Subclasses can override this to provide database-dependent
        quoting behavior for identifier names.

        :param ident: string identifier
        :param force: unused

            .. deprecated:: 0.9

                The :paramref:`.IdentifierPreparer.quote.force`
                parameter is deprecated and will be removed in a future
                release.  This flag has no effect on the behavior of the
                :meth:`.IdentifierPreparer.quote` method; please refer to
                :class:`.quoted_name`.

        NzThe IdentifierPreparer.quote.force parameter is deprecated and will be removed in a future release.  This flag has no effect on the behavior of the IdentifierPreparer.quote method; please refer to quoted_name().r  r  r  )r&   r  r4  r  r_  r  )r  rP  r  s      r   r  zIdentifierPreparer.quote  s    ,    !  w-=%}}U++((/+/+@+@+GDMM%(+0DMM%(}}U++((//Lr   c                @    | j                   r| j                  |      S |S r  )r  r  )r  collation_names     r   r  z#IdentifierPreparer.format_collation  s     //::n--!!r   c                    | j                  |j                        }| j                  |      }| j                  s|r|| j	                  |      dz   |z   }|S rs  )r  r   r  r  r  )r  r>  r,  r   r  s        r   r  z"IdentifierPreparer.format_sequence  sY    zz(--(11(;    ,$$%56<tCDr   c                @    | j                  |xs |j                        S r  r  r   )r  r  r   s      r   ru  zIdentifierPreparer.format_label  s     zz$,%**--r   c                f    ||J | j                  |j                        S | j                  |      S r  r  )r  r  r   s      r   rZ  zIdentifierPreparer.format_alias  s7     <$$$::ejj))::d##r   c                j    |xs |j                   }| j                  |      r| j                  |      }|S r  )rP  r_  r  )r  	savepointr   rP  s       r   r  z#IdentifierPreparer.format_savepoint  s5     '	  '))%0Er   zsqlalchemy.sql.namingc                   t         j                  j                  }|j                  t        u r|j                  ||j                        }|y |j                  }|j                  dk(  r| j                  ||      S | j                  ||      S )Nro  )_alembic_quote)
r&   r  
sql_namingr   r+   _constraint_name_for_tabler   r   truncate_and_render_index_name#truncate_and_render_constraint_name)r  r   r  namingr   s        r   r  z$IdentifierPreparer.format_constraint  s    **??j(44J,,D |??D$$/66^ 7   ;;^ <  r   c                    | j                   j                  xs | j                   j                  }| j                  |||      S r  )r  max_index_name_lengthr^   _truncate_and_render_maxlen_namer  r   r  max_s       r   r  z1IdentifierPreparer.truncate_and_render_index_name  sD    
 LL.. 2||11 	 44$
 	
r   c                    | j                   j                  xs | j                   j                  }| j                  |||      S r  )r  max_constraint_name_lengthr^  r  r  s       r   r  z6IdentifierPreparer.truncate_and_render_constraint_name   sD    
 LL33 2||11 	 44$
 	
r   c                    t        |t        j                        r3t        |      |kD  r@|d|dz
   dz   t	        j
                  |      dd  z   }n| j                  j                  |       |s|S | j                  |      S )Nr   rT  r  )	r  r   rD   r  r&   md5_hexr  validate_identifierr  )r  r   r  r  s       r   r  z3IdentifierPreparer._truncate_and_render_maxlen_name  sq    dH5564y4Aq)C/$,,t2DRS2IILL,,T2K::d##r   c                $    | j                  |      S r  )r  rc  s     r   rt  zIdentifierPreparer.format_index  s    %%e,,r   c                    ||j                   }| j                  |      }| j                  |      }| j                  s|r|r| j	                  |      dz   |z   }|S )z'Prepare a quoted table and schema name.r  )r   r  r  r  r  )r  r   r,  r   r4  r  s         r   r  zIdentifierPreparer.format_table  s_     <::DD!11%8J3C&&'783>GFr   c                $    | j                  |      S )zPrepare a quoted schema name.r  r9  s     r   r0  z IdentifierPreparer.format_schema)  s     zz$r   c                ~    |+t        |t        j                        r|j                  |      }| j	                  |      S )Prepare a quoted column name.)r  r   rD   r0  r  )r  r   r_  s      r   rO  z$IdentifierPreparer.format_label_name.  s;     J(++%
 >>(+Dzz$r   c                n   ||j                   }|+t        |t        j                        r|j	                  |      }t        |dd      sF|r3| j                  |j                  ||      dz   | j                  |      z   S | j                  |      S |r$| j                  |j                  ||      dz   |z   S |S )r  r  F)r,  r   r  )	r   r  r   rD   r0  r4  r  r   r  )r  r   r  r   
table_namer,  r_  s          r   r  z IdentifierPreparer.format_column<  s     <;;DJ(++%
 >>(+Dv|U3%%* &   jj&	' zz$''
 %%* &   	 r   c                    | j                  |      }| j                  s(|r&|r$| j                  |      | j                  |d      fS | j                  |d      fS )z(Format table name and schema as a tuple.Fri  )r  r  r  r  )r  r   r,  r  s       r   r(  z#IdentifierPreparer.format_table_seqi  sj      11%8J3C!!"23!!%E!: 
 %%e%>@@r   c                    d | j                   | j                  | j                  | j                        fD        \  }}}t        j                  d|||dz        }|S )Nc              3  F   K   | ]  }t        j                  |        y wr  )rL  rM  r  s     r   r,  z4IdentifierPreparer._r_identifiers.<locals>.<genexpr>|  s       )
 IIaL)
s   !zM(?:(?:%(initial)s((?:%(escaped)s|[^%(final)s])+)%(final)s|([^\.]+))(?=\.|$))+)initialfinalr  )r  r  r  rL  rN  )r  r  r  escaped_finalrs        r   _r_identifiersz!IdentifierPreparer._r_identifiersz  sp    )
 ""  ''(8(89)
% JJ$ "EmLM
 r   c                    | j                   }|j                  |      D cg c]  \  }}|xs | c}}D cg c]  }| j                  |       c}S c c}}w c c}w )z:Unpack 'schema.table.column'-like strings into components.)r  findallr  )r  identifiersr  arl  r  s         r   unformat_identifiersz'IdentifierPreparer.unformat_identifiers  s]      *+;)?@Aaf1f@
 %%a(
 	
@
s
   AA)r  Nr  TF)r  r   r  r   )r  r   r  r  r  )r#   r   r  r   r  r   )rP  r   r  r   r  r   )T)r  z
Label[Any]r   r7  r  r   )r  zOptional[AliasedReturnsRows]r   r7  r  r   )TN)FNNFN).r   r   r   r   RESERVED_WORDSr  LEGAL_CHARACTERSr  ILLEGAL_INITIAL_CHARACTERSr  r   r/  
attrgetterr  r  r  r  r  r  r  r  r  r_  r8  r  r  r  r  ru  rZ  r  r&   r  r  r  r  r  rt  r  r0  rO  r  r(  r  r  r  r   r   r   r  r    s|   J#N'!;&&2E(2E2Eh2O/O -2#T1
 (,"
H0'FR
F$

;
%"N2h" 8<..'4.	. JN$1$9F$	$ T01 2,




$-   " +ZA" 
 "
r   r  )r   
__future__r   rw  collections.abcabcr  r  enumr   r`  r  r/  rL  timer   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$   r%   r&   r)  _typingr'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   type_apir3   visitorsr4   r5   r7   r8   util.typingr9   r:   r;   
annotationr<   r=   r>   r  r?   r)  r@   dmlrA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   engine.cursorrT   engine.interfacesrU   rV   rW   rX   rY   rZ   r[   r\   r]   r   _FromHintsTyper  rN  Ir  LEGAL_CHARACTERS_PLUS_SPACErd  r   r  r  r  r  UNICODEr  r  r[  r\  r  or_r=  mulr  modnegltlenegtgeeqis_distinct_fromis_not_distinct_from	concat_opr{  not_match_opr  r  r  r  rt  r  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_oprs  r   r   r   r   r   r   r   r   r   r   r   cuberollupgrouping_setsr   r   r  _CompoundSelectKeywordr   	UNION_ALLr   
EXCEPT_ALLr   INTERSECT_ALLr  r   r   r
  r  r  r  r  r  r  r5  rE  rR  r`  re  r.  rf  rg  rh  ri  
namedtuplerk  r  EnsureKWArgr  BinaryElementRoleCompilerColumnElementr  r  r  r  r  r  r{  r  r  r  )r  s   0r   <module>r!	     s   " #  )      	             !                       &     2   # !     %     ! " #	+,"#)*'&'#./&+'"',4<:<=3=C+:lC'(_B 2::.5 (bjj):BDDA .3Arl;c!f;AA3%H rzz<bdd rzz<bdd rzz5rtt<bjjA2::N"**92::F$ "$.NNG. MM6. MM5	.
 MM5. MM5. MM5. MM3. LL%. LL&. LL&. LL%. LL&. LL%.  4.  ""$<!." #.$ 	%.& M'.( OOV).* +., -.. OOX/.0 MM61.2 MM63.4 j5.6 {7.: i;.< ;=.> MM6?.@ fA.B fC.F wG.H fI.J nK.L ]eUec[.	b 
NN!4N.hyNNNFNNFh_-	) & ""$(& %%++W%%//%%,,h%%00,%%//%%33_  >   ! *   
J  i $1 $:J :zt
 tnZ 2!; !$G  g . FKF B
&l
?#'''w6HI ?#DH' H'VF4## F0	C ("@"@2#
	C ("@"@#
LhT
( hT
Vil
[ l
^X( Xvj(, j(Z&, &B/x /;h ;
 
]] <s   a6