
    +hX                       d Z ddlZddlZddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl
mZ ddlmZ ddlmZ  eg d      Z ej0                  dej2                        Z ej0                  dej2                        Z edd      D  ch c]
  }  e|        c} j=                  dg      Z ej0                  dej2                        Z  ej0                  dej2                        Z! ej0                  dej2                        Z" ej0                  dejF                        Z$ ej0                  dejF                        Z%ddddd d!Z& ej0                  d"      Z' e( e)d#d$            Z*i ejV                  d%ejX                  d&ejZ                  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                  d0ejp                  d1ejr                  d2ejt                  d3ejv                  d4i ejx                  d5ejz                  d6ej|                  d7ej~                  d8ej                  d9ej                  d:ej                  d;ej                  d<ej                  d=ej                  d>ej                  d?ej                  d@ej                  dAej                  dBej                  dCej                  dDej                  dEej                  dFej                  dGej                  dHiZPej                  dIej                  dJej                  dKej                  dLej                  dMej                  dNej                  dOej                  dPej                  dQej                  dRej                  dSej                  dTej                  dUej                  dViZ_dWdXdYdZd[d\d]d^d_d`dadbdcdddedfZ`ej                  j                  dgej                  j                  dhej                  j                  diej                  j                  djej                  j                  dkej                  j                  dliZhdZidZjdZkdmZl ej                  dng do      Zn ej                  dpdqdr      Zp ej                  dsdtdr      Zq ej                  dudvdr      Zr ej                  dwdxeqerz  r      Zs G dy dz ej                  dzd{d|g            Zt G d} d~eu      Zv G d d ej                  ej                  eu            Zy G d de
j                        Z{ G d dev      Z| G d de|      Z} G d dev      Z~ G d dey      Z G d de      Z G d deu      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`.

    N   )base)	coercions)crud)elements)	functions)	operators)schema)
selectable)sqltypes)util)NO_ARG)prefix_anon_map)quoted_name   )exc)^allanalyseanalyzeandanyarrayasasc
asymmetricauthorizationbetweenbinarybothcasecastcheckcollatecolumn
constraintcreatecrosscurrent_datecurrent_rolecurrent_timecurrent_timestampcurrent_userdefault
deferrabledescdistinctdoelseendexceptfalseforforeignfreezefromfullgrantgrouphavingilikein	initiallyinner	intersectintoisisnulljoinleadingleftlikelimit	localtimelocaltimestampnaturalnewnotnotnullnulloffoffsetoldononlyororderouteroverlapsplacingprimary
referencesrightselectsession_usersetsimilarsome	symmetrictablethentotrailingtrueunionuniqueuserusingverbosewhenwherez^[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	:%(name)s)pyformatqmarkformatnumericnamedz[%\(\):\[\] ]z%():[] PAZC___ AND z OR z + 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 LASTcoalesceCURRENT_DATECURRENT_TIMECURRENT_TIMESTAMPCURRENT_USER	LOCALTIMELOCALTIMESTAMPrandomsysdateSESSION_USERUSERCUBEROLLUPzGROUPING SETS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 ALL   ExpandedState)	statementadditional_parameters
processorspositiontupparameter_expansion
NO_LINTINGzDisable all linting.)	canonicalCOLLECT_CARTESIAN_PRODUCTSzOCollect data on FROMs and cartesian products and gather into 'self.from_linter'WARN_LINTINGz,Emit warnings for linters that find problemsFROM_LINTINGzQWarn for cartesian products; combines COLLECT_CARTESIAN_PRODUCTS and WARN_LINTINGc                       e Zd ZddZd Zy)
FromLinterNc                   	 | 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N)index).0edgenodes     J/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/sql/compiler.py	<genexpr>z"FromLinter.lint.<locals>.<genexpr>H  s"     NDTdjj&6"67N   ")fromsra   edgesremovepopcollectionsdequepopleftdiscard
extendleftdifference_update)
selfstartr   r   the_rest
start_withstackr   	to_remover   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                         \  }}|rW|}|rRd}dj                   fd|D              }|j                  | j                  |         }t	        j
                  |       y y y )NzSELECT 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   \   K   | ]#  }d j                  j                  |          % yw)z"{elem}")elemN)rv   r   )r   from_r   s     r   r   z"FromLinter.warn.<locals>.<genexpr>_  s0      & %%4::e+<%=&s   ),)r   r   )r   rF   rv   r   r   warn)r   r   r   r   template	froms_strmessages   `      r   r   zFromLinter.warnQ  s    #yy{* E7  !II &!&& 	 #//#4::j+A *  		'"      r   )__name__
__module____qualname__r   r    r   r   r   r   +  s    #J#r   r   r   r   c                       e Zd ZdZdZdZdZej                  Z		 ej                  Z
dZ	 dZ	 dZdZdd ej                         fdZd Zd Zed        Zd Zd	 Z	 dd
Zed        Zy)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.
    NFc                    || _         | j                   j                  | _        |r'|| _        | j                  j	                  |      | _        ||| _        |j                  | _        |j                  | _        | j                  r|j                  | _
         | j                  | j
                  fi || _        |r+| j                  j                  | j                  |      | _        t        j                         | _        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

         .. versionadded:: 1.1

         .. seealso::

            :ref:`schema_translating`

        :param compile_kwargs: additional kwargs that will be
         passed to the initial call to :meth:`.Compiled.process`.


        N)dialectidentifier_preparerpreparerschema_translate_map_with_schema_translater   supports_executioncan_execute_annotations_execution_optionsexecution_optionsprocessstring_render_schema_translatesr   perf_counter	_gen_time)r   r   r   r   render_schema_translatecompile_kwargss         r   __init__zCompiled.__init__  s    : 88(<D% MM@@$DM  &DN(;;D ) 6 6D)2)E)E&&$,,t~~HHDK&"mmEEKK!5 **,r   c                     | j                   r|j                  | |||      S t        j                  | j                        r   )r   _execute_compiledr   ObjectNotExecutableErrorr   )r   
connectionmultiparamsparamsr   s        r   _execute_on_connectionzCompiled._execute_on_connection  sA     //k6+<  ..t~~>>r   c                 l    t        j                  t        j                  | t	        |            |       y Nreplace_context)r   raise_r   UnsupportedCompilationErrortype)r   elementerrs      r   visit_unsupported_compilationz&Compiled.visit_unsupported_compilation  s%    ++D$w-@	
r   c                     t               )zReturn a Compiled that is capable of processing SQL expressions.

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

        NotImplementedErrorr   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                 "    | j                   xs dS )z3Return the string text of the generated SQL or DDL. )r   r  s    r   __str__zCompiled.__str__  s     {{ b 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   r   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   NNT)r   r   r   __doc___cached_metadata_result_columnsr   r   
EMPTY_DICTr   r   compile_statedml_compile_state	cache_keyr   immutabledictr   r   r   propertyr  r   r
  r  r   r   r   r   r   r   j  s    
 O
 ??LM 	 II " %)t))+1-f?
 $ $6! DH
$ ' 'r   r   c                   &    e Zd ZdZdZd Zd Z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                   | fi |S r   r  r   type_kws      r   r   zTypeCompiler.process  s    'u''333r   c                 Z    t        j                  t        j                  | |      |       y r   )r   r   r   r   )r   r   r   r"  s       r   r   z*TypeCompiler.visit_unsupported_compilation  s!    ++D':	
r   N)r   r   r   r  ensure_kwargr   r   r   r   r   r   r  r    s    <L4
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   namec                 6    || _         || _        |f|z   | _        y r   )r   r(  
_alt_names)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,  s    ||%%%r   c                 .    | j                   j                  S r   )r   r   r  s    r   r   z_CompileLabel.type0  s    ||   r   c                     | S r   r   )r   r"  s     r   
self_groupz_CompileLabel.self_group4  s    r   N)r   )r   r   r   r  __visit_name__	__slots__r   r  r.  r   r1  r   r   r   r&  r&     sA    EN!I-
 & & ! !r   r&  c                   2   e Zd ZdZeZeZdxZxZ	Z
	 dZdZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	  e       Z	  e       Z	 ej6                  Z	 dZ	 dxZZdZ 	 dZ!	  e"jF                  d      Z$dZ%	 dZ&dZ'ddde(fdZ)e*d        Z+e*d	        Z,ejZ                  d
        Z.ej^                  d        Z0e1jd                  d        Z3d Z4ejZ                  d        Z5d Z6e*d        Z7	 	 	 	 	 ddZ8ej^                  	 dd       Z9e*d        Z:	 ddZ; ejx                  d      d        Z=ejZ                  d        Z>ejZ                   ejx                  d      d               Z?ejZ                   ejx                  d      d               Z@d ZAddZBd ZC	 ddZD	 ddZE	 	 	 	 	 dd ZFd! ZGd" ZH	 	 	 dd#ZId$ ZJd% ZKd& ZLd' ZMd( ZNd) ZOdd*ZP	 dd+ZQd, ZRd- ZSd. ZTd/ ZUd0 ZVd1 ZWd2 ZXd3 ZYd4 ZZd5 Z[d6 Z\d7 Z]d8 Z^d9 Z_d: Z`d; Zadd<Zbd= Zcd> Zdd? Ze	 dd@ZfdA ZgdB Zh	 ddCZidD ZjdE ZkdF ZldG ZmdH ZndI Zo	 ddJZpdK Zq	 	 	 	 ddLZrdM ZsdN ZtdO ZudP ZvdQ Zw	 ddRZxdS ZydT ZzejZ                  dU        Z{dV Z|dW Z}dX Z~dY ZdZ Zd[ Zd\ Zd] Zd^ Zd_ Zd` Zda Zdb Zdc Zdd Z	 	 	 	 	 ddeZedfdfZdg Zdh Zdi Zdj Z	 	 	 	 ddkZ	 	 	 	 	 ddlZdm Zdn Z	 	 	 	 	 	 	 	 ddoZdp Zdq ZddrZddsZdt Zdu Z	 ddvZ	 	 	 	 	 	 ddwZdx Zdy Zdz Zd{ Zd| Z ejH                  d} e       fd~ e       fg      Z	 ddZdZ	 	 	 	 	 	 	 	 ddZd Zd Zd Zd Z	 	 	 ddZd Zd Zd Zd Zd Zd Zd Zd Z	 	 	 	 	 	 ddZddZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)SQLCompilerz~Default implementation of :class:`.Compiled`.

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

    FNTr   z"__\[POSTCOMPILE_(\S+?)(~~.+?~~)?\]c                    || _         || _        |rI|d   D ci c]  }|j                  | c}x| _        }	|	j	                  |d   D ci c]  }||g c}       || _        || _        i | _        t        j                         | _
        g | _        g | _        |j                  | _        | j                  r"i | _        g | _        |j                   dk(  | _        t$        |j                      | _        d| _        |j*                  xs |j,                  | _        t/               | _        i | _        t5        j6                  | ||fi | | j8                  s| j:                  s| j<                  r|j>                  r|j>                  | _         | j8                  s| j:                  rU|jB                  rd| _"        nA| j
                  r5| j8                  r"| jF                  jH                  r|jJ                  rd| _"        | j                  r| j"                  r| jM                          | jN                  r| jQ                  d       yy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   rw   NT)_populate_self))column_keysr  key_cache_key_bind_matchupdatefor_executemanylintingbindsr   column_dict
bind_namesr   r  
positionalpositiontup_levelr   
paramstyle_numeric_bindsBIND_TEMPLATESbindtemplatecteslabel_lengthmax_identifier_lengthr   anon_maptruncated_namesr   r   isinsertisupdateisdelete
_returning	returning_inlineinliner   insert_executemany_returning_return_defaults_apply_numbered_params_render_postcompile#_process_parameters_for_postcompile)
r   r   r   r  r8  r<  r=  r  bckbms
             r   r   zSQLCompiler.__init__  s   > '""+A,1q1 D& KK16AQC67
  / 
 **, 
  " ",,??%'D"!D")"4"4	"AD*7+=+=>	   AG$A$A 	 ()  "$=f===DMMT]]##!*!5!5}}$$"&DK))AA%66 #'DK??t22'')##44D4I $Q1 7s   H7H<c                     	 | j                   d   d   S # t        $ r*}t        j                  t        d      |       Y d}~y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 entryr   N)r   
