403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.19.244.133
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/sql/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/sql/__pycache__/compiler.cpython-37.pyc
B

��4]���_@sdZddlZddlZddlZddlmZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddlmZdd
lm
Z
ddlmZedddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdlg^�Ze�dmej�Ze�dnej�Zdodp�eddq�D��drg�Ze�dsej�Ze�dsej�Ze�dtej�Ze�duej�Ze�dvej�Zdwdxdydzd{d|�Zejd}ej d~ej!dej"d�ej#d�ej$d�ej%d�ej&d�ej'd�ej(d�ej)d�ej*d�ej+d�ej,d�ej-d�ej.d�ej/d�ej0d�ej1d�ej2d�ej3d�ej4d�ej5d�ej6d�ej7d�ej8d�ej9d�ej:d�ej;d�ej<d�ej=d�ej>d�ej?d�ej@d�ejAd�ejBd�ejCd�i%ZDejEd�ejFd�ejGd�ejHd�ejId�ejJd�ejKd�ejLd�ejMd�ejNd�ejOd�ejPd�ejQd�ejRd�iZSd�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d��ZTe
jUjVd�e
jUjWd�e
jUjXd�e
jUjYd�e
jUjZd�e
jUj[d�iZ\Gd�dƄd�e]�Z^Gd�dȄd�e�_ej`e]��ZaGd�dʄd�ejb�ZcGd�d̄d�e^�ZdGd�d΄d�ed�ZeGd�dЄd�e^�ZfGd�d҄d�ea�ZgGd�dԄd�eg�ZhGd�dքd�e]�ZidS)�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�)�crud)�elements)�	functions)�	operators)�schema)�
selectable)�sqltypes)�visitors�)�exc)�util�allZanalyseZanalyze�and�any�array�asZascZ
asymmetricZ
authorizationZbetween�binaryZboth�case�cast�check�collate�column�
constraint�createZcross�current_dateZcurrent_role�current_time�current_timestamp�current_user�default�
deferrable�descZdistinctZdo�else�end�except�false�forZforeignZfreeze�from�fullZgrant�groupZhavingZilike�in�	initially�innerZ	intersectZinto�isZisnull�joinZleading�leftZlike�limit�	localtime�localtimestampZnatural�new�notZnotnull�null�off�offset�old�on�only�or�orderZouterZoverlapsZplacingZprimaryZ
references�right�select�session_user�setZsimilarZsome�	symmetric�tableZthen�toZtrailing�true�union�unique�userZusing�verboseZwhen�wherez
^[A-Z0-9_$]+$z^[A-Z0-9_ $]+$cCsh|]}t|��qS�)�str)�.0�xrJrJ�J/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/sql/compiler.py�	<setcomp>�srO�
�$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)�pyformatZqmark�format�numeric�namedz AND z OR z + 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 z, z FROM z AS z IS z IS NOT z	 COLLATE zEXISTS z	DISTINCT zNOT zANY zALL z DESCz ASCz NULLS FIRSTz NULLS LAST�coalesceZCURRENT_DATEZCURRENT_TIMEZCURRENT_TIMESTAMPZCURRENT_USERZ	LOCALTIMEZLOCALTIMESTAMP�random�sysdateZSESSION_USERZUSERZCUBEZROLLUPz
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`rarbrcrdrerfrgrhri�UNIONz	UNION ALL�EXCEPTz
EXCEPT ALL�	INTERSECTz
INTERSECT ALLc@s�eZdZdZdZe��Zdde��fdd�Ze�	dd�dd��Z
d	d
�Zedd��Z
d
d�Zdd�Zddd�Zedd��Zdd�Zdd�ZdS)�CompiledaRepresent a compiled SQL or DDL expression.

    The ``__str__`` method of the ``Compiled`` object should produce
    the actual text of the statement.  ``Compiled`` objects are
    specific to their underlying database dialect, and also may
    or may not be specific to the columns referenced within a
    particular set of bind parameters.  In no case should the
    ``Compiled`` object be dependent on the actual values of those
    bind parameters, even though it may reference those values as
    defaults.
    NcCsb||_||_|jj|_|r(|j�|�|_|dk	r^||_|j|_|jrL|j|_	|j
|jf|�|_dS)aqConstruct a new :class:`.Compiled` object.

        :param dialect: :class:`.Dialect` to compile against.

        :param statement: :class:`.ClauseElement` to be compiled.

        :param bind: Optional Engine or Connection to compile this
          statement against.

        :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�bindZidentifier_preparer�preparer�_with_schema_translate�	statementZsupports_execution�can_execute�_execution_options�execution_options�process�string)�selfrnrrro�schema_translate_mapZcompile_kwargsrJrJrN�__init__s 
zCompiled.__init__z0.7z�The :meth:`.Compiled.compile` method is deprecated and will be removed in a future release.   The :class:`.Compiled` object now runs its compilation within the constructor, and this method does nothing.cCsdS)zDProduce the internal string representation of this element.
        NrJ)rxrJrJrN�compileAs
zCompiled.compilecCs$|jr|�|||�St�|j��dS)N)rs�_execute_compiledrZObjectNotExecutableErrorrr)rxZ
connection�multiparams�paramsrJrJrN�_execute_on_connectionMszCompiled._execute_on_connectioncCs
t��dS)z�Return a Compiled that is capable of processing SQL expressions.

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

        N)�NotImplementedError)rxrJrJrN�sql_compilerSszCompiled.sql_compilercKs|j|f|�S)N)�_compiler_dispatch)rx�obj�kwargsrJrJrNrv]szCompiled.processcCs
|jpdS)z3Return the string text of the generated SQL or DDL.�)rw)rxrJrJrN�__str__`szCompiled.__str__cCs
t��dS)z�Return the bind params for this compiled object.

        :param params: a dict of string/object pairs whose values will
                       override bind values compiled in to the
                       statement.
        N)r�)rxr~rJrJrN�construct_paramseszCompiled.construct_paramscCs|��S)z0Return the bind params for this compiled object.)r�)rxrJrJrNr~oszCompiled.paramscOs*|j}|dkrtjddd��|�|||�S)zExecute this compiled object.Nz>This Compiled object is not bound to any Engine or Connection.Z2afi)�code)rorZUnboundExecutionErrorr|)rxr}r~�erJrJrN�executetszCompiled.executecOs|j||���S)zJExecute this compiled object and return the result's
        scalar value.)r��scalar)rxr}r~rJrJrNr��szCompiled.scalar)N)�__name__�
__module__�__qualname__�__doc__Z_cached_metadatar
�
immutabledictrurzZ
deprecatedr{r�propertyr�rvr�r�r~r�r�rJrJrJrNrm�s"
)



rmc@s$eZdZdZdZdd�Zdd�ZdS)�TypeCompilerz2Produces DDL specification for TypeEngine objects.z	visit_\w+cCs
||_dS)N)rn)rxrnrJrJrNrz�szTypeCompiler.__init__cKs|j|f|�S)N)r�)rx�type_�kwrJrJrNrv�szTypeCompiler.processN)r�r�r�r�Zensure_kwargrzrvrJrJrJrNr��sr�c@sBeZdZdZdZdZddd�Zedd��Zed	d
��Z	dd�Z
d
S)�
_CompileLabelz;lightweight label object which acts as an expression.Label.�label)�element�namerJcCs||_||_|f||_dS)N)r�r��
_alt_names)rx�colr��	alt_namesrJrJrNrz�sz_CompileLabel.__init__cCs|jjS)N)r��	proxy_set)rxrJrJrNr��sz_CompileLabel.proxy_setcCs|jjS)N)r��type)rxrJrJrNr��sz_CompileLabel.typecKs|S)NrJ)rxr�rJrJrN�
self_group�sz_CompileLabel.self_groupN)rJ)r�r�r�r��__visit_name__�	__slots__rzr�r�r�r�rJrJrJrNr��s
r�c@s�eZdZdZeZeZdZZ	Z
dZdZdZ
dZdZdZdZdZdZdZZ�ddd�Zedd	��Zejd
d��Zejdd
��Zdd�Zej dd��Z!dd�Z"edd��Z#�ddd�Z$edd��Z%e�&d�dd��Z'dd�Z(�ddd �Z)�dd!d"�Z*�dd#d$�Z+�d	d%d&�Z,d'd(�Z-�d
d)d*�Z.d+d,�Z/d-d.�Z0d/d0�Z1d1d2�Z2d3d4�Z3d5d6�Z4d7d8�Z5�dd9d:�Z6d;d<�Z7d=d>�Z8d?d@�Z9dAdB�Z:dCdD�Z;dEdF�Z<dGdH�Z=dIdJ�Z>dKdL�Z?dMdN�Z@dOdP�ZAdQdR�ZB�ddSdT�ZCdUdV�ZDdWdX�ZEdYdZ�ZF�d
d\d]�ZGd^d_�ZHd`da�ZIdbdc�ZJddde�ZKdfdg�ZLdhdi�ZMdjdk�ZNdldm�ZOdndo�ZP�ddpdq�ZQdrds�ZRdtdu�ZSdvdw�ZTdxdy�ZUdzd{�ZV�dd|d}�ZWd~d�ZXd�d��ZYej d�d���ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Zad�d��Zbd�d��Zcd�d��Zdd�d��Zed�d��Zf�dd�d��Zgd�d��Zhd�d��Zid�d��Zjd�d��Zkd�d��Zld�d��Zm�dd�d��Zn�dd�d��Zo�dd�d��Zpd�d��Zq�dd�d��Zrd�d��Zsd�d��Zt�dd�d��Zud�d��Zvd�d��Zwd�d��Zxd�d��Zyd�dÄZzd�dńZ{d�dDŽZ|e�}d�e~�fd�e~�fg�Z�dd�d˄Z��dd�d̈́Z�d�dτZ�d�dфZ�d�dӄZ�d�dՄZ�d�dׄZ�d�dلZ�d�dۄZ�d�d݄Z�d�d߄Z�d�d�Z�d�d�Z�d�d�Z��dd�d�Z��dd�d�Z�d�d�Z��dd�d�Z�d�d�Z�d�d�Z�d�d�Z��dd�d��Z�ej d�d���Z�d�d��Z�d�d��Z��dd�d��Z�d�d��Z��d�d�Z��d�d�Z�dS(�SQLCompilerzsDefault implementation of :class:`.Compiled`.

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

    FNTrJcKs�||_|pt|dd�|_i|_t��|_g|_g|_|j	|_	|j	rTg|_
|jdk|_t
|j|_d|_|jpp|j|_t�|j�|_i|_tj|||f|�|js�|js�|jr�|jr�|j|_|j	r�|jr�|��dS)aConstruct a new :class:`.SQLCompiler` object.

        :param dialect: :class:`.Dialect` to be used

        :param statement: :class:`.ClauseElement` to be compiled

        :param column_keys:  a list of column names to be compiled into an
         INSERT or UPDATE statement.

        :param inline: whether to generate INSERT statements as "inline", e.g.
         not formatted to return any generated defaults

        :param kwargs: additional keyword arguments to be consumed by the
         superclass.

        �inlineFrUN)�column_keys�getattrr��bindsr
