
    -h                       S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK
Jr  SSKJr  SSKJr  \" / SQ5      r\R0                  " S\R2                  5      r\R0                  " S\R2                  5      r\" SS5       V s1 s H  n \" U 5      iM     sn R=                  S/5      r\R0                  " S\R2                  5      r \R0                  " S\R2                  5      r!\R0                  " S\R2                  5      r"\R0                  " S\RF                  5      r$\R0                  " S\RF                  5      r%SSSSS S!.r&\R0                  " S"5      r'\(" \)" S#S$5      5      r*0 \RV                  S%_\RX                  S&_\RZ                  S'_\R\                  S(_\R^                  S)_\R`                  S*_\Rb                  S+_\Rd                  S*_\Rf                  S,_\Rh                  S-_\Rj                  S._\Rl                  S/_\Rn                  S0_\Rp                  S1_\Rr                  S2_\Rt                  S3_\Rv                  S4_0 \Rx                  S5_\Rz                  S6_\R|                  S7_\R~                  S8_\R                  S9_\R                  S:_\R                  S;_\R                  S<_\R                  S=_\R                  S>_\R                  S?_\R                  S@_\R                  SA_\R                  SB_\R                  SC_\R                  SD_\R                  SE_E\R                  SF\R                  SG\R                  SH0ErP\R                  SI\R                  SJ\R                  SK\R                  SL\R                  SM\R                  SN\R                  SO\R                  SP\R                  SQ\R                  SR\R                  SS\R                  ST\R                  SU\R                  SV0r_SWSXSYSZS[S\S]S^S_S`SaSbScSdSeSf.r`\R                  R                  Sg\R                  R                  Sh\R                  R                  Si\R                  R                  Sj\R                  R                  Sk\R                  R                  Sl0rhSriSrjSrkSmrl\R                  " Sn/ SoQ5      rn\R                  " SpSqSSr9rp\R                  " SsStSSr9rq\R                  " SuSvSSr9rr\R                  " SwSx\q\r-  Sr9rs " Sy Sz\R                  " SzS{S|/5      5      rt " S} S~\u5      rv " S S\R                  " \R                  \u5      5      ry " S S\
R                  5      r{ " S S\v5      r| " S S\|5      r} " S S\v5      r~ " S S\y5      r " S S\5      r " S S\u5      rgs  sn f )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                   $    \ rS rSrSS jrS rSrg)
FromLinteri+  Nc                   ^	 U R                   nU(       d  g[        U R                  5      n[        U5      nUb  UnUR                  U5        OUR	                  5       n[
        R                  " U/5      nU(       a~  U(       aw  UR                  5       m	UR                  T	5        U Vs1 s H  nT	U;   d  M  UiM     nnUR                  U	4S jU 5       5        UR                  U5        U(       a	  U(       a  Mw  U(       a  XE4$ gs  snf )NNNc              3   T   >#    U  H  oUR                  T5      (       +    v   M     g 7fN)index).0edgenodes     lC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/sql/compiler.py	<genexpr>"FromLinter.lint.<locals>.<genexpr>H  s      NIDdjj&6"67I   %()fromsra   edgesremovepopcollectionsdequepopleftdiscard
extendleftdifference_update)
selfstartr   r   the_rest
start_withstackr   	to_remover   s
            @r   lintFromLinter.lint,  s    

DJJu:JOOJ'!J!!:,/==?DT" +0@%$44<%I@ NINN##I.   '' As   '
D5Dc                    ^  T R                  5       u  pU(       a[  UnU(       aQ  SnSR                  U 4S jU 5       5      nUR                  UT R                  U   S9n[        R
                  " U5        g g g )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   \   >#    U  H!  nS R                  TR                  U   S9v   M#     g7f)z"{elem}")elemN)rv   r   )r   from_r   s     r   r   "FromLinter.warn.<locals>.<genexpr>_  s/      &!& %%4::e+<%=!&   ),)r   r   )r   rF   rv   r   r   warn)r   r   r   r   template	froms_strmessages   `      r   r   FromLinter.warnQ  s    #yy{ E7  !II &!&& 	 #//#4::j+A *  		'"       r   )__name__
__module____qualname____firstlineno__r   r   __static_attributes__r   r   r   r   r   +  s    #J#r   r   r   r   c                       \ rS rSrSrSrSrSr\R                  r
 \R                  rSr Sr SrSrSS\R                   " 5       4S jrS rS r\S 5       rS	 rS
 r SS jr\S 5       rSrg)Compiledij  a  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                    Xl         U R                   R                  U l        U(       a&  X0l        U R                  R	                  U5      U l        Ub  X l        UR                  U l        UR                  U l        U R                  (       a  UR                  U l
        U R                  " U R
                  40 UD6U l        U(       a+  U R                  R                  U R                  U5      U l        [        R                  " 5       U l        g)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__Compiled.__init__  s    : 88(<% MM@@$DM  &N(;;D ) 6 6D)2)E)E&,,t~~HHDK&"mmEEKK!5 **,r   c                     U R                   (       a  UR                  XX45      $ [        R                  " U R                  5      er   )r   _execute_compiledr   ObjectNotExecutableErrorr   )r   
connectionmultiparamsparamsr   s        r   _execute_on_connectionCompiled._execute_on_connection  s<     //6  ..t~~>>r   c                 j    [         R                  " [        R                  " U [	        U5      5      US9  g Nreplace_context)r   raise_r   UnsupportedCompilationErrortype)r   elementerrs      r   visit_unsupported_compilation&Compiled.visit_unsupported_compilation  s%    ++D$w-@	
r   c                     [        5       e)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_compilerCompiled.sql_compiler  s     "##r   c                 (    UR                   " U 40 UD6$ r   _compiler_dispatch)r   objkwargss      r   r   Compiled.process  s    %%d5f55r   c                 ,    U R                   =(       d    S$ )z3Return the string text of the generated SQL or DDL. )r   r  s    r   __str__Compiled.__str__  s     {{ b r   c                     [        5       e)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_paramsCompiled.construct_params  s     "##r   c                 "    U R                  5       $ )z0Return the bind params for this compiled object.r  r  s    r   r   Compiled.params  s     $$&&r   )	r   r   r   r   r   r   r   r   r   NNT)r   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   r   j  s    
 O
 ??LM 	 II " %))+1-f?
 $ $6! DH
$ ' 'r   r   c                   .    \ rS rSrSrSrS rS rS rSr	g)	TypeCompileri  z2Produces DDL specification for TypeEngine objects.z	visit_\w+c                     Xl         g r   r   )r   r   s     r   r   TypeCompiler.__init__  s    r   c                 (    UR                   " U 40 UD6$ r   r  r   type_kws      r   r   TypeCompiler.process  s    ''333r   c                 V    [         R                  " [        R                  " X5      US9  g r   )r   r  r   r  )r   r  r  r3  s       r   r  *TypeCompiler.visit_unsupported_compilation  s    ++D:	
r   r.  N)
r   r   r   r   r"  ensure_kwargr   r   r  r   r   r   r   r,  r,    s    <L4
r   r,  c                   P    \ rS rSrSrSrSrSS jr\S 5       r	\S 5       r
S rS	rg
)_CompileLabeli   z;lightweight label object which acts as an expression.Label.label)r  namec                 2    Xl         X l        U4U-   U l        g r   )r  r;  
_alt_names)r   colr;  	alt_namess       r   r   _CompileLabel.__init__'  s    	&9,r   c                 .    U R                   R                  $ r   )r  	proxy_setr  s    r   rB  _CompileLabel.proxy_set,  s    ||%%%r   c                 .    U R                   R                  $ r   )r  r  r  s    r   r  _CompileLabel.type0  s    ||   r   c                     U $ r   r   )r   r3  s     r   
self_group_CompileLabel.self_group4  s    r   )r=  r  r;  N)r   )r   r   r   r   r"  __visit_name__	__slots__r   r*  rB  r  rG  r   r   r   r   r9  r9     sA    EN!I-
 & & ! !r   r9  c                   x   \ rS rSrSr\r\rS=r	=r
r SrSr Sr Sr Sr Sr Sr Sr Sr Sr Sr Sr \" 5       r \" 5       r \R8                  r Sr S=rr Sr! Sr" \#RH                  " S5      r%Sr& Sr'Sr(SSS\)4S jr*\+S	 5       r,\+S
 5       r-\R\                  S 5       r/\R`                  S 5       r1\2Rf                  S 5       r4S r5\R\                  S 5       r6S r7\+S 5       r8     SS jr9\R`                   SS j5       r:\+S 5       r; SS jr<\Rz                  " S5      S 5       r>\R\                  S 5       r?\R\                  \Rz                  " S5      S 5       5       r@\R\                  \Rz                  " S5      S 5       5       rAS rBSS jrCS rD SS jrE SS  jrF     SS! jrGS" rHS# rI   SS$ jrJS% rKS& rLS' rMS( rNS) rOS* rPSS+ jrQ SS, jrRS- rSS. rTS/ rUS0 rVS1 rWS2 rXS3 rYS4 rZS5 r[S6 r\S7 r]S8 r^S9 r_S: r`S; raS< rbSS= jrcS> rdS? reS@ rf SSA jrgSB rhSC ri SSD jrjSE rkSF rlSG rmSH rnSI roSJ rp SSK jrqSL rr    SSM jrsSN rtSO ruSP rvSQ rwSR rx SSS jryST rzSU r{\R\                  SV 5       r|SW r}SX r~SY rSZ rS[ rS\ rS] rS^ rS_ rS` rSa rSb rSc rSd rSe r     SSf jr\S4Sg jrSh rSi rSj rSk r    SSl jr     SSm jrSn rSo r        SSp jrSq rSr rSSs jrSSt jrSu rSv r SSw jr      SSx jrSy rSz rS{ rS| rS} r\GRJ                  " S~\" 5       4S\" 5       4/5      r SS jrSr        SS jrS rS rS rS r   SS jrS rS rS rS rS rS rS rS r      SS jrSS jrS rS rS rS rS rS rS rS rS rS rS rS rSrg)SQLCompileri8  zvDefault implementation of :class:`.Compiled`.

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

FNTr   z"__\[POSTCOMPILE_(\S+?)(~~.+?~~)?\]c                 (   X@l         X0l        U(       aM  US    Vs0 s H  oR                  U_M     sn=U l        n	U	R	                  US    Vs0 s H  oU/_M     sn5        XPl        X`l        0 U l        [        R                  " 5       U l
        / U l        / U l        UR                  U l        U R                  (       a"  0 U l        / U l        UR                   S:H  U l        [$        UR                      U l        SU l        UR*                  =(       d    UR,                  U l        [/        5       U l        0 U l        [4        R6                  " XU40 UD6  U R8                  (       d"  U R:                  (       d  U R<                  (       a  UR>                  (       a  UR>                  U l         U R8                  (       d  U R:                  (       an  URB                  (       a  SU l"        OUU R
                  (       aD  U R8                  (       a,  U RF                  RH                  (       a  URJ                  (       a  SU l"        U R                  (       a!  U R"                  (       a  U RM                  5         U RN                  (       a  U RQ                  SS9  ggs  snf s  snf )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(  rO  rS  rT  r  bckbms
             r   r   SQLCompiler.__init__  s   > '""+A,1".Qq,1 D& KK16AQC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   J
Jc                      U R                   S   S   $ ! [         a(  n[        R                  " [        S5      US9   SnAgSnAff = f)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_executableSQLCompiler.current_executableA  sB    <	::b>,// 	KKAB "	s    
AAAc                 F    [        U R                  U R                  -   5      $ r   )listinsert_prefetchupdate_prefetchr  s    r   prefetchSQLCompiler.prefetchg  s    D((4+?+??@@r   c                     0 $ r   r   r  s    r   _global_attributesSQLCompiler._global_attributesk  s    	r   c                     [         R                  " 5       U l        0 U l        0 U l        SU l        U R                  (       a.  0 U l        0 U l        [        R                  " [        5      U l        gg)zzInitialize collections related to CTEs only if
a CTE is located, to save on the overhead of
these collections otherwise.

FN)r   OrderedDictr^  ctes_by_level_namelevel_name_by_ctectes_recursiverX  cte_positional	cte_levelr   defaultdictry  	cte_orderr  s    r   _init_cte_stateSQLCompiler._init_cte_stateo  s]     $$&	 #% "$#??"$DDN(44T:DN r   c              #     #    U R                   U R                  p!/ SsU l         U l         U R                  (       a  U R                  S   nSUS'   OSnU R                   U R                  4v   U(       a  UR                  S5        UUsU l         U l        g! W(       a  UR                  S5        UUsU l         U l        f = f7f)z;special API to support the use case of 'nested result sets'Frs  Tneed_result_map_for_nestedN)r$  _ordered_columnsr   r   )r   result_columnsordered_columnsentrys       r   _nested_resultSQLCompiler._nested_result  s        !! ( 79%3d3	zz

26:23&&(=(===		67 8D $"7 		67 8D $"7s   'C AB ,(C )B==C c                    ^ [         R                  " S5      m[        R                  " SU4S jU R                  5      U l        g )Nr   z\[_POSITION\]c                 B   > [        [        R                  " T5      5      $ r   )strr   next)mposcounts    r   <lambda>4SQLCompiler._apply_numbered_params.<locals>.<lambda>  s    DIIh,?(@r   )	itertoolscountresubr   )r   r  s    @r   rl  "SQLCompiler._apply_numbered_params  s-    ??1%ff@$++
r   c                 P   ^  [        S U 4S jT R                   5        5       5      $ )Nc              3   8   #    U  H  u  pUc  M
  UU4v   M     g 7fr   r   )r   rP  values      r   r   /SQLCompiler._bind_processors.<locals>.<genexpr>  s-      


 !s   	c              3     >#    U  H}  nTR                   U   UR                  R                  (       d%  UR                  R                  TR                  5      O([        U4S  jUR                  R                   5       5      4v   M     g7f)c              3   Z   >#    U  H   nUR                  TR                  5      v   M"     g 7fr   )_cached_bind_processorr   )r   	elem_typer   s     r   r   9SQLCompiler._bind_processors.<locals>.<genexpr>.<genexpr>  s*      )=I "88FF)=   (+N)rW  r  _is_tuple_typer  r   tupletypes)r   	bindparamr   s     r   r   r    sn       "1I OOI.$>>88 NN99$,,G )2)=)= 	 "1s   BB)dictrW  r  s   `r   _bind_processorsSQLCompiler._bind_processors  s/      

 "&
 
 	
r   c                 2    [        U R                  5      S:  $ Nr   )lenr   r  s    r   is_subquerySQLCompiler.is_subquery  s    4::""r   c                     U $ r   r   r  s    r   r  SQLCompiler.sql_compiler  s    r   c                    U=(       a    [        U R                  5      nU(       aK   U R                  S   nU R                  n	[        WU5       V
VVs0 s H  u  pX     H  nX_M     M     nnn
nOSnU(       Ga4  0 nU R                  R                  5        GH  u  nnU(       a  U R                  R                  UU5      OUnUR                  U;   a  XR                     UU'   MO  UU;   a
  UU   UU'   M_  U(       a^  UR                  (       aM  U(       a$  [        R                  " SUR                  U4-  SS9e[        R                  " SUR                  -  SS9eU(       a  UR                  X5      nOUnUR                   (       a  UR"                  UU'   GM  UR$                  UU'   GM     U$ 0 nU R                  R                  5        H  u  nnU(       a  U R                  R                  UU5      OUnU(       a^  UR                  (       aM  U(       a$  [        R                  " SUR                  U4-  SS9e[        R                  " SUR                  -  SS9eU(       a  UR                  X5      nOUnUR                   (       a  UR"                  UU'   M  UR$                  UU'   M     U$ ! [         a4  n[        R
                  " [        R                  " S5      US9   SnAGNSnAff = fs  snnn
f )	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   CompileErrorrQ  ziprW  itemsgetrP  requiredInvalidRequestErrorcallableeffective_valuer  )r   r   _group_number_checkr  r  has_escaped_namesorig_extractedr  rp  ro  	extractedbindresolved_extractedpdr  r;  escaped_namevalue_params                      r   r  SQLCompiler.construct_params  s    )JT$2I2I-J	!%!2 --D %(8L$M"$MLA GD # $M  " "&B#'??#8#8#:	4 ) ++//d;  ==F*'-mm'<B|$V^'-d|B|$	 2 2$!554(}}m<= "(	  "55G'mm,!'  *&8&<&<%' '0 ))+6+F+F<(+6+<+<<(K $;L IB#'??#8#8#:	4 ) ++//d;  i00$!554(}}m<= "(	  "55G'mm,!'  &"4"8"8"NK"+K%%'2'B'BB|$'2'8'8B|$= $;> Iy  $$N %( "s   J- K.-
K+7)K&&K+c                   ^^^^	 [        U S5      (       d  g U R                  m	U R                  R                  mTc  Tc  UU	4S jnO	UU	UU4S jn0 nU R                  nU R                   Hi  nXe;   a  M
  UR
                  R                  (       a0  UR
                  R                   Vs/ s H
  os" U5      PM     snXF'   MU  U" UR
                  5      XF'   Mk     U$ s  snf )NrW  c                 H   > U R                  T5      R                  T5      nU$ r   )dialect_implget_dbapi_type)typdbtypedbapir   s     r   _lookup_type=SQLCompiler._get_set_input_sizes_lookup.<locals>._lookup_typeJ  s#    ))'2AA%Hr   c                    > U R                  T5      nU R                  T5      R                  T5      nUb2  Tb  UT;  a)  [        U5      T;  a  Tb  UT;   d  [        U5      T;   a  U$ g r   )_unwrapped_dialect_implr  r  r  )r  r  r  r  r   exclude_typesinclude_typess      r   r  r  P  sz    
  #::7C))'2AA%H &%-!6 .mC &-!]2-> "Mr   )hasattrr   r  literal_execute_paramsrW  r  r  r  )
r   r  r  r  
inputsizesr  r  r  r  r   s
    ``     @@r   _get_set_input_sizes_lookup'SQLCompiler._get_set_input_sizes_lookup7  s     t\**,,""  ]%:   4 
!%!<!<I2~~,,1:1E1E)1E#L%1E)
% )5Y^^(D
% ) )s   'Cc                      U R                  SS9$ )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   SQLCompiler.paramsz  s     $$E$22r   c                 R  ^^^ Uc  U R                  SS9n0 nU R                  (       a  / nOSnU R                  m0 nU R                  (       a  U R                  (       a  [	        S5      e0 m0 nU R                  (       a  U R
                  OU R                  R                  5        GH  mU R                  (       a  U R                  R                  TT5      OTnU R                  T   nXR                  ;   a*  UT;  a"  U R                  UUR                  U5      S9TU'   M{  XR                  ;   Ga  UT;   a  Xg   n	O1UR                  T5      n
U R                  nU" XxU
5      u  pXU'   UTU'   UR                   (       d  UR#                  U	5        UR$                  R&                  (       a'  UR#                  UU4S j[)        W
S5       5       5        OUR#                  UU4S jU	 5       5        U R                  (       a  UR+                  S	 U	 5       5        U	 VVs/ s H  u  pUPM	     snnUT'   GM  GM  U R                  (       d  GM  UR-                  T5        GM     U4S
 jn[.        R0                  " U R2                  UU R4                  5      n[7        UUUUU5      nU(       a  UR8                  U l        U R                  R#                  UR:                  5        UR
                  U l        [=        5       U l        UR>                   H  nU R                  R                  U5      nU R                  R                  U5        [A        URB                  UR>                  U   5       H5  u  nnURE                  U5      =U R                  U'   nUU R                  U'   M7     M     U$ s  snnf )af  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      >#    U  HK  u  p[        US 5        H5  u  p4TT;   d  M  TT   US -
     c  M  T< SU< SU< 3TT   US -
     4v   M7     MM     g7f)r   N_)	enumerate)r   ituple_elementjr  r;  r   s        r   r   BSQLCompiler._process_parameters_for_postcompile.<locals>.<genexpr>  sz      	.
 5I 0,5mQ,G#z1 !+4 0Q 7.2Aq 9 *4 0Q 7
 -H 5Is   A
A#Ar   c              3   F   >#    U  H  u  pTT;   d  M  UTT   4v   M     g 7fr   r   )r   rP  r  r;  r   s      r   r   r    s.      ..7
#z1 4S*T"23.7s   !!c              3   *   #    U  H	  u  pUv   M     g 7fr   r   )r   r;  r  s      r   r   r    s     *M9KD49   c                   >^^ U R                  S5      nTU   nU R                  S5      (       aV  U R                  S5      R                  S5      nUS   US   smmSR                  UU4S jUR                  S5       5       5      nU$ )Nr   r   ~~r   r}   c              3   :   >#    U  H  nT< U< T< 3v   M     g 7fr   r   )r   expbe_leftbe_rights     r   r   ]SQLCompiler._process_parameters_for_postcompile.<locals>.process_expanding.<locals>.<genexpr>
  s      !/ !(h7/s   )r<   splitrF   )r  rP  exprtokr  r  replacement_expressionss       @@r   process_expandingJSQLCompiler._process_parameters_for_postcompile.<locals>.process_expanding  s    ''!*C*3/D wwqzzggaj&&t,$'FCF!yy !#zz$/!  Kr   )#r  rX  r  r[  r
  r   rW  valuesr  r  rU  r  render_literal_bindparamr   post_compile_params$_literal_execute_expanding_parameterliteral_executerR  r  r  r  extendappendr  r  _post_compile_patternr   r   r   r   	frozensetr   r  r  _with_value)r   
parametersrN  expanded_parametersr   new_processorsto_update_setsr  	parameter	to_updater   leepreplacement_expr
expand_keyr  r  r   expanded_staterP  r  expanded_key	new_paramr;  r   r  s                         @@@r   rn  /SQLCompiler._process_parameters_for_postcompile  su     ..E.BJ ??KK**
??t22 &9 
 #% !%DT__5K5K5MM 
 ** ''++D$7  

4(I777'>> 55!-7^^L-I 6  ,$ 444#:: . <I (^^D1FDDD26$3/I 4=<0<L+L9 00%%i0 ~~44&-- 	.
 5>fa4H	. 	 '-- ..7. 
 #***M9*MM<E1<E'8z
I1'-+ 10 ""4(K NN	 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   N#zsqlalchemy.engine.cursorc                     [         R                  R                  nUR                  R	                  U R
                  5      $ )z(utility method used for unit tests only.)r   	preloadedengine_cursorCursorResultMetaData_create_description_match_mapr$  )r   cursors     r   _create_result_mapSQLCompiler._create_result_map3  s5     --**HH  
 	
r   c                 $    U R                   S   nU$ )Nr   )_key_getters_for_crud_column)r   getters     r   _within_exec_param_key_getter)SQLCompiler._within_exec_param_key_getter;  s    2215r   zsqlalchemy.engine.resultc           	        ^^^^	 [         R                  R                  nU R                  nU R                  R
                  nUR                   Vs/ s H#  n[        R                  " SU" U5      S 5      U4PM%     snmUR                  mTb'  TR                  R                  U R                  S 5      mOS mUR                  UR                   Vs/ s H  oDR                  PM     sn5      m	UUUU	4S jnU$ s  snf s  snf )Nr  c                 p   >^ ^ Tb  T" T 5      m T c  T" U4S jT 5       5      $ T" UU U4S jT 5       5      $ )zgiven 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   8   >#    U  H  u  pU" T5      v   M     g 7fr   r   )r   r!  r>  r
  s      r   r   WSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.get.<locals>.<genexpr>c  s     LG[VfZ00Gs   c              3   F   >#    U  H  u  pUTL a  TOU" T5      v   M     g 7fr   r   )r   r!  r>  autoinc_col	lastrowidr
  s      r   r   r'  e  s+      '. "%!3I
9KK'.   !r   )r*  r
  r)  gettersprocrow_fns   ``r   r  DSQLCompiler._inserted_primary_key_from_lastrowid_getter.<locals>.getX  sE      O	 LGLLL '.  r   )r   r  engine_resultr"  r   re   primary_keyoperatormethodcaller_autoincrement_columnr  _cached_result_processorr   result_tuplerP  )
r   resultparam_key_getterre   r>  r  r)  r,  r-  r.  s
         @@@@r   +_inserted_primary_key_from_lastrowid_getter7SQLCompiler._inserted_primary_key_from_lastrowid_getter@  s     --==$$ ((
( ""5*:3*?FL(

 11"##<<dD D$$9J9J%K9J#gg9J%KL	 	$ 
E
 &Ls   *C4C9c           	         ^^	 [         R                  R                  nU R                  nU R                  R
                  n[        U R                  5       VVs0 s H  u  pEXT_M	     nnnUR                   Vs/ s HB  nXV;   a  [        R                  " Xe   5      S4O[        R                  " SU" U5      S 5      S4PMD     snmUR                  UR                   Vs/ s H  oUR                  PM     sn5      m	UU	4S jnU$ s  snnf s  snf s  snf )NTr  Fc                 .   >^ ^ T" UU 4S jT 5       5      $ )Nc              3   V   >#    U  H  u  pU(       a  U" T5      OU" T5      v   M      g 7fr   r   )r   r!  use_rowr
  rows      r   r   WSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.get.<locals>.<genexpr>  s*      '.OF  'sF:,>>'.s   &)r   )r?  r
  r,  r.  s   ``r   r  DSQLCompiler._inserted_primary_key_from_returning_getter.<locals>.get  s     '.  r   )r   r  r0  r"  r   re   r  rg  r1  r2  
itemgetterr3  r6  rP  )
r   r7  r8  re   idxr>  retr  r,  r.  s
           @@r   +_inserted_primary_key_from_returning_getter7SQLCompiler._inserted_primary_key_from_returning_getterl  s    --==$$(1$..(AB(AHCsx(AB ((
 ) z   *D1 %%e-=c-BDI )
 $$9J9J%K9J#gg9J%KL	 
) C
 &Ls   D 6A	DDc                     g)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_fromSQLCompiler.default_from  s     r   c                 H    SUR                   R                  " U 40 UD6-   S-   $ N()r  r  )r   groupingasfromr  s       r   visit_groupingSQLCompiler.visit_grouping  (    X%%88HHH3NNr   c                 H    SUR                   R                  " U 40 UD6-   S-   $ rK  rN  )r   rO  r  s      r   visit_select_statement_grouping+SQLCompiler.visit_select_statement_grouping  rS  r   c                    U R                   (       a  U R                  R                  (       a  U R                   S   S   nUR                  u  nnnU(       a  UnOUnUR                  R
                  n	U	bK  U	R                  U;   a;  U	R                  XR                     5      (       a  UR                  R
                  US'   U R                  " UR                  4SU0UD6$ )Nrs  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  rY  r  r&  	with_cols
only_froms	only_colsresolve_dictorder_by_elems
             r   visit_label_reference!SQLCompiler.visit_label_reference  s     ::$,,EE JJrN?;M 11	$)( $OOCCM )!&&,6!00 !3!34  OO;; + ||OO
"7
 
 	
r   c                    U R                   (       d  U R                  UR                  5      $ U R                   S   S   nUR                  u  pVn U(       a  XaR                     nOXQR                     nXS'   U R                  " U4SU0UD6$ ! [
         a9  n	[        R                  " UR                  S[        R                  U	S9   S n	A	g S n	A	ff = f)Nrs  r&  rX  rY  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  rY  r  r&  r^  r_  r`  r>  r  s
             r   visit_textual_label_reference)SQLCompiler.visit_textual_label_reference  s     zz<< 4 455

27+8+L+L(	y	$ 10 /2*+<<+@DJ   		''/ ((		s   $B 
C/C

Cc                    U=(       a    U(       + nXQL n	U	(       d  U(       aR  [        UR                  [        R                  5      (       a  U R	                  SUR                  5      n
OUR                  n
U(       a  Ub0  U" W
UR                  X4UR
                  -   U-   UR                  5        UR                  R                  " U 4SSS.UD6[        [        R                     -   U R                  R                  UW
5      -   $ U	(       a  U R                  R                  UW
5      $ UR                  R                  " U 4SS0UD6$ )NcolidentT)rY  within_label_clauserY  F)
isinstancer;  r   _truncated_label_truncated_identifierr=  r  r  r  	OPERATORSr	   as_r   format_label)r   r:  add_to_result_mapro  rY  rX  result_map_targetsr3  render_label_with_asrender_label_only	labelnames              r   visit_labelSQLCompiler.visit_label  s:    "=*=&= 	 2: 4%**h&?&?@@ 66z5::N	!JJ	 ,!JJ&)9)99<NNJJ	 00*.(, 	 IMM*+ --,,UI>?	 ==--eY??==33,157 r   c                 .    [         R                  " S5      e)Nz:Cannot compile Column object until its 'name' is assigned.r   r  r   r$   s     r   _fallback_column_name!SQLCompiler._fallback_column_name  s    K
 	
r   c                 @    UR                   nU R                  " U40 UD6$ r   )	_resolvedr   )r   r  r3  sql_elements       r   visit_lambda_element SQLCompiler.visit_lambda_element  s!    ''||K.2..r   c                 Z   UR                   =pgUc  U R                  U5      nUR                  nU(       d1  [        U[        R
                  5      (       a  U R                  SU5      nUbD  XUR                  4U-   n	UR                  (       a  XR                  4-  n	U" XgXR                  5        U(       a  U R                  U5      nOU R                  R                  U5      nUR                  n
U
b  U(       a  U
R                  (       d  U$ U R                  R                  U
5      nU(       a  U R                  R!                  U5      S-   nOSnU
R                   n[        U[        R
                  5      (       a  U R                  SU5      nXR                  R                  U5      -   S-   U-   $ )Nrn  .r  alias)r;  r  
is_literalrp  r   rq  rr  rP  	_tq_labelr  escape_literal_columnr   quotere   named_with_columnschema_for_objectquote_schema)r   r$   rv  include_tablerw  r  r;  	orig_namer  targetsre   effective_schemaschema_prefix	tablenames                 r   visit_columnSQLCompiler.visit_column  sk    ";;&<--f5D&&
jx/H/HII--j$?D(VZZ03EEG,,..dwD --d3D==&&t,D=U5L5LK#}}>>uEMM../?@3F  !#

I)X%>%>?? 66w	J	 ==#6#6y#AACG$NNr   c                 L    U R                   R                  UR                  5      $ r   )r   format_collation	collationr   r  r3  s      r   visit_collationSQLCompiler.visit_collationF  s    }}--g.?.?@@r   c                     UR                   $ r   r;  )r   
fromclauser  s      r   visit_fromclauseSQLCompiler.visit_fromclauseI  s    r   c                     UR                   $ r   r  )r   r   r  s      r   visit_indexSQLCompiler.visit_indexL  s    zzr   c                     XS'   U R                   US'   U R                  R                  R                  " UR                  40 UD6$ )Ntype_expressionr   )r   r   type_compilerr   r  )r   
typeclauser3  s      r   visit_typeclauseSQLCompiler.visit_typeclauseO  s>     *$(MM !||))11*//HRHHr   c                 `    U R                   R                  (       a  UR                  SS5      nU$ N%%%r   _double_percentsreplacer   texts     r   post_process_textSQLCompiler.post_process_textT  $    ==))<<T*Dr   c                 `    U R                   R                  (       a  UR                  SS5      nU$ r  r  r  s     r   r  !SQLCompiler.escape_literal_columnY  r  r   c           	        ^ ^^ UU U4S jnT R                   (       d  ST l        U(       a  U" S S T4[        R                  5        [        R                  S [        R                  UT R                  TR                  5      5      5      $ )Nc                    > U R                  S5      nUTR                  ;   a   TR                  " TR                  U   40 TD6$ TR                  " U40 TD6$ r  )r<   _bindparamsr   bindparam_string)r  r;  r3  r   
textclauses     r   do_bindparam2SQLCompiler.visit_textclause.<locals>.do_bindparam_  sS    771:Dz---||J$:$:4$@GBGG,,T8R88r   Tc                 $    U R                  S5      $ r  )r<   r  s    r   r  .SQLCompiler.visit_textclause.<locals>.<lambda>q  s    aggajr   )	r   isplaintextr   NULLTYPEBIND_PARAMS_ESCr  BIND_PARAMSr  r  )r   r  rv  r3  r  s   `` ` r   visit_textclauseSQLCompiler.visit_textclause^  sl    	9 zz#D dD:-9J9JK "" OOd44Z__E
 	
r   c                    U R                   (       + nU(       a  U R                  OU R                   S   n[        5       [        5       US.nU R                   R                  U5        UR                  (       a&  UR                   H  nUR
                  " U 40 UD6  M     U=(       d7    US:H  =(       a    UR                  SS5      =(       d    UR                  SS5      n	U	(       ax  UR                  =U l        U l	        UR                  (       + =(       a    [        UR                  5      U l        UR                   H  n
U R                  U
SU R                  S9  M      U R                  " UR                  40 UD6nU R                   (       a@  U(       d  [#        U R                   5      OS nU R%                  UUR                  S	5      S
9U-   nU R                   R'                  S5        U$ )Nrs  correlate_fromsasfrom_fromsr   r   need_result_map_for_compoundFr  TrY  rv  visiting_ctenesting_levelr  )r   _default_stack_entryra   r  _independent_ctesr  r  rX  r  _textual_ordered_columnsr  column_args_loose_column_name_matchingr   _add_to_result_mapr  r^  r  _render_cte_clauser   )r   tafcompound_indexrP  r3  toplevelr  	new_entryctepopulate_result_mapcr  r  s                r   visit_textual_select SQLCompiler.visit_textual_selectw  s    zz>-5))4::b>  #uE
	
 	

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

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

rr   c                     gNNULLr   r   r  r3  s      r   
visit_nullSQLCompiler.visit_null      r   c                 <    U R                   R                  (       a  gg)Nri   1r   supports_native_booleanr  s      r   
visit_trueSQLCompiler.visit_true  s    <<//r   c                 <    U R                   R                  (       a  gg)Nr5   0r  r  s      r   visit_falseSQLCompiler.visit_false  s    <<//r   c                 L   ^ ^ UR                  S UU 4S jU 5        5       5      $ )Nc              3   8   #    U  H  nU(       d  M  Uv   M     g 7fr   r   r   ss     r   r   7SQLCompiler._generate_delimited_list.<locals>.<genexpr>  s      
I AI   	c              3   H   >#    U  H  oR                   " T40 TD6v   M     g 7fr   r  r   r  r3  r   s     r   r   r    s     I1**4626   "rF   )r   r   	separatorr3  s   `  `r   _generate_delimited_list$SQLCompiler._generate_delimited_list  s&    ~~ 
II
 
 	
r   c                 v  ^ ^ [         R                  R                  [        R                  [         R
                  R                  [         R                  R                  U5      u  p1US:X  a  US   R                  " T 40 TD6$ [        [        R                     nUR                  S UU 4S jU 5        5       5      $ )Nr   r   c              3   8   #    U  H  nU(       d  M  Uv   M     g 7fr   r   r  s     r   r   ;SQLCompiler._generate_delimited_and_list.<locals>.<genexpr>  s      "LA Lr  c              3   H   >#    U  H  oR                   " T40 TD6v   M     g 7fr   r  r  s     r   r   r    s     LGq..t:r:Gr  )r   BooleanClauseList_process_clauses_for_booleanr	   and_True_
_singletonFalse_r  rs  rF   )r   clausesr3  lccr  s   ` `  r   _generate_delimited_and_list(SQLCompiler._generate_delimited_and_list  s    11NNNNNN%%OO&&	
 !81:00<<<!)..1I>> "LGL"  r   c                 .    SU R                   " U40 UD6-  $ N(%s))visit_clauselist)r   
clauselistr3  s      r   visit_tupleSQLCompiler.visit_tuple  s    --j?B???r   c                     UR                   nUc  SnO[        UR                      nU R                  " UR                  U40 UD6$ N )r2  rs  r   r  )r   r  r3  seps       r   r  SQLCompiler.visit_clauselist  sE    !!;CJ//0C,,Z-?-?KKKr   c                 h   SnUR                   b"  X1R                   R                  " U 40 UD6S-   -  nUR                   H8  u  pEUSUR                  " U 40 UD6-   S-   UR                  " U 40 UD6-   S-   -  nM:     UR                  b&  USUR                  R                  " U 40 UD6-   S-   -  nUS-  nU$ )NzCASE r  zWHEN z THEN zELSE END)r  r  whenselse_)r   clauser  xcondr7  s         r   
visit_caseSQLCompiler.visit_case  s    <<#00@@3FFA"LLLD))$9&9: ++D;F;< 	A ) <<#&,,99$I&IICOA 	
U
r   c                 <    UR                   R                  " U 40 UD6$ r   )typed_expressionr  )r   type_coercer3  s      r   visit_type_coerceSQLCompiler.visit_type_coerce  s    ++>>tJrJJr   c                     SUR                   R                  " U 40 UD6< SUR                  R                  " U 40 UD6< S3$ )NzCAST(r   rM  )r   r  r  )r   r!   r  s      r   
visit_castSQLCompiler.visit_cast  s:    KK**4:6:OO..t>v>
 	
r   c           
         US   [         R                  L a  SOUS   [         R                  L a  SOmUS   S:  a7  U R                  " [         R                  " [        US   5      5      40 UD6< S3O-U R                  " [         R                  " US   5      40 UD6< S3< SUS   [         R                  L a  S< 3$ US   [         R                  L a  S< 3$ US   S:  a:  U R                  " [         R                  " [        US   5      5      40 UD6< S3< 3$ U R                  " [         R                  " US   5      40 UD6< S3< 3$ )	Nr   zUNBOUNDED PRECEDINGzCURRENT ROWz
 PRECEDINGz
 FOLLOWINGrz   r   zUNBOUNDED FOLLOWING)r   RANGE_UNBOUNDEDRANGE_CURRENTr   literalabs)r   range_r3  s      r   _format_frame_clause SQLCompiler._format_frame_clause  sn    ayH444 " ayH222  ay1} ||H,,S^<CCF ||H,,VAY7>2>AA ayH444 " A
 	
 ayH222 A
 	
  ay1} ||H,,S^<CCF	A
 	
$ ||H,,VAY7>2>AA
 	
r   c                    UR                   R                  " U 40 UD6nUR                  (       a!  SU R                  " UR                  40 UD6-  nO4UR                  (       a!  SU R                  " UR                  40 UD6-  nOS nU< SSR                  SUR                  4SUR                  44 VVs/ s H6  u  pVUc  M
  [        U5      (       d  M  U< SUR                  " U 40 UD6< 3PM8     snnU(       a  U/O/ -   5      < S3$ s  snnf )	NzRANGE BETWEEN %szROWS BETWEEN %sz OVER (r  	PARTITIONORDERz BY rM  )	r  r  r2  r3  rowsrF   partition_byorder_byr  )r   overr  r  r2  wordr   s          r   
visit_overSQLCompiler.visit_over  s   ||..t>v>;;'$*C*C+%+ F YY&)B)B		*#* F F HH
 %d&7&78 $--0)) H /2&kHV66tFvFH)  &F82	/
 	
s   2	D?DDc                     UR                   R                  " U 40 UD6< SUR                  R                  " U 40 UD6< S3$ )Nz WITHIN GROUP (ORDER BY rM  )r  r  r:  )r   withingroupr  s      r   visit_withingroupSQLCompiler.visit_withingroup7  s>    224B6B  33DCFC
 	
r   c                     UR                   R                  " U 40 UD6< SUR                  R                  " U 40 UD6< S3$ )Nz FILTER (WHERE rM  )funcr  	criterion)r   
funcfilterr  s      r   visit_funcfilterSQLCompiler.visit_funcfilter=  s<    OO..t>v>  33DCFC
 	
r   c                     U R                   R                  UR                  UR                  5      nSU< SUR                  R                  " U 40 UD6< S3$ )NzEXTRACT(r~   rM  )extract_mapr  fieldr  r  )r   extractr  rK  s       r   visit_extractSQLCompiler.visit_extractC  sF      $$W]]GMMBLL++D;F;
 	
r   c                 v    U R                   " UR                  40 UD6nU R                  " U40 UD6nSU< SU< 3$ )NrL  z).)visit_functionfnr  )r   r  r3  compiled_fncompiled_cols        r   visit_scalar_function_column(SQLCompiler.visit_scalar_function_columnJ  s;    ))'**;;((7B7'66r   c           	         Ub)  U" UR                   UR                   SUR                  5        [        U SUR                   R                  5       -  S 5      nU(       a  U" U40 UD6nGOY[        R                  UR                  5       R                  S 5      nU(       a  UR                  (       a  US-  nOmUR                   nU R                  R                  U5      (       d  [        U[        R                  5      (       a  U R                  R                  U5      OUnUS-   nSR                  UR                    Vs/ s H_  nU R                  R                  U5      (       d  [        U[        R                  5      (       a  U R                  R                  U5      OUPMa     snU/-   5      SU R"                  " U40 UD60-  nUR$                  (       a  US-  nU$ s  snf )Nr   zvisit_%s_funcz%(expr)sr  r  z WITH ORDINALITY)r;  r  getattrlower	FUNCTIONSr  _deannotate	__class__	_has_argsr   _requires_quotes_illegal_charsrp  r   r   r  rF   packagenamesfunction_argspec_with_ordinality)r   rD  rv  r  dispr  r;  r  s           r   rP  SQLCompiler.visit_functionO  s   (diiB		Bt_tyy/@@$G''D==!1!1!3!=!=tDD>>J&Dyy }}CCDII!$(<(<== MM''- 	  j(88  $00  1	  ==GGLL%dH,@,@AA ++C0 !!
  1 &	 ..t>v>?@D   &&Ds   9A&Gc                 8    U R                  UR                  5      $ r   )visit_sequencesequence)r   
next_valuer3  s      r   visit_next_value_func!SQLCompiler.visit_next_value_funcu  s    "":#6#677r   c                 F    [        SU R                  R                  -  5      e)Nz2Dialect '%s' does not support sequence increments.r
  r   r;  )r   re  r3  s      r   rd  SQLCompiler.visit_sequencex  s$    !@ll 
 	
r   c                 <    UR                   R                  " U 40 UD6$ r   )clause_exprr  )r   rD  r  s      r   r_  SQLCompiler.function_argspec~  s    224B6BBr   c           
      h  ^ ^^ T R                   (       + nUR                  " UT 40 TD6nU(       a  T R                  (       d  UT l        UR                  nU(       a  T R                  OT R                   S   nU=(       d     U(       + =(       a    UR                  SS5      n	US:X  a  XS'   T R                   R                  US   US   UUU	S.5        UR                  (       a&  UR                   H  n
U
R                  " T 40 TD6  M     T R                  R                  UR                  5      nS	U-   S	-   R                  UUU 4S
 j[        UR                  5       5       5      nSTS'   UT R                  " U40 [        SST0TD6D6-  nUT R                   " U40 TD6-  nUR"                  (       a  UT R$                  " U40 TD6-  nT R&                  (       aA  U(       d  [)        T R                   5      OS nT R+                  USTR                  S5      S9U-   nT R                   R-                  S5        U$ )Nrs  r  Fr   select_0r  r  )r  r  r   r&  r  r  c              3   T   >#    U  H  u  pUR                   " T4TUS .TD6v   M     g7f))rP  r  Nr  )r   r  r  rP  r  r   s      r   r   4SQLCompiler.visit_compound_select.<locals>.<genexpr>  s>       2DA $$!'=C 2r   r  rP  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_clauser^  r  r  r   )r   csrP  r  r  r  r&  compound_stmtr  need_result_mapr  rw  r  r  s   ` ` `         r   visit_compound_select!SQLCompiler.visit_compound_select  s    zz>11"dEfED..!.D%//-5))4::b>" 
 A		8%@ 	 Q "*

#():#; %n 5 !.0?	
 **$66&&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                 h    UR                   b  U R                  " U40 UD6$ U R                  " U40 UD6$ r   )_fetch_clausefetch_clauselimit_clause)r   r}  r  s      r   r|  SQLCompiler._row_limit_clause  s:    '$$R2622$$R2622r   c                 `    SUR                   < SU< U(       a  SU-   OS< 3n[        XS 5      $ )Nvisit_r  r  )r   rW  )r   	operator_
qualifier1
qualifier2attrnames        r   _get_operator_dispatch"SQLCompiler._get_operator_dispatch  s3     *C*2

 tt,,r   c                 P   Ub  X14-  nX$S'   X4S'   UR                   (       a  UR                  (       a  [        R                  " S5      eU R	                  UR                   SS5      nU(       a  U" XR                   40 UD6$ U R
                  " U[        UR                      40 UD6$ UR                  (       a\  U R	                  UR                  SS5      nU(       a  U" XR                  40 UD6$ U R                  " U[        UR                     40 UD6$ [        R                  " S5      e)Nrv  rw  zFUnary expression does not support operator and modifier simultaneouslyunaryr2  modifierz,Unary expression has no operator or modifier)r2  r  r   r  r   _generate_generic_unary_operatorrs   _generate_generic_unary_modifier)r   r  rv  rw  r3  ra  s         r   visit_unarySQLCompiler.visit_unary  s*    ((*&7"#'9#$>>~~&&2  ..D E>>8R88<<9U^^48:  ^^..D E>>8R88<<9U^^48:  ""> r   c                     UR                   (       d  U R                  R                  (       a  U R                  " UR                  40 UD6$ SU R                  " UR                  40 UD6-  $ )Nz%s = 1_is_implicitly_booleanr   r  r   r  r   r  r2  r3  s       r   visit_is_true_unary_operator(SQLCompiler.visit_is_true_unary_operator  sM    **||33<<6266dll7??AbAAAr   c                     UR                   (       d  U R                  R                  (       a   SU R                  " UR                  40 UD6-  $ SU R                  " UR                  40 UD6-  $ )NNOT %sz%s = 0r  r  s       r   visit_is_false_unary_operator)SQLCompiler.visit_is_false_unary_operator  sR    **||33dll7??AbAAAdll7??AbAAAr   c                 D    SU R                  U[        R                  S9-  $ )Nr  )override_operator)visit_binaryr	   match_opr   r   r2  r3  s       r   visit_not_match_op_binary%SQLCompiler.visit_not_match_op_binary  s,    $++i&8&8 , 
 
 	
r   c                 >    SU R                   " U[        U   40 UD6-  $ r  )_generate_generic_binaryrs  r  s       r   visit_not_in_op_binary"SQLCompiler.visit_not_in_op_binary  s0     55Ih'
+-
 
 	
r   c                    U[         R                  L a+  [        U5      S:  a  SSR                  S U 5       5      -  $ gU[         R                  L a+  [        U5      S:  a  SSR                  S U 5       5      -  $ gU R                  U5      $ )	Nr   z(%s)) OR (1 = 1r}   c              3   &   #    U  H  nS v   M	     g7fr  Nr   r   r  s     r   r   6SQLCompiler.visit_empty_set_op_expr.<locals>.<genexpr>       :EfE   zNULL) OR (1 = 1z(%s)) AND (1 != 1c              3   &   #    U  H  nS v   M	     g7fr  r   r  s     r   r   r  #  r  r  zNULL) AND (1 != 1)r	   	not_in_opr  rF   in_opvisit_empty_set_expr)r   r2  	expand_ops      r   visit_empty_set_op_expr#SQLCompiler.visit_empty_set_op_expr  s    	+++5zA~(II:E::  ))//)5zA~*II:E::  +,,U33r   c                 F    [        SU R                  R                  -  5      e)Nz3Dialect '%s' does not support empty set expression.rj  )r   element_typess     r   r   SQLCompiler.visit_empty_set_expr*  s$    !All 
 	
r   c                   ^ ^^	^
 TR                   R                  T R                  5      nU(       d  UR                  (       aT  T R                  R                  (       a  SOST R                  TR                   R                  TR                  5      -   nSU4$ T R                  TR                   /TR                  5      n SU4$ UR                  (       dp  UR                  (       a  [        US   [        R                  R                  5      (       a  [        US   [        R                  [        R                  -   5      (       de  UR                  (       a  [!        S5      eT R                  R                  (       a  SOSSR#                  UU 4S j[%        U5       5       5      -   nSU4$ U(       a  T R&                  nUR)                  U5      nU(       a  UR+                  S5      (       d   S5       eUR+                  S5      R-                  S	5      nUS
   US   sm	m
SR#                  U	U
UU 4S jU 5       5      nSU4$ SR#                  UU 4S jU 5       5      nSU4$ )NVALUES r  r   z?bind_expression() on TupleType not supported with literal_bindsr}   c           	   3      >#    U  HC  u  pS SR                  U4S j[        UTR                  R                  5       5       5      -  v   ME     g7f)r  r}   c              3   J   >#    U  H  u  pTR                  X5      v   M     g 7fr   r  )r   r  
param_typer   s      r   r   [SQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>.<genexpr>Z  s-      2-E 11%DD2    #N)rF   r  r  r  )r   r  r  r  r   s      r   r   QSQLCompiler._literal_execute_expanding_parameter_literal_binds.<locals>.<genexpr>W  sQ       ):$A II 14)9>>+?+?2  ):s   AAr   )unexpected format for expanding parameterr  r   r   c              3   n   >#    U  H*  nT< TR                  UTR                  5      < T< 3v   M,     g 7fr   r  r  )r   r  r  r  r  r   s     r   r   r  m  s8      3 "(	  11%H 	 "(   25c              3   \   >#    U  H!  nTR                  UTR                  5      v   M#     g 7fr   r  )r   r  r  r   s     r   r   r  w  s,      3!' --eY^^DD!'r   r   )r  r  r   r  tuple_in_valuesr  r  r  _isnullrp  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_binds>SQLCompiler._literal_execute_expanding_parameter_literal_binds0  s<    %>>AA$,,O
  ..!%!=!=I200NN(()*=*=*&@ )))s *.)E)E^^$i&9&9*&r )))k ,,$$6!9d&:&:&C&CD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                   ^ ^
 UR                   (       a  T R                  X#5      $ UR                  R                  T R                  5      nU(       ds  / m
UR
                  (       a4  T R                  UR                  R                  UR                  5      nT
U4$ T R                  UR                  /UR                  5      n T
U4$ UR
                  (       dq  UR                  (       Ga  [        US   [        R                  R                  5      (       a  [        US   [        R                  [        R                  -   5      (       d  UR                   (       a   e[#        US5       VVVV	s/ s H*  u  pg[#        US5        H  u  pU< SU< SU< 3U	4PM     M,     sn	nnnm
T R                  R$                  (       a  SOSSR'                  U U
4S j[#        U5       5       5      -   nT
U4$ [#        US5       VV	s/ s H  u  piU< SU< 3U	4PM     sn	nm
SR'                  U 4S jT
 5       5      nT
U4$ s  sn	nnnf s  sn	nf )	Nr   r   r  r  r  r}   c              3      >^^#    U  H2  u  mmS SR                  UUUU4S j[        T5       5       5      -  v   M4     g7f)r  r}   c              3   t   >#    U  H-  u  pTR                   S TT[        T5      -  U-      S   0-  v   M/     g7f)r;  r   N)r]  r  )r   r  r  r  r   r  r  s      r   r   MSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>.<genexpr>  sJ       )AHA ))!9Q]1C-Ca-G#H#KLM(@s   58N)rF   r  )r   r  r  r   r  s    @@r   r   CSQLCompiler._literal_execute_expanding_parameter.<locals>.<genexpr>  sF      
 ):$A} II  )2-(@  ):s   :?c              3   J   >#    U  H  u  pTR                   S U0-  v   M     g7f)r;  N)r]  )r   rP  r  r   s      r   r   r    s%      /DMjc!!VSM1Ir  )r  r  r  r  r   r  r  r  r  r  rp  r   r  r  r  r  	_is_arrayr  r  rF   )r   r;  r  r   r  r  r  r  r  r  r  s   `         @r   r  0SQLCompiler._literal_execute_expanding_parameter~  s!   $$JJ  %>>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Dq	4,,t/@/@@  (1111 )2&!(<(<$A )- ;HA  $Q*E2 ; 3(<I "\\99	r		 
 )2&(9
 
&", 000 !*&! 4 4HA !!$e, 4I &*YY /DM/ &" 0007&s   *1H3
9H;c                    U(       a  [         R                  " UR                  5      (       a  Ubf  US   nUR                  R	                  [
        R                  " UR                  R                  U/-   UR                  R                  U/-   5      5        OXUR                  R	                  [
        R                  " UR                  R                  UR                  R                  5      5        U R                  (       aW  [        UR                  [        R                  5      (       a.  [        UR                  [        R                  5      (       a  SUS'   U=(       d    UR                  nU R                  USS 5      n	U	(       a	  U	" X40 UD6$  [        U   n
U R                   " UU
4UUS.UD6$ ! ["         a3  n[$        R&                  " [(        R*                  " X5      US9   S nAg S nAff = f)Nenclosing_lateralTr  r   )from_linterlateral_from_linterr   )r	   is_comparisonr2  r   rR  r  productrH   _from_objectsr^   ansi_bind_rulesrp  r   BindParameterr  rs  r  ri  r   r  r   r  )r   r   r  eager_groupingr  r  r3  r  r  ra  opstringr  s               r   r  SQLCompiler.visit_binary  s    9226??CC".$&':$;!#))00%%115F4GG226G5HH !!((%%116<<3M3M   6;;(>(>??6<<)?)?@@$(B !%8	**9hE0R00$Y/ 44 !,(;	
    33DD$'s   	F/ /
G,9)G''G,c                 <    U R                   " UR                  40 UD6$ r   )r   sql_functionr  s       r   &visit_function_as_comparison_op_binary2SQLCompiler.visit_function_as_comparison_op_binary  s    ||G007B77r   c                 0   U R                   R                  (       a>  U R                  " UR                  40 UD6S-   U R                  " UR                  40 UD6-   $ U R                  " UR                  40 UD6S-   U R                  " UR                  40 UD6-   $ )Nz %% r{   )r   r  r   rH   r^   r  s       r   visit_mod_binarySQLCompiler.visit_mod_binary  s    ==))V[[/B/,,v||2r23 V[[/B/,,v||2r23r   c                     UR                   US'   U R                  " USU R                  UR                  5      -   S-   40 UD6$ )Nr  r  )r  r  r  r  r  s       r   visit_custom_op_binary"SQLCompiler.visit_custom_op_binary  sQ    '66,,$,,X->->??#E
 
 	
r   c                 `    U R                   " XR                  UR                  5      S-   40 UD6$ r  )r  r  r  r  s       r   visit_custom_op_unary_operator*SQLCompiler.visit_custom_op_unary_operator	  s6    44//0A0ABSH
LN
 	
r   c                 b    U R                   " USU R                  UR                  5      -   40 UD6$ r  )r  r  r  r  s       r   visit_custom_op_unary_modifier*SQLCompiler.visit_custom_op_unary_modifier	  s8    44S455h6G6GHH
LN
 	
r   c                     UR                  SS5      nSUS'   UR                  US'   UR                  R                  " U 4SU0UD6U-   UR                  R                  " U 4SU0UD6-   nU(       a  U(       a  SU-  nU$ )N
_in_binaryFT
_binary_opr  r  )r  r2  rH   r  r^   )r   r   r  r  r3  r  r  s          r   r  $SQLCompiler._generate_generic_binary	  s     VVL%0
<!??<KK**%379  ll--%379	 	 .D=Dr   c                 @    X!R                   R                  " U 40 UD6-   $ r   rN  r   r  r  r3  s       r   r  ,SQLCompiler._generate_generic_unary_operator'	  s    --::4F2FFFr   c                 B    UR                   R                  " U 40 UD6U-   $ r   rN  r   s       r   r  ,SQLCompiler._generate_generic_unary_modifier*	  s!    }}//;;hFFr   c                 H    [         R                  " S[        R                  S9$ )Nz'%')r2  )r   literal_columnr   
STRINGTYPEr  s    r   _like_percent_literal!SQLCompiler._like_percent_literal-	  s    &&uH4G4GHHr   c                     UR                  5       nU R                  nUR                  UR                  5      R                  U5      Ul        U R                  " X40 UD6$ r   _cloner  concatr^   visit_like_op_binaryr   r   r2  r3  percents        r   visit_contains_op_binary$SQLCompiler.visit_contains_op_binary1	  sM    ,,~~fll3::7C((@R@@r   c                     UR                  5       nU R                  nUR                  UR                  5      R                  U5      Ul        U R                  " X40 UD6$ r   r  r  r  r^   visit_not_like_op_binaryr  s        r   visit_not_contains_op_binary(SQLCompiler.visit_not_contains_op_binary7	  sM    ,,~~fll3::7C,,VDDDr   c                     UR                  5       nU R                  nUR                  UR                  5      Ul        U R                  " X40 UD6$ r   )r  r  _rconcatr^   r  r  s        r   visit_startswith_op_binary&SQLCompiler.visit_startswith_op_binary=	  sD    ,,''5((@R@@r   c                     UR                  5       nU R                  nUR                  UR                  5      Ul        U R                  " X40 UD6$ r   )r  r  r  r^   r  r  s        r   visit_not_startswith_op_binary*SQLCompiler.visit_not_startswith_op_binaryC	  sD    ,,''5,,VDDDr   c                     UR                  5       nU R                  nUR                  UR                  5      Ul        U R                  " X40 UD6$ r   r
  r  s        r   visit_endswith_op_binary$SQLCompiler.visit_endswith_op_binaryI	  sB    ,,~~fll3((@R@@r   c                     UR                  5       nU R                  nUR                  UR                  5      Ul        U R                  " X40 UD6$ r   r  r  s        r   visit_not_endswith_op_binary(SQLCompiler.visit_not_endswith_op_binaryO	  sB    ,,~~fll3,,VDDDr   c                    UR                   R                  SS 5      nUR                  R                  " U 40 UD6< SUR                  R                  " U 40 UD6< 3U(       a%  SU R                  U[        R                  5      -   -   $ S-   $ )Nescapez LIKE  ESCAPE r  	modifiersr  rH   r  r^   r  r   r  r   r   r2  r3  r%  s        r   r   SQLCompiler.visit_like_op_binaryU	  s    !!%%h5 KK**4626LL++D7B7

  2268;N;NOO	
 	
 
 	
r   c                    UR                   R                  SS 5      nUR                  R                  " U 40 UD6< SUR                  R                  " U 40 UD6< 3U(       a%  SU R                  U[        R                  5      -   -   $ S-   $ )Nr%  z
 NOT LIKE r&  r  r'  r)  s        r   r  $SQLCompiler.visit_not_like_op_binaryb	  s    !!%%h5KK**4626LL++D7B7

  2268;N;NOO	
 	
 
 	
r   c                    UR                   R                  SS 5      nSUR                  R                  " U 40 UD6< SUR                  R                  " U 40 UD6< S3U(       a%  SU R                  U[        R                  5      -   -   $ S-   $ )Nr%  lower(z) LIKE lower(rM  r&  r  r'  r)  s        r   visit_ilike_op_binary!SQLCompiler.visit_ilike_op_binarym	      !!%%h5KK**4626LL++D7B7

  2268;N;NOO	
 	
 
 	
r   c                    UR                   R                  SS 5      nSUR                  R                  " U 40 UD6< SUR                  R                  " U 40 UD6< S3U(       a%  SU R                  U[        R                  5      -   -   $ S-   $ )Nr%  r.  z) NOT LIKE lower(rM  r&  r  r'  r)  s        r   visit_not_ilike_op_binary%SQLCompiler.visit_not_ilike_op_binaryx	  r1  r   c                 r    UR                   R                  SS5      nU R                  " X(       a  SOS40 UD6$ )Nrd   Fz BETWEEN SYMMETRIC z	 BETWEEN r(  r  r  r   r   r2  r3  rd   s        r   visit_between_op_binary#SQLCompiler.visit_between_op_binary	  s?    $$((e<	,,Y)K
KM
 	
r   c                 t    UR                   R                  SS5      nU R                  " UU(       a  SOS40 UD6$ )Nrd   Fz NOT BETWEEN SYMMETRIC z NOT BETWEEN r6  r7  s        r   visit_not_between_op_binary'SQLCompiler.visit_not_between_op_binary	  sB    $$((e<	,,)2%
 
 	
r   c                 \    [         R                  " SU R                  R                  -  5      eNz/%s dialect does not support regular expressionsr   r  r   r;  r  s       r   visit_regexp_match_op_binary(SQLCompiler.visit_regexp_match_op_binary	  *    =ll 
 	
r   c                 \    [         R                  " SU R                  R                  -  5      er>  r?  r  s       r    visit_not_regexp_match_op_binary,SQLCompiler.visit_not_regexp_match_op_binary	  rB  r   c                 \    [         R                  " SU R                  R                  -  5      e)Nz;%s dialect does not support regular expression replacementsr?  r  s       r   visit_regexp_replace_op_binary*SQLCompiler.visit_regexp_replace_op_binary	  s*    Ill 
 	
r   c           	      
   U(       Gd  UR                   R                  U R                  5      nUR                  (       a  UR	                  U5      n	U R
                  " U	4SUU=(       a    UR                  (       + UUS.UD6n
UR                  (       a  [        R                  " SU
5      nU(       d   S5       eSUR                  S5      < SUR                  S5      < S	UR                  S
5      < S3n
U(       a  U R                  " U4SU
S.UD6nSU-  $ U
$ U(       dG  U=(       d(    UR                  =(       d    U=(       a    U R                  nU=(       d    UR                  nOSnU(       a-  U R                  " U4SS0UD6nUR                  (       a  SU-  nU$ U R                  U5      nXR                  ;   Ga-  U R                  U   nXLGa  UR                  (       d  UR                  (       am  UR                   R#                  UR                   5      (       dC  UR$                  R#                  UR$                  5      (       d  [&        R(                  " SU-  5      eUR                  UR                  :w  a  [&        R(                  " SU< S35      eUR*                  (       d  UR*                  (       a3  [&        R(                  " SUR,                  < SUR,                  < S35      eU=U R                  UR,                  '   U R                  U'   U R.                  nU(       aH  UR$                   H8  nUR,                  U;   d  M  UUR,                     nUU   R1                  U5        M:     UR2                  (       a  SU l        U(       aB  U(       a  SU l        U(       a  U =R8                  U1-  sl        OU =R:                  U1-  sl        U R<                  " U4UUR                  S.UD6nUR                  (       a  SU-  nU$ )NT)skip_bind_expressionrY  literal_bindsr  render_postcompilez&^(.*)\(__\[POSTCOMPILE_(\S+?)\]\)(.*)$r  z(__[POSTCOMPILE_r   r  r   z~~REPL~~r   z~~]))rY  r  r  FrY  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   r  bind_expressionr   rN  r  matchr<   r  r  r  _truncate_bindparamrU  rk   rB  intersection_cloned_setr   r  _is_crudrP  rQ  r  
isoutparamhas_out_parametersrm  r  r  r  )r   r  rY  rK  rJ  r  rL  r  implrO  wrappedr  rD  rM  r;  existingrp  bpcbs                      r   visit_bindparamSQLCompiler.visit_bindparam	  s    $>>..t||<D(("&"6"6y"A,,#)-*?"/"K	8K8K4K$3'9  && A7A III1


G %";;%265< %	  &|+ D,,D)Bd.B.B 
 +Ai.A.AL L//159?C ""slJ''	2::zz$'H(__	(8(8$..;;!++  %00==!--  **ACGH  ''9+>+>>** :>@  &&)*<*<** %==)--9  8A@

9==!DJJt$4 ))++66T>bffBHOOI. ,
 &*D#!+/(++	{:+((YK7(##
%))
 	
 3,C
r   c                    U[         La  UnOUR                  c  UR                  c  UR                  SS 5      nU(       aF  U[        R
                  [        R                  4;  a"  [        R                  " SUR                  45        U R                  " [        R                  40 UD6$ UR                  nUR                  (       a  U R                  nU" UUUS9u  pU	$ U R!                  XQR"                  5      $ )Nr  zBound parameter '%s' rendering literal NULL in a SQL expression; comparisons to NULL should not use operators outside of 'is' or 'is not')r  )r   r  r  r  r	   is_is_notr   warn_limitedrP  r   r   r  r  rN  r  r  r  )
r   r  r  r  r3  r  opr  r  r  s
             r   r  $SQLCompiler.render_literal_bindparam3
  s      v-(E&9+=+=+EVVL$/"Y]]I4D4D$EE%%@ #(	 ||H$5$5<<<--EJJD*.)A+'I
 $#,,UNNCCr   c           
      v   UR                  U R                  5      nU(       a	   U" U5      $ [
        R                  " S[        R                  " U5      < SU< 35      e! [         aP  n[        R                  " [
        R                  " S[        R                  " U5      < SU< S35      US9   SnAgSnAff = f)zRender 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  r2  	processores        r   r   SQLCompiler.render_literal_valueT
  s     33DLLA	 ''$ "" ..u5u> #  $$ %77>!
 s   A 
B8(AB33B8c                     XR                   ;   a  U R                   U   $ UR                  n[        U[        R                  5      (       a  U R                  SU5      nX R                   U'   U$ )Nr  )rW  rP  rp  r   rq  rr  )r   r  	bind_names      r   rQ  SQLCompiler._truncate_bindparamz
  s]    '??9--MM	i!:!:;;22;	JI &/	"r   c                    X4U R                   ;   a  U R                   X4   $ UR                  U R                  5      n[        U5      U R                  S-
  :  a]  U R                   R                  US5      nUS[        U R                  S-
  S5       S-   [        U5      SS  -   nUS-   U R                   U'   OUnXPR                   X4'   U$ )N   r   r   r  r   )rb  	apply_mapra  r  r_  r  maxhex)r   ident_classr;  anonnamecounter	truncnames         r   rr  !SQLCompiler._truncated_identifier
  s    $"6"66''(;<<>>$--0x=4,,q00**..{A>GS!2!2Q!6:;g,qr"# 
 18!D  - I4=k01r   c                     XR                   -  $ r   ra  r   r;  s     r   
_anonymizeSQLCompiler._anonymize
  s    mm##r   c                    U R                   (       aR  Ub  UR                  U5        OU R                  R                  U5        [        U R                  5      U R
                  U'   U(       d5  [        R                  U5      (       a  [        R                  S U5      nUnUnU(       a&  U R                  (       d  0 U l	        XR                  U'   U(       a  SU-  $ U R                  SU0-  $ )Nc                 2    [         U R                  S5         $ Nr   )_BIND_TRANSLATE_CHARSr<   r  s    r   r  .SQLCompiler.bindparam_string.<locals>.<lambda>
  s    3AGGAJ?r   z__[POSTCOMPILE_%s]r;  )rX  r  r   r  r   rY  _BIND_TRANSLATE_REr  r  r  r]  )r   r;  positional_namesrM  rN  escaped_fromr3  new_names           r   r  SQLCompiler.bindparam_string
  s     ??+ ''-  ''-+.tzz?D""4(!((.. .11?  $***,'48##L1'$..$$~55r   c                   ^  T R                  5         XS'   UR                  n[        U[        R                  5      (       a  T R                  SU5      nSn	Sn
UR                  5       nUT R                  ;   a  T R                  U   u  pX:X  d   eO(UR                  (       a  [        T R                  5      OSnX4nUT R                  ;   a  T R                  U   nX_L n
XR                  L d  XL a  Sn	OXR                  L a+  T R                  U	 UR                  5       nT R                  U	 OLUR                  c  UR                  b  UR                  U5      (       a  Sn	O[         R"                  " SU-  5      eU(       d  U	(       d  g UR$                  bT  UR$                  nUR$                  R                  n[        U[        R                  5      (       a  T R                  SU5      nOUnS nU	(       Ga  UT R                  U'   UT R                  U'   SUR&                  R(                  ;   aI  ST R*                  ;  a9  T R*                  R-                  SUR&                  R(                  S   05      T l        T R.                  (       a  UT R0                  U'   UT R                  ;  a  T R2                  " U40 UD6  U(       Gd0  UT R                  ;  Ga  UR4                  (       a  ST l        T R8                  R;                  X5      nUR4                  (       a  [        UR&                  [<        R>                  5      (       a  UR&                  nOJ[        UR&                  [<        R@                  5      (       a  UR&                  RB                  S   nO S	5       eURE                  S5       VVVVVs/ s H  u  nnnnnU(       a  M  U=(       d    UPM     nnnnnnUS
SRG                  U 4S jU 5       5      -  -  nT R.                  (       a  / =US'   T RH                  U'   URK                  SS5      SL d   eT R                  (       d  UR&                  RL                  " T 4SU0UD6$ T RN                  " XRP                  40 UD6nUR&                  RL                  " T 4SS0UD6nUSU< SU< S3-  nURR                  (       a#  UST RN                  " XRR                  40 UD6-   -  nUT R                  U'   U(       a  U(       a  XRT                  U'   U	(       d"  U
(       a  T R8                  R;                  X5      $ U(       am  T R8                  R;                  UU5      nT R8                  RW                  U5      (       a  T R8                  RY                  U5      nUT R[                  U5      -  nU$ T R8                  R;                  X5      $ g s  snnnnnf )Nr  r  TFr   z5Multiple, unrelated CTEs found with the same name: %r
autocommitr   z%cte should only be against SelectBaser  r}   c              3   l   >#    U  H)  nTR                   R                  UTR                  S 9v   M+     g7f)r{  N)r   format_label_namera  )r   identr   s     r   r   (SQLCompiler.visit_cte.<locals>.<genexpr>J  s9      " *4 !MM;; % <  *4s   14r  subqueryrP  r   z
(rM  r  ).r  r;  rp  r   rq  rr  _get_reference_cter  nestingr  r   r  	_restatesr^  _is_clone_ofcomparer   r  
_cte_aliasr  r   r   rj   rX  r  	visit_cte	recursiver  r   format_aliasr   SelectCompoundSelectrx  _generate_columns_plus_namesrF   r  r  r  _generate_prefixes	_prefixes	_suffixesr   _requires_quotesr  get_render_as_alias_suffix)r   r  rP  ashint	fromhintsr  r  r  cte_name
is_new_cteembedded_in_current_named_cte_reference_cter  r  cte_level_nameexisting_cteexisting_cte_reference_ctepre_alias_ctecte_pre_alias_namer  
col_source
proxy_namefallback_label_namer  repeated
recur_colsprefixesrA   s   `                           r   r  SQLCompiler.visit_cte
  sI    	!$~88h 9 9::11'8DH
(-%//1T33311.ALI= =+.;;DJJAI#.T44422>BL,8,H) ,,,0C"
. IIl+-9-L-L-N* **+EF $$0#00<kk,//!&J**,.67 
 j>>%NNM!$!4!4,h.G.GHH%)%?%?/&"  M!%69D##N35CD"">2  > >> (>(>>)-)?)?)E)E$ckk&D&D('*& &/s#DII-}77%#TYY*>==*.D'}}11#@==!#++z/@/@AA%([[
#CKK1J1JKK%([[%8%8%;
M&MMu" )EEdK" L&/$' :+9z9 L  "  F		 " *4	"  D ??LNNF-.1D1DS1Izz*e4===zz ;;99%+/5   $66]] .4 H  KK::%)-3E h>>D==C$"9"9]]#.4#  D "&		#)1!!#&"?}}11#@@!}}11#7IJ==11(;;#}}228<H77AA}}11#@@ m"s   +W Wc                     UR                   (       a  S US'   UR                  (       a  U R                  " U40 UD6$ U R                  " U40 UD6$ )Nr  )joins_implicitly_is_lateralvisit_lateralvisit_aliasr  s      r   visit_table_valued_alias$SQLCompiler.visit_table_valued_alias  sJ    ## $B}%%g444##G2r22r   c                 (    U R                   " U40 UD6$ r   )r  r  s      r   visit_table_valued_column%SQLCompiler.visit_table_valued_column  s      /B//r   c
           
      X  ^ ^^
 U(       a6  ST
;  a  TR                   (       d   eTT
S'   U	(       a  ST
;  a  ST
;   a  U	T
S'   UbQ  UR                  TL aB  TR                  R                  " T 4UUUUUTS.T
D6nU(       a  U(       d  U(       a  SU< S3nU$ T=nT
S'   U(       d  U(       aR  [        TR                  [
        R                  5      (       a  T R                  STR                  5      nOTR                  nU(       a  T R                  R                  TW5      $ U(       a  U	(       a  WU	R                  T'   TR                  R                  " T 4SUS	.T
D6nU(       a  SU< S3nUT R                  T R                  R                  TW5      5      -   nTR                  (       a>  TR                  (       a-  US
SR                  UU
U 4S jTR                   5       5      -  -  nU(       a  TU;   a  T R!                  UTUT   U5      nU$ TR                  R                  " T 4SU0T
D6$ )Nr  r  )rP  r  iscrudr  lateralenclosing_aliasrL  rM  r  r  T)rP  r  r  r}   c              3     >#    U  Hu  nTR                   R                  UR                  5      < TR                  (       a4  S TR                  R
                  R                  " UR                  40 TD6-  OS< 3v   Mw     g7f) %sr  N)r   r  r;  _render_derived_w_typesr   r  r   r  )r   r>  r  r  r   s     r   r   *SQLCompiler.visit_alias.<locals>.<genexpr>  sz       $+C !MM//9
  %<<	 ""ll88@@ #,2
 "$$	 $+s   A=B r  )r  r  r  rp  r;  r   rq  rr  r   r  r   r  _supports_derived_columns_render_derivedrF   r  format_from_hint_text)r   r  rP  r  r  r  r  r  r  r  r  rA   
alias_namerD  s   ``        `   r   r  SQLCompiler.visit_alias  s*    "&0 ((((.3*+
 )7'610;,-&?+B+Be+KMM44	# %	 	E Vw"')L:??Of%67V%**h&?&?@@!77L
"ZZ
==--eZ@@+5!!%(MM44!76<E "')$99**5*= C ..53H3HvII  $)77    Ui/00	% 0& J ==33%)/ r   c                 2    SUS'   U R                   " U40 UD6$ )NTr  r  )r   r  r3  s      r   visit_subquerySQLCompiler.visit_subquery  s!    :/B//r   c                 8    SUS'   SU R                   " U40 UD6-  $ )NTr  z
LATERAL %sr  )r   lateral_r3  s      r   r  SQLCompiler.visit_lateral  s&    9d..x>2>>>r   c                     U R                   " U4SS0UD6< SUR                  5       R                  " U 40 UD6< 3nUR                  b#  USUR                  R                  " U 40 UD6-  -  nU$ )NrP  Tz TABLESAMPLE z REPEATABLE (%s))r  _get_methodr  seed)r   tablesamplerP  r3  r  s        r   visit_tablesampleSQLCompiler.visit_tablesample  s}    [<<<##%88DD

 '&  33D?B? D r   c           
        ^ ^^ TR                  STR                  5        SSR                  UUU 4S jTR                   5       5      -  n[	        TR
                  [        R                  5      (       a  T R                  STR
                  5      nOTR
                  nTR                  (       a  SnOSnU(       a  U(       a  Ub  UOSUR                  T'   U(       a`  U< S	U< S
T R                  T R                  R                  U5      5      < SSR                  UU 4S jTR                   5       5      < S
3nU$ U< S	U< S
3nU$ )NrK  z	VALUES %sr}   c           	   3      >#    U  HN  nU  HD  nTR                   " [        R                  " US TR                  06R	                  5       40 TD6v   MF     MP     g7f)r  N)r   r   Tuple_column_typesrG  )r   chunkr   r  r3  r   s      r   r   +SQLCompiler.visit_values.<locals>.<genexpr>  sb      	$
 ' LL26!//*, 	  's   AAr   zLATERAL r  z(unnamed VALUES element)rL  rM   (c              3   N   >#    U  H  nUR                   " T4S S0TD6v   M     g7f)r  FNr  r  s     r   r   r  %  s:      " &5 00 $49=? &5   "%)
setdefaultrK  rF   _datarp  r;  r   rq  rr  r  r   r  r   r  columns)r   r  rP  r  r3  vr;  r  s   ``  `   r   visit_valuesSQLCompiler.visit_values  s   
ow'<'<=$)) 	$
 !	$
 	
 	
 gllH$=$=>>--hED<<D GG ,D2L !!'* 33DMM4G4G4MN		 " &-__	"   !(+r   c                     SU-   $ )Nr   r   )r   alias_name_texts     r   r  &SQLCompiler.get_render_as_alias_suffix1  s    ''r   c                     Ub  US:X  a  SU l         SU l        UR                  (       a  [        R                  " S5      eU R
                  R                  XX445        g )N*FTzxMost backends don't support SELECTing from a tuple() object.  If this is an ORM query, consider using the Bundle object.)r  _ad_hoc_textualr  r   r  r$  r  )r   keynamer;  objectsr2  s        r   r  SQLCompiler._add_to_result_map4  sY    ?gn$)D!#'D ""4 
 	##WG$CDr   c                 :    U R                   " SUSSUc  0 OU40 UD6$ )a$  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_argsr3  s        r   _label_returning_column#SQLCompiler._label_returning_column@  s8     (($,B2D
 
 	
r   c                   ^^ TR                   R                  U R                  5      nUR                  (       a   U(       d  U(       a  UR	                  T5      nOTnU(       a+  U R
                  nU
(       a	  UmU4S jnOUTLa	  UmUU4S jnOSnU	(       d   S5       e[        T[        R                  5      (       a+  UTLa"  [        UTR                  TR                  4S9nGOuUnGOqU(       a#  Uc   S5       e[        UUUTR                  4S9nGOGUTLa  SnO[        T[        R                  5      (       a0  U=(       a&    TR                  (       + =(       a    TR                  SLnO[        T[        R                   5      (       a  SnOf[        T[        R"                  5      (       a  TR$                  =(       d    UnO1[        T[        R&                  5      (       d  TR(                  c  SnOSnU(       a_  U(       d  U
(       a   eTR*                  n[        U[        R,                  5      (       d  [        R,                  " U5      OUn[        XU4S9nOUnUR/                  U	US	9  UR0                  " U 40 UD6$ )
z.produce labeled columns present in a select().c                    > T" XSU5        g Nr   r   )r  r;  r  r2  r  s       r   rv  ;SQLCompiler._label_select_column.<locals>.add_to_result_mapz  s    &wb%@r   c                 "   > T" XT4U-   U5        g r   r   )r  r;  r  r2  r  r$   s       r   rv  r    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  rp  r   Labelr9  r;  r  r  ColumnClauser  re   
TextClauseUnaryExpressionwraps_column_expressionNamedColumn_non_anon_label_anon_name_labelrq  rR  r  )r   r_   r$   r  rP  r  r;  r  r  rY  column_is_repeatedneed_column_expressionsrW  col_exprrv  result_exprrender_with_labelr  s     `              @r   r   SQLCompiler._label_select_columnU  ss    {{''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8$)!FH$<$<==$*$B$B$Lf!
 vx';';<< **2$(!$)! *
  211*0*A*A' &+X-F-F  --.AB - $ ,j] '!!"7/ 	" 	
 --dI6HIIr   c                 F    U R                  X#5      nU(       a  USU-   -  nU$ r  )get_from_hint_text)r   sqltextre   hintr  hinttexts         r   r  !SQLCompiler.format_from_hint_text  s(    **57sX~%Gr   c                     g r   r   )r   byfromss     r   get_select_hint_text SQLCompiler.get_select_hint_text      r   c                     g r   r   r   re   r  s      r   r  SQLCompiler.get_from_hint_text   r  r   c                     g r   r   r  s      r   get_crud_hint_textSQLCompiler.get_crud_hint_text  r  r   c                 $    SR                  U5      $ r  r  )r   
hint_textss     r   get_statement_hint_text#SQLCompiler.get_statement_hint_text  s    xx
##r   r  r  c                     U R                   (       + nU(       a  U R                  OU R                   S   nUR                  X5      nUS   nUS   n	U(       a(  U(       d!  UR                  UR	                  U	5      SS9n
U
$ UR                  UU	S9n
U
$ )Nrs  r  r  r   explicit_correlate_fromsimplicit_correlate_froms)r   r  ru  _get_display_froms
difference)r   select_stmtrP  r  r3  r  r  r&  r  r  r   s              r   _display_froms_for_select%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	                 	  ^& Ub   S5       eSU	S'   UR                   " X40 U	D6n
U
R                  nU R                  (       + nU(       a  U R                  (       d  Xl        US L=(       d    UnU R                  (       a>  U R                  " U4SU0U	D6nXLa%  U
nUnUnUR                   " X40 U	D6n
U
R                  nU(       a  U R
                  OU R                  S   nU=(       d+    UR                  SS5      =(       d    UR                  SS5      =nnU(       a  SnU(       d	  SU	;   a  U	S	 U R                  XXXu5      nU	R                  5       nUR                  SSS	.5        S
nUR                  (       a$  U R                  U5      u  nnU(       a  UUS-   -  nOS nUR                  (       a&  UR                   H  nUR                  " U 40 U	D6  M     UR                  (       a   UU R                  " XR                  40 U	D6-  nUU R                   " U40 U	D6-  nU
R"                   VVVVVs/ s H!  u  nnnnnU R%                  UUUUUUUUUUS9
PM#     snnnnn Vs/ s H
  nUc  M  UPM     nnU(       a  Ub  ['        [)        U
R"                   VVVVVs/ s H  u  nnnnnUPM     snnnnnWR"                   VVVVVs/ s H  u  nnnnnUPM     snnnnn5      5      m&U R*                   VVV V!s/ s H!  u  nnn n!UU[-        U&4S jU  5       5      U!4PM#     sn!n nnU l        U R/                  UUU
UUUUU	5      nUR0                  (       a]  UR0                   V"V#s/ s H&  u  n"n#U"SU R2                  R4                  4;   d  M$  U#PM(     n$n"n#U$(       a  USU R7                  U$5      -   -  nU R8                  (       aN  U(       a  U(       a@  U(       d  [;        U R                  5      OS n%U R=                  U%U	R                  S5      S9U-   nUR>                  (       a#  USU R                  " XR>                  40 U	D6-   -  nU R                  RA                  S5        U$ s  snnnnnf s  snf s  snnnnnf s  snnnnnf s  sn!n nnf s  sn#n"f )NzpSQLAlchemy 1.4 requires use of the translate_select_structure hook for structural translations of SELECT objectsFrY  rP  rs  r  r  rv  )ro  rY  zSELECT r  )r;  r  r  r  r  c              3   F   >#    U  H  nTR                  X5      v   M     g 7fr   )r  )r   o	translates     r   r   +SQLCompiler.visit_select.<locals>.<genexpr>  s     !Cs!)--"5"5sr+  r  r  r  )!ru  r   r   r&  translate_select_structurer  r  _setup_select_stackcopyrR  _hints_setup_select_hintsr  r  r  r  get_select_precolumnscolumns_plus_namesr  r  r  r$  r  _compose_select_body_statement_hintsr   r;  r  r^  r  r  r  r   )'r   r%  rP  insert_intor  r  select_wraps_forr  r  r  r&  r  is_embedded_selectnew_select_stmtcompile_state_wraps_forr  r  r  r   r  r  	hint_textbyfromr  r;  r  r  r$   r  r  inner_columnsrP  r  r2  dialect_namehtper_dialectr  r+  s'                                         @r   visit_selectSQLCompiler.visit_select1  s     ' 	
-	
' +0&'#::
!'
 $--zz>D..!.+47F;
 **"==$*.4O 1*7'#. - + B B!)/! ,55-5))4::b>  >yy7?>yy5u=	
5 "'
 #':f'D*+((w
 $[[]!!$)EJ	
  $ 8 8 EIv	C'F(("44&&t6v6 5   D++226< D 	**;A&AA. #55'& 6'# ))'&)(;'/,C * $ 6'
* -  	 
4 #3#?  +==	 >&/ $  >	$ 5GG	 H&/ $  H	I6 .2-A-A$-A)CsE dE!Cs!CCUK-A$D 
 ((	
 '' +6*F*F*F&\2C):):#;; *F  
 d::;GGG 990H3;C

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

rA
@		$"s0   ,(QQ$(Q$Q) Q22(Q;
#RRc                    [        UR                  R                  5        VVVs/ s H=  u  u  p#nUSU R                  R                  4;   d  M&  UUSUR                  U SS90-  4PM?     snnn5      nU R                  U5      nXe4$ s  snnnf )Nr  r;  T)r  )r  r0  r  r   r;  r  r  )r   r_   r   r   r  r<  r;  s          r   r1  SQLCompiler._setup_select_hints  s     39--2E2E2G 3H.$UhsDLL$5$566u77T7JKL
 3H

 --f5	  s   %BBc           	      $   US   nUS   nUS:X  a  XS'   OmU(       af  US   n	[        U	R                  5      n
[        UR                  5      U
:w  a3  [        R                  " SSU
US-   [        UR                  5      4-  5      eU(       a'  U(       d   UR                  UR                  U5      SS9nOUR                  UUS9n[        [        R                  " U6 5      nUR                  U5      nUUUUS	.nU R                  R                  U5        U$ )
Nr  r  r   rp  z}All selectables passed to CompoundSelect must have identical numbers of columns; select #%d has %d columns, select #%d has %dr   r   r   )r  r  r   r&  )r  _all_selected_columnsr3  r   r  r#  r$  ra   r   r  rj   r   r  )r   r_   r&  r  rP  r  r  r  r  rp  numcolsr   new_correlate_fromsall_correlate_fromsr  s                  r   r.  SQLCompiler._setup_select_stack  s?      12^,Q &*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	                 z   USR                  U5      -  nU R                  [        -  (       a5  [        0 [	        5       5      n	U R                  [
        -  n
U(       a  Xl        OS n	Sn
U(       a  US-  nUR                  (       a;  USR                  U Vs/ s H  nUR                  " U 4SUU	S.UD6PM     sn5      -  nOLUSR                  U Vs/ s H  nUR                  " U 4SU	S.UD6PM     sn5      -  nOXR                  5       -  nUR                  (       a.  U R                  " UR                  4SU	0UD6nU(       a  USU-   -  nU
(       a  U	R                  5         UR                  (       a  XR                  " U40 UD6-  nUR                  (       a,  U R                  " UR                  40 UD6nU(       a  US	U-   -  nUR                   (       a  XR"                  " U40 UD6-  nUR$                  (       a  XR&                  " U40 UD6-  nUR(                  b  XR*                  " U40 UD6-  nU$ s  snf s  snf )
Nr}   Fz 
FROM T)rP  r  r  rP  r  r  z 
WHERE z	 
HAVING )rF   rT  r   r   ra   r   r  r0  r  rH  _where_criteriar  r   _group_by_clausesry  _having_criteria_order_by_clausesrz  r{  r|  _for_update_argfor_update_clause)r   r  r_   r&  r=  r   r<  r  r  r  warn_lintingfts                r   r4   SQLCompiler._compose_select_bodyB  s[    			-((<<44$R/K<<,6L#. K LJD}}		 "'	 "'A ,, #'&,(3	
 % "'	  		 "' "'A ,, #'(3 %	 "'
 
 %%''D!!11&&4?CIA a'##((:6::D""11''+1A q((##((:6::D****6<V<<D!!-**6<V<<Do	s   !H3
 H8
c                 Z   ^ ^ SR                  UU 4S jU 5       5      nU(       a  US-  nU$ )Nr  c              3      >#    U  H9  u  pUb  UTR                   R                  :X  d  M$  UR                  " T40 TD6v   M;     g 7fr   )r   r;  r  )r   prefixr>  r3  r   s      r   r   1SQLCompiler._generate_prefixes.<locals>.<genexpr>  sD      
(0$#|t||7H7H'H 2F%%d1b1(0s
   #AAr  )r   r  r  r3  r   s   `  ` r   r  SQLCompiler._generate_prefixes  s1     
(0
 

 cMFr   c                   ^ ^^ T R                   (       d  gU(       a  US:  a  [        R                  " 5       n[        T R                   R	                  5       5       Hh  nT R
                  UR                  5          u  pgXa:H  =(       d    U=(       a    XaS-   :H  nUR                  (       a  U(       d  MW  T R                   U   XE'   Mj     OT R                   nU(       d  g[        U Vs/ s H  oUR                  PM     sn5      n	T R                  (       ao  T R                  U   R                  U5        UcN  T R                  (       a=  T R                  c   eUUU 4S jmU 4S jmT" S5      n
T" T R                  X5      T l        T R                  U	5      S-   nUSR                  UR!                  5        Vs/ s H  oPM     sn5      -  nUS-  nU(       a{  US:  au  [        UR	                  5       5       HX  nT R
                  UR                  5          u  pgT R                   U	 T R"                  Xg4	 T R
                  UR                  5       	 MZ     U$ s  snf s  snf )	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                 h  > U TR                   ;   a  TR                   R                  U 5      n[        [        R                  R                  U4S jU 5       5      5      nU TR                  ;   a'  T" TR                  U    UTR                  US      5      $ U$ TR                  R                  U / 5      $ )Nc              3   4   >#    U  H  nT" U5      v   M     g 7fr   r   )r   	child_cteget_nested_positionals     r   r   PSQLCompiler._render_cte_clause.<locals>.get_nested_positional.<locals>.<genexpr>  s       :19I !6i @ @19s   r   )	r  r   ry  r  chainfrom_iterabler  r  r  )r  childrento_addr`  reorder_positionalr   s      r   r`  =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                    > U(       d  X-   $ Sn[        [        U 5      5       H  u  p4TR                  U   U:  d  M    O   U S U*  U-   X* S  -   $ r  )r  reversedrY  )posre  levelr   r;  r   s        r   rf  :SQLCompiler._render_cte_clause.<locals>.reorder_positional  s_     %|+E'0#'?11$7%?! (@ w<&03vw<??r   r  , 
z
 )r^  r   r  ry  keysr  r  r  r   r  rX  r  r  r   get_cte_preamblerF   r   r  )r   r  rt  r  r^  r  r  r  is_rendered_levelr  re  cte_texttxtr`  rf  s   `            @@r   r  SQLCompiler._render_cte_clause  s    yy]Q.##%DDIINN,-&*&<&<**,'#	 %.$> %+N	Q=N0N " (9 IIcN	 . 99Dt<tmmt<=??NN<(//5#''333@(@ /t4#5$$f$  ((83>FKK > >??E]Q.DIIK(&*&<&<**,'#	 IIcN++Y,AB**3+A+A+CD ) o =V !?s   %I3I
c                     U(       a  gg)NzWITH RECURSIVEWITHr   )r   r  s     r   ro  SQLCompiler.get_cte_preamble  s    #r   c                 x    UR                   (       a  [        R                  " SSS9  UR                  (       a  S$ S$ )zSCalled 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_   r3  s      r   r2  !SQLCompiler.get_select_precolumns  s:    
   3
  %..{6B6r   c                     U R                   " UR                  [        [        R                     40 UD6nU(       a  SU-   $ g)z5allow dialects to customize how GROUP BY is rendered.z
 GROUP BY r  )r   rN  rs  r	   comma_op)r   r_   r3  group_bys       r   ry  SQLCompiler.group_by_clause  sE     00$$i	0B0B&C
GI
 (**r   c                     U R                   " UR                  [        [        R                     40 UD6nU(       a  SU-   $ g)z5allow dialects to customize how ORDER BY is rendered.z
 ORDER BY r  )r   rP  rs  r	   r  )r   r_   r3  r:  s       r   rz  SQLCompiler.order_by_clause  sE     00$$i	0B0B&C
GI
 (**r   c                     g)Nz FOR UPDATEr   r}  s      r   rR  SQLCompiler.for_update_clause(  s    r   c                 .    [         R                  " S5      e)Nz@RETURNING is not supported by this dialect's statement compiler.r~  )r   r  returning_colss      r   returning_clauseSQLCompiler.returning_clause+  s    ,
 	
r   c                     SnUR                   b#  USU R                  " UR                   40 UD6-   -  nUR                  b5  UR                   c  US-  nUSU R                  " UR                  40 UD6-   -  nU$ )Nr  z
 LIMIT z

 LIMIT -1z OFFSET )_limit_clauser   _offset_clauser   r_   r3  r  s       r   r  SQLCompiler.limit_clause1  s    +K$,,v/C/C"Jr"JJJD  ,##+%Jf.C.C!Jr!JJJDr   c                 2   SnUR                   b#  USU R                  " UR                   40 UD6-  -  nUR                  bW  USU R                  " UR                  40 UD6< UR                  S   (       a  SOS< SUR                  S   (       a  SOS	< 3-  nU$ )
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  SQLCompiler.fetch_clause;  s      ,'$,,%%+)++  D +V118R8$::9E
2M//<  D r   c                    U(       a  UR                   UR                  U'   U(       d  U(       a  U R                  R                  U5      n	U(       aL  U	(       aE  U R                  R	                  U	5      S-   U R                  R                  UR                  5      -   n
O%U R                  R                  UR                  5      n
U(       a  X;   a  U R                  XXQ   U5      n
U
$ g)Nr  r  )fullnamer   r   r  r  r  r;  r  )r   re   rP  r  r  r  
use_schemar  r  r  rD  s              r   visit_tableSQLCompiler.visit_tableK  s     ',~~Ke$V#}}>>uE.MM../?@mm))%**56  mm))%**5U/00	 0& Jr   c                    U(       aX  UR                   R                  [        R                  " UR                  R
                  UR                  R
                  5      5        UR                  (       a  SnOUR                  (       a  SnOSnUR                  R                  " U 4SUS.UD6U-   UR                  R                  " U 4SUS.UD6-   S-   UR                  R                  " U 4SU0UD6-   $ )Nz FULL OUTER JOIN z LEFT OUTER JOIN z JOIN TrL   ON r  )r   rR  r  r  rH   r  r^   r:   isouterr  onclause)r   rF   rP  r  r  	join_types         r   
visit_joinSQLCompiler.visit_joinl  s    $$!!II++TZZ-E-E 99+I\\+I III((!{>D  jj++!{>D	  mm.."-17	
r   c           
      @   [        UR                  R                  5        VVVs/ s H)  u  u  p4nUSU R                  R                  4;   d  M&  X54PM+     snnn5      nUR
                  U;   a)  U R                  X!R
                  XaR
                     S5      nXb4$ s  snnnf )Nr  T)r  r0  r  r   r;  re   r  )r   r  
table_textre   r   r;  dialect_hintss          r   _setup_crud_hintsSQLCompiler._setup_crud_hints  s     48;;3D3D3F3F/$UisDLL$5$566 #"3F
 ::&33JJjj(A4J ((s   %BBc                 p
   UR                   " X40 UD6nUR                  nU R                  (       + nU(       a5  SU l        U R                  (       d  X0l        U R
                  (       d  X0l        U R                  R                  [        5       [        5       US.5        [        R                  " XU40 UD6nU(       d~  U R                  R                  (       dc  U R                  R                  (       dH  U R                  R                  (       d-  [        R                  " SU R                  R                   -  5      eUR"                  (       aN  U R                  R$                  (       d-  [        R                  " SU R                  R                   -  5      eUS   nOUnU R&                  nU R                  R                  nSn	UR(                  (       a  XR*                  " XR(                  40 UD6-  n	U	S-  n	UR-                  UR.                  5      n
UR0                  (       a  U R3                  X5      u  pUR4                  (       a&  UR4                   H  nUR6                  " U 40 UD6  M     X-  n	U(       d  U(       d.  U	SS	R9                  U VVVs/ s H  u  poPM	     snnn5      -  -  n	U R:                  (       d  UR<                  (       aH  U R?                  XR:                  =(       d    UR<                  5      nU R@                  (       a  U	S
U-   -  n	OS nURB                  b  U RD                  " U R                  S   S   4SS0UD6nU RF                  (       ad  U R                  RH                  (       aI  U(       d  [K        U R                  5      OS nU	S
U RM                  USURO                  S5      S9< U< 3-  n	OU	SU-  -  n	OU(       d  U(       a  U	S-  n	OnUR"                  (       a  U	SS	R9                  S U 5       5      -  -  n	O>S	R9                  U VVVs/ s H  u  poPM	     snnn5      nU	SU-  -  n	U(       a  UU l(        URR                  b,  U RD                  " URR                  40 UD6nU(       a  U	S
U-   -  n	U(       a  U R@                  (       d  U	S
U-   -  n	U RF                  (       a\  U R                  RH                  (       dA  U(       d  [K        U R                  5      OS nU RM                  USURO                  S5      S9U	-   n	U R                  RU                  S5        U	$ s  snnnf s  snnnf )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  rs  insert_from_selectr6  r  rs  r  z DEFAULT VALUESz
 VALUES %sc              3   X   #    U  H   nS SR                  S U 5       5      -  v   M"     g7f)r  r}   c              3   *   #    U  H	  u  po3v   M     g 7fr   r   r   r  r  r  s       r   r   5SQLCompiler.visit_insert.<locals>.<genexpr>.<genexpr>  s      L^>1E^r  Nr  )r   crud_param_sets     r   r   +SQLCompiler.visit_insert.<locals>.<genexpr>  s1       +6 yy L^ LLN*5s   (*z VALUES (%s))+ru  r   r   rc  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   r0  r  r  r  rF   rg  rf  r  returning_precedes_valuesr_   r   r^  cte_follows_insertr  r  r  insert_single_values_expr_post_values_clauser   )r   insert_stmtr3  r&  r  crud_paramscrud_params_singler   r  r  r  r  r  r  r  r  r  select_textr  r  post_values_clauses                        r   visit_insertSQLCompiler.visit_insert  s   #::
!#
 $--zz> DM)))6&%%%2"

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

234BFJLK yyT\\<<7?DJJT++&304%'VVN%; , 
    ++!8%%D00L		  +6  D )-		-89[>1E[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   T*T1c                     g)z3Provide a hook for MySQL to add LIMIT to the UPDATENr   )r   update_stmts     r   update_limit_clauseSQLCompiler.update_limit_clause,  s    r   c                 6    SUS'   UR                   " U 4SS0UD6$ )zdProvide a hook to override the initial table clause
in an UPDATE statement.

MySQL overrides this.

TrP  r  r  )r   r  
from_tableextra_fromsr3  s        r   update_tables_clause SQLCompiler.update_tables_clause0  s(     8,,TE$E"EEr   c                     [        S5      e)zfProvide 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_hintsr3  s         r   update_from_clauseSQLCompiler.update_from_clause:  s     "%
 	
r   c                    UR                   " X40 UD6nUR                  nU R                  (       + nU(       a5  SU l        U R                  (       d  X0l        U R
                  (       d  X0l        UR                  n[        U5      nU(       aT  [        [        R                  " UR                  5      5      nU Vs/ s H  oU;  d  M
  UPM     n	nUR                  U5      n
O/ n	UR                  1n
U R                  R                  U
U
US.5        SnUR                  (       a  XR                  " XR                  40 UD6-  nU R                   " XR                  U	40 UD6n["        R$                  " XU40 UD6nUR&                  (       a  U R)                  X5      u  pOS nUR*                  (       a&  UR*                   H  nUR,                  " U 40 UD6  M     X-  nUS-  nUSR/                  S U 5       5      -  nU R0                  (       d  UR2                  (       aE  U R4                  (       a4  USU R7                  XR0                  =(       d    UR2                  5      -   -  nU(       a/  U R8                  " UUR                  U	U40 UD6nU(       a  USU-   -  nUR:                  (       a,  U R<                  " UR:                  40 UD6nU(       a  USU-   -  nU R?                  U5      nU(       a  USU-   -  nU R0                  (       d  UR2                  (       aE  U R4                  (       d4  USU R7                  XR0                  =(       d    UR2                  5      -   -  nU R@                  (       a@  U(       d  [C        U R                  5      OS nU RE                  UURG                  S	5      S
9U-   nU R                  RI                  S5        U$ s  snf )NTr  zUPDATE z SET r}   c              3   6   #    U  H  u  po2S -   U-   v   M     g7f)=Nr   r  s       r   r   +SQLCompiler.visit_update.<locals>.<genexpr>  s     O;%*u,;s   r   WHERE r  r  rs  )%ru  r   r   rd  r'  r&  _extra_fromsr  ra   r   r  re   rj   r  r  r  r  r   r  r0  r  r  r  rF   rg  rf  r  r  r  rM  r  r  r^  r  r  r  r   )r   r  r3  r&  r  r  is_multitable
main_fromsrT  render_extra_fromsr  r  r  r  r  r  extra_from_textrU  r  r  s                       r   visit_updateSQLCompiler.visit_updateH  s   #::
!#
 $--zz> DM)))6&%%%2"#00[)Z55k6G6GHIJ&"&a:*=;  " )..{;O!#*001O

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

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

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

r{"s   8	OOc                     [        S5      e)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_clause$SQLCompiler.delete_extra_from_clause  s     "%
 	
r   c                 $    UR                  U SSS9$ )NT)rP  r  r  )r   delete_stmtr  r  s       r   delete_table_clauseSQLCompiler.delete_table_clause  s    ,,T$t,LLr   c                    UR                   " X40 UD6nUR                  nU R                  (       + nU(       a5  SU l        U R                  (       d  X0l        U R
                  (       d  X0l        UR                  nUR                  1R                  U5      nU R                  R                  UUUS.5        SnUR                  (       a  XpR                  " XR                  40 UD6-  nUS-  nU R                  XR                  U5      nUR                  (       a  U R                  X5      u  pOS n	UR                  (       a&  UR                   H  n
U
R                   " U 40 UD6  M     Xx-  nUR"                  (       a2  U R$                  (       a!  USU R'                  XR"                  5      -   -  nU(       a/  U R(                  " UUR                  UU	40 UD6nU(       a  USU-   -  nUR*                  (       a,  U R,                  " UR*                  40 UD6nU(       a  USU-   -  nUR"                  (       a2  U R$                  (       d!  USU R'                  XR"                  5      -   -  nU R.                  (       a@  U(       d  [1        U R                  5      OS nU R3                  UUR5                  S5      S9U-   nU R                  R7                  S	5        U$ )
NTr  zDELETE FROM r  r  r  r  rs  )ru  r   r   re  r'  r&  r  re   rj   r  r  r  r  r0  r  r  r  rf  r  r  r  rM  r  r^  r  r  r  r   )r   r  r3  r&  r  r  r  r  r  r  r  r  rU  r  s                 r   visit_deleteSQLCompiler.visit_delete  s   #::
!#
 $--zz> DM)))6&%%%2"#00&,,-33K@

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

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

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

rr   c                 >    SU R                   R                  U5      -  $ )NzSAVEPOINT %sr   format_savepointr   savepoint_stmts     r   visit_savepointSQLCompiler.visit_savepoint+  s     > >~ NNNr   c                 >    SU R                   R                  U5      -  $ )NzROLLBACK TO SAVEPOINT %sr  r  s     r   visit_rollback_to_savepoint'SQLCompiler.visit_rollback_to_savepoint.  s#    )DMM,J,J-
 
 	
r   c                 >    SU R                   R                  U5      -  $ )NzRELEASE SAVEPOINT %sr  r  s     r   visit_release_savepoint#SQLCompiler.visit_release_savepoint3  s#    %(F(F)
 
 	
r   ),r  rQ  r  r[  r  rm  r$  r  ra  rW  rU  r]  r(  rO  r&  r  r  r  r^  r  r  r'  r  r   rS  r  rV  ri  r  re  rc  r  rd  r_  r  rT  rX  r   rY  r  rg  r   r   rb  )NNTNTr   )NFF)NFFNr   )NTr   r   )FNr  )NFNN)FFFFF)NFFN)FFNNN)FFFNFFNN)NNNTFF)FFNNNFN)NFN)FFFNTN)r   r   r   r   r"  EXTRACT_MAPrJ  COMPOUND_KEYWORDSrv  re  rc  rd  r  rg  r  'render_table_with_column_in_update_fromr  r  r  r  r  r[  rm  r  r  r  r  r   r%  r  rV  rz  r{  postfetch_lastrowidrQ  r  compiler  r   rY  ri  r   r   r*  rv  r|  memoized_propertyr  memoized_instancemethodr  
contextlibcontextmanagerr  rl  r  r  r  r  r  r   rn  preload_moduler  r"  r9  rE  rH  rQ  rU  rc  rk  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r#  r(  r+  r3  r=  rA  rG  rM  rT  rP  rg  rd  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/  r3  r8  r;  r@  rD  rG  r\  r   r  r  rQ  rr  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r)  r  r&  r-  rA  r1  r.  r4  r  r  ro  r2  ry  rz  rR  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   rL  rL  8  s    K)%**H*x(
 KI
 !& /4+
 O  % O  #( N  
 !% '[
 $+
 
  )+*Oo% ! JJ'LMK F mJ^ # #J A A 
  
!!; ";0  .
 

 
,#  
 !qf 
!!04@ "@D 
3 
3 /4jX 
34
 5
 
  
	34( 5 (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$  --
Y[	)NIK+HI
 ,1: "& L\!2hRh  %	Yv7 	

& B
:)SjF
qf
 M[zO


r   rL  c                      ^  \ rS rSrSrS r\R                  " S5      U 4S j5       rS r	S r
S rS	 rS
 rS rS rS rS rS rS rS rSrU =r$ )StrSQLCompileri9  a_  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                     g)Nz<name unknown>r   r  s     r   r  $StrSQLCompiler._fallback_column_nameM  s    r   zsqlalchemy.engine.urlc                 ^  > UR                   S:w  a  [        R                  R                  nUR                  R                  UR                   5      R                  5       " 5       nUR                  US 5      n[        U[        5      (       d  UR                  U5      $ [        [        U ]3  X5      $ )Nr-   )stringify_dialectr   r  
engine_urlURLr&   get_dialectstatement_compilerrp  r  r   superr  )r   r  r  r3  urlr   compilerr[  s          r   r  ,StrSQLCompiler.visit_unsupported_compilationP  s    $$	1..++CggnnW%>%>?KKMOG11'4@Hh77''00^TH
 	
r   c                     U R                   " UR                  40 UD6< SU R                   " UR                  40 UD6< S3$ )N[])r   rH   r^   r  s       r   visit_getitem_binary#StrSQLCompiler.visit_getitem_binary^  s6    LL++LL,,
 	
r   c                 (    U R                   " X40 UD6$ r   r  r  s       r   visit_json_getitem_op_binary+StrSQLCompiler.visit_json_getitem_op_binaryd      ((@R@@r   c                 (    U R                   " X40 UD6$ r   r  r  s       r   !visit_json_path_getitem_op_binary0StrSQLCompiler.visit_json_path_getitem_op_binaryg  r  r   c                 >    SU R                   R                  U5      -  $ )Nz<next sequence value: %s>)r   format_sequence)r   seqr3  s      r   rd  StrSQLCompiler.visit_sequencej  s    *T]]-J-J3-OOOr   c                     [         R                  " U5       Vs/ s H!  nU R                  S USS0 UR                  S9PM#     nnSSR	                  U5      -   $ s  snf )NTF)r  z
RETURNING r}   )r   _select_iterablesr  r  rF   )r   r  r  r  r  s        r   r  StrSQLCompiler.returning_clausem  sq    
 ++N;	
 < %%auba>O>O &  <	 	 
 dii000
s   (Ac                 R   ^ ^^ STS'   SSR                  UUU 4S jU 5       5      -   $ )NTrP  r  r}   c              3   N   >#    U  H  nUR                   " T4S T0TD6v   M     g7fr  Nr  r   rU  r  r3  r   s     r   r   4StrSQLCompiler.update_from_clause.<locals>.<genexpr>{  s-      #
    BBrB r  r  r  s   `   ``r   r  !StrSQLCompiler.update_from_clausew  s3     8 #
 #
 
 
 	
r   c                 R   ^ ^^ STS'   SSR                  UUU 4S jU 5       5      -   $ )NTrP  r}   c              3   N   >#    U  H  nUR                   " T4S T0TD6v   M     g7fr"  r  r#  s     r   r   :StrSQLCompiler.delete_extra_from_clause.<locals>.<genexpr>  s-       
    BBrB r  r  r  s   `   ``r   r  'StrSQLCompiler.delete_extra_from_clause  s3     8dii  
  
 
 
 	
r   c                     g)NzSELECT 1 WHERE 1!=1r   )r   r2  s     r   r  #StrSQLCompiler.visit_empty_set_expr  s    $r   c                     SU-  $ )Nz[%s]r   r  s      r   r  !StrSQLCompiler.get_from_hint_text  s    }r   c                 *    U R                   " US40 UD6$ )Nz
 <regexp> r  r  s       r   r@  +StrSQLCompiler.visit_regexp_match_op_binary  s    ,,V\HRHHr   c                 *    U R                   " US40 UD6$ )Nz <not regexp> r/  r  s       r   rD  /StrSQLCompiler.visit_not_regexp_match_op_binary  s    ,,V5ELLLr   c                     SUR                   R                  " U 40 UD6< SUR                  R                  " U 40 UD6< S3$ )Nz<regexp replace>(r}   rM  )rH   r  r^   r  s       r   rG  -StrSQLCompiler.visit_regexp_replace_op_binary  s:    KK**4626LL++D7B7
 	
r   r   )r   r   r   r   r"  r  r   r  r  r  r  r  rd  r  r  r  r  r  r@  rD  rG  r   __classcell__)r[  s   @r   r  r  9  ss    &  
01
 2

AAP1

%IM
 
r   r  c                   ^   \ rS rSr\R
                  S 5       r\R
                  S 5       r S,S jrS r	S r
S rS	 rS-S
 jr S.S jrS rS rS r S/S jrS rS-S jrS rS rS rS rS rS rS.S jrS rS rS rS rS r S r!S r"S  r#S! r$S" r%S# r&S$ r'S% r(S& r)S' r*S( r+S) r,S* r-S+r.g)0DDLCompileri  c                 `    U R                   R                  U R                   S U R                  S9$ )N)r   )r   r  r   r  s    r   r  DDLCompiler.sql_compiler  s/    ||..LL$T5N5N / 
 	
r   c                 .    U R                   R                  $ r   )r   r  r  s    r   r  DDLCompiler.type_compiler  s    ||)))r   Nc                     g r   r   r  s       r   r  DDLCompiler.construct_params  s     r   c                    UR                   n[        UR                  [        R                  5      (       a  UR                  5       nU R                  nUR                  UR                  5      n[        U5      S:X  a  US   SpvO	US   US   pvUR                  SU5        UR                  SU5        UR                  SUR                  UR                  5      5        U R                  R                  UR                  U-  5      $ )Nr   r   r  rs  re   r
   r  )contextrp  targetr
   Tabler/  r   format_table_seqr  r  r  r  r  r   )r   ddlr  r?  r   pathre   schs           r   	visit_ddlDDLCompiler.visit_ddl  s    ++cjj&,,//llnG}}H,,SZZ8D4yA~!!Wbs!"XtAwsw.x-z8+@+@+LM  223==73JKKr   c                 V    U R                   R                  UR                  5      nSU-   $ )NzCREATE SCHEMA )r   format_schemar  )r   r&   r3  r
   s       r   visit_create_schemaDDLCompiler.visit_create_schema  s%    ,,V^^<&((r   c                     U R                   R                  UR                  5      nSU-   nUR                  (       a  US-  nU$ )NzDROP SCHEMA  CASCADE)r   rI  r  cascade)r   dropr3  r
   r  s        r   visit_drop_schemaDDLCompiler.visit_drop_schema  s:    ,,T\\:&<<JDr   c                    UR                   nU R                  nSnUR                  (       a!  USR                  UR                  5      S-   -  nUS-  nUR                  (       a  US-  nXTR                  U5      S-   -  nU R                  U5      nU(       a  XVS-   -  nUS-  nSnSnUR                   H]  n	U	R                   n
 U R                  XR                  =(       a    U(       + S9nUb  XW-  nS	nUS
U-   -  nU
R                  (       a  SnM]  M_     U R%                  UUR&                  S9nU(       a
  XWS
-   U-   -  nUSU R)                  U5      -  -  nU$ ! [        R                   ap  n[        R                  " [        R                  " [        R                  " S5      UR                  U
R                   UR"                  S   4-  5      US9   S nAGM$  S nAff = f)Nz
CREATE r  zTABLE IF NOT EXISTS rL  
Ffirst_pkrm  	Tz (in table '%s', column '%s'): %sr   re  ) _include_foreign_key_constraintsz
)%s

)r  r   r  rF   if_not_existsr  create_table_suffixr  r   r1  r   r  r   r  udescriptionr;  argscreate_table_constraintsinclude_foreign_key_constraintspost_create_table)r   r&   r3  re   r   r  rZ  r  rV  create_columnr$   	processedceconsts                 r   visit_create_tableDDLCompiler.visit_create_table  s   ==??CHHU__-33D$$D%%e,s22"66u=#--D	 #^^M"**F LL!,>,>,Ox< ) 	 (%D &ID9,,D%%#H & ,* ---3-S-S . 
 $u,,Dd44U;;;# ## $$AB ,,fkk2771:FG  s   AEG+A$GGc                    ^  UR                   nUR                  (       a  g T R                  XBS9nSR                  U 4S jUR                   5       5      nU(       a  USU-   -  nU$ )NrU  r  c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr   )r   r   r%   r   s     r   r   2DDLCompiler.visit_create_column.<locals>.<genexpr>  s!      
7IDLL$$7Ir+  )r  systemget_column_specificationrF   constraints)r   r&   rV  r3  r$   r  rd  s   `      r   visit_create_columnDDLCompiler.visit_create_column  sb    ==,,V,G 
7=7I7I
 
 C%KDr   c                   ^  / nUR                   (       a  UR                  UR                   5        UR                  nUb  UR                  U5      nO
[	        5       nUR                  UR                   Vs/ s H  nXqR                   Ld  M  Xv;  d  M  UPM     sn5        SR                  S U 4S jU 5        5       5      $ s  snf )Nz, 
	c              3   0   #    U  H  nUc  M  Uv   M     g 7fr   r   )r   ps     r   r   7DDLCompiler.create_table_constraints.<locals>.<genexpr>(  s"      
  As   	c              3      >#    U  Hj  nUR                   b  UR                  T5      (       d  M(  TR                  R                  (       a  [        USS5      (       a  MW  TR	                  U5      v   Ml     g 7f)N	use_alterF)_create_ruler   supports_alterrW  r   ri  s     r   r   rs  *  s`      "-J++3!..t4	 ) 33":{EB )Z(("-s   'A5+A5A5)r1  r  foreign_key_constraintsr$  ra   r  _sorted_constraintsrF   )r   re   rX  r3  rm  all_fkcs	omit_fkcsr  s   `       r   r^  $DDLCompiler.create_table_constraints  s     u00100+7 ++,LMII 222A--- 232D 2	
 }} 
"-
 
 	
s   4C 
C C c                     SnUR                   (       a  US-  nX0R                  R                  UR                  5      -   $ )Nz
DROP TABLE 
IF EXISTS )	if_existsr   r  r  )r   rO  r3  r  s       r   visit_drop_tableDDLCompiler.visit_drop_table9  s4    >>L Dmm00>>>r   c                 R    SU R                   R                  UR                  5      -   $ )Nz
DROP VIEW r   r  r  r   rO  r3  s      r   visit_drop_viewDDLCompiler.visit_drop_view?  s      : :4<< HHHr   c                 d    UR                   c#  [        R                  " SUR                  -  5      eg )Nz,Index '%s' is not associated with any table.)re   r   r  r;  r   r   s     r   _verify_index_tableDDLCompiler._verify_index_tableB  s0    ;;""AEJJN  r   c           	        ^  UR                   nT R                  U5        T R                  nSnUR                  (       a  US-  nUR                  c  [
        R                  " S5      eUS-  nUR                  (       a  US-  nUT R                  XRS9< SUR                  UR                  US9< S	S
R                  U 4S jUR                   5       5      < S3-  nU$ )NzCREATE zUNIQUE z0CREATE INDEX requires that the index have a namezINDEX rS  include_schemar  r  r  r}   c              3   Z   >#    U  H   nTR                   R                  US SS9v   M"     g7f)FTr  rK  N)r  r   )r   r  r   s     r   r   1DDLCompiler.visit_create_index.<locals>.<genexpr>_  s9       .D !!))T *  .r  rM  )r  r  r   rk   r;  r   r  rY  _prepared_index_namer  re   rF   expressions)r   r&   r  include_table_schemar3  r   r   r  s   `       r   visit_create_indexDDLCompiler.visit_create_indexH  s       '==<<ID::""B  	$$D%%e%K!!(< "  II  "--	 
 	
 r   c                     UR                   nUR                  c  [        R                  " S5      eSnUR                  (       a  US-  nX@R                  USS9-   $ )Nz.DROP INDEX requires that the index have a namez
DROP INDEX r~  Tr  )r  r;  r   r  r  r  )r   rO  r3  r   r  s        r   visit_drop_indexDDLCompiler.visit_drop_indexh  s\    ::""@  >>L D//d/KKKr   c                    UR                   b&  U R                  R                  UR                   5      nOS nU(       a#  U(       a  U R                  R                  U5      nOS nU R                  R	                  U5      nU(       a  US-   U-   nU$ Nr  )re   r   r  r  format_index)r   r   r  r  schema_name
index_names         r   r   DDLCompiler._prepared_index_nameu  sw    ;;"#}}>>u{{K#.--445EFKK]]//6
$s*Z7Jr   c                     SU R                   R                  UR                  R                  5      < SU R	                  UR                  5      < 3$ )NALTER TABLE z ADD )r   r  r  re   r   r   r&   r3  s      r   visit_add_constraint DDLCompiler.visit_add_constraint  s8    MM&&v~~';';<LL(
 	
r   c                     SU R                   R                  UR                  5      < SU R                  R	                  UR                  R
                  [        R                  " 5       5      < 3$ )NzCOMMENT ON TABLE r   )r   r  r  r  r  commentr   Stringr  s      r   visit_set_table_comment#DDLCompiler.visit_set_table_comment  sL    MM&&v~~622&&(9
 	
r   c                 R    SU R                   R                  UR                  5      -  $ )NzCOMMENT ON TABLE %s IS NULLr  r  s      r   visit_drop_table_comment$DDLCompiler.visit_drop_table_comment  s'    ,t}}/I/ILL0
 
 	
r   c                     SU R                   R                  UR                  SSS9< SU R                  R	                  UR                  R
                  [        R                  " 5       5      < 3$ )NzCOMMENT ON COLUMN T)	use_tabler  r   )r   format_columnr  r  r  r  r   r  r  s      r   visit_set_column_comment$DDLCompiler.visit_set_column_comment  sZ    MM''$4 (  22&&(9	
 	
r   c                 P    SU R                   R                  UR                  SS9-  $ )NzCOMMENT ON COLUMN %s IS NULLT)r  )r   r  r  r  s      r   visit_drop_column_comment%DDLCompiler.visit_drop_column_comment  s/    -0K0KLLD 1L 1
 
 	
r   c                    / nUR                   b  UR                  SUR                   -  5        UR                  b  UR                  SUR                  -  5        UR                  b  UR                  SUR                  -  5        UR                  b  UR                  SUR                  -  5        UR
                  b  UR                  S5        UR                  b  UR                  S5        UR                  b  UR                  SUR                  -  5        UR                  b$  UR                  UR                  (       a  SOS	5        S
R                  U5      $ )NzINCREMENT BY %dzSTART WITH %dzMINVALUE %dzMAXVALUE %dzNO MINVALUEzNO MAXVALUEzCACHE %dCYCLEzNO CYCLEr  )
	incrementr  r   minvaluemaxvalue
nominvalue
nomaxvaluecachecyclerF   )r   identity_optionsr  s      r   get_identity_options DDLCompiler.get_identity_options  s   %%1KK),<,F,FFG!!-KK*:*@*@@A$$0KK(8(A(AAB$$0KK(8(A(AAB&&2KK&&&2KK&!!-KK
%5%;%;;<!!-KK#3#9#9zJxx~r   c                 8   SU R                   R                  UR                  5      -  nU(       a  XB-  nUR                  R                  c%  U R                  R
                  UR                  l        U R                  UR                  5      nU(       a  USU-   -  nU$ )NzCREATE SEQUENCE %sr  )r   r  r  r   r   default_sequence_baser  )r   r&   rY  r3  r  optionss         r   visit_create_sequence!DDLCompiler.visit_create_sequence  s    #dmm&C&CNN'
 
 ND>>'#'<<#E#EFNN ++FNN;C'M!Dr   c                 R    SU R                   R                  UR                  5      -  $ )NzDROP SEQUENCE %s)r   r  r  r  s      r   visit_drop_sequenceDDLCompiler.visit_drop_sequence  s     !DMM$A$A$,,$OOOr   c                 h   UR                   nUR                  b  U R                  R                  U5      nOS nUc#  [        R
                  " SUR                   -  5      eSU R                  R                  UR                   R                  5      < SU< UR                  =(       a    S=(       d    S< 3$ )Nz<Can't emit DROP CONSTRAINT for constraint %r; it has no namer  z DROP CONSTRAINT rM  r  )	r  r;  r   format_constraintr   r  r  re   rN  )r   rO  r3  r%   formatted_names        r   visit_drop_constraint!DDLCompiler.visit_drop_constraint  s    \\
??&!]]<<ZHN!N!""!#'<<0  " MM&&t||'9'9:LL'Z-2-
 	
r   c                 J   U R                   R                  U5      S-   U R                  R                  R	                  UR
                  US9-   nU R                  U5      nUb  USU-   -  nUR                  b!  USU R	                  UR                  5      -   -  nUR                  b<  U R                  R                  (       a!  USU R	                  UR                  5      -   -  nUR                  (       d1  UR                  (       a  U R                  R                  (       d  US-  nU$ )Nr  )r  z	 DEFAULT z	 NOT NULL)r   r  r   r  r   r  get_column_default_stringcomputedidentitysupports_identity_columnsnullable)r   r$   r  colspecr-   s        r   rl  $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                     gNr  r   r   re   s     r   rZ  DDLCompiler.create_table_suffix      r   c                     gr  r   r  s     r   r`  DDLCompiler.post_create_table  r  r   c                    [        UR                  [        R                  5      (       a  [        UR                  R                  [
        R                  5      (       a>  U R                  R                  UR                  R                  [        R                  5      $ U R                  R                  UR                  R                  SS9$ g )NT)rK  )rp  server_defaultr
   DefaultClauseargr   r  r  r  r   r  r   r  s     r   r  %DDLCompiler.get_column_default_string  s    f++V-A-ABB&//33T5F5FGG((==))--x/B/B  ((00))--T 1   r   c                 h    UR                   (       a  U R                  U5      $ U R                  U5      $ r   )is_column_levelvisit_column_check_constraintvisit_check_constraint)r   r%   r3  s      r   &visit_table_or_column_check_constraint2DDLCompiler.visit_table_or_column_check_constraint  s-    %%55jAA..z::r   c                     SnUR                   b&  U R                  R                  U5      nUb  USU-  -  nUSU R                  R	                  UR
                  SSS9-  -  nX0R                  U5      -  nU$ Nr  CONSTRAINT %s z
CHECK (%s)FTr  r;  r   r  r  r   r  define_constraint_deferrabilityr   r%   r3  r  r  s        r   r  "DDLCompiler.visit_check_constraint      ??&!]]<<ZHN)(>99t0088e4  9  
 
 	
 	44Z@@r   c                     SnUR                   b&  U R                  R                  U5      nUb  USU-  -  nUSU R                  R	                  UR
                  SSS9-  -  nX0R                  U5      -  nU$ r  r  r  s        r   r  )DDLCompiler.visit_column_check_constraint  r  r   c                 T  ^  [        U5      S:X  a  gSnUR                  b&  T R                  R                  U5      nUb  USU-  -  nUS-  nUSSR	                  U 4S jUR
                  (       a  UR                  OUR                   5       5      -  -  nUT R                  U5      -  nU$ )Nr   r  r  zPRIMARY KEY r  r}   c              3   n   >#    U  H*  nTR                   R                  UR                  5      v   M,     g 7fr   r   r  r;  r   r  r   s     r   r   ;DDLCompiler.visit_primary_key_constraint.<locals>.<genexpr>2  s5      #
(  MM''(r  )	r  r;  r   r  rF   _implicit_generatedcolumns_autoinc_firstr  r  r  s   `    r   visit_primary_key_constraint(DDLCompiler.visit_primary_key_constraint)  s    z?a??&!]]<<ZHN)(>99 #
 11 00''(#
 
 
 	
 	44Z@@r   c           
      $  ^ U R                   mSnUR                  b&  U R                   R                  U5      nUb  USU-  -  n[        UR                  5      S   R
                  R                  nUSSR                  U4S jUR                   5       5      < SU R                  XT5      < SSR                  U4S	 jUR                   5       5      < S
3-  nX0R                  U5      -  nX0R                  U5      -  nX0R                  U5      -  nU$ )Nr  r  r   zFOREIGN KEY(r}   c              3   n   >#    U  H*  nTR                  UR                  R                  5      v   M,     g 7fr   )r  parentr;  r   rT  r   s     r   r   ;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>F  )      7J!qxx}}--7Jr  z) REFERENCES r  c              3   n   >#    U  H*  nTR                  UR                  R                  5      v   M,     g 7fr   )r  r$   r;  r  s     r   r   r  L  r   r  rM  )r   r;  r  ry  r   r$   re   rF   define_constraint_remote_tabledefine_constraint_matchdefine_constraint_cascadesr  )r   r%   r3  r  r  remote_tabler   s         @r   visit_foreign_key_constraint(DDLCompiler.visit_foreign_key_constraint=  s
   ==??&!]]<<ZHN)(>99J//03::@@II 7A7J7J  //( II 7A7J7J 

 
	
 	,,Z88//
;;44Z@@r   c                 $    UR                  U5      $ )z=Format the remote table clause of a CREATE CONSTRAINT clause.)r  )r   r%   re   r   s       r   r  *DDLCompiler.define_constraint_remote_tableU  s     $$U++r   c                    ^  [        U5      S:X  a  gSnUR                  b&  T R                  R                  U5      nUb  USU-  -  nUSSR	                  U 4S jU 5       5      -  -  nUT R                  U5      -  nU$ )Nr   r  r  zUNIQUE (%s)r}   c              3   n   >#    U  H*  nTR                   R                  UR                  5      v   M,     g 7fr   r  r  s     r   r   6DDLCompiler.visit_unique_constraint.<locals>.<genexpr>c  s'     F:admm))!&&11:r  )r  r;  r   r  rF   r  r  s   `    r   visit_unique_constraint#DDLCompiler.visit_unique_constraintZ  s    z?a??&!]]<<ZHN)(>99IIF:FF
 	
 	44Z@@r   c                     SnUR                   b0  USU R                  R                  UR                   [        5      -  -  nUR                  b0  USU R                  R                  UR                  [
        5      -  -  nU$ )Nr  z ON DELETE %sz ON UPDATE %s)ondeleter   validate_sql_phraseFK_ON_DELETEonupdateFK_ON_UPDATEr   r%   r  s      r   r  &DDLCompiler.define_constraint_cascadesh  s    *Odmm&G&G##\'  D *Odmm&G&G##\'  D r   c                     SnUR                   b  UR                   (       a  US-  nOUS-  nUR                  b0  USU R                  R                  UR                  [        5      -  -  nU$ )Nr  z DEFERRABLEz NOT DEFERRABLEz INITIALLY %s)r.   r@   r   r  FK_INITIALLYr  s      r   r  +DDLCompiler.define_constraint_deferrabilityt  sq      ,$$%))+Odmm&G&G$$l'  D r   c                 H    SnUR                   b  USUR                   -  -  nU$ )Nr  z	 MATCH %s)rP  r  s      r   r  #DDLCompiler.define_constraint_match  s-    'K*"2"222Dr   c                     SU R                   R                  UR                  SSS9-  nUR                  SL a  US-  nU$ UR                  SL a  US-  nU$ )NzGENERATED ALWAYS AS (%s)FTr  z STOREDz VIRTUAL)r  r   r  	persisted)r   	generatedr3  r  s       r   visit_computed_column!DDLCompiler.visit_computed_column  sr    )D,=,=,E,EU$ -F -
 
 $&ID    E)JDr   c                 z    SUR                   (       a  SOS< S3nU R                  U5      nU(       a  USU-  -  nU$ )Nz
GENERATED ALWAYSz
BY DEFAULTz AS IDENTITYr  )alwaysr  )r   r  r3  r  r  s        r   visit_identity_column!DDLCompiler.visit_identity_column  s@     H\9
 ++H5Gg%%Dr   r   r!  r  r   )FT)/r   r   r   r   r   r  r  r  r  rF  rJ  rP  re  rn  r^  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rl  rZ  r`  r  r  r  r  r  r  r  r  r  r  r  r  r$  r   r   r   r   r7  r7    s   	
 

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




(P
$6;

(0,

r   r7  c                      \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S  r"S! r#S" r$S# r%S$ r&S% r'S& r(S' r)S( r*S) r+S* r,S+ r-S,r.g-).GenericTypeCompileri  c                     g)NFLOATr   r1  s      r   visit_FLOATGenericTypeCompiler.visit_FLOAT      r   c                     g)NREALr   r1  s      r   
visit_REALGenericTypeCompiler.visit_REAL  r  r   c                     UR                   c  gUR                  c  SSUR                   0-  $ SUR                   UR                  S.-  $ )NNUMERICzNUMERIC(%(precision)s)	precisionz!NUMERIC(%(precision)s, %(scale)s)r3  scaler4  r1  s      r   visit_NUMERIC!GenericTypeCompiler.visit_NUMERIC  M    ??"[[ +{EOO.LLL6"__:  r   c                     UR                   c  gUR                  c  SSUR                   0-  $ SUR                   UR                  S.-  $ )NDECIMALzDECIMAL(%(precision)s)r3  z!DECIMAL(%(precision)s, %(scale)s)r4  r4  r1  s      r   visit_DECIMAL!GenericTypeCompiler.visit_DECIMAL  r8  r   c                     g)NINTEGERr   r1  s      r   visit_INTEGER!GenericTypeCompiler.visit_INTEGER      r   c                     g)NSMALLINTr   r1  s      r   visit_SMALLINT"GenericTypeCompiler.visit_SMALLINT      r   c                     g)NBIGINTr   r1  s      r   visit_BIGINT GenericTypeCompiler.visit_BIGINT  s    r   c                     g)N	TIMESTAMPr   r1  s      r   visit_TIMESTAMP#GenericTypeCompiler.visit_TIMESTAMP  s    r   c                     g)NDATETIMEr   r1  s      r   visit_DATETIME"GenericTypeCompiler.visit_DATETIME  rF  r   c                     g)NDATEr   r1  s      r   
visit_DATEGenericTypeCompiler.visit_DATE  r  r   c                     g)NTIMEr   r1  s      r   
visit_TIMEGenericTypeCompiler.visit_TIME  r  r   c                     g)NCLOBr   r1  s      r   
visit_CLOBGenericTypeCompiler.visit_CLOB  r  r   c                     g)NNCLOBr   r1  s      r   visit_NCLOBGenericTypeCompiler.visit_NCLOB  r,  r   c                     UnUR                   (       a  USUR                   -  -  nUR                  (       a  USUR                  -  -  nU$ )N(%d)z COLLATE "%s")lengthr  )r   r2  r;  r  s       r   _render_string_type'GenericTypeCompiler._render_string_type  s@    <<FU\\))D??Oeoo55Dr   c                 &    U R                  US5      $ )NCHARrf  r1  s      r   
visit_CHARGenericTypeCompiler.visit_CHAR      ''v66r   c                 &    U R                  US5      $ )NNCHARrj  r1  s      r   visit_NCHARGenericTypeCompiler.visit_NCHAR  s    ''w77r   c                 &    U R                  US5      $ )NVARCHARrj  r1  s      r   visit_VARCHAR!GenericTypeCompiler.visit_VARCHAR  s    ''y99r   c                 &    U R                  US5      $ )NNVARCHARrj  r1  s      r   visit_NVARCHAR"GenericTypeCompiler.visit_NVARCHAR  s    ''z::r   c                 &    U R                  US5      $ )NTEXTrj  r1  s      r   
visit_TEXTGenericTypeCompiler.visit_TEXT  rm  r   c                     g)NBLOBr   r1  s      r   
visit_BLOBGenericTypeCompiler.visit_BLOB  r  r   c                 ^    SUR                   =(       a    SUR                   -  =(       d    S-   $ )NBINARYrd  r  re  r1  s      r   visit_BINARY GenericTypeCompiler.visit_BINARY  s$    5<<AFU\\,AGRHHr   c                 ^    SUR                   =(       a    SUR                   -  =(       d    S-   $ )N	VARBINARYrd  r  r  r1  s      r   visit_VARBINARY#GenericTypeCompiler.visit_VARBINARY  s$    ellDv/DJKKr   c                     g)NBOOLEANr   r1  s      r   visit_BOOLEAN!GenericTypeCompiler.visit_BOOLEAN  rA  r   c                 (    U R                   " U40 UD6$ r   )r  r1  s      r   visit_large_binary&GenericTypeCompiler.visit_large_binary      u+++r   c                 (    U R                   " U40 UD6$ r   )r  r1  s      r   visit_boolean!GenericTypeCompiler.visit_boolean      !!%.2..r   c                 (    U R                   " U40 UD6$ r   )rY  r1  s      r   
visit_timeGenericTypeCompiler.visit_time  r  r   c                 (    U R                   " U40 UD6$ r   )rQ  r1  s      r   visit_datetime"GenericTypeCompiler.visit_datetime       ""5/B//r   c                 (    U R                   " U40 UD6$ r   )rU  r1  s      r   
visit_dateGenericTypeCompiler.visit_date  r  r   c                 (    U R                   " U40 UD6$ r   )rI  r1  s      r   visit_big_integer%GenericTypeCompiler.visit_big_integer  s      -"--r   c                 (    U R                   " U40 UD6$ r   )rD  r1  s      r   visit_small_integer'GenericTypeCompiler.visit_small_integer	  r  r   c                 (    U R                   " U40 UD6$ r   )r?  r1  s      r   visit_integer!GenericTypeCompiler.visit_integer  r  r   c                 (    U R                   " U40 UD6$ r   )r/  r1  s      r   
visit_realGenericTypeCompiler.visit_real  r  r   c                 (    U R                   " U40 UD6$ r   )r*  r1  s      r   visit_floatGenericTypeCompiler.visit_float  s    ,,,r   c                 (    U R                   " U40 UD6$ r   )r6  r1  s      r   visit_numeric!GenericTypeCompiler.visit_numeric  r  r   c                 (    U R                   " U40 UD6$ r   rt  r1  s      r   visit_string GenericTypeCompiler.visit_string  r  r   c                 (    U R                   " U40 UD6$ r   r  r1  s      r   visit_unicode!GenericTypeCompiler.visit_unicode  r  r   c                 (    U R                   " U40 UD6$ r   r|  r1  s      r   
visit_textGenericTypeCompiler.visit_text  r  r   c                 (    U R                   " U40 UD6$ r   r  r1  s      r   visit_unicode_text&GenericTypeCompiler.visit_unicode_text!  r  r   c                 (    U R                   " U40 UD6$ r   r  r1  s      r   
visit_enumGenericTypeCompiler.visit_enum$  r  r   c                 4    [         R                  " SU-  5      e)NzKCan't generate DDL for %r; did you forget to specify a type on this Column?r~  r1  s      r   r  GenericTypeCompiler.visit_null'  s"    #%*+
 	
r   c                 Z    U R                   " UR                  U R                  5      40 UD6$ r   )r   type_enginer   r1  s      r   visit_type_decorator(GenericTypeCompiler.visit_type_decorator.  s%    ||E--dll;BrBBr   c                 &    UR                   " S0 UD6$ r  )get_col_specr1  s      r   visit_user_defined&GenericTypeCompiler.visit_user_defined1  s    !!'B''r   r   N)/r   r   r   r   r*  r/  r6  r;  r?  rD  rI  rM  rQ  rU  rY  r]  ra  rf  rk  rp  rt  rx  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'    s    		78:;7IL,/,0,.0/,-///,,/
C(r   r'  c                   2    \ rS rSrS rS rS rS rS rSr	g)	StrSQLTypeCompileri5  c                 t     UR                   nU" U 40 UD6$ ! [         a    U R                  " U40 UD6s $ f = fr   )r  AttributeError_visit_unknown)r   r2  r3  r  s       r   r   StrSQLTypeCompiler.process6  sL    	2!&!9!9 &d1b11  	4&&u333	4s    77c                 \    UR                  S5      (       a  U R                  $ [        U5      e)Nr  )
startswithr  r  )r   rP  s     r   __getattr__StrSQLTypeCompiler.__getattr__>  s(    >>(##&&& %%r   c                     UR                   R                  UR                   R                  R                  5       :X  a  UR                   R                  $ [        U5      $ r   )r[  r   upperreprr1  s      r   r  !StrSQLTypeCompiler._visit_unknownD  sA    ??##u'?'?'E'E'GG??+++;r   c                     gr  r   r1  s      r   r  StrSQLTypeCompiler.visit_nullJ  r  r   c                 b     UR                   nU" S0 UD6$ ! [         a    [        U5      s $ f = fr  )r  r  r  )r   r2  r3  r  s       r   r  %StrSQLTypeCompiler.visit_user_definedM  s=    	& --L  %"%%  	;	s    ..r   N)
r   r   r   r   r   r  r  r  r  r   r   r   r   r  r  5  s    2&&r   r  c                      \ rS rSrSr\r\r\	r
\R                  " S5      r      S#S jrS rS rS rS	 rS
 rS rS rS rS$S jrS$S jrS rS%S jrS$S jrS$S jrS$S jr\R>                  " S5      S%S j5       r S%S jr!S%S jr"S r#S r$S&S jr%S r& S$S jr'     S'S jr(S%S jr)\RT                  S  5       r+S! r,S"r-g)(IdentifierPrepareriV  z@Handle quoting and case-folding of identifiers based on options.r
   Nc                     Xl         X l        U=(       d    U R                  U l        X@l        U R                  S-  U l        X`l        XPl        0 U l        U R                   R                  S;   U l	        g)a+  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_stringsrZ  r  )r   r   r  r  r  r  r  s          r   r   IdentifierPreparer.__init__k  sj    . *&<$*<*<(#0014&/N, $ 7 7 <
 !
r   c                    ^ U R                   R                  U R                   5      nUR                  R                  U R                  5        U4S jnX2l        U$ )Nc                    > U R                   nUT;   aO  U R                  (       a>  Ub%  SU;   d  SU;   a  [        R                  " SU-  5      e[	        SU=(       d    S-  SS9$ U R                   $ )Nr  r  zJSquare bracket characters ([]) not supported in schema translate name '%s'z__[SCHEMA_%s]_noneFr  )r
   _use_schema_mapr   r  r   )r  r;  r   s     r   symbol_getter@IdentifierPreparer._with_schema_translate.<locals>.symbol_getter  sx    ::D++0C0C#t**8:>?  ##tw7u  zz!r   )r[  __new____dict__rR  r  )r   r   prepr  s    `  r   r   )IdentifierPreparer._with_schema_translate  sC    ~~%%dnn5T]]+	" "/r   c                 b   ^ ^ UmS T;   a  TS    TS'   UU 4S jn[         R                  " SX15      $ )Nr  c                    > U R                  S5      nTU   nU(       d3  TR                  R                  nU(       d  [        R                  " S5      eTR                  U5      $ )Nr   zLDialect has no default schema name; can't use None as dynamic schema target.)r<   r   default_schema_namer   r  r  )r  r;  r  dr   s      r   r  =IdentifierPreparer._render_schema_translates.<locals>.replace  s\    771:D w##'<<#C#C '**=  $$%566r   z(__\[SCHEMA_([^\]]+)\]))r  r  )r   r   r   r  r  s   `   @r   r   ,IdentifierPreparer._render_schema_translates  s5     194AgJ	7 vv0'EEr   c                     UR                  U R                  U R                  5      nU R                  (       a  UR                  SS5      nU$ )zhEscape an identifier.

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

Subclasses should override this to provide database-dependent
unescaping behavior that reverses _escape_identifier.
)r  r  r  r  s     r   _unescape_identifier'IdentifierPreparer._unescape_identifier  s!     }}T1143D3DEEr   c                     Ub?  UR                  U5      (       d)  [        R                  " SU< SUR                  < S35      eU$ )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 rM  )rP  r   r  pattern)r   r  regs      r   r  &IdentifierPreparer.validate_sql_phrase  s@     syy'9'9""CKK)  r   c                 X    U R                   U R                  U5      -   U R                  -   $ )zfQuote an identifier.

Subclasses should override this to provide database-dependent
quoting behavior.
)r  r  r  r  s     r   quote_identifier#IdentifierPreparer.quote_identifier  s3     %%e,-	
r   c                     UR                  5       nX R                  ;   =(       dX    US   U R                  ;   =(       d?    U R                  R	                  [
        R                  " U5      5      (       + =(       d    X!:g  $ )z5Return True if the given identifier requires quoting.r   )rX  reserved_wordsillegal_initial_characterslegal_charactersrP  r   	text_type)r   r  lc_values      r   r  #IdentifierPreparer._requires_quotes  sg    ;;=+++ #Qx4:::#((..t~~e/DEE# !		
r   c                 j    U R                   R                  [        R                  " U5      5      (       + $ )zbReturn True if the given identifier requires quoting, but
not taking case convention into account.)r  rP  r   r  r  s     r   r]  1IdentifierPreparer._requires_quotes_illegal_chars  s'     ((..t~~e/DEEEr   c                 T    Ub  [         R                  " SSS9  U R                  U5      $ )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.9rx  )r   r{  r  )r   r
   forces      r   r  IdentifierPreparer.quote_schema  s5    .    !  zz&!!r   c                 f   Ub  [         R                  " SSS9  [        USS5      nUcp  XR                  ;   a  U R                  U   $ U R	                  U5      (       a  U R                  U5      U R                  U'   OXR                  U'   U R                  U   $ U(       a  U R                  U5      $ U$ )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  rx  r  )r   r{  rW  r  r  r  )r   r  r  s      r   r  IdentifierPreparer.quote"  s    ,    !  w-=%}}U++((//+/+@+@+GDMM%(+0MM%(}}U++((//Lr   c                 J    U R                   (       a  U R                  U5      $ U$ r   )r  r  )r   collation_names     r   r  #IdentifierPreparer.format_collationV  s     //::n--!!r   c                     U R                  UR                  5      nU R                  U5      nU R                  (       d!  U(       a  Ub  U R	                  U5      S-   U-   nU$ r  )r  r;  r  r  r  )r   re  r  r;  r  s        r   r  "IdentifierPreparer.format_sequence\  sY    zz(--(11(;    ,$$%56<tCDr   c                 J    U R                  U=(       d    UR                  5      $ r   r  r;  )r   r:  r;  s      r   ru  IdentifierPreparer.format_labeli      zz$,%**--r   c                 J    U R                  U=(       d    UR                  5      $ r   r  )r   r  r;  s      r   r  IdentifierPreparer.format_aliasl  r!  r   c                 ~    U=(       d    UR                   nU R                  U5      (       a  U R                  U5      nU$ r   )r  r  r  )r   	savepointr;  r  s       r   r  #IdentifierPreparer.format_savepointo  s8     '	  ''))%0Er   zsqlalchemy.sql.namingc                 $   [         R                  R                  nUR                  [        R
                  L a   UR                  XR                  5      nUc  g OUR                  nUR                  S:X  a  U R                  XBS9$ U R                  XBS9$ )Nr   )_alembic_quote)r   r  
sql_namingr;  r   
_NONE_NAME_constraint_name_for_tablere   rI  truncate_and_render_index_name#truncate_and_render_constraint_name)r   r%   r(  namingr;  s        r   r  $IdentifierPreparer.format_constraintx  s    **??h11144,,D |  ??D$$/66 7   ;; <  r   c                     U R                   R                  =(       d    U R                   R                  nU R                  XU5      $ r   )r   max_index_name_lengthr`   _truncate_and_render_maxlen_namer   r;  r(  max_s       r   r,  1IdentifierPreparer.truncate_and_render_index_name  sB    
 LL.. 2||11 	 44
 	
r   c                     U R                   R                  =(       d    U R                   R                  nU R                  XU5      $ r   )r   max_constraint_name_lengthr`  r2  r3  s       r   r-  6IdentifierPreparer.truncate_and_render_constraint_name  sB    
 LL33 2||11 	 44
 	
r   c                    [        U[        R                  5      (       a5  [        U5      U:  a%  USUS-
   S-   [        R
                  " U5      SS  -   nOU R                  R                  U5        U(       d  U$ U R                  U5      $ )Nr      r  )	rp  r   rq  r  r   md5_hexr   validate_identifierr  )r   r;  r4  r(  s       r   r2  3IdentifierPreparer._truncate_and_render_maxlen_name  su    dH55664y4Aq)C/$,,t2DRS2IILL,,T2K::d##r   c                 $    U R                  U5      $ r   )r  r  s     r   r  IdentifierPreparer.format_index  s    %%e,,r   c                     Uc  UR                   nU R                  U5      nU R                  U5      nU R                  (       d%  U(       a  U(       a  U R	                  U5      S-   U-   nU$ )z'Prepare a quoted table and schema name.r  )r;  r  r  r  r  )r   re   r  r;  r7  r  s         r   r  IdentifierPreparer.format_table  s_     <::DD!11%8J3C&&'783>GFr   c                 $    U R                  U5      $ )zPrepare a quoted schema name.r  r|  s     r   rI   IdentifierPreparer.format_schema  s     zz$r   c                     Ub0  [        U[        R                  5      (       a  UR                  U5      nU R	                  U5      $ )Prepare a quoted column name.)rp  r   rq  rr  r  )r   r;  ra  s      r   r  $IdentifierPreparer.format_label_name  s@     J(++%
 %
 >>(+Dzz$r   c                    Uc  UR                   nUb0  [        U[        R                  5      (       a  UR	                  U5      n[        USS5      (       dG  U(       a/  U R                  UR                  XTS9S-   U R                  U5      -   $ U R                  U5      $ U(       a   U R                  UR                  XTS9S-   U-   $ U$ )rF  r  F)r  r;  r  )	r;  rp  r   rq  rr  rW  r  re   r  )r   r$   r  r;  
table_namer  ra  s          r   r   IdentifierPreparer.format_column  s     <;;DJ(++%
 %
 >>(+Dv|U33%% &   jj&	' zz$''
 %% &   	 r   c                     U R                  U5      nU R                  (       d/  U(       a(  U(       a!  U R                  U5      U R                  USS94$ U R                  USS94$ )z(Format table name and schema as a tuple.Fr  )r  r  r  r  )r   re   r  r  s       r   rB  #IdentifierPreparer.format_table_seq  sj      11%8J3C!!"23!!%E!: 
 %%e%>@@r   c                     U R                   U R                  U R                  U R                  5      4 Vs/ s H  n[        R                  " U5      PM     snu  p#n[        R
                  " SX#US.-  5      nU$ s  snf )NzM(?:(?:%(initial)s((?:%(escaped)s|[^%(final)s])+)%(final)s|([^\.]+))(?=\.|$))+)initialfinalescaped)r  r  r  r  r%  r  )r   r  rN  rO  escaped_finalrs         r   _r_identifiers!IdentifierPreparer._r_identifiers  s    
 ""  ''(8(89)
 IIaL)
% JJ$ "mLM
 )
s    A9c                     U R                   nUR                  U5       VVs/ s H  u  p4U=(       d    UPM     snn Vs/ s H  nU R                  U5      PM     sn$ s  snnf s  snf )z:Unpack 'schema.table.column'-like strings into components.)rS  findallr  )r   identifiersrR  aro  r  s         r   unformat_identifiers'IdentifierPreparer.unformat_identifiers'  sf      *+;)?@)?af1f)?@
@ %%a(@
 	
@
s
   AA")	r  r  r   r  r  r  r  r  r  )"Nr[  TFr   )T)TN)FNNFN).r   r   r   r   r"  RESERVED_WORDSr  LEGAL_CHARACTERSr  ILLEGAL_INITIAL_CHARACTERSr  r2  
attrgetterr  r   r   r   r  r  r  r  r  r]  r  r  r  r  ru  r  r  r   r  r  r,  r-  r2  r  r  rI  r  r  rB  r  rS  rY  r   r   r   r   r  r  V  s   J#N'!; ++H5 (,"
H*F(
F$

F
%"N2h".. 
01 2,




$-   " +ZA" 
 "
r   r  )r"  r   r  r  r2  r  r  r   r   r   r   r   r	   r
   r   r   r   rh  r   r   r   r   ra   r\  r  Ir]  LEGAL_CHARACTERS_PLUS_SPACEranger  rj   r^  r  r  r  UNICODEr  r  r\  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_opr  r  r  r   rt  r_  r`  r#   existsdistinct_opinvany_opall_opdesc_opasc_opnulls_first_opnulls_last_oprs  r   r(   r*   r+   r,   rK   rL   r   r   r`   rl   cuberollupgrouping_setsrY  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,  ColumnElementr9  rL  r  r7  r'  r  r  )r!  s   0r   <module>r     sy  $     	            ! !  _aF ::.5  jj):BDDA .3Arl;lc!fl;AA3%H zz<bdd zz<bdd zz5rtt<jjA2::N**92::F   ZZ 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((,''++_   


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