IndexErrorr   r   )r   ies     r   current_executablezSQLCompiler.current_executableA  sG    <	::b>,// 	KKAB " 	s    	A AAc                 F    t        | j                  | j                  z         S r   )listinsert_prefetchupdate_prefetchr  s    r   prefetchzSQLCompiler.prefetchg  s    D((4+?+??@@r   c                     i S r   r   r  s    r   _global_attributeszSQLCompiler._global_attributesk  s    	r   c                     t        j                         | _        i | _        i | _        d| _        | j                  r-i | _        i | _        t        j                  t              | _        yy)zInitialize collections related to CTEs only if
        a CTE is located, to save on the overhead of
        these collections otherwise.

        FN)r   OrderedDictrG  ctes_by_level_namelevel_name_by_ctectes_recursiverA  cte_positional	cte_levelr   defaultdictr`  	cte_orderr  s    r   _init_cte_statezSQLCompiler._init_cte_stateo  s]     $$&	 #% "$#??"$DDN(44T:DN 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[  Tneed_result_map_for_nestedN)r  _ordered_columnsr   r   )r   result_columnsordered_columnsentrys       r   _nested_resultzSQLCompiler._nested_result  s        !! ( 79%3d3	zz

26:23&&(=(===		67 8D $"7 		67 8D $"7s   (B2=B (#B2$B//B2c                     t        j                  d      t        j                  dfd| j                        | _        y )Nr   z\[_POSITION\]c                 @    t        t        j                              S r   )strr   next)mposcounts    r   <lambda>z4SQLCompiler._apply_numbered_params.<locals>.<lambda>  s    DIIh,?(@ r   )	itertoolscountresubr   )r   r|  s    @r   rU  z"SQLCompiler._apply_numbered_params  s-    ??1%ff@$++
r   c                 N     t        d  fd j                  D        D              S )Nc              3   .   K   | ]  \  }}|||f  y wr   r   )r   r9  values      r   r   z/SQLCompiler._bind_processors.<locals>.<genexpr>  s.      

 U   
s   c              3     K   | ]v  }j                   |   |j                  j                  s%|j                  j                  j                        n't        fd |j                  j                  D              f x 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(      % "88Fs   %(N)r@  r   _is_tuple_typer  r   tupletypes)r   	bindparamr   s     r   r   z/SQLCompiler._bind_processors.<locals>.<genexpr>  sm        OOI.$>>88 NN99$,,G )2)=)= 	s   A<A?)dictr@  r  s   `r   _bind_processorszSQLCompiler._bind_processors  s/      

 "&
 
 	
r   c                 2    t        | j                        dkD  S Nr   )lenr   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                 F   |xr t        | j                        }|rH	 | j                  d   }| 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 # t        $ r5}t	        j
                  t        j                  d      |       Y d}~hd}~ww xY wc c}}}
w )	z5return a dictionary of bind parameter keys and valuesr   zcThis compiled object has no original cache key; can't pass extracted_parameters to construct_paramsr   Nz@A value is required for bind parameter %r, in parameter group %dcd3x)codez)A value is required for bind parameter %r)boolescaped_bind_namesr  	TypeErrorr   r   r   CompileErrorr:  zipr@  itemsgetr9  requiredInvalidRequestErrorcallableeffective_valuer  )r   r   _group_number_checkr  r  has_escaped_namesorig_extractedr   rY  rX  	extractedbindresolved_extractedpdr  r(  escaped_namevalue_params                      r   r  zSQLCompiler.construct_params  s    )JT$2I2I-J	!%!2 --D %(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> Iy  $$N %( "s   I J	J$*JJc                   	 t        | d      sy | j                  	| j                  j                  		fd}n	fd}i }| j                  }| j                  D ]`  }||v r|j
                  j                  r.|j
                  j                  D cg c]
  } ||       c}||<   L ||j
                        ||<   b |S c c}w )Nr@  c                 H    | j                        j                        }|S r   )dialect_implget_dbapi_type)typdbtypedbapir   s     r   _lookup_typez=SQLCompiler._get_set_input_sizes_lookup.<locals>._lookup_typeJ  s#    ))'2AA%Hr   c                     | j                        }| j                        j                        }|(|vr"t        |      vr|v st        |      v r|S y r   )_unwrapped_dialect_implr  r  r   )r  r  r  r  r   exclude_typesinclude_typess      r   r  z=SQLCompiler._get_set_input_sizes_lookup.<locals>._lookup_typeP  sz    
  #::7C))'2AA%H &%-!6 .mC &-!]2-> "Mr   )hasattrr   r  literal_execute_paramsr@  r   r  r  )
r   r  r  r  
inputsizesr  r  r  r  r   s
    ``     @@r   _get_set_input_sizes_lookupz'SQLCompiler._get_set_input_sizes_lookup7  s     t\*,,""  ]%: 4 
!%!<!< 		EI22~~,,1:1E1E)*-L%)
9% )5Y^^(D
9%		E )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.paramsz  s     $$E$22r   c                    || j                  d      }i }| j                  rg }nd}| j                  i }| j                  r| j                  rt	        d      i i }| j                  r| j
                  n| j                  j                         D ]  | j                  r| j                  j                        n}| j                     }|| j                  v r,|vr|j                        }	| j                  |	      |<   w|| j                  v r|v r||   }
n4|j                        }| j                  } ||||      \  }
}|
||<   ||<   |j                   r|j#                  |
       |j$                  j&                  r&|j#                  fdt)        d      D               n|j#                  fd|
D               | j                  r|j+                  d	 |
D               |
D 	cg c]  \  }}	|	 c}	}|<   v| j                  s|j-                          fd
}t/        j0                  | j2                  || j4                        }t7        |||||      }|r|j8                  | _        | j                  j#                  |j:                         |j
                  | _        t=               | _        |j>                  D ]  }| j                  j                  |      }| j                  j                  |       tA        |jB                  |j>                  |         D ]4  \  }	}|jE                  |	      x| j                  |<   }|| j                  |<   6  |S 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.

        NF)r  z\'post-compile' bind parameters are not supported with the 'numeric' paramstyle at this time.render_literal_valuec              3      K   | ]?  \  }}t        |d       D ]+  \  }}v r"   |d z
     d|d|   |d z
     f - A yw)r   N_)	enumerate)r   ituple_elementjr  r(  r   s        r   r   zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>  sz      	.
 !1=,5mQ,G	. !)5#z1 *4 0Q 7 C /3Aq 9 *4 0Q 7	.	.s   AAr   c              3   :   K   | ]  \  }}v r	|   f  y wr   r   )r   r9  r  r(  r   s      r   r   zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>  s/      . *U#z1 !*T"23.s   c              3   &   K   | ]	  \  }}|  y wr   r   )r   r(  r  s      r   r   zBSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>  s     *MKD%4*Ms   c                    | j                  d      }|   }| j                  d      rU| j                  d      j                  d      }|d   |d   cdj                  fd|j                  d      D              }|S )Nr   r   ~~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>  s       ! !(h7!   )r<   splitrF   )r{  r9  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   )#r  rA  r  rD  r   r   r@  valuesr  r  r>  r  r   render_literal_bindparampost_compile_params$_literal_execute_expanding_parameterliteral_executer;  r   r  r  extendappendr  r  _post_compile_patternr   r   r   r   	frozensetr   r  r  _with_value)r   
parametersr7  expanded_parametersr   new_processorsto_update_setsr  	parameterr  	to_updater  leepreplacement_expr
expand_keyr  r   expanded_stater9  r  expanded_key	new_paramr(  r   r  s                         @@@r   rW  z/SQLCompiler._process_parameters_for_postcompile  s     ..E.BJ ??KK**
??t22 &9 
 #% !%DT__5K5K5MH	)D
 ** ''++D$7  

4(ID777'>>&NN40E 11). 2  (  D444#:: .| <I (^^D1FDDD26$i3/I/ 4=N<0<L+L9 00%%i0 ~~44&-- 	.
 5>fa4H	. 	 '-- ..7. 
 #***M9*MM<E1'8z5
1'- ""4(QH	)T	 FF&&KK
	 '
  )22DK!!(()B)BC-99D'0{D$%99 	>zz~~c*##D)+.JJ B B3 G, >'E< <@;K;K< DJJ|,y 2>DOOI.>	> m1s   3M$zsqlalchemy.engine.cursorc                     t         j                  j                  }|j                  j	                  | j
                        S )z(utility method used for unit tests only.)r   	preloadedengine_cursorCursorResultMetaData_create_description_match_mapr  )r   cursors     r   _create_result_mapzSQLCompiler._create_result_map5  s5     --**HH  
 	
r   c                 $    | j                   d   }|S )Nr   )_key_getters_for_crud_column)r   getters     r   _within_exec_param_key_getterz)SQLCompiler._within_exec_param_key_getter=  s    2215r   zsqlalchemy.engine.resultc           	        	 t         j                  j                  }| j                  }| j                  j
                  }|j                  D cg c]!  }t        j                  d ||      d       |f# c}|j                  'j                  j                  | j                  d       nd |j                  |j                  D cg c]  }|j                   c}      		fd}|S c c}w c c}w )Nr  c                 h                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>e  s     L[VSfZ0Ls   c              3   @   K   | ]  \  }}|u rn |        y wr   r   )r   r  r+  autoinc_col	lastrowidr  s      r   r   zWSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get.<locals>.<genexpr>g  s.      # "%!3I
9KK   r   )r  r  r  gettersprocrow_fns   ``r   r  zDSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.getZ  sE      O	 LGLLL '.  r   )r   r  engine_resultr  r   re   primary_keyoperatormethodcaller_autoincrement_columnr   _cached_result_processorr   result_tupler9  )
r   resultparam_key_getterre   r+  r  r  r  r  r  s
         @@@@r   +_inserted_primary_key_from_lastrowid_getterz7SQLCompiler._inserted_primary_key_from_lastrowid_getterB  s     --==$$ ((
 ""5*:3*?FL

 11"##<<dD D$$9J9J%K#cgg%KL	$ 
E
 &Ls   &C,C1c           	        	 t         j                  j                  }| j                  }| j                  j
                  }t        | j                        D ci c]  \  }}||
 }}}|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 )NTr  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:,>>r   r   )r  r  r  r  s   ``r   r  zDSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.get  s     '.  r   )r   r  r  r  r   re   r  rP  r   r  
itemgetterr  r  r9  )
r   r  r  re   idxr+  retr  r  r  s
           @@r   +_inserted_primary_key_from_returning_getterz7SQLCompiler._inserted_primary_key_from_returning_gettern  s     --==$$(1$..(ABHCsCxBB ((
  cz   S*D1 %%e-=c-BDI
 $$9J9J%K#cgg%KL	 
) C
 &Ls   C75AC=Dc                      y)zCalled when a SELECT statement has no froms, and no FROM clause is
        to be appended.

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

        r	  r   r  s    r   default_fromzSQLCompiler.default_from  s     r   c                 H    d |j                   j                  | fi |z   dz   S N()r   r  )r   groupingasfromr  s       r   visit_groupingzSQLCompiler.visit_grouping  +    8X%%88HHH3NNr   c                 H    d |j                   j                  | fi |z   dz   S r  r  )r   r  r  s      r   visit_select_statement_groupingz+SQLCompiler.visit_select_statement_grouping  r  r   c                    | j                   r| j                  j                  r| j                   d   d   }|j                  \  }}}|r|}n|}|j                  j
                  }	|	E|	j                  |v r7|	j                  ||	j                           r|j                  j
                  |d<    | j                  |j                  fd|i|S )Nr[  r  render_label_as_labelwithin_columns_clause)	r   r   supports_simple_order_by_label_label_resolve_dictr   _order_by_label_elementr(  shares_lineager   )
r   r   r!  r  r  	with_cols
only_froms	only_colsresolve_dictorder_by_elems
             r   visit_label_referencez!SQLCompiler.visit_label_reference  s     ::$,,EE JJrN?;M 11	$)( $OOCCM )!&&,6!00 !3!34 OO;; + t||OO
"7
 
 	
r   c                    | j                   s| j                  |j                        S | j                   d   d   }|j                  \  }}}	 |r||j                     }n||j                     }||d<    | j                  |fd|i|S # t
        $ r;}	t        j                  |j                  dt        j                  |	       Y d }	~	y d }	~	ww xY w)Nr[  r  r   r!  zECan't resolve label reference for ORDER BY / GROUP BY / DISTINCT etc.)extraexc_clsr   )
r   r   _text_clauser#  r   KeyErrorr   _no_text_coercionr   r  )
r   r   r!  r  r  r&  r'  r(  r+  r   s
             r   visit_textual_label_referencez)SQLCompiler.visit_textual_label_reference  s     zz<< 4 455