Zcolumn_dict�
bind_names�stack�_result_columns�
positional�positiontup�
paramstyle�_numeric_binds�BIND_TEMPLATES�bindtemplate�ctes�label_length�max_identifier_lengthZPopulateDict�
_process_anon�anon_map�truncated_namesrmrz�isinsert�isupdate�isdelete�
_returning�	returning�_apply_numbered_params)rxrnrrr�r�r�rJrJrNrz�s*
zSQLCompiler.__init__cCst|j|j�S)N)�list�insert_prefetch�update_prefetch)rxrJrJrN�prefetch<szSQLCompiler.prefetchcCs&t��|_i|_d|_|jr"i|_dS)z�Initialize collections related to CTEs only if
        a CTE is located, to save on the overhead of
        these collections otherwise.

        FN)r
�OrderedDictr��ctes_by_name�ctes_recursiver��cte_positional)rxrJrJrN�_init_cte_state@s

zSQLCompiler._init_cte_statec	csp|j|j}}gd|_|_z0|jr8|jd}d|d<nd}|j|jfVWd|r\|�d�|||_|_XdS)z;special API to support the use case of 'nested result sets'F���T�need_result_map_for_nestedN)r��_ordered_columnsr��pop)rxZresult_columnsZordered_columns�entryrJrJrN�_nested_resultNs



zSQLCompiler._nested_resultcs(t�d��t�d�fdd�|j�|_dS)Nrz
\[_POSITION\]cstt����S)N)rKr
�next)�m)�poscountrJrN�<lambda>i�z4SQLCompiler._apply_numbered_params.<locals>.<lambda>)�	itertools�count�re�subrw)rxrJ)r�rNr�fs
z"SQLCompiler._apply_numbered_paramscs"tdd��fdd��jD�D��S)Ncss"|]\}}|dk	r||fVqdS)NrJ)rL�key�valuerJrJrN�	<genexpr>osz/SQLCompiler._bind_processors.<locals>.<genexpr>c3s&|]}�j||j��j�fVqdS)N)r�r�Z_cached_bind_processorrn)rL�	bindparam)rxrJrNr�qs)�dictr�)rxrJ)rxrN�_bind_processorsls
zSQLCompiler._bind_processorscCst|j�dkS)Nr)�lenr�)rxrJrJrN�is_subqueryzszSQLCompiler.is_subquerycCs|S)NrJ)rxrJrJrNr�}szSQLCompiler.sql_compilercCs2|r�i}x�|jD]�}|j|}|j|kr8||j||<q||krN||||<q|r�|jr�|rvtjd|j|fdd��q�tjd|jdd��q|jr�|j||<q|j||<qW|Si}xt|jD]j}|r�|jr�|r�tjd|j|fdd��ntjd|jdd��|j�r|j||j|<q�|j||j|<q�W|SdS)z5return a dictionary of bind parameter keys and valuesz@A value is required for bind parameter %r, in parameter group %dZcd3x)r�z)A value is required for bind parameter %rN)r�r��requiredrZInvalidRequestError�callable�effective_valuer�)rxr~Z
_group_number�_check�pdr�r�rJrJrNr��sL








zSQLCompiler.construct_paramscCs|jdd�S)zoReturn the bind param dictionary embedded into this
        compiled object, for those values that are present.F)r�)r�)rxrJrJrNr~�szSQLCompiler.paramszsqlalchemy.engine.resultcCs|j�|j�S)z(utility method used for unit tests only.)ZResultMetaData�_create_result_mapr�)rx�resultrJrJrNr��szSQLCompiler._create_result_mapcCsdS)z�Called 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�rJ)rxrJrJrN�default_from�szSQLCompiler.default_fromcKsd|jj|f|�dS)N�(�))r�r�)rx�grouping�asfromr�rJrJrN�visit_grouping�szSQLCompiler.visit_groupingc
Ks�|jrl|jjrl|jdd}|j\}}}|r2|}n|}|jj}	|	dk	rl|	j|krl|	�||	j�rl|jj|d<|j|jfd|i|��S)Nr�r�render_label_as_label�within_columns_clause)	r�rnZsupports_simple_order_by_label�_label_resolve_dictr�Z_order_by_label_elementr�Zshares_lineagerv)
rxr�r�r�r�	with_cols�
only_froms�	only_colsZresolve_dictZ
order_by_elemrJrJrN�visit_label_reference�s 
z!SQLCompiler.visit_label_referencec	Ks�|js|�|j�S|jdd}|j\}}}y|r>||j}n
||j}Wn&tk
rpt�|jtj	d�Yn X||d<|j|fd|i|��SdS)Nr�rz6Can't resolve label reference for ORDER BY / GROUP BY.r�r�)
r�rvZ_text_clauser�r��KeyErrorrZ_no_text_coercionr�CompileError)	rxr�r�r�rr�r�r�r�rJrJrN�visit_textual_label_reference�s z)SQLCompiler.visit_textual_label_referencec
Ks�|o|}||k}|s|r>t|jtj�r8|�d|j�}	n|j}	|r�|dk	rf||	|j||	f|j|j�|jj|fddd�|��t	t
j|j�
||	�S|r�|j�
||	�S|jj|fddi|��SdS)N�colidentT)r��within_label_clauser�F)�
isinstancer�r�_truncated_label�_truncated_identifierr�r�r�r��	OPERATORSr�as_rp�format_label)
rxr��add_to_result_mapr�r�r�r�Zrender_label_with_asZrender_label_onlyZ	labelnamerJrJrN�visit_labels$
2zSQLCompiler.visit_labelcCst�d��dS)Nz:Cannot compile Column object until its 'name' is assigned.)rr�)rxrrJrJrN�_fallback_column_name=sz!SQLCompiler._fallback_column_namecKs�|j}}|dkr|�|�}|j}|s>t|tj�r>|�d|�}|dk	r^||||||jf|j�|rn|�	|�}n|j
�|�}|j}|dks�|r�|j
s�|S|j
�|�}	|	r�|j
�|	�d}
nd}
|j}t|tj�r�|�d|�}|
|j
�|�d|SdS)Nr��.r��alias)r�r��
is_literalr�rr�r�r�r��escape_literal_columnrp�quoterBZnamed_with_column�schema_for_object�quote_schema)rxrr��
include_tabler�r��	orig_namer�rB�effective_schemaZ
schema_prefixZ	tablenamerJrJrN�visit_columnBs.

zSQLCompiler.visit_columncKs|j�|j�S)N)rp�format_collation�	collation)rxr�r�rJrJrN�visit_collationjszSQLCompiler.visit_collationcKs|jS)N)r�)rxZ
fromclauser�rJrJrN�visit_fromclausemszSQLCompiler.visit_fromclausecKs|jS)N)r�)rx�indexr�rJrJrN�visit_indexpszSQLCompiler.visit_indexcKs||d<|jjj|jf|�S)N�type_expression)rn�
type_compilerrvr�)rx�
typeclauser�rJrJrN�visit_typeclausesszSQLCompiler.visit_typeclausecCs|jjr|�dd�}|S)N�%z%%)rp�_double_percents�replace)rx�textrJrJrN�post_process_textwszSQLCompiler.post_process_textcCs|jjr|�dd�}|S)Nrz%%)rprr)rxrrJrJrNr|sz!SQLCompiler.escape_literal_columnc	s<���fdd�}�jsd�_t�dd�t�|���j���S)Ncs:|�d�}|�jkr(�j�j|f��S�j|f��SdS)Nr)r)Z_bindparamsrv�bindparam_string)r�r�)r�rx�
textclauserJrN�do_bindparam�s

z2SQLCompiler.visit_textclause.<locals>.do_bindparamTcSs
|�d�S)Nr)r))r�rJrJrNr��r�z.SQLCompiler.visit_textclause.<locals>.<lambda>)r��isplaintext�BIND_PARAMS_ESCr��BIND_PARAMSrr)rxrr�rrJ)r�rxrrN�visit_textclause�szSQLCompiler.visit_textclausecKs�|j}|r|jn|jd}|p>|dkr4|�dd�p>|�dd�}|rt|j|_|_x |jD]}	|j|	d|jd�qZW|j|j	f|�}
|r�|r�d|
}
|
S)	Nr�r�need_result_map_for_compoundFr�T)r�r�z(%s))
r��_default_stack_entry�getr�r��_textual_ordered_columnsZcolumn_argsrv�_add_to_result_mapr�)rxZtaf�compound_indexr��parensr��toplevelr��populate_result_map�crrJrJrN�visit_text_as_from�s"zSQLCompiler.visit_text_as_fromcKsdS)N�NULLrJ)rx�exprr�rJrJrN�
visit_null�szSQLCompiler.visit_nullcKs|jjrdSdSdS)NrD�1)rn�supports_native_boolean)rxr*r�rJrJrN�
visit_true�szSQLCompiler.visit_truecKs|jjrdSdSdS)Nr%�0)rnr-)rxr*r�rJrJrN�visit_false�szSQLCompiler.visit_falsecs^|j}|dkrd}n
t|j}|�dd���fdd�|jD�D��}|jrZ�jjrZd|}|S)N� css|]}|r|VqdS)NrJ)rL�srJrJrNr��sz/SQLCompiler.visit_clauselist.<locals>.<genexpr>c3s|]}|j�f��VqdS)N)r�)rLr')r�rxrJrNr��szVALUES )�operatorr�r.�clausesZ
_tuple_valuesrnZtuple_in_values)rxZ
clauselistr��seprrJ)r�rxrN�visit_clauselist�s
zSQLCompiler.visit_clauselistcKs�d}|jdk	r&||jj|f|�d7}x>|jD]4\}}|d|j|f|�d|j|f|�d7}q.W|jdk	r�|d|jj|f|�d7}|d7}|S)NzCASE r1zWHEN z THEN zELSE ZEND)r�r�ZwhensZelse_)rx�clauser�rM�condr�rJrJrN�
visit_case�s
.
zSQLCompiler.visit_casecKs|jj|f|�S)N)Ztyped_expressionr�)rxZtype_coercer�rJrJrN�visit_type_coerce�szSQLCompiler.visit_type_coercecKs$d|jj|f|�|jj|f|�fS)NzCAST(%s AS %s))r7r�r)rxrr�rJrJrN�
visit_cast�szSQLCompiler.visit_castc	Ks�d|dtjkrdn\|dtjkr&dnJ|ddkrTd|jt�t|d��f|�fnd|jt�|d�f|�f|dtjkr�dn\|dtjkr�dnJ|ddkr�d|jt�t|d��f|�fnd|jt�|d�f|�ffS)	Nz	%s AND %srzUNBOUNDED PRECEDINGzCURRENT ROWz%s PRECEDINGz%s FOLLOWINGrzUNBOUNDED FOLLOWING)rZRANGE_UNBOUNDEDZ
RANGE_CURRENTrv�literal�abs)rx�range_r�rJrJrN�_format_frame_clause�s..z SQLCompiler._format_frame_clausecs�|jrd�j|jf��}n |jr8d�j|jf��}nd}d|jj�f��d���fdd�d|jfd|jffD�|r||gng�fS)	NzRANGE BETWEEN %szROWS BETWEEN %sz%s OVER (%s)r1cs6g|].\}}|dk	rt|�rd||j�f��f�qS)Nz%s BY %s)r�r�)rL�wordr7)r�rxrJrN�
<listcomp>sz*SQLCompiler.visit_over.<locals>.<listcomp>Z	PARTITIONZORDER)r>r?Zrowsr�r�r.Zpartition_by�order_by)rxZoverr�r>rJ)r�rxrN�
visit_overszSQLCompiler.visit_overcKs$d|jj|f|�|jj|f|�fS)Nz%s WITHIN GROUP (ORDER BY %s))r�r�rB)rxZwithingroupr�rJrJrN�visit_withingroup$szSQLCompiler.visit_withingroupcKs$d|jj|f|�|jj|f|�fS)Nz%s FILTER (WHERE %s))�funcr�Z	criterion)rxZ
funcfilterr�rJrJrN�visit_funcfilter*szSQLCompiler.visit_funcfiltercKs*|j�|j|j�}d||jj|f|�fS)NzEXTRACT(%s FROM %s))�extract_mapr �fieldr*r�)rx�extractr�rHrJrJrN�
visit_extract0szSQLCompiler.visit_extractcs�|dk	r||j|jd|j�t�d|j��d�}|rB||f|�St�|jd�}|rd|jr�|d7}n*|j}�j�	|�r��j�
|�n|}|d}d��fdd�|jD�|g�d�j
|f|�iSdS)NrJz
visit_%s_funcz%(expr)sr�cs(g|] }�j�|�r �j�|�n|�qSrJ)rp�_requires_quotes_illegal_charsr)rL�tok)rxrJrNrAMsz.SQLCompiler.visit_function.<locals>.<listcomp>r*)r�r�r��lower�	FUNCTIONSr �	__class__Z	_has_argsrprKrr.Zpackagenames�function_argspec)rxrEr�r��dispr�rJ)rxrN�visit_function7s$