27+8+L+L(	:y	$ 10 /2F*+4<<+@DJ   		''/ (( 		s   !B 	C
1CC
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)
isinstancer(  r   _truncated_label_truncated_identifierr*  r   r   r  	OPERATORSr	   as_r   format_label)r   r'  add_to_result_mapr5  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.r   r  r   r$   s     r   _fallback_column_namez!SQLCompiler._fallback_column_name  s    K
 	
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                    |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}|
j                   }t        |t        j
                        r| j                  d|      }|| j                  j                  |      z   dz   |z   S )Nr4  .r	  alias)r(  rE  
is_literalr6  r   r7  r8  r9  	_tq_labelr   escape_literal_columnr   quotere   named_with_columnschema_for_objectquote_schema)r   r$   r<  include_tabler=  r  r(  	orig_namerM  targetsre   effective_schemaschema_prefix	tablenames                 r   visit_columnzSQLCompiler.visit_column  sq    ";;&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  !#

I)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_collationH  s    }}--g.?.?@@r   c                     |j                   S r   r(  )r   
fromclauser  s      r   visit_fromclausezSQLCompiler.visit_fromclauseK  s    r   c                     |j                   S r   ra  )r   r   r  s      r   visit_indexzSQLCompiler.visit_indexN  s    zzr   c                     ||d<   | j                   |d<    | j                  j                  j                  |j                  fi |S )Ntype_expressionr   )r   r   type_compilerr   r   )r   
typeclauser"  s      r   visit_typeclausezSQLCompiler.visit_typeclauseQ  sB     *$(MM !1t||))11*//HRHHr   c                 V    | j                   j                  r|j                  dd      }|S N%%%r   _double_percentsreplacer   texts     r   post_process_textzSQLCompiler.post_process_textV  $    ==))<<T*Dr   c                 V    | j                   j                  r|j                  dd      }|S rl  ro  rr  s     r   rO  z!SQLCompiler.escape_literal_column[  ru  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_bindparama  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>s  s    aggaj r   )	r   isplaintextr   NULLTYPEBIND_PARAMS_ESCr  BIND_PARAMSrt  rs  )r   r{  r<  r"  r|  s   `` ` r   visit_textclausezSQLCompiler.visit_textclause`  sl    	9 zz#D dD:-9J9JK "" OOd44Z__E
 	
r   c                 f   | j                    }|r| j                  n| j                   d   }t               t               |d}| j                   j                  |       |j                  r$|j                  D ]  } |j
                  | fi |  |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%                  ||j                  d	      
      |z   }| j                   j'                  d       |S )Nr[  correlate_fromsasfrom_fromsr   r   need_result_map_for_compoundFrq  Tr!  r<  visiting_ctenesting_levelr  )r   _default_stack_entryra   r  _independent_ctesr  r  rA  rr  _textual_ordered_columnsr  column_args_loose_column_name_matchingr   _add_to_result_mapr   rG  r  _render_cte_clauser   )r   tafcompound_indexr  r"  toplevelru  	new_entryctepopulate_result_mapcrs  r  s                r   visit_textual_selectz SQLCompiler.visit_textual_selecty  s    zz>-5))4::b>  #uE
	
 	

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

OM''"/!#!7 (  	  	

rr   c                      yNNULLr   r   r  r"  s      r   
visit_nullzSQLCompiler.visit_null      r   c                 2    | j                   j                  ryy)Nri   1r   supports_native_booleanr  s      r   
visit_truezSQLCompiler.visit_true  s    <<//r   c                 2    | j                   j                  ryy)Nr5   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   r  r"  r   s     r   r   z7SQLCompiler._generate_delimited_list.<locals>.<genexpr>  s$     I1*a**4626I    rF   )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  r9  rF   )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 N )r  r9  r  r  )r   r  r"  seps       r   r  zSQLCompiler.visit_clauselist  sG    !!;CJ//0C,t,,Z-?-?KKKr   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condr  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                     d |j                   j                  | fi |d |j                  j                  | fi |dS )NzCAST(r   r  )r  r  ri  )r   r!   r  s      r   
visit_castzSQLCompiler.visit_cast  s>    *DKK**4:6:.DOO..t>v>
 	
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
 FOLLOWINGrz   r   zUNBOUNDED FOLLOWING)r   RANGE_UNBOUNDEDRANGE_CURRENTr   literalabs)r   range_r"  s      r   _format_frame_clausez SQLCompiler._format_frame_clause  sv    ayH444 " ayH222  ay1} t||H,,S^<CCF t||H,,VAY7>2>AA ayH444 " A
 	
 ayH222 A
 	
  ay1} t||H,,S^<CCF	A
 	
$ t||H,,VAY7>2>AA
 	
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  rowsrF   partition_byorder_byr  )r   overr  rs  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_withingroup9  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_funcfilter?  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_extractE  sH      $$W]]GMMB+GLL++D;F;
 	
r   c                 r     | j                   |j                  fi |} | j                  |fi |}d|d|S )Nr  z).)visit_functionfnrZ  )r   r   r"  compiled_fncompiled_cols        r   visit_scalar_function_columnz(SQLCompiler.visit_scalar_function_columnL  s?    )d))'**;;(t((7B7'66r   c           	      b   |) ||j                   |j                   d|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 )Nr   zvisit_%s_funcz%(expr)srK  r  z WITH ORDINALITY)r(  r   getattrlower	FUNCTIONSr  _deannotate	__class__	_has_argsr   _requires_quotes_illegal_charsr6  r   r   rP  rF   packagenamesfunction_argspec_with_ordinality)r   r  r<  r  disprs  r(  r  s           r   r  zSQLCompiler.visit_functionQ  s   (diiB		B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F,c                 8    | j                  |j                        S r   )visit_sequencesequence)r   
next_valuer"  s      r   visit_next_value_funcz!SQLCompiler.visit_next_value_funcw  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_sequencez  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                  D ]  }
 |
j                   fi    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j                  d            |z   } j                   j-                  d       |S )Nr[  r  Fr   select_0r  r  )r  r  r   r  r  r  c              3   P   K   | ]  \  }} |j                   f|d   yw))r  r  Nr  )r   r  r  r  r  r   s      r   r   z4SQLCompiler.visit_compound_select.<locals>.<genexpr>  sA       Aq %$$!'=Cs   #&rT  r  Tr  r  include_following_stackr  r   )r   _compile_state_factoryr  r   r  r  r  r  r  compound_keywordskeywordrF   r  selectsgroup_by_clauser  order_by_clause_has_row_limiting_clause_row_limit_clauserG  r  r  r   )r   csr  r  r  r  r  compound_stmtru  need_result_mapr  r  rs  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?	
 **$66 7&&&t6v67 ((,,RZZ8g#)) &bjj1	
 #($$$RI4+Hv+H+HII$$$R2622&&*D**2888D993;C

OM''"/,0!'N!; ( 
   	

rr   c                 f    |j                    | j                  |fi |S  | j                  |fi |S r   )_fetch_clausefetch_clauselimit_clause)r   r  r  s      r   r  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   r  )r   	operator_
qualifier1
qualifier2attrnames        r   _get_operator_dispatchz"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      )Nr<  r=  zFUnary expression does not support operator and modifier simultaneouslyunaryr  modifierz,Unary expression has no operator or modifier)r  r/  r   r  r,   _generate_generic_unary_operatorr9   _generate_generic_unary_modifier)r   r.  r<  r=  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                   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_operator  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 = 0r4  r6  s       r   visit_is_false_unary_operatorz)SQLCompiler.visit_is_false_unary_operator  sV    **||33ldll7??AbAAAldll7??AbAAAr   c                 J    d| j                  |t        j                        z  S )Nr9  )override_operator)visit_binaryr	   match_opr   r   r  r"  s       r   visit_not_match_op_binaryz%SQLCompiler.visit_not_match_op_binary  s,    $++i&8&8 , 
 
 	
r   c                 >    d | j                   |t        |   fi |z  S r  )_generate_generic_binaryr9  r?  s       r   visit_not_in_op_binaryz"SQLCompiler.visit_not_in_op_binary  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>       :f:   zNULL) OR (1 = 1z(%s)) AND (1 != 1c              3       K   | ]  }d   ywrF  r   rG  s     r   r   z6SQLCompiler.visit_empty_set_op_expr.<locals>.<genexpr>%  rH  rI  zNULL) AND (1 != 1)r	   	not_in_opr  rF   in_opvisit_empty_set_expr)r   r!  	expand_ops      r   visit_empty_set_op_exprz#SQLCompiler.visit_empty_set_op_expr  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.r  )r   element_typess     r   rM  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                  sa|j                  rt        |d   t        j                  j                        rt        |d   t        j                  t        j                  z         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r   N)rF   r  r   r  )r   r  r  r  r   s      r   r   zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>Y  sQ       %A} II 14)9>>+?+?2 s   AAr   )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>o  s7      3 	  11%H 	3s   ,/c              3   V   K   | ]   }j                  |j                         " y wr   rY  )r   r  r  r   s     r   r   zQSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>y  s*      3 --eY^^D3s   &)r   )r   r  r   r  tuple_in_valuesrO  r  rN  _isnullr6  r   collections_abcSequencestring_typesbinary_types_has_bind_expressionr   rF   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_binds2  s/    %>>AA$,,O
  ..!%!=!=I200NN(()*=*=*&@ )))s *.)E)E^^$i&9&9*&r )))k ,,$$6!9d&:&:&C&CDq	4,,t/@/@@
  44)$  "\\99	r		  )2&(9 &"N )))1 ('+'A'A$(//0HIQWW ?>?  ggaj&&t,$'FCF!)- 3 "(3 *& ))) *. 3!'3 *&
 )))r   c                    
 |j                   r j                  ||      S |j                  j                   j                        }|smg 
|j
                  r4 j                  |j                  j                  |j                        }
|fS  j                  |j                  g|j                        }
|fS |j
                  sa|j                  rt        |d   t        j                  j                        rt        |d   t        j                  t        j                  z         s|j                   rJ t#        |d      D 	cg c]%  \  }}t#        |d      D ]  \  }}	|d|d||	f ' c}	}}}
 j                  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 )	Nr   r   r  rS  r	  r}   c              3   z   K   | ]0  \  d dj                  fdt              D              z   2 yw)r  r}   c              3   p   K   | ]-  \  }}j                   d t              z  |z      d   iz   / yw)r(  r   N)rF  r  )r   r  r  r  r   r  r  s      r   r   zMSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>.<genexpr>  sL       %Au ))!9Q]1C-Ca-G#H#KLMs   36N)rF   r  )r   r  r  r   r  s    @@r   r   zCSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>  sD      
 %A} II  )2-(@ 
s   6;c              3   F   K   | ]  \  }}j                   d |iz    yw)r(  N)rF  )r   r9  r  r   s      r   r   zCSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>  s)      /6@c5!!VSM1/s   !)r  rg  r   r  r   r  rO  r  rN  r\  r6  r   r]  r^  r_  r`  	_is_arrayr  r[  rF   )r   r(  r  r  rd  re  r  r  r  r  r  s   `         @r   r  z0SQLCompiler._literal_execute_expanding_parameter  s    $$JJ6  %>>AA$,,OI..)-)E)ENN(()*=*=*&V 000O *.)E)E^^$i&9&9*&N 000G ,,$$6!9d&:&:&C&CDq	4,,t/@/@@ (1111 )2&!(< $A} )- ; Au  $Q*E22I "\\99	r		 
 )2&(9
 
&", 000 !*&! 4Au !!$e,I &*YY /DM/ &" 0007&s   *G8
H c                    |rt        j                  |j                        r|e|d   }|j                  j	                  t        j                  |j                  j                  |gz   |j                  j                  |gz                nW|j                  j	                  t        j                  |j                  j                  |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"        $ r5}t%        j&                  t)        j*                  | |      |       Y d }~y d }~ww xY w)Nenclosing_lateralTr  r   )from_linterlateral_from_linterr   )r	   is_comparisonr  r   r;  r~  productrH   _from_objectsr^   ansi_bind_rulesr6  r   BindParameterr,  r9  rB  r0  r   r   r   r   )r   r   r<  eager_groupingro  rp  r"  rn  r(  r  opstringr   s               r   r=  zSQLCompiler.visit_binary  s    9226??C".$&':$;!#))00%%115F4GG226G5HH !!((%%116<<3M3M   6;;(>(>?6<<)?)?@$(B !%8	**9hE	0R00$Y/ 5t44 !,(;	
    33D)D$' s   )	F	 		G+GGc                 <     | j                   |j                  fi |S r   )r   sql_functionr6  s       r   &visit_function_as_comparison_op_binaryz2SQLCompiler.visit_function_as_comparison_op_binary  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   rp  r   rH   r^   r?  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 )Nrv  r  )rv  rB  rO  rw  r6  s       r   visit_custom_op_binaryz"SQLCompiler.visit_custom_op_binary	  sS    '66,t,,$,,X->->??#E
 
 	
r   c                 b     | j                   || j                  |j                        dz   fi |S r  )r0  rO  rw  r6  s       r   visit_custom_op_unary_operatorz*SQLCompiler.visit_custom_op_unary_operator		  s:    4t44T//0A0ABSH
LN
 	
r   c                 b     | j                   |d| j                  |j                        z   fi |S r  )r1  rO  rw  r6  s       r   visit_custom_op_unary_modifierz*SQLCompiler.visit_custom_op_unary_modifier	  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 )N
_in_binaryFT
_binary_oprv  r  )r  r  rH   r  r^   )r   r   rw  rv  r"  r  rs  s          r   rB  z$SQLCompiler._generate_generic_binary	  s     VVL%0
<!??<*FKK**%379  .fll--%379	 	 .D=Dr   c                 B    | |j                   j                  | fi |z   S r   r  r   r.  rw  r"  s       r   r0  z,SQLCompiler._generate_generic_unary_operator)	  s$    :%--::4F2FFFr   c                 B     |j                   j                  | fi ||z   S r   r  r  s       r   r1  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                     |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_binary3	  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_binary9	  sQ    ,,~~fll3::7C,t,,VXDDDr   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_binaryE	  sH    ,,''5,t,,VXDDDr   c                     |j                         }| j                  }|j                  |j                        |_         | j                  ||fi |S r   r  r  s        r   visit_endswith_op_binaryz$SQLCompiler.visit_endswith_op_binaryK	  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_binaryQ	  sF    ,,~~fll3,t,,VXDDDr   c                    |j                   j                  dd       } |j                  j                  | fi |d |j                  j                  | fi ||r%d| j                  |t        j                        z   z   S dz   S )Nescapez LIKE  ESCAPE r	  	modifiersr  rH   r  r^   r  r   r  r   r   r  r"  r  s        r   r  z SQLCompiler.visit_like_op_binaryW	  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 ||r%d| j                  |t        j                        z   z   S dz   S )Nr  z
 NOT LIKE r  r	  r  r  s        r   r  z$SQLCompiler.visit_not_like_op_binaryd	  s    !!%%h5*FKK**4626+FLL++D7B7

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

  2268;N;NOO	
 	
 
 	
r   c                    |j                   j                  dd       }d |j                  j                  | fi |d |j                  j                  | fi |d|r%d| j                  |t        j                        z   z   S dz   S )Nr  r  z) NOT LIKE lower(r  r  r	  r  r  s        r   visit_not_ilike_op_binaryz%SQLCompiler.visit_not_ilike_op_binaryz	  r  r   c                 j    |j                   j                  dd      } | j                  ||rdndfi |S )Nrd   Fz BETWEEN SYMMETRIC z	 BETWEEN r  r  rB  r   r   r  r"  rd   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 )Nrd   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r   r  r   r(  r?  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  r?  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  r?  s       r   visit_regexp_replace_op_binaryz*SQLCompiler.visit_regexp_replace_op_binary	  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 r| 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*                  r0t'        j(                  d|j,                  d|j,                  d      |x| j                  |j,                  <   | j                  |<   | j.                  }|rC|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                  d|}|j                  rd|z  }|S )NT)skip_bind_expressionr!  literal_bindsr  render_postcompilez&^(.*)\(__\[POSTCOMPILE_(\S+?)\]\)(.*)$rW  z(__[POSTCOMPILE_r   r  r   z~~REPL~~r   z~~]))r!  rc  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.z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)r   r  r   ra  bind_expressionr   r  r  matchr<   r  r  rt  _truncate_bindparamr>  rk   r.  intersection_cloned_setr   r  _is_crudr9  r:  r  
isoutparamhas_out_parametersrV  r  r  rz  )r   r  r!  r  r  r  r  r  implr  wrappedr{  r  r  r(  existingrY  bpcbs                      r   visit_bindparamzSQLCompiler.visit_bindparam	  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+>+>>** :>@  &&)*<*<** %==)--9  8A@

9==!DJJt$4 ))++ /66T>bffBHOOI./
 &*D#!+/(++	{:+((YK7(#d##
%))
 	
 3,C
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')rc  )r   r  r  r  r	   is_is_notr   warn_limitedr9  r   r   r  r  r  rg  r  r   )
r   r  r  rc  r"  r  opr  r  r  s
             r   r  z$SQLCompiler.render_literal_bindparam5
  s      v-(E&9+=+=+EVVL$/"Y]]I4D4D$EE%%@ #(	 $t||H$5$5<<<--EJJD*.)A+'I'
 $#,,UINNCCr   c           
      ^   |j                  | j                        }|r		  ||      S t        j                  dt        j                  |      d|      # t        $ rN}t        j                  t        j                  dt        j                  |      d|d      |       Y d}~y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.

        z Could not render literal value "z" with datatype z); see parent stack trace for more detail.r   Nz:No literal value renderer is available for literal value ")	_cached_literal_processorr   	Exceptionr   r   r   r  sql_util_repr_single_value)r   r  r!  	processores        r   r  z SQLCompiler.render_literal_valueV
  s     33DLLA	 ''$ "" ..u5u> #  $$ %77>!
  s   A 	B,AB''B,c                     || j                   v r| j                   |   S |j                  }t        |t        j                        r| j                  d|      }|| j                   |<   |S )Nr  )r@  r9  r6  r   r7  r8  )r   r  	bind_names      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  r   )rK  	apply_maprJ  r  rH  r  maxhex)r   ident_classr(  anonnamecounter	truncnames         r   r8  z!SQLCompiler._truncated_identifier
  s    $"6"66''d(;<<>>$--0x=4,,q00**..{A>GS!2!2Q!6:;g,qr"# 
 18!D  - I4=k401r   c                      || j                   z  S r   rJ  r   r(  s     r   
_anonymizezSQLCompiler._anonymize
  s    dmm##r   c                    | j                   rQ||j                  |       n| j                  j                  |       t        | j                        | j
                  |<   |s0t        j                  |      rt        j                  d |      }|}|}|r"| j                  si | _	        || j                  |<   |rd|z  S | j                  d|iz  S )Nc                 2    t         | j                  d         S Nr   )_BIND_TRANSLATE_CHARSr<   r~  s    r   r}  z.SQLCompiler.bindparam_string.<locals>.<lambda>
  s    3AGGAJ? r   z__[POSTCOMPILE_%s]r(  )rA  r  r   r  r   rB  _BIND_TRANSLATE_RErb  r  r  rF  )r   r(  positional_namesr  r  escaped_fromr"  new_names           r   rz  zSQLCompiler.bindparam_string
  s     ??+ ''-  ''-+.tzz?D""4(!((. .11?  $***,'48D##L1'$..$$~55r   c                 
     j                          ||d<   |j                  }t        |t        j                        r j                  d|      }d}	d}
|j                         }| j                  v r j                  |   \  }}||k(  s%J |j                  rt         j                        nd}||f}| j                  v r j                  |   }||u }
||j                  u s||u rd}	n}||j                  u r+ j                  |= |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                  |<   | j                  |<   d|j&                  j(                  v rGd j*                  vr9 j*                  j-                  d|j&                  j(                  d   i       _         j.                  r| j0                  |<   | j                  vr  j2                  |fi | |s| j                  vr|j4                  rd _         j8                  j;                  ||      }|j4                  rt        |j&                  t<        j>                        r|j&                  }nEt        |j&                  t<        j@                        r|j&                  jB                  d   }nJ d	       |jE                  d      D cg c]  \  }}}}}|s|xs | }}}}}}|d
djG                   fd|D              z  z  } j.                  rg x|d<    jH                  |<   |jK                  dd      du sJ  j                  s |j&                  jL                   fd|i|S   jN                  ||jP                  fi |} |j&                  jL                   fddi|}|d|d|dz  }|jR                  r$|d  jN                  ||jR                  fi |z   z  }| j                  |<   |r|r||jT                  |<   |	s|
r j8                  j;                  ||      S |rh j8                  j;                  ||      } j8                  jW                  |      r j8                  jY                  |      }| j[                  |      z  }|S  j8                  j;                  ||      S y c c}}}}}w )Nr  rL  TFr   z5Multiple, unrelated CTEs found with the same name: %r
autocommitr   z%cte should only be against SelectBaser  r}   c              3   l   K   | ]+  }j                   j                  |j                          - yw)r  N)r   format_label_namerJ  )r   identr   s     r   r   z(SQLCompiler.visit_cte.<locals>.<genexpr>L  s8      " !& !MM;; % < "s   14r  subqueryr  r   z
(r  r  ).ro  r(  r6  r   r7  r8  _get_reference_cteri  nestingr  r   rh  	_restatesrG  _is_clone_ofcomparer   r  
_cte_aliasr   r   r   rj   rA  rl  	visit_cte	recursiverj  r   format_aliasr   SelectCompoundSelectr  _generate_columns_plus_namesrF   rk  r  r  _generate_prefixes	_prefixes	_suffixesr   _requires_quotesrP  get_render_as_alias_suffix)r   r  r  ashint	fromhintsr  ro  r  cte_name
is_new_cteembedded_in_current_named_cte_reference_cterl  r  cte_level_nameexisting_cteexisting_cte_reference_ctepre_alias_ctecte_pre_alias_namers  
col_source
proxy_namefallback_label_namer  repeated
recur_colsprefixesrA   s   `                           r   r  zSQLCompiler.visit_cte
  sU    	!$~88h 9 9:11'8DH
(-%//1T33311.ALIq= =+.;;DJJAI#X.T44422>BL,8L,H) l,,,|0C"
. IIl+-9-L-L-N* **+EF $$0#00<kk,/!&J**,.67 
 j>>%NNM!$!4!4,h.G.GH%)%?%?/&"  M!%69D##N35CD"">2  > >> (>(>>)-)?)?)E)E$ckk&D&D('*& &/s#DII-}77%#TYY*>==*.D'}}11#x@==!#++z/@/@A%([[
#CKK1J1JK%([[%8%8%;
M&MMu" )EEdK" "&/$' ,9z9"J "  F		 " *4	"  D ??LNNF-.1D1DS1I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 "&		#)1!!#&"?}}11#x@@!}}11#7IJ==11(;#}}228<H77AA}}11#x@@ m"s   T<c                     |j                   rd |d<   |j                  r | j                  |fi |S  | j                  |fi |S )Nro  )joins_implicitly_is_lateralvisit_lateralvisit_aliasr^  s      r   visit_table_valued_aliasz$SQLCompiler.visit_table_valued_alias  sN    ## $B}%4%%g444#4##G2r22r   c                 (     | j                   |fi |S r   )rZ  r^  s      r   visit_table_valued_columnz%SQLCompiler.visit_table_valued_column  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                   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 )Nrn  rp  )r  r  iscrudr  lateralenclosing_aliasr  r  r)  rL  T)r  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   rP  r(  _render_derived_w_typesr   rh  r   r   )r   r+  rL  r  r   s     r   r   z*SQLCompiler.visit_alias.<locals>.<genexpr>  s{         !MM//9
  %<<	 "@dll88@@ #,2
 "$$	s   A3A6r(  )r   r   r  r6  r(  r   r7  r8  r   r  r   r  _supports_derived_columns_render_derivedrF   r  format_from_hint_text)r   rL  r  r  r'  r  r  r(  r)  ro  r  rA   
alias_namer  s   ``        `   r   r"  zSQLCompiler.visit_alias  s-    "&0 ((((.3*+
 )7'610;,-&?+B+Be+K4EMM44	# %	 	E Vw"')L:??Of%67V%**h&?&?@!77L
"ZZ
==--eZ@@+5!!%(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 )NTr  r"  )r   r  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 %sr2  )r   lateral_r"  s      r   r!  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 )Nr  Tz TABLESAMPLE z REPEATABLE (%s))r"  _get_methodr  seed)r   tablesampler  r"  rs  s        r   visit_tablesamplezSQLCompiler.visit_tablesample  s    D[<<<8K##%88DD

 '&3  33D?B? D r   c           
      J    j                  dj                         ddj                   fdj                  D              z  }t	        j
                  t        j                        r j                  dj
                        }nj
                  }j                  rd}nd}|rz|r||nd|j                  <   |r[|d	|d
 j                   j                  j                  |            ddj                   fdj                  D              d
}|S |d	|d
}|S )Nr  z	VALUES %sr}   c           	   3      K   | ]I  }|D ]B  } j                   t        j                  |d j                  ij	                         fi  D K yw)r  N)r   r   Tuple_column_typesr1  )r   chunkr   r   r"  r   s      r   r   z+SQLCompiler.visit_values.<locals>.<genexpr>  sk      	$
 	$
  DLL26!//*, 		$
	$