zSQLCompiler.visit_functioncKs|�|j�S)N)�visit_sequence�sequence)rxZ
next_valuer�rJrJrN�visit_next_value_funcWsz!SQLCompiler.visit_next_value_funccKstd|jj��dS)Nz2Dialect '%s' does not support sequence increments.)r�rnr�)rxrTr�rJrJrNrSZszSQLCompiler.visit_sequencecKs|jj|f|�S)N)Zclause_exprr�)rxrEr�rJrJrNrP`szSQLCompiler.function_argspecrcs(�j}|r�jn�jd}|p2|dko2|�dd�}�j�|d|d||d���j�|j�}	d|	d����fd	d
�t|j�D��}
|
�j	|ft
fd�i����7}
|
�j|f��7}
|
|jdk	s�|j
dk	r�j|f��p�d7}
�jr�|r����|
}
�j�d���r |�r d
|
dS|
SdS)Nr�rrF�correlate_froms�asfrom_froms)rVrWrrr1c3s,|]$\}}|j�f�d|d����VqdS)F)r�r$r#N)r�)rL�ir')r�r�rxrJrNr�zsz4SQLCompiler.visit_compound_select.<locals>.<genexpr>r�r�r�r�)r�rr �append�compound_keywords�keywordr.�	enumerate�selects�group_by_clauser��order_by_clause�
_limit_clause�_offset_clause�limit_clauser��_render_cte_clauser�)rx�csr�r$r#r�r%r�Zneed_result_mapr[rrJ)r�r�rxrN�visit_compound_selectcs4
 
z!SQLCompiler.visit_compound_selectcCs(d|j||rd|ndf}t||d�S)Nz
visit_%s_%s%s�_r�)r�r�)rx�	operator_Z
qualifier1Z
qualifier2�attrnamerJrJrN�_get_operator_dispatch�s
z"SQLCompiler._get_operator_dispatchcKs�|jrR|jrt�d��|�|jdd�}|r:|||jf|�S|j|t|jf|�SnL|jr�|�|jdd�}|r||||jf|�S|j|t|jf|�Sn
t�d��dS)NzFUnary expression does not support operator and modifier simultaneously�unaryr3�modifierz,Unary expression has no operator or modifier)r3rkrr�ri� _generate_generic_unary_operatorr�� _generate_generic_unary_modifier)rxrjr�rQrJrJrN�visit_unary�s&zSQLCompiler.visit_unarycKs6|js|jjr|j|jf|�Sd|j|jf|�SdS)Nz%s = 1)�_is_implicitly_booleanrnr-rvr�)rxr�r3r�rJrJrN�visit_istrue_unary_operator�sz'SQLCompiler.visit_istrue_unary_operatorcKs:|js|jjr"d|j|jf|�Sd|j|jf|�SdS)NzNOT %sz%s = 0)rornr-rvr�)rxr�r3r�rJrJrN�visit_isfalse_unary_operator�sz(SQLCompiler.visit_isfalse_unary_operatorcKsd|j|tjd�S)NzNOT %s)�override_operator)�visit_binaryr�match_op)rxrr3r�rJrJrN�visit_notmatch_op_binary�sz$SQLCompiler.visit_notmatch_op_binarycCst�d�dS)Nz�The IN-predicate was invoked with an empty sequence. This results in a contradiction, which nonetheless can be expensive to evaluate.  Consider alternative strategies for improved performance.)r
�warn)rxrJrJrN�_emit_empty_in_warning�sz"SQLCompiler._emit_empty_in_warningcKs2|jjrdS|jjr|��|�|j|jk�SdS)Nz1 != 1)rn�_use_static_in�_warn_on_empty_inrwrvr/)rxrr3r�rJrJrN�visit_empty_in_op_binary�s
z$SQLCompiler.visit_empty_in_op_binarycKs2|jjrdS|jjr|��|�|j|jk�SdS)Nz1 = 1)rnrxryrwrvr/)rxrr3r�rJrJrN�visit_empty_notin_op_binary�s
z'SQLCompiler.visit_empty_notin_op_binarycCstd|jj��dS)Nz3Dialect '%s' does not support empty set expression.)r�rnr�)rxZ
element_typesrJrJrN�visit_empty_set_expr�sz SQLCompiler.visit_empty_set_exprcKs�|jr*t|jtj�r*t|jtj�r*d|d<|p2|j}|�|dd�}|rT|||f|�Syt|}Wn t	k
r�t
�||��YnX|j||f|�SdS)NT�
literal_bindsr)
�ansi_bind_rulesr�r/rZ
BindParameterr=r3rir�r�rZUnsupportedCompilationError�_generate_generic_binary)rxrrr�eager_groupingr�rgrQ�opstringrJrJrNrs�s
zSQLCompiler.visit_binarycKs|j|jf|�S)N)rvZsql_function)rxr�r3r�rJrJrN�&visit_function_as_comparison_op_binarysz2SQLCompiler.visit_function_as_comparison_op_binarycKsT|jjr,|j|jf|�d|j|jf|�S|j|jf|�d|j|jf|�SdS)Nz %% z % )rprrvr/r=)rxrr3r�rJrJrN�visit_mod_binarys$zSQLCompiler.visit_mod_binarycKs$|j|d<|j|d|jdf|�S)Nr�r1)r�rr�)rxr�r3r�rJrJrN�visit_custom_op_binarys
z"SQLCompiler.visit_custom_op_binarycKs|j||jdf|�S)Nr1)rlr�)rxr�r3r�rJrJrN�visit_custom_op_unary_operator"sz*SQLCompiler.visit_custom_op_unary_operatorcKs|j|d|jf|�S)Nr1)rmr�)rxr�r3r�rJrJrN�visit_custom_op_unary_modifier'sz*SQLCompiler.visit_custom_op_unary_modifiercKs\|�dd�}d|d<|jj|fd|i|��||jj|fd|i|��}|rX|rXd|}|S)N�
_in_binaryFTr�z(%s))r r/r�r=)rxrr�r�r�r�rrJrJrNr,s z$SQLCompiler._generate_generic_binarycKs||jj|f|�S)N)r�r�)rxrjr�r�rJrJrNrlAsz,SQLCompiler._generate_generic_unary_operatorcKs|jj|f|�|S)N)r�r�)rxrjr�r�rJrJrNrmDsz,SQLCompiler._generate_generic_unary_modifiercCstjdtjd�S)Nz'%')r�)rZliteral_columnr	�
STRINGTYPE)rxrJrJrN�_like_percent_literalGsz!SQLCompiler._like_percent_literalcKs2|��}|j}|�|j��|�|_|j||f|�S)N)�_cloner��__add__r=�visit_like_op_binary)rxrr3r��percentrJrJrN�visit_contains_op_binaryKsz$SQLCompiler.visit_contains_op_binarycKs2|��}|j}|�|j��|�|_|j||f|�S)N)r�r�r�r=�visit_notlike_op_binary)rxrr3r�r�rJrJrN�visit_notcontains_op_binaryQsz'SQLCompiler.visit_notcontains_op_binarycKs,|��}|j}|�|j�|_|j||f|�S)N)r�r��__radd__r=r�)rxrr3r�r�rJrJrN�visit_startswith_op_binaryWsz&SQLCompiler.visit_startswith_op_binarycKs,|��}|j}|�|j�|_|j||f|�S)N)r�r�r�r=r�)rxrr3r�r�rJrJrN�visit_notstartswith_op_binary]sz)SQLCompiler.visit_notstartswith_op_binarycKs,|��}|j}|�|j�|_|j||f|�S)N)r�r�r�r=r�)rxrr3r�r�rJrJrN�visit_endswith_op_binarycsz$SQLCompiler.visit_endswith_op_binarycKs,|��}|j}|�|j�|_|j||f|�S)N)r�r�r�r=r�)rxrr3r�r�rJrJrN�visit_notendswith_op_binaryisz'SQLCompiler.visit_notendswith_op_binarycKsL|j�dd�}d|jj|f|�|jj|f|�f|rFd|�|tj�ndS)N�escapez
%s LIKE %sz ESCAPE r�)�	modifiersr r/r�r=�render_literal_valuer	r�)rxrr3r�r�rJrJrNr�osz SQLCompiler.visit_like_op_binarycKsL|j�dd�}d|jj|f|�|jj|f|�f|rFd|�|tj�ndS)Nr�z%s NOT LIKE %sz ESCAPE r�)r�r r/r�r=r�r	r�)rxrr3r�r�rJrJrNr�|sz#SQLCompiler.visit_notlike_op_binarycKsL|j�dd�}d|jj|f|�|jj|f|�f|rFd|�|tj�ndS)Nr�zlower(%s) LIKE lower(%s)z ESCAPE r�)r�r r/r�r=r�r	r�)rxrr3r�r�rJrJrN�visit_ilike_op_binary�sz!SQLCompiler.visit_ilike_op_binarycKsL|j�dd�}d|jj|f|�|jj|f|�f|rFd|�|tj�ndS)Nr�zlower(%s) NOT LIKE lower(%s)z ESCAPE r�)r�r r/r�r=r�r	r�)rxrr3r�r�rJrJrN�visit_notilike_op_binary�sz$SQLCompiler.visit_notilike_op_binarycKs&|j�dd�}|j||rdndf|�S)NrAFz BETWEEN SYMMETRIC z	 BETWEEN )r�r r)rxrr3r�rArJrJrN�visit_between_op_binary�sz#SQLCompiler.visit_between_op_binarycKs&|j�dd�}|j||rdndf|�S)NrAFz NOT BETWEEN SYMMETRIC z
 NOT BETWEEN )r�r r)rxrr3r�rArJrJrN�visit_notbetween_op_binary�s
z&SQLCompiler.visit_notbetween_op_binaryc
Ks&|s<|j�|j�}|jr<|�|�}|j|fd||d�|��S|sJ|r�|jr�|jdkrn|jdkrnt	�
d|j��|j|fddi|��S|�
|�}||jkr�|j|}	|	|k	r�|	js�|jr�|	j�|j�s�t	�
d|j��n"|	js�|jr�t	�
d|j|jf��||j|j<|j|<|j|fd|ji|��S)NT)�skip_bind_expressionr�r}z@Bind parameter '%s' without a renderable value not allowed here.r�zIBind parameter '%s' conflicts with unique bind parameter of the same namez�bindparam() name '%s' 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_%s').�	expanding)r��dialect_implrnZ_has_bind_expression�bind_expressionrvr~r�r�rr�r��render_literal_bindparam�_truncate_bindparamr�rFr��intersectionZ_is_crudrr�)
rxr�r�r}r�r��implr�r��existingrJrJrN�visit_bindparam�sB	




zSQLCompiler.visit_bindparamcKs|j}|�||j�S)N)r�r�r�)rxr�r�r�rJrJrNr��sz$SQLCompiler.render_literal_bindparamcCs(|�|j�}|r||�Std|��dS)aRender the value of a bind parameter as a quoted literal.

        This is used for statement sections that do not accept bind parameters
        on the target driver/database.

        This should be implemented by subclasses using the quoting services
        of the DBAPI.

        z(Don't know how to literal-quote value %rN)Z_cached_literal_processorrnr�)rxr�r��	processorrJrJrNr��s
z SQLCompiler.render_literal_valuecCs@||jkr|j|S|j}t|tj�r2|�d|�}||j|<|S)Nr�)r�r�r�rr�r�)rxr�Z	bind_namerJrJrNr��s


zSQLCompiler._truncate_bindparamcCs�||f|jkr|j||fS|�|j�}t|�|jdkr�|j�|d�}|dt|jdd��dt|�dd�}|d|j|<n|}||j||f<|S)N�rrrfr)r�Z	apply_mapr�r�r�r �max�hex)rxZident_classr�Zanonname�counterZ	truncnamerJrJrNr�s,z!SQLCompiler._truncated_identifiercCs
||jS)N)r�)rxr�rJrJrN�
_anonymizeszSQLCompiler._anonymizecCs<|�dd�\}}|j�|d�}|d|j|<|dt|�S)Nr1rrf)�splitr�r rK)rxr��identZderivedZanonymous_counterrJrJrNr�"szSQLCompiler._process_anoncKsJ|jr&|dk	r|�|�n|j�|�|r8d|_d|S|jd|iSdS)NTz([EXPANDING_%s])r�)r�rYr��contains_expanding_parametersr�)rxr��positional_namesr�r�rJrJrNr(szSQLCompiler.bindparam_stringcs����||d<t|jtj�r.��d|j�}n|j}d}d}	|�jkr��j|}
||
k}	||
jksj||
krpd}n"|
|jkr��j|
=nt	�
d|��|s�|r�|jdk	r�|j}|jj}t|tj�rԈ�d|�}n|}d}|�rD|�j|<d|jj
k�rd�jk�r�j�d|jj
di��_|�jk�r2�j|f|�|�sD|�jk�rD|j�rRd�_�j�||�}
|j�r�t|jtj��r�|j}n(t|jtj��r�|jjd}n
d�s�t�dd	�t�|j�D�}|
d
d��fdd
�|D��7}
�j�r�g|d<�j |<|
d|jj!�fddi|��7}
|j"�r:|
d�j#||j"f|�7}
|
�j|<|�r�|�sd|	�rd�j�||�S|�r��j�||�}
�j�$|��r��j�%|�}|
��&|�7}
|
S�j�||�SdS)N�visiting_cter�TFz5Multiple, unrelated CTEs found with the same name: %rZ
autocommitrcSsg|]}|dk	r|�qS)NrJ)rLr'rJrJrNrA�sz)SQLCompiler.visit_cte.<locals>.<listcomp>z(%s)z, c3s|]}�j�|�VqdS)N)rp�
format_column)rLr�)rxrJrNr��sz(SQLCompiler.visit_cte.<locals>.<genexpr>r�z AS 
r�r1)'r�r�r�rr�r�r�Z	_restatesr�rr�Z
_cte_aliasr�rtrurE�	visit_cte�	recursiver�rp�format_alias�originalr�Select�CompoundSelectr]�AssertionErrorr
Zunique_list�
inner_columnsr.r�r�r��	_suffixes�_generate_prefixes�_requires_quotesr�get_render_as_alias_suffix)rx�cter��ashint�	fromhintsr�r�Zcte_nameZ
is_new_cteZembedded_in_current_named_cteZexisting_cteZ
pre_alias_cteZcte_pre_alias_namerZ
col_sourceZ
recur_colsrJ)rxrNr�6s�	










zSQLCompiler.visit_ctec	Ks�|s|r,t|jtj�r&|�d|j�}n|j}|r>|j�||�S|r�|jj|fddi|��|�	|j�||��}|r�||kr�|�
|||||�}|S|jj|f|�SdS)Nr�r�T)r�r�rr�r�rpr�r�r�r��format_from_hint_text)	rxr�r�r��iscrudr�r�Z
alias_name�retrJrJrN�visit_alias�s 	zSQLCompiler.visit_aliascKsd|d<d|j|f|�S)NT�lateralz
LATERAL %s)r�)rxr�r�rJrJrN�
visit_lateral�szSQLCompiler.visit_lateralcKsRd|j|fddi|��|��j|f|�f}|jdk	rN|d|jj|f|�7}|S)Nz%s TABLESAMPLE %sr�Tz REPEATABLE (%s))r�Z_get_methodr��seed)rxZtablesampler�r�rrJrJrN�visit_tablesample�s
zSQLCompiler.visit_tablesamplecCsd|S)Nz AS rJ)rxZalias_name_textrJrJrNr��sz&SQLCompiler.get_render_as_alias_suffixcCs|j�||||f�dS)N)r�rY)rx�keynamer��objectsr�rJrJrNr"�szSQLCompiler._add_to_result_mapcs~�j��j�}|jr2|r2|���}	��fdd�}
n�}	|rB�j}
nd}
|sR|	}�nt�tj�r�|	�k	r|t	|	�j
�jfd�}n|	}n�|dk	r�|r�t	|	|�jfd�}n�|r�t�tj
�r�js�jdk	r�t�jtj�s�t	|	t��j
��jfd�}nvt�tj��s8t�tj��r�j�r8t�d��r*t�tj��r8t	|	�j�}n*|	�k	�r^t	|	t��j
��jfd�}n|	}|j||
d�|j�f|�S)z.produce labeled columns present in a select().cs��||�f||�dS)N)r")r�r�r�r�)rrxrJrNr��sz;SQLCompiler._label_select_column.<locals>.add_to_result_mapN)r�r�)r�r�)r�r�rnZ_has_column_expressionZcolumn_expressionr"r�rZLabelr�r�r��
_key_labelZColumnClauser�rBrr�Z
_as_truncatedr�Z
TextClauseZUnaryExpressionZwraps_column_expression�hasattrrZFunctionZ
anon_label�updater�)rxr>rr&r��column_clause_argsr�r�r�Zcol_exprr�Zresult_exprrJ)rrxrN�_label_select_column�sV





z SQLCompiler._label_select_columncCs |�||�}|r|d|7}|S)Nr1)�get_from_hint_text)rx�sqltextrB�hintr��hinttextrJrJrNr�;sz!SQLCompiler.format_from_hint_textcCsdS)NrJ)rxZbyfromsrJrJrN�get_select_hint_textAsz SQLCompiler.get_select_hint_textcCsdS)NrJ)rxrBrrJrJrNr�DszSQLCompiler.get_from_hint_textcCsdS)NrJ)rxrBrrJrJrN�get_crud_hint_textGszSQLCompiler.get_crud_hint_textcCs
d�|�S)Nr1)r.)rxZ
hint_textsrJrJrN�get_statement_hint_textJsz#SQLCompiler.get_statement_hint_textcs"i�ig����fdd���|�S)z�Rewrite any "a JOIN (b JOIN c)" expression as
        "a JOIN (select * from b JOIN c) AS anon", to support
        databases that can't parse a parenthesized join correctly
        (i.e. sqlite < 3.7.16).

        c
s�|�dkr�d|S|�kr(�|S|��}�|<|j�r^|j�r^t|jtj��r^|���|jf|�|_�|jf|�}tj	|j
gdd���}x|jD]}|j
|_|j|_q�Wtt|jj
j|j��}|||j
j<|||j
j<|||jj
j<|||jj
j<x8t�d���D]$\}}||k�r||�d|<�qW�d�|�||_�|jf|�|_n�|j�r�d|d<|jfd�i|��nn|j�r�|j�r�|�dd�dk}	|	�r���i�d|d<|jfd�i|��|	�r�d=n|jfd�i|��|S)Nr�T)�
use_labelsZselect_containerZtransform_clue�cloneZ
inside_select)r�Z
is_selectableZ_is_joinr�r=rZFromGroupingZ_reset_exportedr/r�r�r�r'r�r�r�Z_labelr��zipr��itemsr��onclauseZ_is_from_containerZ_copy_internalsZ
_is_selectr rY)
r�r�Znewelemr=Zselectable_r'Ztranslate_dict�k�vZbarrier_select)�cloned�column_translate�visitrJrNr�WsR

z=SQLCompiler._transform_select_for_nested_joins.<locals>.visitrJ)rxr>rJ)r�r�r�rN�"_transform_select_for_nested_joinsMsQz.SQLCompiler._transform_select_for_nested_joinscsFtdd�|jD���t�fdd�|jD����fdd�|jD�|_dS)Ncss|]}|j|fVqdS)N)r�)rLr'rJrJrNr��szESQLCompiler._transform_result_map_for_nested_joins.<locals>.<genexpr>c3s|]}�|j|fVqdS)N)r�)rLr')�	inner_colrJrNr��scs2g|]*\}}}}||t�fdd�|D��|f�qS)csg|]}��||��qSrJ)r )rLr�)�drJrNrA�szQSQLCompiler._transform_result_map_for_nested_joins.<locals>.<listcomp>.<listcomp>)�tuple)rLr�r�Zobjs�typ)r�rJrNrA�szFSQLCompiler._transform_result_map_for_nested_joins.<locals>.<listcomp>)r�r�r�)rxr>�transformed_selectrJ)r�r�rN�&_transform_result_map_for_nested_joins�s

z2SQLCompiler._transform_result_map_for_nested_joinsrVrWc	Cs\|j}|r|jn|jd}|d}|d}|rJ|sJ|j|�|�dd�}n|j||d�}|S)Nr�rVrWrJ)�explicit_correlate_froms�implicit_correlate_froms)r�r�_get_display_froms�
difference)	rxr>r�r�r%r�rVrW�fromsrJrJrN�_display_froms_for_select�s
z%SQLCompiler._display_froms_for_selectc	sf�jo|o�jo�jj}
|
rJ����}�j|f�|||dd�|	��}�j}
|
r\�jn�jd}|
p�|dkr~|�dd�p�|�dd���s�d|	kr�|	d=|
r��r����|�|S��	�|�|�}|	�
����ddd	��d
}�j�r
��
��\}}|�r||d7}nd}�j�r,|�j��jf|	�7}|�j�f|	�7}dd
������fdd
��jD�D�}��r�|dk	�r�ttdd
��jD�dd
�|jD�����fdd
��jD��_��|�||||	�}�j�r��fdd
��jD�}|�r�|d��|�7}�j�r|
�r���|}�j�r4|d�j��jf|	�7}�j�d���sL|�r^|�r^d|dS|SdS)NT)r�r$r�r#�nested_join_translationr�rrFr�r�)r�r�zSELECT r1cSsg|]}|dk	r|�qS)NrJ)rLr'rJrJrNrA&sz,SQLCompiler.visit_select.<locals>.<listcomp>c
s&g|]\}}�j�|���|d��qS))r�)r�)rLr�r)r�r�r&r>rxrJrNrA(scSsg|]\}}|�qSrJrJ)rLr�r�rJrJrNrA;scSsg|]\}}|�qSrJrJ)rLr�r�rJrJrNrA=scs2g|]*\}}}}||t�fdd�|D��|f�qS)c3s|]}��||�VqdS)N)r )rL�o)�	translaterJrNr�Dsz6SQLCompiler.visit_select.<locals>.<listcomp>.<genexpr>)r�)rLr�r�r�r�)r�rJrNrADscs$g|]\}}|d�jjfkr|�qS)�*)rnr�)rL�dialect_nameZht)rxrJrNrANsr�r�)r�r�rnZsupports_right_nested_joinsr��visit_selectrr r��_setup_select_stack�copyr��_hints�_setup_select_hints�	_prefixesr��get_select_precolumnsZ_columns_plus_namesr�r�r��_compose_select_bodyZ_statement_hintsr�r�rcr�r�)rxr>r�r$r�r#r�Zselect_wraps_forr�r�Zneeds_nested_translationr�rr%r�r��	hint_text�byfromr�Zper_dialectrJ)r�r�r&r>rxr�rNr��s�



zSQLCompiler.visit_selectcs.t�fdd�|j��D��}��|�}||fS)Nc	s>g|]6\\}}}|d�jjfkr||d|j�dd�if�qS)r�r�T)r�)rnr�r�)rL�from_rnr�)rxrJrNrAgs
z3SQLCompiler._setup_select_hints.<locals>.<listcomp>)r�r�r�r�)rxr>r�r�rJ)rxrNr�ds


zSQLCompiler._setup_select_hintscCsp|d}|d}|r.|s.|j|�|�dd�}n|j||d�}ttj|��}|�|�}	||	|d�}
|j�|
�|S)NrVrWrJ)r�r�)rWrVr)r�r�r@r�
_from_objectsrEr�rY)rxr>r�r�r�rVrWr�Znew_correlate_fromsZall_correlate_fromsZ	new_entryrJrJrNr�ss"

zSQLCompiler._setup_select_stackcsB|d�|�7}|rb|d7}|jrB|d����fdd�|D��7}qn|d���fdd�|D��7}n|���7}|jdk	r�|jj�f��}|r�|d|7}|jjr�|�j|f��7}|jdk	r�|jj�f��}|r�|d|7}|j	jr�|�j
|f��7}|jdk	�s|jdk	�r |�j
|f��7}|jdk	�r>|�j|f��7}|S)Nz, z 
FROM cs$g|]}|j�fd�d�����qS)T)r�r�)r�)rL�f)r�r�rxrJrNrA�sz4SQLCompiler._compose_select_body.<locals>.<listcomp>cs"g|]}|j�fddi����qS)r�T)r�)rLr)r�rxrJrNrA�sz 
WHERE z	 
HAVING )r.r�r��_whereclauser��_group_by_clauser4r^Z_having�_order_by_clauser_r`rarbZ_for_update_arg�for_update_clause)rxrr>r�r�r�r��trJ)r�r�rxrNr��s:

z SQLCompiler._compose_select_bodycs*d���fdd�|D��}|r&|d7}|S)Nr1c3s4|],\}}|dks|�jjkr|j�f��VqdS)N)rnr�r�)rL�prefixr�)r�rxrJrNr��sz1SQLCompiler._generate_prefixes.<locals>.<genexpr>)r.)rx�stmt�prefixesr�r7rJ)r�rxrNr��s
zSQLCompiler._generate_prefixescsb�jr(t�fdd��jD�g��j�_���j�d}|d�dd��j��D��7}|d7}|S)Ncsg|]}�j|�qSrJ)r�)rLr�)rxrJrNrA�sz2SQLCompiler._render_cte_clause.<locals>.<listcomp>r1z, 
cSsg|]}|�qSrJrJ)rLZtxtrJrJrNrA�sz
 )r��sumr�r��get_cte_preambler�r.�values)rxZcte_textrJ)rxrNrc�s
zSQLCompiler._render_cte_clausecCs|rdSdSdS)NzWITH RECURSIVEZWITHrJ)rxr�rJrJrNr
�szSQLCompiler.get_cte_preamblecKs|jr
dpdS)zcCalled when building a ``SELECT`` statement, position is just
        before column list.

        z	DISTINCT r�)Z	_distinct)rxr>r�rJrJrNr��sz!SQLCompiler.get_select_precolumnscKs$|jj|f|�}|rd|SdSdS)z5allow dialects to customize how GROUP BY is rendered.z
 GROUP BY r�N)rr�)rxr>r�Zgroup_byrJrJrNr^�szSQLCompiler.group_by_clausecKs$|jj|f|�}|rd|SdSdS)z5allow dialects to customize how ORDER BY is rendered.z
 ORDER BY r�N)rr�)rxr>r�rBrJrJrNr_�szSQLCompiler.order_by_clausecKsdS)Nz FOR UPDATErJ)rxr>r�rJrJrNr�szSQLCompiler.for_update_clausecCst�d��dS)Nz@RETURNING is not supported by this dialect's statement compiler.)rr�)rxr�returning_colsrJrJrN�returning_clause�szSQLCompiler.returning_clausecKs^d}|jdk	r&|d|j|jf|�7}|jdk	rZ|jdkrB|d7}|d|j|jf|�7}|S)Nr�z
 LIMIT z

 LIMIT -1z OFFSET )r`rvra)rxr>r�rrJrJrNrb	s


zSQLCompiler.limit_clausec
Ksv|s|rn|j�|�}|r<|r<|j�|�d|j�|j�}	n|j�|j�}	|rj||krj|�|	||||�}	|	SdSdS)Nr�r�)rprrrr�r�)
rxrBr�r�r�r��
use_schemar�rr�rJrJrN�visit_table
	s
 zSQLCompiler.visit_tablecKsd|jrd}n|jrd}nd}|jj|fddi|��||jj|fddi|��d|jj|f|�S)Nz FULL OUTER JOIN z LEFT OUTER JOIN z JOIN r�Tz ON )r(Zisouterr/r�r=r�)rxr.r�r�Z	join_typerJrJrN�
visit_join*	szSQLCompiler.visit_joincsFt�fdd�|j��D��}|j|kr>��||j||jd�}||fS)Ncs,g|]$\\}}}|d�jjfkr||f�qS)r�)rnr�)rLrBrnr�)rxrJrNrA<	s
z1SQLCompiler._setup_crud_hints.<locals>.<listcomp>T)r�r�r�rBr�)rxr�
table_text�
dialect_hintsrJ)rxrN�_setup_crud_hints9	s

zSQLCompiler._setup_crud_hintscs�|j}|j�t�t�|d��tj||tjf|�}|sZ|jjsZ|jjsZt	�
d|jj��|jr�|jj
szt	�
d|jj��|d}n|}|j�|jj}d}|jr�||j||jf|�7}|d7}��|j�}	|jr�|�||	�\}
}	||	7}|s�|�s|dd��fd	d
�|D��7}|j�s"|j�rN|�||j�p4|j�}|j�rR|d|7}nd}|jdk	�r�|j|jf|�}|j�r�|�r�|jj�r�|d|��|f7}n|d
|7}nX|�s�|�r�|d7}nB|j�r�|dd�dd�|D��7}n|dd�dd
�|D��7}|j dk	�r0|j|j f|�}
|
�r0|d|
7}|�rJ|j�sJ|d|7}|j�rn|�rn|jj�sn|��|}|j�!d�|�r�d|dS|SdS)N)rVrWrzWThe '%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.rzINSERT zINTO z (%s)z, csg|]}��|d��qS)r)r�)rLr')rprJrNrA�	sz,SQLCompiler.visit_insert.<locals>.<listcomp>r1z %s%sz %sz DEFAULT VALUESz
 VALUES %scss&|]}dd�dd�|D��VqdS)z(%s)z, css|]}|dVqdS)rNrJ)rLr'rJrJrNr��	sz5SQLCompiler.visit_insert.<locals>.<genexpr>.<genexpr>N)r.)rLZcrud_param_setrJrJrNr��	sz+SQLCompiler.visit_insert.<locals>.<genexpr>z VALUES (%s)cSsg|]}|d�qS)rrJ)rLr'rJrJrNrA�	sr�r�r�)"r�rYr@r�_setup_crud_paramsZISINSERTrn�supports_default_valuesZsupports_empty_insertrr�r�Z_has_multi_parametersZsupports_multivalues_insertrpr�r��format_tablerBr�rr.r�r�r
�returning_precedes_valuesr>rvZ_insert_from_selectr�Zcte_follows_insertrcZ_post_values_clauser�)rxZinsert_stmtr�r�r%�crud_paramsZcrud_params_singlerrrrfr
Zselect_textZpost_values_clauserJ)rprN�visit_insertG	s�



zSQLCompiler.visit_insertcCsdS)z3Provide a hook for MySQL to add LIMIT to the UPDATENrJ)rx�update_stmtrJrJrN�update_limit_clause�	szSQLCompiler.update_limit_clausecKsd|d<|j|fddi|��S)z|Provide a hook to override the initial table clause
        in an UPDATE statement.

        MySQL overrides this.

        Tr�r�)r�)rxr�
from_table�extra_fromsr�rJrJrN�update_tables_clause�	sz SQLCompiler.update_tables_clausecKstd��dS)z~Provide a hook to override the generation of an
        UPDATE..FROM clause.

        MySQL and MSSQL override this.

        zCThis backend does not support multiple-table criteria within UPDATEN)r�)rxrrr�
from_hintsr�rJrJrN�update_from_clause�	s	zSQLCompiler.update_from_clausecs(�j}|j}t|�}|rHtt�|j����fdd�|D�}��|�}ng}|jh}�j�|||d��d}	|j	r�|	�j
||j	f|�7}	�j||j|f|�}
tj
�|tjf|�}|jrȈ�||
�\}}
nd}|	|
7}	|	d7}	|o�j�|	d���fdd�|D��7}	�j�s|j�r:�j�r:|	d	��|�j�p2|j�7}	|�rh�j||j||f|�}
|
�rh|	d	|
7}	|jdk	�r��j|jf|�}|�r�|	d
|7}	��|�}|�r�|	d	|7}	�j�s�|j�r�j�s�|	d	��|�j�p�|j�7}	�j�r|�r���|	}	�j�d�|�r d|	d
S|	SdS)Ncsg|]}|�kr|�qSrJrJ)rLr)�
main_fromsrJrNrA�	sz,SQLCompiler.visit_update.<locals>.<listcomp>)rVrWrzUPDATE z SET z, c3s,|]$}|dj��d�d|dVqdS)r)r�=rN)r�)rLr')rrxrJrNr�
sz+SQLCompiler.visit_update.<locals>.<genexpr>r1z WHERE r�r�r�)r��_extra_froms�boolr@rr�rBrErYr�r�rrrZISUPDATEr�r�'render_table_with_column_in_update_fromr.r�r�rr
r rrvrr�rcr�)rxrr�r�r%rZ
is_multitableZrender_extra_fromsrVrrrr�extra_from_textrrbrJ)rr!rxrN�visit_update�	sz


zSQLCompiler.visit_updatecCst�||j�S)N)r�_key_getters_for_crud_columnrr)rxrJrJrNr(6
sz(SQLCompiler._key_getters_for_crud_columncKstd��dS)z�Provide a hook to override the generation of an
        DELETE..FROM clause.

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

        MySQL and MSSQL override this.

        zCThis backend does not support multiple-table criteria within DELETEN)r�)rxrrrrr�rJrJrN�delete_extra_from_clause:
sz$SQLCompiler.delete_extra_from_clausecCs|j|ddd�S)NT)r�r�)r�)rx�delete_stmtrrrJrJrN�delete_table_clauseJ
szSQLCompiler.delete_table_clausecKs�|j}tj||tjf|�|j}|jh�|�}|j�|||d��d}|jrd||j	||jf|�7}|d7}|�
||j|�}|jr�|�||�\}	}nd}	||7}|j
r�|jr�|d|�||j
�7}|r�|j||j||	f|�}
|
r�|d|
7}|jdk	�r|jj|f|�}|�r|d|7}|j
�r@|j�s@|d|�||j
�7}|j�rZ|�rZ|��|}|j�d�|�rxd|dS|SdS)	N)rVrWrzDELETE zFROM r1z WHERE r�r�r�)r�rrZISDELETEr#rBrErYr�r�r+r�rr�rr
r)rr�r�rcr�)rxr*r�r�r%rrVrrrr&rrJrJrN�visit_deleteM
s\
zSQLCompiler.visit_deletecCsd|j�|�S)NzSAVEPOINT %s)rp�format_savepoint)rx�savepoint_stmtrJrJrN�visit_savepoint�
szSQLCompiler.visit_savepointcCsd|j�|�S)NzROLLBACK TO SAVEPOINT %s)rpr-)rxr.rJrJrN�visit_rollback_to_savepoint�
sz'SQLCompiler.visit_rollback_to_savepointcCsd|j�|�S)NzRELEASE SAVEPOINT %s)rpr-)rxr.rJrJrN�visit_release_savepoint�
sz#SQLCompiler.visit_release_savepoint)NF)NNT)F)F)F)NFFN)NT)NFT)N)FTr)NF)F)FFF)NF)FFNN)FFFN)F)NT)F)FTNrFNF)FFFNT)F)F)F)F)�r�r�r�r��EXTRACT_MAPrG�COMPOUND_KEYWORDSrZr�r�r�rr�rr%r�r~r!r�r�r�r�rzr�r�r
Zmemoized_instancemethodr��
contextlib�contextmanagerr�r��memoized_propertyr�r�r�r�r~�dependenciesr�r�r�r�r�r�r�rr
rr
rrrrr(r+r.r0r6r9r:r;r?rCrDrFrJrRrUrSrPrerirnrprqrurwrzr{r|rsr�r�r�r�r�rrlrmr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r�r"r�r�r�r�r�r�r�r�r��	frozensetrr�r�r�r�r�r�rcr
r�r^r_rr
rbrrrrrrr r'r(r)r+r,r/r0r1rJrJrJrNr��sHG8	"+' 2			
8
v

L]6
		
m
fJr�c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�StrSQLCompilerawA :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:`.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:`.ClauseElement.compile`
    directly.

    .. seealso::

        :ref:`faq_sql_expression_string`

    cCsdS)Nz<name unknown>rJ)rxrrJrJrNr��
sz$StrSQLCompiler._fallback_column_namecKs$d|j|jf|�|j|jf|�fS)Nz%s[%s])rvr/r=)rxrr3r�rJrJrN�visit_getitem_binary�
sz#StrSQLCompiler.visit_getitem_binarycKs|j||f|�S)N)r:)rxrr3r�rJrJrN�visit_json_getitem_op_binary�
sz+StrSQLCompiler.visit_json_getitem_op_binarycKs|j||f|�S)N)r:)rxrr3r�rJrJrN�!visit_json_path_getitem_op_binary�
sz0StrSQLCompiler.visit_json_path_getitem_op_binarycKsd|j�|�S)Nz<next sequence value: %s>)rp�format_sequence)rx�seqr�rJrJrNrS�
szStrSQLCompiler.visit_sequencecs&�fdd�t�|�D�}dd�|�S)Nc	sg|]}��d|ddi��qS)NTF)r�)rLr')rxrJrNrA�
sz3StrSQLCompiler.returning_clause.<locals>.<listcomp>z
RETURNING z, )rZ_select_iterablesr.)rxrr�columnsrJ)rxrNr
�
s
zStrSQLCompiler.returning_clausecs dd����fdd�|D��S)NzFROM z, c3s&|]}|j�fd�d����VqdS)T)r�r�N)r�)rLr)rr�rxrJrNr��
sz4StrSQLCompiler.update_from_clause.<locals>.<genexpr>)r.)rxrrrrr�rJ)rr�rxrNr �
sz!StrSQLCompiler.update_from_clausecs dd����fdd�|D��S)Nz, c3s&|]}|j�fd�d����VqdS)T)r�r�N)r�)rLr)rr�rxrJrNr��
sz:StrSQLCompiler.delete_extra_from_clause.<locals>.<genexpr>)r.)rxrrrrr�rJ)rr�rxrNr)�
sz'StrSQLCompiler.delete_extra_from_clauseN)r�r�r�r�r�r:r;r<rSr
r r)rJrJrJrNr9�
sr9c@sBeZdZejdd��Zejdd��ZdLdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZdMdd�ZdNdd�Z
dd�Zdd�Zdd�ZdOdd�Zdd�ZdPd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dS)Q�DDLCompilercCs|j�|jd�S)N)rnZstatement_compiler)rxrJrJrNr��
szDDLCompiler.sql_compilercCs|jjS)N)rnr)rxrJrJrNr�
szDDLCompiler.type_compilerNcCsdS)NrJ)rxr~rJrJrNr��
szDDLCompiler.construct_paramscKs�|j}t|jtj�r�|��}|j}|�|j�}t|�dkrJ|dd}}n|d|d}}|�	d|�|�	d|�|�	d|�
|j��|j�|j
|�S)Nrrr�r�rBr�fullname)�contextr��targetrZTabler�rp�format_table_seqr��
setdefaultrr�rrr)rxZddlr�rBrp�pathrBZschrJrJrN�	visit_ddl�
szDDLCompiler.visit_ddlcCs|j�|j�}d|S)NzCREATE SCHEMA )rp�
format_schemar�)rxrrrJrJrN�visit_create_schemaszDDLCompiler.visit_create_schemacCs(|j�|j�}d|}|jr$|d7}|S)NzDROP SCHEMA z CASCADE)rprHr��cascade)rx�droprrrJrJrN�visit_drop_schemas
zDDLCompiler.visit_drop_schemac