s   AAr  zLATERAL r	  z(unnamed VALUES element)r  r   (c              3   H   K   | ]  } |j                   fd di  yw)rT  FNr  r  s     r   r   z+SQLCompiler.visit_values.<locals>.<genexpr>'  s;      " !" 1A00 $49=?"r   )
setdefaultr  rF   _datar6  r(  r   r7  r8  r   r   r  r   rP  columns)r   r   r  ro  r"  vr(  r(  s   ``  `   r   visit_valueszSQLCompiler.visit_values  s   
ow'<'<=$)) 	$
 !	$
 	
 	
 gllH$=$=>--hED<<D GG ,D2L !!'* 33DMM4G4G4MN		 " &-__	"   !(+r   c                     d|z   S )Nr   r   )r   alias_name_texts     r   r  z&SQLCompiler.get_render_as_alias_suffix3  s    ''r   c                     ||dk(  rd| _         d| _        |j                  rt        j                  d      | j
                  j                  ||||f       y )N*FTzxMost backends don't support SELECTing from a tuple() object.  If this is an ORM query, consider using the Bundle object.)rr  _ad_hoc_textualr  r   r  r  r  )r   keynamer(  objectsr!  s        r   r  zSQLCompiler._add_to_result_map6  s]    ?gn$)D!#'D ""4 
 	##WdGU$CDr   c                 8     | j                   d|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

        NTF)_label_select_column)r   stmtr$   column_clause_argsr"  s        r   _label_returning_columnz#SQLCompiler._label_returning_columnB  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                      | |d|       y Nr   r   )rL  r(  rM  r!  r  s       r   r<  z;SQLCompiler._label_select_column.<locals>.add_to_result_map|  s    &wb%@r   c                 $     | |f|z   |       y r   r   )rL  r(  rM  r!  r  r$   s       r   r<  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 passedTFr  )r   r  r   _has_column_expressioncolumn_expressionr  r6  r   Labelr&  r(  r   rN  ColumnClauserM  re   
TextClauseUnaryExpressionwraps_column_expressionNamedColumn_non_anon_label_anon_name_labelr7  r;  r  )r   r_   r$   r  r  rQ  r(  r  r  r!  column_is_repeatedneed_column_expressionsr  col_exprr<  result_exprrender_with_labelr  s     `              @r   rO  z SQLCompiler._label_select_columnW  sc    {{''5&&#':--f5HH
 !% 7 7
 "%6"A
 '%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   sqltextre   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   re   rs  s      r   rg  zSQLCompiler.get_from_hint_text  rn  r   c                      y r   r   rp  s      r   get_crud_hint_textzSQLCompiler.get_crud_hint_text  rn  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  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  r  _get_display_froms
difference)r   select_stmtr  r(  r"  r  ru  r  r  r  r   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   c	                   & |J d       d|	d<    |j                   || fi |	}
|
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                  D ]  } |j                  | fi |	  |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-        &fd| D              |!f! c}!} }}| _        | j/                  |||
|||||	      }|j0                  rQ|j0                  D "#cg c]!  \  }"}#|"d| j2                  j4                  fv r|## }$}"}#|$r|d| j7                  |$      z   z  }| j8                  rB|r|r>|st;        | j                        nd }%| j=                  |%|	j                  d            |z   }|j>                  r$|d | j                  ||j>                  fi |	z   z  }| j                  jA                  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  r[  r  rq  r<  )r5  r!  zSELECT r  )r(  r  r  ra  rb  c              3   B   K   | ]  }j                  ||        y wr   )r  )r   o	translates     r   r   z+SQLCompiler.visit_select.<locals>.<genexpr>  s     !C!)--1"5!Cs   rJ  r  r  )!r  r   r   r  translate_select_structurer  r  _setup_select_stackcopyr;  _hints_setup_select_hintsr  r  r	  r  get_select_precolumnscolumns_plus_namesrO  r  r  r  r  _compose_select_body_statement_hintsr   r(  ru  rG  r  r  r
  r   )'r   r|  r  insert_intor  r  select_wraps_forr(  ro  r  r  r  is_embedded_selectnew_select_stmtcompile_state_wraps_forru  r  rb  r   rQ  rs  	hint_textbyfromr  r(  r  r  r$   r  r  inner_columnsr9  r  r!  dialect_namehtper_dialectr  r  s'                                         @r   visit_selectzSQLCompiler.visit_select3  s     ' 	
-	
' +0&':::
!'
 $--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(("44 7&&&t6v67   +D++[226< D 	***;A&AA. #55' '# ))'&)(;'/,C * 
* }- 
 
4 #3#?  +==	 	&/ $ 	$ 5GG	 	&/ $ 	I6 .2-A-A$ $)CsE dE!Cs!CCUK$D 
 ((	
 '' +6*F*F&\2C):):#;; K 
 d::;GGG 990H3;C

OM''"/!'N!; (  	    C1$11[226<  D 	

rA
@		$"s$   )(OO%O*.O3$O<
?&Pc                    t        |j                  j                         D cg c]<  \  \  }}}|d| j                  j                  fv r||d|j                  | d      iz  f> c}}}      }| j                  |      }||fS c c}}}w )NrJ  r(  T)r  )r  r  r  r   r(  r  rm  )r   r_   r   r   rj  r  r  s          r   r  zSQLCompiler._setup_select_hints  s     39--2E2E2G  /$UGhsDLL$5$566 u77T7JKL

 --f5	&  s   AB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                  |       }|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   rw  )r  r  r   r  )r  _all_selected_columnsr  r   r  rz  r{  ra   r   rs  rj   r   r  )r   r_   r  ru  r  r(  r  r  r  r  numcolsr   new_correlate_fromsall_correlate_fromsr  s                  r   r  zSQLCompiler._setup_select_stack  sA      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
 "*":":E"BC177H 02 *	
	 	

)$r   c	                     |dj                  |      z  }| j                  t        z  r1t        i t	                     }	| j                  t
        z  }
|r|	| _        nd }	d}
|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                  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)r  r  ro  r  ro  ro  z 
WHERE z	 
HAVING )rF   r=  r   r   ra   r   ro  r  r  r  _where_criteriar  r   _group_by_clausesr  _having_criteria_order_by_clausesr  r  r  _for_update_argfor_update_clause)r   rs  r_   r  r  r   r  r  r  ro  warn_lintingfts                r   r  z SQLCompiler._compose_select_bodyD  sl    			-((<<44$R/K<<,6L#. K L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o	s    G6
8G;
c                 N     dj                   fd|D              }|r|dz  }|S )Nr  c              3      K   | ]5  \  }}||j                   j                  k(  r |j                  fi  7 y wr   )r   r(  r  )r   prefixr  r"  r   s      r   r   z1SQLCompiler._generate_prefixes.<locals>.<genexpr>  sF      
$#|t||7H7H'H &F%%d1b1
s   ;>r  )r   rP  r  r"  r  s   `  ` r   r  zSQLCompiler._generate_prefixes  s1     
(0
 

 cMFr   c                 >     j                   sy|r|dkD  rt        j                         }t         j                   j	                               D ]V  } j
                  |j                            \  }}||k(  xs |xr ||dz   k(  }|j                  r|sE j                   |   ||<   X n j                   }|syt        |D cg c]  }|j                   c}      }	 j                  rg j                  |   j                  |       |G j                  r; j                  J  fd fd d      }
  j                  |
|       _         j                  |	      dz   }|dj                  |j!                         D cg c]  }| c}      z  }|dz  }|rz|dkD  rut        |j	                               D ]Y  } 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   Nc                 ^   | j                   v rj                   j                  |       }t        t        j                  j                  fd|D                    }| j                  v r' j                  |    |j                  |d            S |S j                  j                  | g       S )Nc              3   .   K   | ]  } |        y wr   r   )r   	child_cteget_nested_positionals     r   r   zPSQLCompiler._render_cte_clause.<locals>.get_nested_positional.<locals>.<genexpr>  s      :$- !6i @:r  r   )	rn  r   r`  r~  chainfrom_iterablerk  rl  r  )r  childrento_addr  reorder_positionalr   s      r   r  z=SQLCompiler._render_cte_clause.<locals>.get_nested_positional  s    dnn,#'>>#5#5c#:!%%OO99 :19: " $"5"55#5 $ 3 3C 8 & $x{ ;$  $*M#2266sB??r   c                     |s|| z   S d}t        t        |             D ]  \  }}j                  |   |k  s n | d |  |z   | | d  z   S r  )r  reversedrB  )posr  levelr   r(  r   s        r   r  z:SQLCompiler._render_cte_clause.<locals>.reorder_positional  si     %|+E'0#'? "t11$7%?!" w<&03vw<??r   r  , 
z
 )rG  r   rg  r`  keysri  r  r  r   r  rA  rn  r  r   get_cte_preamblerF   r  rh  )r   r  r  r  rG  r  rl  r  is_rendered_levelrj  r  cte_texttxtr  r  s   `            @@r   r  zSQLCompiler._render_cte_clause  s    yy]Q.##%DDIINN,- 
+&*&<&<**,'#	8 %.$> %+N	]Q=N0N " (9 IIcNS	
+ 99Dt<cmm<=??NN<(//5#''333@(@ /t4#5$$fm$  ((83>FKK > >??E]Q.DIIK( E&*&<&<**,'#	8 IIcN++Y,AB**3+A+A+CDE o =V !?s   H 	H
c                 
    |ryy)NzWITH RECURSIVEWITHr   )r   r  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  r9  r	   comma_op)r   r_   r"  group_bys       r   r  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  r9  r	   r  )r   r_   r"  r  s       r   r  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                 ,    t        j                  d      )Nz@RETURNING is not supported by this dialect's statement compiler.rC  )r   rP  returning_colss      r   returning_clausezSQLCompiler.returning_clause-  s    ,
 	
r   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"  rs  s       r   r%  zSQLCompiler.limit_clause3  s    +K,$,,v/C/C"Jr"JJJD  ,##+%Jf.C.C!Jr!JJJDr   c                    d}|j                   #|d | j                  |j                   fi |z  z  }|j                  J|d | j                  |j                  fi ||j                  d   rdndd|j                  d   rdnd	z  }|S )
Nr	  z
 OFFSET %s ROWSz
 FETCH FIRST r  z PERCENTz ROWS 	with_tiesz	WITH TIESONLY)r  r   r#  _fetch_clause_optionsr  s       r   r$  zSQLCompiler.fetch_clause=  s      ,',$,,%%+)++  D +V118R8$::9E
2M//<  D r   c                    |r|j                   |j                  |<   |s|r| j                  j                  |      }	|rG|	rE| j                  j	                  |	      dz   | j                  j                  |j                        z   }
n%| j                  j                  |j                        }
|r||v r| j                  |
|||   |      }
|
S y)NrK  r	  )fullnamer   r   rR  rS  rP  r(  r/  )r   re   r  r'  r  r  
use_schemaro  r  rW  r  s              r   visit_tablezSQLCompiler.visit_tableM  s     ',~~Ke$V#}}>>uE.MM../?@mm))%**56  mm))%**5Ui/00	% 0& Jr   c                    |rW|j                   j                  t        j                  |j                  j
                  |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 ro  )r   r;  r~  rr  rH   rs  r^   r:   isouterr  onclause)r   rF   r  ro  r  	join_types         r   
visit_joinzSQLCompiler.visit_joinn  s    $$!!II++TZZ-E-E 99+I\\+I I(DII((!{>D  ,djj++!{>D	  /dmm.."-17	
r   c           
      8   t        |j                  j                         D cg c]&  \  \  }}}|d| j                  j                  fv r||f( c}}}      }|j
                  |v r+| j                  ||j
                  ||j
                     d      }||fS c c}}}w )NrJ  T)r  r  r  r   r(  re   r/  )r   rP  
table_textre   r   r  dialect_hintss          r   _setup_crud_hintszSQLCompiler._setup_crud_hints  s     48;;3D3D3F /$UGisDLL$5$566 	"
 ::&33DJJdjj(A4J j((s   +Bc                 <	    |j                   || fi |}|j                  }| j                   }|r-d| _        | j                  s|| _        | j
                  s|| _        | j                  j                  t               t               |d       t        j                  | ||fi |}|sn| j                  j                  sX| j                  j                  sB| j                  j                  s,t        j                  d| j                  j                   z        |j"                  rH| j                  j$                  s,t        j                  d| j                  j                   z        |d   }n|}| j&                  }| j                  j                  }d}	|j(                  r!|	 | j*                  ||j(                  fi |z  }	|	dz  }	|j-                  |j.                        }
|j0                  r| j3                  ||
      \  }}
|j4                  r$|j4                  D ]  } |j6                  | fi |  |	|
z  }	|s|s-|	dd	j9                  |D cg c]  \  }}}|
 c}}}      z  z  }	| j:                  s|j<                  r?| j?                  || j:                  xs |j<                        }| j@                  r|	d
|z   z  }	nd }|jB                   | jD                  | j                  d   d   fddi|}| jF                  r[| j                  jH                  rE|stK        | j                        nd }|	d
| jM                  |d|jO                  d            |z  }	nv|	d|z  z  }	nm|s|r|	dz  }	nc|j"                  r|	dd	j9                  d |D              z  z  }	n8d	j9                  |D cg c]  \  }}}|
 c}}}      }|	d|z  z  }	|r|| _(        |jR                  ' | jD                  |jR                  fi |}|r|	d
|z   z  }	|r| j@                  s|	d
|z   z  }	| jF                  rU| j                  jH                  s?|stK        | j                        nd }| jM                  |d|jO                  d            |	z   }	| j                  jU                  d       |	S c c}}}w c c}}}w )NTr  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.r   zINSERT zINTO  (%s)r}   r  r[  insert_from_selectr  r  r  r+  z DEFAULT VALUESz
 VALUES %sc              3   R   K   | ]  }d dj                  d |D              z   ! yw)r  r}   c              3   (   K   | ]
  \  }}}|  y wr   r   r   r  r  r  s       r   r   z5SQLCompiler.visit_insert.<locals>.<genexpr>.<genexpr>	  s      L>1dE Ls   Nr  )r   crud_param_sets     r   r   z+SQLCompiler.visit_insert.<locals>.<genexpr>  s2       ' yy L^ LLNs   %'z VALUES (%s))+r  r   r   rL  r  r  r  ra   r   _get_crud_paramsr   supports_default_valuessupports_default_metavaluesupports_empty_insertr   r  r(  _has_multi_parameterssupports_multivalues_insertr   r	  r  format_tablere   r  r  r  r  rF   rP  rO  r  returning_precedes_valuesr_   r   rG  cte_follows_insertr  r  r  insert_single_values_expr_post_values_clauser   )r   insert_stmtr"  r  r  crud_paramscrud_params_singler   r  rs  r  r  r  r  r  r  r  select_textr  r  post_values_clauses                        r   visit_insertzSQLCompiler.visit_insert  s   :::
!#
 $--zz> DM)))6&%%%2"

#&5 #)	
 +++}
02

 LL88LL;;LL66""!\\../  ..<<;;&&137<<3D3DE 
 "-Q!,=="&,,"F"F  +D++[2268 D 	**;+<+<=
 22;
KMAz(("44 3&&&t2r23 	
%<Gdii,>??.!T5?  D >>[33#44T^^E{/E/E  --...#)&$,,

234BFJLK yyT\\<<7?DJJT++&304%'VVN%; , 
    ++!8%%D00L		  +6  D )-		-899>1dE9)% N%>>>D1J.**6!-//"35" "000D$B$BC***D99T\\<<3;C

OM''"/,0!#!7 ( 
   	

rQ @V :s   R"Rc                      y)z3Provide a hook for MySQL to add LIMIT to the UPDATENr   )r   update_stmts     r   update_limit_clausezSQLCompiler.update_limit_clause.  s    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.

        Tr  r'  r  )r   r  
from_tableextra_fromsr"  s        r   update_tables_clausez SQLCompiler.update_tables_clause2  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                  }| j                   }|r-d| _        | j                  s|| _        | j
                  s|| _        |j                  }t        |      }|rNt        t        j                  |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i |}t#        j$                  | ||fi |}|j&                  r| j)                  ||      \  }}nd }|j*                  r$|j*                  D ]  } |j,                  | fi |  ||z  }|dz  }|dj/                  d |D              z  }| j0                  s|j2                  r<| j4                  r0|d| j7                  || j0                  xs |j2                        z   z  }|r* | j8                  ||j                  |	|fi |}|r|d|z   z  }|j:                  r' | j<                  |j:                  fi |}|r|d|z   z  }| j?                  |      }|r|d|z   z  }| j0                  s|j2                  r<| j4                  s0|d| j7                  || j0                  xs |j2                        z   z  }| j@                  r>|stC        | j                        nd }| jE                  ||jG                  d	      
      |z   }| j                  jI                  d       |S c c}w )NTr  zUPDATE z SET r}   c              3   4   K   | ]  \  }}}|d z   |z     yw)=Nr   r  s       r   r   z+SQLCompiler.visit_update.<locals>.<genexpr>  s     OD%$*u,Os   r   WHERE r  r  r[  )%r  r   r   rM  r  r  _extra_fromsr  ra   r   rs  re   rj   r  r	  r  r  r   r  r  r  r  r  rF   rP  rO  r  r  r  r  r  r   rG  r  r  r  r   )r   r  r"  r  r  r  is_multitable
main_fromsr  render_extra_fromsr  rs  r  r  r  r  extra_from_textr  r%  r  s                       r   visit_updatezSQLCompiler.visit_updateJ  s   :::
!#
 $--zz> DM)))6&%%%2"#00[)Z55k6G6GHIJ&"!:*=" " )..{;O!#*001O

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

 +++}
02
 (,(>(>Z)%M: !M(("44 3&&&t2r23 	
		O;OOO>>[33--d33!I;3I3I   5d55!!"	
 O o--&&111++/1A 	A%//<C,&&D NNk4400C$//T^^E{/E/E  D 993;C

OM''"/!#!7 (  	  	

r{"s   "	M,M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                  | dd      S )NT)r  r'  r  )r   delete_stmtr  r  s       r   delete_table_clausezSQLCompiler.delete_table_clause  s    ,,T$t,LLr   c                     |j                   || fi |}|j                  }| j                   }|r-d| _        | j                  s|| _        | j
                  s|| _        |j                  }|j                  hj                  |      }| j                  j                  |||d       d}|j                  r!| | j                  ||j                  fi |z  }|dz  }| j                  ||j                  |      }|j                  r| j                  ||      \  }	}nd }	|j                  r$|j                  D ]  }
 |
j                   | fi |  ||z  }|j"                  r.| j$                  r"|d| j'                  ||j"                        z   z  }|r* | j(                  ||j                  ||	fi |}|r|d|z   z  }|j*                  r' | j,                  |j*                  fi |}|r|d|z   z  }|j"                  r.| j$                  s"|d| j'                  ||j"                        z   z  }| j.                  r>|st1        | j                        nd }| j3                  ||j5                  d            |z   }| j                  j7                  d	       |S )
NTr  zDELETE FROM r  r  r  r  r[  )r  r   r   rN  r  r  r  re   rj   r  r	  r  r  r  r  r  r  rO  r  r  r  r  r  rG  r  r  r  r   )r   r  r"  r  r  r  r  rs  r  r  r  r  r  r  s                 r   visit_deletezSQLCompiler.visit_delete  s   :::
!#
 $--zz> DM)))6&%%%2"#00&,,-33K@

#2 /)	
   +D++[2268 D 	--**K

 (,(>(>Z)%M: !M(("44 3&&&t2r23 	
!!--d33!7!7   ;d;;!!	
 O o--&&111++/1A 	A%!!$*H*HC$//[33  D 993;C

OM''"/!#!7 (  	  	

rr   c                 >    d| j                   j                  |      z  S )NzSAVEPOINT %sr   format_savepointr   savepoint_stmts     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_savepoint0  s#    )DMM,J,J-
 
 	
r   c                 >    d| j                   j                  |      z  S )NzRELEASE SAVEPOINT %sr  r  s     r   visit_release_savepointz#SQLCompiler.visit_release_savepoint5  s#    %(F(F)
 
 	
r   )NNTNTr   )NFF)NFFNr   )NTr   r   )FNrU  )NFNN)FFFFF)NFFN)FFNNN)FFFNFFNN)NNNTFF)FFNNNFN)NFN)FFFNTN)r   r   r   r  EXTRACT_MAPr  COMPOUND_KEYWORDSr  rN  rL  rM  r  rP  r  'render_table_with_column_in_update_fromrt  r  rK  rr  r  rD  rV  r  r  r  r  r   r  r  r  ra  rb  postfetch_lastrowidr:  r  compiler  r   rB  rR  r   r   r  r^  rc  memoized_propertyre  memoized_instancemethodro  
contextlibcontextmanagerrv  rU  r  r  r  r  r  r   rW  preload_moduler  r  r  r  r  r  r  r+  r2  rA  rE  rI  rZ  r_  rc  re  rj  rt  rO  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  r7  r:  r@  rC  rO  rM  rg  r  r=  rz  r|  r~  r  r  rB  r0  r1  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r8  r  rz  r  r#  r%  r"  r3  r!  r:  rF  r  r  rR  rO  r/  rm  rg  rr  ru  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   r5  r5  8  s    K)%**H*x(
 KI
 !& /4+
 O  % O  #( N  
 !% '[
 $+
 
  )+*Oo% ! 'BJJ'LMK F mJ^ # #J A A 
  
!!; ";0  .
 

 
,#  
 !qf 
!!04@ "@D 
3 
3 /4l\ T34
 5
 
  
T34( 5 (T 
T34 5 8OO .3$
N .3B !#"/b

/ -O^AI



4 05:x
$@L&K

.
:


7
$L8
C 04AF3- AC%NBB


4$
 ;?L*\81z  4l8



 05,GG 
I IAEAEAE
	
	
	





 $" Nf $!%	DB$L&$ $6R zAx30 aF0?-^(
E 04
8  "  %`JD$ .4--
Y[	)NIK+HI
 ,1: "& L\!2hRh  %	Yv7 	

& B
:)SjF
qf
 M[zO


r   r5  c                        e Zd ZdZd Z ej                  d       f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 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   rD  s     r   rE  z$StrSQLCompiler._fallback_column_nameO  s    r   zsqlalchemy.engine.urlc                 T   |j                   dk7  rt        j                  j                  } |j                  j                  |j                         j                                }|j                  |d       }t        |t              s|j                  |      S t        t        | 3  ||      S )Nr-   )stringify_dialectr   r  
engine_urlURLr&   get_dialectstatement_compilerr6  r1  r   superr   )r   r   r   r"  urlr   compilerr  s          r   r   z,StrSQLCompiler.visit_unsupported_compilationR  s    $$	1..++CMcggnnW%>%>?KKMOG11'4@Hh7''00^THS
 	
r   c                 ~     | j                   |j                  fi |d | j                   |j                  fi |dS )N[])r   rH   r^   r?  s       r   visit_getitem_binaryz#StrSQLCompiler.visit_getitem_binary`  s:    DLL++DLL,,
 	
r   c                 *     | j                   ||fi |S r   r?  r?  s       r   visit_json_getitem_op_binaryz+StrSQLCompiler.visit_json_getitem_op_binaryf      (t((@R@@r   c                 *     | j                   ||fi |S r   rA  r?  s       r   !visit_json_path_getitem_op_binaryz0StrSQLCompiler.visit_json_path_getitem_op_binaryi  rC  r   c                 >    d| j                   j                  |      z  S )Nz<next sequence value: %s>)r   format_sequence)r   seqr"  s      r   r	  zStrSQLCompiler.visit_sequencel  s    *T]]-J-J3-OOOr   c                     t        j                  |      D cg c]#  }| j                  d |ddi |j                        % }}ddj	                  |      z   S c c}w )NTF)r  z
RETURNING r}   )r   _select_iterablesrO  r_  rF   )r   rP  r  r  rD  s        r   r  zStrSQLCompiler.returning_clauseo  sl    
 ++N;	
  %%auba>O>O & 
 
 dii000
s   (Ac                 P     dd<   ddj                   fd|D              z   S )NTr  r  r}   c              3   H   K   | ]  } |j                   fd i  ywr  Nr  r   r  r  r"  r   s     r   r   z4StrSQLCompiler.update_from_clause.<locals>.<genexpr>}  s0      #
 !A  BBrB#