CsR|j}|j}d}|jr*|d�|j�d7}|d|�|�d7}|�|�}|rZ||d7}|d7}d}d}x�|jD]�}|j}	yD|j||	jo�|d�}
|
dk	r�||7}d}|d	|
7}|	jr�d
}Wqrt	j
k
�r}z.t�t	�
t�
d�|j|	j|jdf��Wdd}~XYqrXqrW|j||jd
�}|�r<||d	|7}|d|�|�7}|S)Nz
CREATE r1zTABLE r��
F)�first_pkz, 
�	Tz (in table '%s', column '%s'): %sr)� _include_foreign_key_constraintsz
)%s

)r�rpr�r.r�create_table_suffixr?rv�primary_keyrr�r
Zraise_from_cause�u�descriptionr��args�create_table_constraintsZinclude_foreign_key_constraints�post_create_table)
rxrrBrprrQ�	separatorrNZ
create_columnr�	processedZce�constrJrJrN�visit_create_tablesF
0
zDDLCompiler.visit_create_tableFcsL|j}|jrdS�j||d�}d��fdd�|jD��}|rH|d|7}|S)N)rNr1c3s|]}��|�VqdS)N)rv)rLr)rxrJrNr�Esz2DDLCompiler.visit_create_column.<locals>.<genexpr>)r��system�get_column_specificationr.�constraints)rxrrNrrrZrJ)rxrN�visit_create_column=szDDLCompiler.visit_create_columncstg}�jr|��j��j}|dk	r0|�|��nt��|���fdd��jD��d�dd��fdd�|D�D��S)Ncs"g|]}|�jk	r|�kr|�qSrJ)rR)rLr')�	omit_fkcsrBrJrNrA^sz8DDLCompiler.create_table_constraints.<locals>.<listcomp>z, 
	css|]}|dk	r|VqdS)NrJ)rL�prJrJrNr�esz7DDLCompiler.create_table_constraints.<locals>.<genexpr>c3s@|]8}|jdks|���r�jjr.t|dd�s��|�VqdS)NZ	use_alterF)Z_create_rulernZsupports_alterr�rv)rLr)rxrJrNr�gs


)rRrYZforeign_key_constraintsr�r@�extendZ_sorted_constraintsr.)rxrBrPr^Zall_fkcsrJ)r`rxrBrNrVLs
z$DDLCompiler.create_table_constraintscCsd|j�|j�S)Nz
DROP TABLE )rprr�)rxrKrJrJrN�visit_drop_tableuszDDLCompiler.visit_drop_tablecCsd|j�|j�S)Nz
DROP VIEW )rprr�)rxrKrJrJrN�visit_drop_viewxszDDLCompiler.visit_drop_viewcCs|jdkrt�d|j��dS)Nz,Index '%s' is not associated with any table.)rBrr�r�)rxrrJrJrN�_verify_index_table{s
zDDLCompiler._verify_index_tableTc	sj|j}��|��j}d}|jr(|d7}|d�j||d�|j|j|d�d��fdd�|jD��f7}|S)	NzCREATE zUNIQUE zINDEX %s ON %s (%s))�include_schema)rz, c3s |]}�jj|ddd�VqdS)FT)rr}N)r�rv)rLr*)rxrJrNr��sz1DDLCompiler.visit_create_index.<locals>.<genexpr>)	r�rerprF�_prepared_index_namerrBr.Zexpressions)rxrrfZinclude_table_schemarrprrJ)rxrN�visit_create_index�s


zDDLCompiler.visit_create_indexcCs|j}d|j|dd�S)Nz
DROP INDEX T)rf)r�rg)rxrKrrJrJrN�visit_drop_index�szDDLCompiler.visit_drop_indexcCsX|jdk	r|j�|j�}nd}|r4|r4|j�|�}nd}|j�|�}|rT|d|}|S)Nr�)rBrprr�format_index)rxrrfrZschema_nameZ
index_namerJrJrNrg�s
z DDLCompiler._prepared_index_namecCs d|j�|jj�|�|j�fS)NzALTER TABLE %s ADD %s)rprr�rBrv)rxrrJrJrN�visit_add_constraint�sz DDLCompiler.visit_add_constraintcCs(d|j�|j�|j�|jjt���fS)NzCOMMENT ON TABLE %s IS %s)rprr�r�r��commentr	�String)rxrrJrJrN�visit_set_table_comment�sz#DDLCompiler.visit_set_table_commentcCsd|j�|j�S)NzCOMMENT ON TABLE %s IS NULL)rprr�)rxrKrJrJrN�visit_drop_table_comment�sz$DDLCompiler.visit_drop_table_commentcCs.d|jj|jddd�|j�|jjt���fS)NzCOMMENT ON COLUMN %s IS %sT)�	use_tabler)rpr�r�r�r�rlr	rm)rxrrJrJrN�visit_set_column_comment�s
z$DDLCompiler.visit_set_column_commentcCsd|jj|jdd�S)NzCOMMENT ON COLUMN %s IS NULLT)rp)rpr�r�)rxrKrJrJrN�visit_drop_column_comment�sz%DDLCompiler.visit_drop_column_commentcCs�d|j�|j�}|jjdk	r.|d|jj7}|jjdk	rJ|d|jj7}|jjdk	rf|d|jj7}|jjdk	r�|d|jj7}|jjdk	r�|d7}|jjdk	r�|d7}|jj	dk	r�|d|jj	7}|jj
d	kr�|d
7}|jjdk	r�|d7}|S)NzCREATE SEQUENCE %sz INCREMENT BY %dz START WITH %dz MINVALUE %dz MAXVALUE %dz NO MINVALUEz NO MAXVALUEz	 CACHE %dTz ORDERz CYCLE)rpr=r�Z	increment�startZminvalueZmaxvalueZ
nominvalueZ
nomaxvalue�cacher<�cycle)rxrrrJrJrN�visit_create_sequence�s*
z!DDLCompiler.visit_create_sequencecCsd|j�|j�S)NzDROP SEQUENCE %s)rpr=r�)rxrKrJrJrN�visit_drop_sequence�szDDLCompiler.visit_drop_sequencecCs^|j}|jdk	r|j�|�}nd}|dkr:t�d|j��d|j�|jj�||jrVdpXdfS)Nz<Can't emit DROP CONSTRAINT for constraint %r; it has no namez#ALTER TABLE %s DROP CONSTRAINT %s%sz CASCADEr�)	r�r�rp�format_constraintrr�rrBrJ)rxrKr�formatted_namerJrJrN�visit_drop_constraint�s

z!DDLCompiler.visit_drop_constraintcKsT|j�|�d|jjj|j|d�}|�|�}|dk	rB|d|7}|jsP|d7}|S)Nr1)rz	 DEFAULT z	 NOT NULL)rpr�rnrrvr��get_column_default_stringZnullable)rxrr�ZcolspecrrJrJrNr]�s
z$DDLCompiler.get_column_specificationcCsdS)Nr�rJ)rxrBrJrJrNrQ
szDDLCompiler.create_table_suffixcCsdS)Nr�rJ)rxrBrJrJrNrWszDDLCompiler.post_create_tablecCsPt|jtj�rHt|jjtj�r2|j�|jjt	j
�S|jj|jjdd�SndSdS)NT)r})r�Zserver_defaultrZ
DefaultClause�argr
�string_typesr�r�r	r�rv)rxrrJrJrNr{sz%DDLCompiler.get_column_default_stringcCs\d}|jdk	r.|j�|�}|dk	r.|d|7}|d|jj|jddd�7}||�|�7}|S)Nr�zCONSTRAINT %s z
CHECK (%s)FT)rr})r�rprxr�rvr��define_constraint_deferrability)rxrrryrJrJrN�visit_check_constraint s

z"DDLCompiler.visit_check_constraintcCs\d}|jdk	r.|j�|�}|dk	r.|d|7}|d|jj|jddd�7}||�|�7}|S)Nr�zCONSTRAINT %s z
CHECK (%s)FT)rr})r�rprxr�rvr�r~)rxrrryrJrJrN�visit_column_check_constraint,s

z)DDLCompiler.visit_column_check_constraintcs�t|�dkrdSd}|jdk	r>�j�|�}|dk	r>|d|7}|d7}|dd��fdd�|jrd|jn|jD��7}|��|�7}|S)	Nrr�zCONSTRAINT %s zPRIMARY KEY z(%s)z, c3s|]}�j�|j�VqdS)N)rprr�)rLr')rxrJrNr�Bsz;DDLCompiler.visit_primary_key_constraint.<locals>.<genexpr>)	r�r�rprxr.Z_implicit_generatedZcolumns_autoinc_firstr?r~)rxrrryrJ)rxrN�visit_primary_key_constraint8s

z(DDLCompiler.visit_primary_key_constraintc	s�|j�d}|jdk	r4|j�|�}|dk	r4|d|7}t|j�djj}|dd��fdd�|jD��|�||��d��fdd�|jD��f7}||�	|�7}||�
|�7}||�|�7}|S)	Nr�zCONSTRAINT %s rz"FOREIGN KEY(%s) REFERENCES %s (%s)z, c3s|]}��|jj�VqdS)N)r�parentr�)rLr)rprJrNr�Vsz;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>c3s|]}��|jj�VqdS)N)rrr�)rLr)rprJrNr�\s)rpr�rxr�rrrBr.�define_constraint_remote_table�define_constraint_match�define_constraint_cascadesr~)rxrrryZremote_tablerJ)rprN�visit_foreign_key_constraintLs$
z(DDLCompiler.visit_foreign_key_constraintcCs
|�|�S)z=Format the remote table clause of a CREATE CONSTRAINT clause.)r)rxrrBrprJrJrNr�dsz*DDLCompiler.define_constraint_remote_tablecsht|�dkrdSd}|jdk	r6�j�|�}|d|7}|dd��fdd�|D��7}|��|�7}|S)Nrr�zCONSTRAINT %s zUNIQUE (%s)z, c3s|]}�j�|j�VqdS)N)rprr�)rLr')rxrJrNr�qsz6DDLCompiler.visit_unique_constraint.<locals>.<genexpr>)r�r�rprxr.r~)rxrrryrJ)rxrN�visit_unique_constraintis
z#DDLCompiler.visit_unique_constraintcCsLd}|jdk	r&|d|j�|jt�7}|jdk	rH|d|j�|jt�7}|S)Nr�z
 ON DELETE %sz
 ON UPDATE %s)Zondeleterp�validate_sql_phrase�FK_ON_DELETEZonupdate�FK_ON_UPDATE)rxrrrJrJrNr�vs



z&DDLCompiler.define_constraint_cascadescCsLd}|jdk	r&|jr|d7}n|d7}|jdk	rH|d|j�|jt�7}|S)Nr�z DEFERRABLEz NOT DEFERRABLEz
 INITIALLY %s)r r+rpr��FK_INITIALLY)rxrrrJrJrNr~�s



z+DDLCompiler.define_constraint_deferrabilitycCs d}|jdk	r|d|j7}|S)Nr�z	 MATCH %s)�match)rxrrrJrJrNr��s
z#DDLCompiler.define_constraint_match)N)F)N)FT)F))r�r�r�r
r6r�rr�rGrIrLr[r_rVrcrdrerhrirgrkrnrorqrrrvrwrzr]rQrWr{rr�r�r�r�r�r�r~r�rJrJrJrNr@�
sH
1

(





r@c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUS)V�GenericTypeCompilercKsdS)NZFLOATrJ)rxr�r�rJrJrN�visit_FLOAT�szGenericTypeCompiler.visit_FLOATcKsdS)NZREALrJ)rxr�r�rJrJrN�
visit_REAL�szGenericTypeCompiler.visit_REALcKs<|jdkrdS|jdkr&dd|jiSd|j|jd�SdS)NZNUMERICzNUMERIC(%(precision)s)�	precisionz!NUMERIC(%(precision)s, %(scale)s))r��scale)r�r�)rxr�r�rJrJrN�
visit_NUMERIC�s

z!GenericTypeCompiler.visit_NUMERICcKs<|jdkrdS|jdkr&dd|jiSd|j|jd�SdS)NZDECIMALzDECIMAL(%(precision)s)r�z!DECIMAL(%(precision)s, %(scale)s))r�r�)r�r�)rxr�r�rJrJrN�
visit_DECIMAL�s

z!GenericTypeCompiler.visit_DECIMALcKsdS)NZINTEGERrJ)rxr�r�rJrJrN�
visit_INTEGER�sz!GenericTypeCompiler.visit_INTEGERcKsdS)NZSMALLINTrJ)rxr�r�rJrJrN�visit_SMALLINT�sz"GenericTypeCompiler.visit_SMALLINTcKsdS)NZBIGINTrJ)rxr�r�rJrJrN�visit_BIGINT�sz GenericTypeCompiler.visit_BIGINTcKsdS)N�	TIMESTAMPrJ)rxr�r�rJrJrN�visit_TIMESTAMP�sz#GenericTypeCompiler.visit_TIMESTAMPcKsdS)NZDATETIMErJ)rxr�r�rJrJrN�visit_DATETIME�sz"GenericTypeCompiler.visit_DATETIMEcKsdS)NZDATErJ)rxr�r�rJrJrN�
visit_DATE�szGenericTypeCompiler.visit_DATEcKsdS)NZTIMErJ)rxr�r�rJrJrN�
visit_TIME�szGenericTypeCompiler.visit_TIMEcKsdS)NZCLOBrJ)rxr�r�rJrJrN�
visit_CLOB�szGenericTypeCompiler.visit_CLOBcKsdS)NZNCLOBrJ)rxr�r�rJrJrN�visit_NCLOB�szGenericTypeCompiler.visit_NCLOBcCs0|}|jr|d|j7}|jr,|d|j7}|S)Nz(%d)z
 COLLATE "%s")�lengthr	)rxr�r�rrJrJrN�_render_string_type�sz'GenericTypeCompiler._render_string_typecKs|�|d�S)NZCHAR)r�)rxr�r�rJrJrN�
visit_CHAR�szGenericTypeCompiler.visit_CHARcKs|�|d�S)NZNCHAR)r�)rxr�r�rJrJrN�visit_NCHAR�szGenericTypeCompiler.visit_NCHARcKs|�|d�S)NZVARCHAR)r�)rxr�r�rJrJrN�
visit_VARCHAR�sz!GenericTypeCompiler.visit_VARCHARcKs|�|d�S)NZNVARCHAR)r�)rxr�r�rJrJrN�visit_NVARCHAR�sz"GenericTypeCompiler.visit_NVARCHARcKs|�|d�S)NZTEXT)r�)rxr�r�rJrJrN�
visit_TEXT�szGenericTypeCompiler.visit_TEXTcKsdS)NZBLOBrJ)rxr�r�rJrJrN�
visit_BLOB�szGenericTypeCompiler.visit_BLOBcKsd|jrd|jpdS)NZBINARYz(%d)r�)r�)rxr�r�rJrJrN�visit_BINARY�sz GenericTypeCompiler.visit_BINARYcKsd|jrd|jpdS)NZ	VARBINARYz(%d)r�)r�)rxr�r�rJrJrN�visit_VARBINARY�sz#GenericTypeCompiler.visit_VARBINARYcKsdS)NZBOOLEANrJ)rxr�r�rJrJrN�
visit_BOOLEAN�sz!GenericTypeCompiler.visit_BOOLEANcKs|j|f|�S)N)r�)rxr�r�rJrJrN�visit_large_binary�sz&GenericTypeCompiler.visit_large_binarycKs|j|f|�S)N)r�)rxr�r�rJrJrN�
visit_boolean�sz!GenericTypeCompiler.visit_booleancKs|j|f|�S)N)r�)rxr�r�rJrJrN�
visit_time�szGenericTypeCompiler.visit_timecKs|j|f|�S)N)r�)rxr�r�rJrJrN�visit_datetime�sz"GenericTypeCompiler.visit_datetimecKs|j|f|�S)N)r�)rxr�r�rJrJrN�
visit_date�szGenericTypeCompiler.visit_datecKs|j|f|�S)N)r�)rxr�r�rJrJrN�visit_big_integer
sz%GenericTypeCompiler.visit_big_integercKs|j|f|�S)N)r�)rxr�r�rJrJrN�visit_small_integer
sz'GenericTypeCompiler.visit_small_integercKs|j|f|�S)N)r�)rxr�r�rJrJrN�
visit_integer
sz!GenericTypeCompiler.visit_integercKs|j|f|�S)N)r�)rxr�r�rJrJrN�
visit_real

szGenericTypeCompiler.visit_realcKs|j|f|�S)N)r�)rxr�r�rJrJrN�visit_float

szGenericTypeCompiler.visit_floatcKs|j|f|�S)N)r�)rxr�r�rJrJrN�
visit_numeric
sz!GenericTypeCompiler.visit_numericcKs|j|f|�S)N)r�)rxr�r�rJrJrN�visit_string
sz GenericTypeCompiler.visit_stringcKs|j|f|�S)N)r�)rxr�r�rJrJrN�
visit_unicode
sz!GenericTypeCompiler.visit_unicodecKs|j|f|�S)N)r�)rxr�r�rJrJrN�
visit_text
szGenericTypeCompiler.visit_textcKs|j|f|�S)N)r�)rxr�r�rJrJrN�visit_unicode_text
sz&GenericTypeCompiler.visit_unicode_textcKs|j|f|�S)N)r�)rxr�r�rJrJrN�
visit_enum
szGenericTypeCompiler.visit_enumcKst�d|��dS)NzKCan't generate DDL for %r; did you forget to specify a type on this Column?)rr�)rxr�r�rJrJrNr+"
szGenericTypeCompiler.visit_nullcKs|j|�|j�f|�S)N)rvZtype_enginern)rxr�r�rJrJrN�visit_type_decorator)
sz(GenericTypeCompiler.visit_type_decoratorcKs|jf|�S)N)Zget_col_spec)rxr�r�rJrJrN�visit_user_defined,
sz&GenericTypeCompiler.visit_user_definedN)-r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r+r�r�rJrJrJrNr��sT	r�c@seZdZdd�Zdd�ZdS)�StrSQLTypeCompilercCs|�d�r|jSt|��dS)N�visit_)�
startswith�_visit_unknown�AttributeError)rxr�rJrJrN�__getattr__1
s
zStrSQLTypeCompiler.__getattr__cKsd|jjS)Nz%s)rOr�)rxr�r�rJrJrNr�7
sz!StrSQLTypeCompiler._visit_unknownN)r�r�r�r�r�rJrJrJrNr�0
sr�c@seZdZdZeZeZeZ	e
�d�Zd5dd�Z
dd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zd6dd�Zd7dd�Zdd�Zd8dd�Zd9dd�Zd:d d!�Zd;d"d#�Ze�d$�d%d&��Zd'd(�Zd<d)d*�Z d+d,�Z!d=d-d.�Z"d>d/d0�Z#ej$d1d2��Z%d3d4�Z&dS)?�IdentifierPreparerz@Handle quoting and case-folding of identifiers based on options.N�"TFcCsN||_||_|p|j|_||_|jd|_||_||_i|_|jjdk|_	dS)asConstruct a new ``IdentifierPreparer`` object.

        initial_quote
          Character that begins a delimited identifier.

        final_quote
          Character that ends a delimited identifier. Defaults to
          `initial_quote`.

        omit_schema
          Prevent prepending schema name. Useful for databases that do
          not support schemae.
        r)rTrSN)
rn�
initial_quote�final_quote�escape_quote�escape_to_quote�omit_schema�quote_case_sensitive_collations�_stringsr�r)rxrnr�r�r�r�r�rJrJrNrzG
szIdentifierPreparer.__init__cCs,|j�|j�}|j�|j�t�|�|_|S)N)rO�__new__�__dict__r�r�_schema_getterr)rxryZpreprJrJrNrqk
sz)IdentifierPreparer._with_schema_translatecCs&|�|j|j�}|jr"|�dd�}|S)z�Escape an identifier.

        Subclasses should override this to provide database-dependent
        escaping behavior.
        rz%%)rr�r�r)rxr�rJrJrN�_escape_identifierq
sz%IdentifierPreparer._escape_identifiercCs|�|j|j�S)z�Canonicalize an escaped identifier.

        Subclasses should override this to provide database-dependent
        unescaping behavior that reverses _escape_identifier.
        )rr�r�)rxr�rJrJrN�_unescape_identifier}
sz'IdentifierPreparer._unescape_identifiercCs*|dk	r&|�|�s&t�d||jf��|S)z�keyword sequence filter.

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

        .. versionadded:: 1.3

        Nz/Unexpected SQL phrase: %r (matching against %r))r�rr��pattern)rxr�ZregrJrJrNr��
s
z&IdentifierPreparer.validate_sql_phrasecCs|j|�|�|jS)z~Quote an identifier.

        Subclasses should override this to provide database-dependent
        quoting behavior.
        )r�r�r�)rxr�rJrJrN�quote_identifier�
s
z#IdentifierPreparer.quote_identifiercCs<|��}||jkp:|d|jkp:|j�t�|��p:||kS)z5Return True if the given identifier requires quoting.r)rM�reserved_words�illegal_initial_characters�legal_charactersr�r
�	text_type)rxr�Zlc_valuerJrJrNr��
s

z#IdentifierPreparer._requires_quotescCs|j�t�|��S)zjReturn True if the given identifier requires quoting, but
        not taking case convention into account.)r�r�r
r�)rxr�rJrJrNrK�
sz1IdentifierPreparer._requires_quotes_illegal_charscCs|dk	rt�d�|�|�S)aConditionally quote a schema name.


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

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

        :param schema: string schema name
        :param force: unused

            .. deprecated:: 0.9

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

        Nz�The IdentifierPreparer.quote_schema.force parameter is deprecated and will be removed in a future release.  This flag has no effect on the behavior of the IdentifierPreparer.quote method; please refer to quoted_name().)r
�warn_deprecatedr)rxr�forcerJrJrNr�
szIdentifierPreparer.quote_schemacCs�|dk	rt�d�t|dd�}|dkrl||jkr:|j|S|�|�rV|�|�|j|<n
||j|<|j|Sn|rz|�|�S|SdS)aConditionally quote an identfier.

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

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

        :param ident: string identifier
        :param force: unused

            .. deprecated:: 0.9

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

        Nz�The IdentifierPreparer.quote.force parameter is deprecated and will be removed in a future release.  This flag has no effect on the behavior of the IdentifierPreparer.quote method; please refer to quoted_name().r)r
r�r�r�r�r�)rxr�r�rJrJrNr�
s




zIdentifierPreparer.quotecCs|jr|�|�S|SdS)N)r�r)rxZcollation_namerJrJrNrs
z#IdentifierPreparer.format_collationcCs>|�|j�}|�|�}|js:|r:|dk	r:|�|�d|}|S)Nr�)rr�rr�r)rxrTrr�rrJrJrNr=s
z"IdentifierPreparer.format_sequencecCs|�|p|j�S)N)rr�)rxr�r�rJrJrNr�szIdentifierPreparer.format_labelcCs|�|p|j�S)N)rr�)rxr�r�rJrJrNr�!szIdentifierPreparer.format_aliascCs"|p|j}|�|�r|�|�}|S)N)r�r�r�)rxZ	savepointr�r�rJrJrNr-$s


z#IdentifierPreparer.format_savepointzsqlalchemy.sql.namingcCs�t|jtj�r>|�||j�}|dkrDt|jtj�r6dS|j}n|j}t|tj�r�|jdkrl|j	j
ph|j	j}n|j	j}t|�|kr�|d|d�dt
�|�dd�}n|j	�|�|�|�S)Nrr�rf���)r�r�rZ_defer_nameZ_constraint_name_for_tablerBZ_defer_none_namer�r�rnZmax_index_name_lengthr�r�r
Zmd5_hexZvalidate_identifierr)rxZnamingrr�Zmax_rJrJrNrx-s"


(z$IdentifierPreparer.format_constraintcCs
|�|�S)N)rx)rxrrJrJrNrjKszIdentifierPreparer.format_indexcCsF|dkr|j}|�|�}|�|�}|jsB|rB|rB|�|�d|}|S)z'Prepare a quoted table and schema name.Nr�)r�rrr�r)rxrBrr�r�rrJrJrNrNs

zIdentifierPreparer.format_tablecCs
|�|�S)zPrepare a quoted schema name.)r)rxr�rJrJrNrH[sz IdentifierPreparer.format_schemacCsp|dkr|j}t|dd�sJ|r>|j|j||d�d|�|�S|�|�Sn"|rh|j|j||d�d|S|SdS)zPrepare a quoted column name.Nr�F)rr�r�)r�r�rrBr)rxrrpr�Z
table_namerrJrJrNr�`s
 z IdentifierPreparer.format_columncCsD|�|�}|js0|r0|r0|�|�|j|dd�fS|j|dd�fSdS)z(Format table name and schema as a tuple.F)rN)rr�rr)rxrBrrrJrJrNrD�s