r   r  r  s   `   ``r   r  z!StrSQLCompiler.update_from_clausey  s3     8 #
 #
 
 
 	
r   c                 P     dd<   ddj                   fd|D              z   S )NTr  r}   c              3   H   K   | ]  } |j                   fd i  ywrM  r  rN  s     r   r   z:StrSQLCompiler.delete_extra_from_clause.<locals>.<genexpr>  s0       
 !A  BBrB 
r   r  r  s   `   ``r   r  z'StrSQLCompiler.delete_extra_from_clause  s3     8dii  
  
 
 
 	
r   c                      y)NzSELECT 1 WHERE 1!=1r   )r   r!  s     r   rM  z#StrSQLCompiler.visit_empty_set_expr  s    $r   c                     d|z  S )Nz[%s]r   rp  s      r   rg  z!StrSQLCompiler.get_from_hint_text  s    }r   c                 *     | j                   |dfi |S )Nz
 <regexp> rB  r?  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> rT  r?  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  )rH   r  r^   r?  s       r   r  z-StrSQLCompiler.visit_regexp_replace_op_binary  s>    *FKK**4626+FLL++D7B7
 	
r   )r   r   r   r  rE  r   r/  r   r?  rB  rE  r	  r  r  r  rM  rg  r  r  r  __classcell__)r  s   @r   r1  r1  ;  sp    &  T01
 2

AAP1

%IM
r   r1  c                   J   e Zd Zej                  d        Zej                  d        Z	 d*dZd Zd Z	d Z
d Zd+d	Z	 d,d
Zd Zd Zd Z	 d-dZd Zd+dZd Z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"d  Z#d! Z$d" Z%d# Z&d$ Z'd% Z(d& Z)d' Z*d( Z+d) Z,y).DDLCompilerc                 f    | j                   j                  | j                   d | j                        S )N)r   )r   r8  r   r  s    r   r  zDDLCompiler.sql_compiler  s/    ||..LL$T5N5N / 
 	
r   c                 .    | j                   j                  S r   )r   rh  r  s    r   rh  zDDLCompiler.type_compiler  s    ||)))r   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[  re   r
   r  )contextr6  targetr
   Tabler  r   format_table_seqr  rB  r  r  rt  r   )r   ddlr  r^  r   pathre   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                 V    | j                   j                  |j                        }d|z   S )NzCREATE SCHEMA )r   format_schemar   )r   r&   r"  r
   s       r   visit_create_schemazDDLCompiler.visit_create_schema  s%    ,,V^^<&((r   c                 |    | j                   j                  |j                        }d|z   }|j                  r|dz  }|S )NzDROP SCHEMA  CASCADE)r   rg  r   cascade)r   dropr"  r
   rs  s        r   visit_drop_schemazDDLCompiler.visit_drop_schema  s:    ,,T\\:&<<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                  $ ro}t        j                  t        j                  t        j                  d      |j                  |
j                   |j"                  d   fz        |       Y d }~d }~ww xY w)Nz
CREATE r  zTABLE IF NOT EXISTS r  
Ffirst_pkr  	Tz (in table '%s', column '%s'): %sr   r  ) _include_foreign_key_constraintsz
)%s

)r   r   r	  rF   if_not_existsr  create_table_suffixrD  r   r   r   r  r   r   udescriptionr(  argscreate_table_constraintsinclude_foreign_key_constraintspost_create_table)r   r&   r"  re   r   rs  rv  r  rr  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;;;# ## $$AB ,,fkk2771:FG  s   5AD;;F=A$F88F=c                      |j                   }|j                  ry  j                  ||      }dj                   fd|j                  D              }|r|d|z   z  }|S )Nrq  r  c              3   @   K   | ]  }j                  |        y wr   )r   r   r%   r   s     r   r   z2DDLCompiler.visit_create_column.<locals>.<genexpr>
  s      
)3DLL$
r  )r   systemget_column_specificationrF   constraints)r   r&   rr  r"  r$   rs  r  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   ps     r   r   z7DDLCompiler.create_table_constraints.<locals>.<genexpr>*  s      
 } 
r  c              3      K   | ]U  }|j                   |j                        r6j                  j                  rt        |dd      sj	                  |       W y w)N	use_alterF)_create_ruler   supports_alterr  r   r  s     r   r   z7DDLCompiler.create_table_constraints.<locals>.<genexpr>,  sW      ++3!..t4 33":{EB Z(s   AA)r   r  foreign_key_constraintsr{  ra   r  _sorted_constraintsrF   )r   re   rt  r"  r  all_fkcs	omit_fkcsr  s   `       r   rz  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 
IF EXISTS )	if_existsr   r  r   )r   rl  r"  rs  s       r   visit_drop_tablezDDLCompiler.visit_drop_table;  s6    >>L Ddmm00>>>r   c                 R    d| j                   j                  |j                        z   S )Nz
DROP VIEW r   r  r   r   rl  r"  s      r   visit_drop_viewzDDLCompiler.visit_drop_viewA  s      : :4<< HHHr   c                 `    |j                   "t        j                  d|j                  z        y )Nz,Index '%s' is not associated with any table.)re   r   r  r(  r   r   s     r   _verify_index_tablezDDLCompiler._verify_index_tableD  s0    ;;""AEJJN  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 zUNIQUE z0CREATE INDEX requires that the index have a namezINDEX ro  include_schemar  r  r@  r}   c              3   Z   K   | ]"  }j                   j                  |d d       $ yw)FTrT  r  N)r  r   )r   r  r   s     r   r   z1DDLCompiler.visit_create_index.<locals>.<genexpr>a  s8        !!))T * s   (+r  )r   r  r   rk   r(  r   r  ru  _prepared_index_namer  re   rF   expressions)r   r&   r  include_table_schemar"  r   r   rs  s   `       r   visit_create_indexzDDLCompiler.visit_create_indexJ  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 r  Tr  )r   r(  r   r  r  r  )r   rl  r"  r   rs  s        r   visit_drop_indexzDDLCompiler.visit_drop_indexj  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 NrK  )re   r   rR  rS  format_index)r   r   r  rW  schema_name
index_names         r   r  z DDLCompiler._prepared_index_namew  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   re   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   Stringr  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  r  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                    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	       |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 %dr  zNO ORDERCYCLEzNO CYCLEr  )	incrementr  r   minvaluemaxvalue
nominvalue
nomaxvaluecacherX   cyclerF   )r   identity_optionsrs  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!!-KK#3#9#9zJxx~r   c                 $   d| j                   j                  |j                        z  }|r||z  }|j                  j                  %| j                  j
                  |j                  _        | j                  |j                        }|r|d|z   z  }|S )NzCREATE SEQUENCE %sr  )r   rG  r   r   r   default_sequence_baser  )r   r&   r  r"  rs  optionss         r   visit_create_sequencez!DDLCompiler.visit_create_sequence  s    #dmm&C&CNN'
 
 FND>>'#'<<#E#EFNN ++FNN;C'M!Dr   c                 R    d| j                   j                  |j                        z  S )NzDROP SEQUENCE %s)r   rG  r   r  s      r   visit_drop_sequencezDDLCompiler.visit_drop_sequence  s     !DMM$A$A$,,$OOOr   c                 H   |j                   }|j                  | j                  j                  |      }nd }|"t	        j
                  d|j                   z        d| j                  j                  |j                   j                        d||j                  xr dxs dS )Nz<Can't emit DROP CONSTRAINT for constraint %r; it has no namer  z DROP CONSTRAINT rj  r	  )	r   r(  r   format_constraintr   r  r  re   rk  )r   rl  r"  r%   formatted_names        r   visit_drop_constraintz!DDLCompiler.visit_drop_constraint  s    \\
??&!]]<<ZHN!N!""!#'<<0  " MM&&t||'9'9:LL'Z-2-
 	
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  )rg  z	 DEFAULT z	 NOT NULL)r   r  r   rh  r   r   get_column_default_stringcomputedidentitysupports_identity_columnsnullable)r   r$   r  colspecr-   s        r   r  z$DDLCompiler.get_column_specification  s    MM''/ll((00V 1  	 008{W,,G??&sT\\&//:::G OO'66sT\\&//:::Gt||'M'M{"Gr   c                      yNr	  r   r   re   s     r   rv  zDDLCompiler.create_table_suffix      r   c                      yr  r   r  s     r   r|  zDDLCompiler.post_create_table  r  r   c                    t        |j                  t        j                        rt        |j                  j                  t
        j                        r>| j                  j                  |j                  j                  t        j                        S | j                  j                  |j                  j                  d      S y )NT)r  )r6  server_defaultr
   DefaultClauseargr   r_  r  r  r   r  r   rD  s     r   r  z%DDLCompiler.get_column_default_string  s    f++V-A-AB&//33T5F5FG((==))--x/B/B  ((00))--T 1   r   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)FTr  r(  r   r  r  r   rh  define_constraint_deferrabilityr   r%   r"  rs  r  s        r   r  z"DDLCompiler.visit_check_constraint      ??&!]]<<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   rP  r(  r   r  r   s     r   r   z;DDLCompiler.visit_primary_key_constraint.<locals>.<genexpr>6  s,      #
 MM'#
   /2)	r  r(  r   r  rF   _implicit_generatedcolumns_autoinc_firstrD  r  r  s   `    r   visit_primary_key_constraintz(DDLCompiler.visit_primary_key_constraint-  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   )rP  parentr(  r   r  r   s     r   r   z;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>J  '      23qxx}}-r  z) REFERENCES r@  c              3   h   K   | ])  }j                  |j                  j                         + y wr   )rP  r$   r(  r  s     r   r   z;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>P  r  r  r  )r   r(  r  r`  r   r$   re   rF   define_constraint_remote_tabledefine_constraint_matchdefine_constraint_cascadesr  )r   r%   r"  rs  r  remote_tabler   s         @r   visit_foreign_key_constraintz(DDLCompiler.visit_foreign_key_constraintA  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%   re   r   s       r   r   z*DDLCompiler.define_constraint_remote_tableY  s     $$U++r   c                      t        |      dk(  ryd}|j                  % j                  j                  |      }||d|z  z  }|ddj	                   fd|D              z  z  }| j                  |      z  }|S )Nr   r	  r  zUNIQUE (%s)r}   c              3   h   K   | ])  }j                   j                  |j                         + y wr   r  r  s     r   r   z6DDLCompiler.visit_unique_constraint.<locals>.<genexpr>g  s$     Fadmm))!&&1Fr  )r  r(  r   r  rF   r  r  s   `    r   visit_unique_constraintz#DDLCompiler.visit_unique_constraint^  s    z?a??&!]]<<ZHN)(>99IIF:FF
 	
 	44Z@@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%   rs  s      r   r  z&DDLCompiler.define_constraint_cascadesl  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_deferrabilityx  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)FTr  z STOREDz VIRTUAL)r  r   rh  	persisted)r   	generatedr"  rs  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"  rs  r  s        r   visit_identity_columnz!DDLCompiler.visit_identity_column  s@     H\9
 ++H5Gg%%Dr   r  r%  r   )FT)-r   r   r   r   r+  r  rh  r  re  rh  rm  r  r  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rv  r|  r  r  r  r  r  r  r   r  r  r  r  r  r  r   r   r   rY  rY    s   	
 

 
* * DH
L&)5n  7;'
R?I BF@L 






,P
$6;

(0,

r   rY  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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,y+),GenericTypeCompilerc                      y)NFLOATr   r   s      r   visit_FLOATzGenericTypeCompiler.visit_FLOAT      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  s    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  r5  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   c                     |}|j                   r|d|j                   z  z  }|j                  r|d|j                  z  z  }|S )N(%d)z COLLATE "%s")lengthr]  )r   r!  r(  rs  s       r   _render_string_typez'GenericTypeCompiler._render_string_type  s@    <<FU\\))D??Oeoo55Dr   c                 &    | j                  |d      S )NCHARrN  r   s      r   
visit_CHARzGenericTypeCompiler.visit_CHAR      ''v66r   c                 &    | j                  |d      S )NNCHARrQ  r   s      r   visit_NCHARzGenericTypeCompiler.visit_NCHAR  s    ''w77r   c                 &    | j                  |d      S )NVARCHARrQ  r   s      r   visit_VARCHARz!GenericTypeCompiler.visit_VARCHAR  s    ''y99r   c                 &    | j                  |d      S )NNVARCHARrQ  r   s      r   visit_NVARCHARz"GenericTypeCompiler.visit_NVARCHAR  s    ''z::r   c                 &    | j                  |d      S )NTEXTrQ  r   s      r   
visit_TEXTzGenericTypeCompiler.visit_TEXT  rS  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BINARYrL  r	  rM  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	VARBINARYrL  r	  re  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  r1  r   c                 (     | j                   |fi |S r   )rb  r   s      r   visit_large_binaryz&GenericTypeCompiler.visit_large_binary      tu+++r   c                 (     | j                   |fi |S r   )rl  r   s      r   visit_booleanz!GenericTypeCompiler.visit_boolean      !t!!%.2..r   c                 (     | j                   |fi |S r   )rD  r   s      r   
visit_timezGenericTypeCompiler.visit_time  ro  r   c                 (     | j                   |fi |S r   )r>  r   s      r   visit_datetimez"GenericTypeCompiler.visit_datetime      "t""5/B//r   c                 (     | j                   |fi |S r   )rA  r   s      r   
visit_datezGenericTypeCompiler.visit_date  ro  r   c                 (     | j                   |fi |S r   )r8  r   s      r   visit_big_integerz%GenericTypeCompiler.visit_big_integer
  s     t  -"--r   c                 (     | j                   |fi |S r   )r4  r   s      r   visit_small_integerz'GenericTypeCompiler.visit_small_integer  rw  r   c                 (     | j                   |fi |S r   )r0  r   s      r   visit_integerz!GenericTypeCompiler.visit_integer  rr  r   c                 (     | j                   |fi |S r   )r#  r   s      r   
visit_realzGenericTypeCompiler.visit_real  ro  r   c                 (     | j                   |fi |S r   )r  r   s      r   visit_floatzGenericTypeCompiler.visit_float  s    t,,,r   c                 (     | j                   |fi |S r   )r)  r   s      r   visit_numericz!GenericTypeCompiler.visit_numeric  rr  r   c                 (     | j                   |fi |S r   rY  r   s      r   visit_stringz GenericTypeCompiler.visit_string  rr  r   c                 (     | j                   |fi |S r   r  r   s      r   visit_unicodez!GenericTypeCompiler.visit_unicode  rr  r   c                 (     | j                   |fi |S r   r_  r   s      r   
visit_textzGenericTypeCompiler.visit_text"  ro  r   c                 (     | j                   |fi |S r   r  r   s      r   visit_unicode_textz&GenericTypeCompiler.visit_unicode_text%  ro  r   c                 (     | j                   |fi |S r   r  r   s      r   
visit_enumzGenericTypeCompiler.visit_enum(  rr  r   c                 2    t        j                  d|z        )NzKCan't generate DDL for %r; did you forget to specify a type on this Column?rC  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_decorator2  s'    t||E--dll;BrBBr   c                 &     |j                   di |S rU  )get_col_specr   s      r   visit_user_definedz&GenericTypeCompiler.visit_user_defined5  s    !u!!'B''r   N)-r   r   r   r  r#  r)  r-  r0  r4  r8  r;  r>  rA  rD  rG  rJ  rN  rR  rV  rY  r\  r_  rb  rf  ri  rl  rn  rq  rt  rv  ry  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r  r    s    		78:;7IL,/,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.process:  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'  )
startswithr  r  )r   r9  s     r   __getattr__zStrSQLTypeCompiler.__getattr__B  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_unknownH  sA    ??##u'?'?'E'E'GG??+++;r   c                      yr  r   r   s      r   r  zStrSQLTypeCompiler.visit_nullN  r  r   c                 `    	 |j                   } |di |S # t        $ r t        |      cY S w xY wrU  )r  r  r  )r   r!  r"  r  s       r   r  z%StrSQLTypeCompiler.visit_user_definedQ  s=    	& --L  %"%%  	;	s    --N)r   r   r   r   r  r  r  r  r   r   r   r  r  9  s    2&&r   r  c                   d   e Zd ZdZeZeZeZ	 e
j                  d      Z	 	 	 	 	 	 d!dZd Zd Zd Zd Zd	 Zd
 Zd Zd Zd"dZd"dZd Zd#dZd"dZd"dZd"dZ ej<                  d      d#d       Zd#dZ d#dZ!d Z"d Z#d$dZ$d Z%	 d"dZ&	 	 	 	 	 d%dZ'd#dZ(ejR                  d        Z*d  Z+y)&IdentifierPreparerz@Handle quoting and case-folding of identifiers based on options.r
   Nc                     || _         || _        |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.
        r   )rv   rt   N)
r   initial_quotefinal_quoteescape_quoteescape_to_quoteomit_schemaquote_case_sensitive_collations_stringsrC  rp  )r   r   r  r  r  r  r  s          r   r   zIdentifierPreparer.__init__o  st    . *&<$*<*<(#0014&/N, $ 7 7 <
 !
r   c                     | j                   j                  | j                         }|j                  j                  | j                         fd}||_        |S )Nc                     | j                   }|v rB| j                  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rP  )r
   _use_schema_mapr   r  r   )r  r(  r   s     r   symbol_getterz@IdentifierPreparer._with_schema_translate.<locals>.symbol_getter  sx    ::D++0C0C#t**8:>?  ##tw7u  zz!r   )r  __new____dict__r;  rR  )r   r   prepr  s    `  r   r   z)IdentifierPreparer._with_schema_translate  sE    ~~%%dnn5T]]+	" "/r   c                 \     |d v rd    d<    fd}t        j                  d||      S )Nr  c                     | j                  d      }|   }|s-j                  j                  }|st        j                  d      j                  |      S )Nr   zLDialect has no default schema name; can't use None as dynamic schema target.)r<   r   default_schema_namer   r  rS  )r{  r(  rW  dr   s      r   rq  z=IdentifierPreparer._render_schema_translates.<locals>.replace  s\    771:D w##'<<#C#C '**=  $$%566r   z(__\[SCHEMA_([^\]]+)\]))r  r  )r   r   r   rq  r  s   `   @r   r   z,IdentifierPreparer._render_schema_translates  s7     194AgJ	7 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.
        rm  rn  )rq  r  r  rp  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.
        )rq  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  r   r  pattern)r   r   regs      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sI |d   | j                  v xs6 | j                  j	                  t        j                  |             xs ||k7  S )z5Return True if the given identifier requires quoting.r   )r  reserved_wordsillegal_initial_characterslegal_charactersr  r   	text_type)r   r  lc_values      r   r  z#IdentifierPreparer._requires_quotes  sk    ;;=+++ #Qx4:::#((..t~~e/DEE# E!		
r   c                 `    | j                   j                  t        j                  |             S )zjReturn True if the given identifier requires quoting, but
        not taking case convention into account.)r  r  r   r  r  s     r   r  z1IdentifierPreparer._requires_quotes_illegal_chars  s'     ((..t~~e/DEEEr   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  rP  )r   r
   forces      r   rS  zIdentifierPreparer.quote_schema  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  rP  )r   r  r  r  r  r  )r   r  r  s      r   rP  zIdentifierPreparer.quote&  s    ,    !  w-=%}}U++((/+/+@+@+GDMM%(+0DMM%(}}U++((//Lr   c                 @    | j                   r| j                  |      S |S r   )r  rP  )r   collation_names     r   r\  z#IdentifierPreparer.format_collationZ  s     //::n--!!r   c                     | j                  |j                        }| j                  |      }| j                  s|r|| j	                  |      dz   |z   }|S r  )rP  r(  rR  r  rS  )r   r
  r  r(  rW  s        r   rG  z"IdentifierPreparer.format_sequence`  sY    zz(--(11(;    ,$$%56<tCDr   c                 @    | j                  |xs |j                        S r   rP  r(  )r   r'  r(  s      r   r;  zIdentifierPreparer.format_labelm      zz$,%**--r   c                 @    | j                  |xs |j                        S r   r  )r   rL  r(  s      r   r  zIdentifierPreparer.format_aliasp  r  r   c                 j    |xs |j                   }| j                  |      r| j                  |      }|S r   )r  r  r  )r   	savepointr(  r  s       r   r  z#IdentifierPreparer.format_savepoints  s5     '	  '))%0Er   zsqlalchemy.sql.namingc                 .   t         j                  j                  }|j                  t        j
                  u r|j                  ||j                        }|y |j                  }|j                  dk(  r| j                  ||      S | j                  ||      S )Nr   )_alembic_quote)r   r  
sql_namingr(  r   
_NONE_NAME_constraint_name_for_tablere   r2  truncate_and_render_index_name#truncate_and_render_constraint_name)r   r%   r  namingr(  s        r   r  z$IdentifierPreparer.format_constraint|  s    **??h11144J,,D |??D$$/66^ 7   ;;^ <  r   c                     | j                   j                  xs | j                   j                  }| j                  |||      S r   )r   max_index_name_lengthrI   _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_lengthrI  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      r  )	r6  r   r7  r  r   md5_hexr   validate_identifierrP  )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  r  s     r   r  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.rK  )r(  rP  rR  r  rS  )r   re   r  r(  r  rW  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  r  s     r   rg  z IdentifierPreparer.format_schema  s     zz$r   c                 ~    |+t        |t        j                        r|j                  |      }| j	                  |      S )Prepare a quoted column name.)r6  r   r7  r  rP  )r   r(  rJ  s      r   r  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  rM  F)r  r(  rK  )	r(  r6  r   r7  r  r  r  re   rP  )r   r$   r  r(  
table_namer  rJ  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.Fr  )rR  r  rS  r  )r   re   r  rW  s       r   ra  z#IdentifierPreparer.format_table_seq  sj      11%8J3C!!"23!!%E!: 
 %%e%>@@r   c                     | j                   | j                  | j                  | j                        fD cg c]  }t        j                  |       c}\  }}}t        j
                  d|||dz        }|S c c}w )NzM(?:(?:%(initial)s((?:%(escaped)s|[^%(final)s])+)%(final)s|([^\.]+))(?=\.|$))+)initialfinalescaped)r  r  r  r  r  r*  )r   r  r  r  escaped_finalrs         r   _r_identifiersz!IdentifierPreparer._r_identifiers  s    
 ""  ''(8(89)
 IIaL)
% JJ$ "EmLM
 )
s   A6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  arX  r  s         r   unformat_identifiersz'IdentifierPreparer.unformat_identifiers+  s]      *+;)?@Aaf1f@
 %%a(
 	
@
s
   AA)"Nr  TFr   )T)TN)FNNFN),r   r   r   r  RESERVED_WORDSr  LEGAL_CHARACTERSr  ILLEGAL_INITIAL_CHARACTERSr  r  
attrgetterrR  r   r   r   r  r  r  r  r  r  rS  rP  r\  rG  r;  r  r  r   r/  r  r  r  r  r  r  rg  r  r  ra  r+  r  r  r   r   r   r  r  Z  s   J#N'!;+++H5 (,"
H*F(
F$

F
%"N2h".. T01 2,




$-   " +ZA" 
 "
r   r  )r  r   r-  r~  r  r  r	  r   r   r   r   r   r	   r
   r   r   r   r  r   r   r   r   ra   r  r*  Ir  LEGAL_CHARACTERS_PLUS_SPACErangery  rj   r  r  r  r  UNICODEr  r  rE  r  r  r  r  r  or_addmulr  divmodtruedivnegltlenegtgeeqis_distinct_fromis_not_distinct_from	concat_opr>  not_match_oprL  rK  r  r   r:  r  r  r#   existsdistinct_opinvany_opall_opdesc_opasc_opnulls_first_opnulls_last_opr9  r   r(   r*   r+   r,   rK   rL   r   r   r`   rl   cuberollupgrouping_setsr  r&  r  r   	UNION_ALLr   
EXCEPT_ALLr   INTERSECT_ALLr'  RM_RENDERED_NAMERM_NAME
RM_OBJECTSRM_TYPE
namedtupler   symbolr   r   r   r   r   objectr   with_metaclassEnsureKWArgTyper  ColumnElementr&  r5  r1  rY  r  r  r  )r  s   0r   <module>r6     s  $     	            ! !  _aF 2::.5 (bjj):BDDA .3Arl;c!f;AA3%H rzz<bdd rzz<bdd rzz5rtt<bjjA2::N"**92::F    RZZ 01 SI67 )NNG) MM6) MM5	)
 MM5) MM5) MM5) MM5) u) MM3) LL%) LL&) LL&) LL%) LL&)  LL%!)"  4#)$ ""$<%)& ')( 	))* M+), OOV-). /)0 1)2 OOX3)4 MM65)6 MM67)8 j9): {;)> i?)@ ;A)B MM6C)D fE)F fG)J wK)L fn]Q)	X 
NN!4N.hyNNNFNNFh_	$ ""$(& ##W''$$h((,''++_   


 '&&	 T[['=K
(T[[ 	  t{{Ba t{{;(<7	<#'''w6HI <#~_'v _'D
&4&&t';';VD 
(H** 0@<
( @<
Fx`
[ `
F~( ~BW(, W(t&, &BX
 X
K^ <s    W