z#IdentifierPreparer.format_table_seqcCs@dd�|j|j|�|j�fD�\}}}t�d|||d��}|S)NcSsg|]}t�|��qSrJ)r�r�)rLr2rJrJrNrA�sz5IdentifierPreparer._r_identifiers.<locals>.<listcomp>zM(?:(?:%(initial)s((?:%(escaped)s|[^%(final)s])+)%(final)s|([^\.]+))(?=\.|$))+)�initial�final�escaped)r�r�r�r�r{)rxr�r�Z
escaped_final�rrJrJrN�_r_identifiers�sz!IdentifierPreparer._r_identifierscs(�j}�fdd�dd�|�|�D�D�S)z:Unpack 'schema.table.column'-like strings into components.csg|]}��|��qSrJ)r�)rLrX)rxrJrNrA�sz;IdentifierPreparer.unformat_identifiers.<locals>.<listcomp>cSsg|]\}}|p|�qSrJrJ)rL�a�brJrJrNrA�s)r��findall)rxZidentifiersr�rJ)rxrN�unformat_identifiers�s
z'IdentifierPreparer.unformat_identifiers)r�Nr�TF)N)N)T)N)N)N)TN)FNNF)T)'r�r�r�r��RESERVED_WORDSr��LEGAL_CHARACTERSr��ILLEGAL_INITIAL_CHARACTERSr�rr�rrzrqr�r�r�r�r�rKrrrr=r�r�r-r
r7rxrjrrHr�rDr6r�r�rJrJrJrNr�;
sF

	


%
2



	


 
r�)jr�r4r�r�r�rrrrrrr	r
rr
r@r�r{�Ir�ZLEGAL_CHARACTERS_PLUS_SPACE�rangerEr�r�r�r��UNICODErrr��and_�or_�add�mulr�Zdiv�mod�truediv�neg�lt�le�ne�gt�ge�eqZis_distinct_fromZisnot_distinct_fromZ	concat_oprtZnotmatch_opZin_opZnotin_opZcomma_opr�r��is_Zisnotr�existsZdistinct_op�invZany_opZall_opZdesc_opZasc_opZ
nullsfirst_opZnullslast_opr�rXrrrrr1r2rYrZr?rGZcubeZrollupZ
grouping_setsrNr2r�rjZ	UNION_ALLrkZ
EXCEPT_ALLrlZ
INTERSECT_ALLr3�objectrm�with_metaclassZEnsureKWArgTyper�Z	Visitabler�r�r9r@r�r�r�rJrJrJrN�<module>s�



=7

Youez - 2016 - github.com/yon3zu
LinuXploit