%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/sql/__pycache__/
Upload File :
Create Path :
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�anyZarray�asZascZ
asymmetricZ
authorizationZbetween�binaryZbothZcase�castZcheck�collate�column�
constraint�createZcross�current_dateZcurrent_role�current_time�current_timestamp�current_user�default�
deferrableZdescZdistinctZdo�else�end�except�false�forZforeignZfreeze�from�fullZgrant�groupZhavingZilike�in�	initially�innerZ	intersectZinto�isZisnull�joinZleading�leftZlike�limit�	localtime�localtimestampZnatural�new�notZnotnullZnullZoff�offset�oldZonZonly�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�xrBrB�J/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/sql/compiler.py�	<setcomp>�srG�
�$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�numericZnamedz 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)rRrSrTrUrVrWrXrYrZr[r\r]r^r_r`�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)�selfrerirf�schema_translate_mapZcompile_kwargsrBrBrF�__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.
        NrB)rorBrBrF�compileAs
zCompiled.compilecCs$|jr|�|||�St�|j��dS)N)rj�_execute_compiledrZObjectNotExecutableErrorri)roZ
connection�multiparams�paramsrBrBrF�_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)rorBrBrF�sql_compilerSszCompiled.sql_compilercKs|j|f|�S)N)�_compiler_dispatch)ro�obj�kwargsrBrBrFrm]szCompiled.processcCs
|jpdS)z3Return the string text of the generated SQL or DDL.�)rn)rorBrBrF�__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)rw)rorurBrBrF�construct_paramseszCompiled.construct_paramscCs|��S)z0Return the bind params for this compiled object.)r~)rorBrBrFruoszCompiled.paramscOs*|j}|dkrtjddd��|�|||�S)zExecute this compiled object.Nz>This Compiled object is not bound to any Engine or Connection.Z2afi)�code)rfrZUnboundExecutionErrorrs)rortru�erBrBrF�executetszCompiled.executecOs|j||���S)zJExecute this compiled object and return the result's
        scalar value.)r��scalar)rortrurBrBrFr��szCompiled.scalar)N)�__name__�
__module__�__qualname__�__doc__Z_cached_metadatar
�
immutabledictrlrqZ
deprecatedrrrv�propertyrxrmr}r~rur�r�rBrBrBrFrd�s"
)



rdc@s$eZdZdZdZdd�Zdd�ZdS)�TypeCompilerz2Produces DDL specification for TypeEngine objects.z	visit_\w+cCs
||_dS)N)re)rorerBrBrFrq�szTypeCompiler.__init__cKs|j|f|�S)N)ry)ro�type_�kwrBrBrFrm�szTypeCompiler.processN)r�r�r�r�Zensure_kwargrqrmrBrBrBrFr��sr�c@sBeZdZdZdZdZddd�Zedd��Zed	d
��Z	dd�Z
d
S)�
_CompileLabelz;lightweight label object which acts as an expression.Label.�label)�element�namerBcCs||_||_|f||_dS)N)r�r��
_alt_names)ro�colr��	alt_namesrBrBrFrq�sz_CompileLabel.__init__cCs|jjS)N)r��	proxy_set)rorBrBrFr��sz_CompileLabel.proxy_setcCs|jjS)N)r��type)rorBrBrFr��sz_CompileLabel.typecKs|S)NrB)ror�rBrBrF�
self_group�sz_CompileLabel.self_groupN)rB)r�r�r�r��__visit_name__�	__slots__rqr�r�r�r�rBrBrBrFr��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.

    FNTrBcKs�||_|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.

        �inlineFrMN)�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_namesrdrq�isinsert�isupdate�isdelete�
_returning�	returning�_apply_numbered_params)rorerir�r�r{rBrBrFrq�s*
zSQLCompiler.__init__cCst|j|j�S)N)�list�insert_prefetch�update_prefetch)rorBrBrF�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)rorBrBrF�_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)roZresult_columnsZordered_columns�entryrBrBrF�_nested_resultNs



zSQLCompiler._nested_resultcs(t�d��t�d�fdd�|j�|_dS)Nrz
\[_POSITION\]cstt����S)N)rCr
�next)�m)�poscountrBrF�<lambda>i�z4SQLCompiler._apply_numbered_params.<locals>.<lambda>)�	itertools�count�re�subrn)rorB)r�rFr�fs
z"SQLCompiler._apply_numbered_paramscs"tdd��fdd��jD�D��S)Ncss"|]\}}|dk	r||fVqdS)NrB)rD�key�valuerBrBrF�	<genexpr>osz/SQLCompiler._bind_processors.<locals>.<genexpr>c3s&|]}�j||j��j�fVqdS)N)r�r�Z_cached_bind_processorre)rD�	bindparam)rorBrFr�qs)�dictr�)rorB)rorF�_bind_processorsls
zSQLCompiler._bind_processorscCst|j�dkS)Nr)�lenr�)rorBrBrF�is_subqueryzszSQLCompiler.is_subquerycCs|S)NrB)rorBrBrFrx}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)rz)A value is required for bind parameter %rN)r�r�ZrequiredrZInvalidRequestError�callable�effective_valuer�)roruZ
_group_number�_checkZpdr�r�rBrBrFr~�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~)rorBrBrFru�szSQLCompiler.paramszsqlalchemy.engine.resultcCs|j�|j�S)z(utility method used for unit tests only.)ZResultMetaData�_create_result_mapr�)ro�resultrBrBrFr��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|rB)rorBrBrF�default_from�szSQLCompiler.default_fromcKsd|jj|f|�dS)N�(�))r�ry)roZgrouping�asfromr{rBrBrF�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�reZsupports_simple_order_by_label�_label_resolve_dictr�Z_order_by_label_elementr�Zshares_lineagerm)
ror�r�r{r�	with_cols�
only_froms�	only_colsZresolve_dictZ
order_by_elemrBrBrF�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�rmZ_text_clauser�r��KeyErrorrZ_no_text_coercionr�CompileError)	ror�r�r{rr�r�r�r�rBrBrF�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�ry�	OPERATORSr�as_rg�format_label)
ror��add_to_result_mapr�r�r�r�Zrender_label_with_asZrender_label_onlyZ	labelnamerBrBrF�visit_labels$
2zSQLCompiler.visit_labelcCst�d��dS)Nz:Cannot compile Column object until its 'name' is assigned.)rr�)rorrBrBrF�_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_columnrg�quoter:Znamed_with_column�schema_for_object�quote_schema)rorr��
include_tabler{r�Z	orig_namer�r:�effective_schemaZ
schema_prefixZ	tablenamerBrBrF�visit_columnBs.

zSQLCompiler.visit_columncKs|j�|j�S)N)rg�format_collation�	collation)ror�r�rBrBrF�visit_collationjszSQLCompiler.visit_collationcKs|jS)N)r�)roZ
fromclauser{rBrBrF�visit_fromclausemszSQLCompiler.visit_fromclausecKs|jS)N)r�)ro�indexr{rBrBrF�visit_indexpszSQLCompiler.visit_indexcKs||d<|jjj|jf|�S)N�type_expression)re�
type_compilerrmr�)ro�
typeclauser�rBrBrF�visit_typeclausesszSQLCompiler.visit_typeclausecCs|jjr|�dd�}|S)N�%z%%)rg�_double_percents�replace)ro�textrBrBrF�post_process_textwszSQLCompiler.post_process_textcCs|jjr|�dd�}|S)Nrz%%)rgrr)rorrBrBrFr�|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_bindparamsrm�bindparam_string)r�r�)r�ro�
textclauserBrF�do_bindparam�s

z2SQLCompiler.visit_textclause.<locals>.do_bindparamTcSs
|�d�S)Nr)r%)r�rBrBrFr��r�z.SQLCompiler.visit_textclause.<locals>.<lambda>)r��isplaintext�BIND_PARAMS_ESCr��BIND_PARAMSr	r)rorr�rrB)r�rorrF�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_argsrm�_add_to_result_mapr�)roZtaf�compound_indexr��parensr��toplevelr��populate_result_map�crrBrBrF�visit_text_as_from�s"zSQLCompiler.visit_text_as_fromcKsdS)NZNULLrB)ro�exprr�rBrBrF�
visit_null�szSQLCompiler.visit_nullcKs|jjrdSdSdS)Nr<�1)re�supports_native_boolean)rorr�rBrBrF�
visit_true�szSQLCompiler.visit_truecKs|jjrdSdSdS)Nr!�0)rer)rorr�rBrBrF�visit_false�szSQLCompiler.visit_falsecs^|j}|dkrd}n
t|j}|�dd���fdd�|jD�D��}|jrZ�jjrZd|}|S)N� css|]}|r|VqdS)NrB)rD�srBrBrFr��sz/SQLCompiler.visit_clauselist.<locals>.<genexpr>c3s|]}|j�f��VqdS)N)ry)rDr)r�rorBrFr��szVALUES )�operatorr�r*�clausesZ
_tuple_valuesreZtuple_in_values)roZ
clauselistr��seprrB)r�rorF�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 r#zWHEN z THEN zELSE ZEND)r�ryZwhensZelse_)ro�clauser{rEZcondr�rBrBrF�
visit_case�s
.
zSQLCompiler.visit_casecKs|jj|f|�S)N)Ztyped_expressionry)roZtype_coercer�rBrBrF�visit_type_coerce�szSQLCompiler.visit_type_coercecKs$d|jj|f|�|jj|f|�fS)NzCAST(%s AS %s))r)ryr)rorr{rBrBrF�
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_CURRENTrm�literal�abs)ro�range_r�rBrBrF�_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)r#cs6g|].\}}|dk	rt|�rd||j�f��f�qS)Nz%s BY %s)r�ry)rDZwordr))r{rorBrF�
<listcomp>sz*SQLCompiler.visit_over.<locals>.<listcomp>Z	PARTITIONZORDER)r/r0Zrowsr�ryr*Zpartition_by�order_by)roZoverr{r/rB)r{rorF�
visit_overszSQLCompiler.visit_overcKs$d|jj|f|�|jj|f|�fS)Nz%s WITHIN GROUP (ORDER BY %s))r�ryr2)roZwithingroupr{rBrBrF�visit_withingroup$szSQLCompiler.visit_withingroupcKs$d|jj|f|�|jj|f|�fS)Nz%s FILTER (WHERE %s))�funcryZ	criterion)roZ
funcfilterr{rBrBrF�visit_funcfilter*szSQLCompiler.visit_funcfiltercKs*|j�|j|j�}d||jj|f|�fS)NzEXTRACT(%s FROM %s))�extract_mapr�fieldrry)ro�extractr{r8rBrBrF�
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)NrBz
visit_%s_funcz%(expr)sr�cs(g|] }�j�|�r �j�|�n|�qSrB)rg�_requires_quotes_illegal_charsr�)rD�tok)rorBrFr1Msz.SQLCompiler.visit_function.<locals>.<listcomp>r)r�r�r��lower�	FUNCTIONSr�	__class__Z	_has_argsrgr;r�r*Zpackagenames�function_argspec)ror5r�r{�dispr�rB)rorF�visit_function7s$

zSQLCompiler.visit_functioncKs|�|j�S)N)�visit_sequence�sequence)roZ
next_valuer�rBrBrF�visit_next_value_funcWsz!SQLCompiler.visit_next_value_funccKstd|jj��dS)Nz2Dialect '%s' does not support sequence increments.)rwrer�)rorDr�rBrBrFrCZszSQLCompiler.visit_sequencecKs|jj|f|�S)N)Zclause_exprry)ror5r{rBrBrFr@`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)rFrGrrr#c3s,|]$\}}|j�f�d|d����VqdS)F)r�rrN)ry)rD�ir)r�r{rorBrFr�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�)roZcsr�rrr{rr�Zneed_result_maprKrrB)r�r{rorF�visit_compound_selectcs4
 
z!SQLCompiler.visit_compound_selectcCs(d|j||rd|ndf}t||d�S)Nz
visit_%s_%s%s�_r|)r�r�)ro�	operator_Z
qualifier1Z
qualifier2ZattrnamerBrBrF�_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�unaryr%�modifierz,Unary expression has no operator or modifier)r%rYrr�rW� _generate_generic_unary_operatorr�� _generate_generic_unary_modifier)rorXr�rArBrBrF�visit_unary�s&zSQLCompiler.visit_unarycKs6|js|jjr|j|jf|�Sd|j|jf|�SdS)Nz%s = 1)�_is_implicitly_booleanrerrmr�)ror�r%r�rBrBrF�visit_istrue_unary_operator�sz'SQLCompiler.visit_istrue_unary_operatorcKs:|js|jjr"d|j|jf|�Sd|j|jf|�SdS)NzNOT %sz%s = 0)r]rerrmr�)ror�r%r�rBrBrF�visit_isfalse_unary_operator�sz(SQLCompiler.visit_isfalse_unary_operatorcKsd|j|tjd�S)NzNOT %s)�override_operator)�visit_binaryr�match_op)rorr%r�rBrBrF�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)rorBrBrF�_emit_empty_in_warning�sz"SQLCompiler._emit_empty_in_warningcKs2|jjrdS|jjr|��|�|j|jk�SdS)Nz1 != 1)re�_use_static_in�_warn_on_empty_inrermr+)rorr%r�rBrBrF�visit_empty_in_op_binary�s
z$SQLCompiler.visit_empty_in_op_binarycKs2|jjrdS|jjr|��|�|j|jk�SdS)Nz1 = 1)rerfrgrermr+)rorr%r�rBrBrF�visit_empty_notin_op_binary�s
z'SQLCompiler.visit_empty_notin_op_binarycCstd|jj��dS)Nz3Dialect '%s' does not support empty set expression.)rwrer�)roZ
element_typesrBrBrF�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
BindParameterr5r%rWr�r�rZUnsupportedCompilationError�_generate_generic_binary)rorr`�eager_groupingr�rVrA�opstringrBrBrFra�s
zSQLCompiler.visit_binarycKs|j|jf|�S)N)rmZsql_function)ror�r%r�rBrBrF�&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 % )rgrrmr+r5)rorr%r�rBrBrF�visit_mod_binarys$zSQLCompiler.visit_mod_binarycKs$|j|d<|j|d|jdf|�S)Nrnr#)rnrmro)ror�r%r�rBrBrF�visit_custom_op_binarys
z"SQLCompiler.visit_custom_op_binarycKs|j||jdf|�S)Nr#)rZro)ror�r%r�rBrBrF�visit_custom_op_unary_operator"sz*SQLCompiler.visit_custom_op_unary_operatorcKs|j|d|jf|�S)Nr#)r[ro)ror�r%r�rBrBrF�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_binaryFTrnz(%s))rr+ryr5)rorrornr�rurrBrBrFrm,s z$SQLCompiler._generate_generic_binarycKs||jj|f|�S)N)r�ry)rorXror�rBrBrFrZAsz,SQLCompiler._generate_generic_unary_operatorcKs|jj|f|�|S)N)r�ry)rorXror�rBrBrFr[Dsz,SQLCompiler._generate_generic_unary_modifiercCstjdtjd�S)Nz'%')r�)rZliteral_columnr	�
STRINGTYPE)rorBrBrF�_like_percent_literalGsz!SQLCompiler._like_percent_literalcKs2|��}|j}|�|j��|�|_|j||f|�S)N)�_clonerw�__add__r5�visit_like_op_binary)rorr%r��percentrBrBrF�visit_contains_op_binaryKsz$SQLCompiler.visit_contains_op_binarycKs2|��}|j}|�|j��|�|_|j||f|�S)N)rxrwryr5�visit_notlike_op_binary)rorr%r�r{rBrBrF�visit_notcontains_op_binaryQsz'SQLCompiler.visit_notcontains_op_binarycKs,|��}|j}|�|j�|_|j||f|�S)N)rxrw�__radd__r5rz)rorr%r�r{rBrBrF�visit_startswith_op_binaryWsz&SQLCompiler.visit_startswith_op_binarycKs,|��}|j}|�|j�|_|j||f|�S)N)rxrwrr5r})rorr%r�r{rBrBrF�visit_notstartswith_op_binary]sz)SQLCompiler.visit_notstartswith_op_binarycKs,|��}|j}|�|j�|_|j||f|�S)N)rxrwryr5rz)rorr%r�r{rBrBrF�visit_endswith_op_binarycsz$SQLCompiler.visit_endswith_op_binarycKs,|��}|j}|�|j�|_|j||f|�S)N)rxrwryr5r})rorr%r�r{rBrBrF�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|)�	modifiersrr+ryr5�render_literal_valuer	rv)rorr%r�r�rBrBrFrzos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�rr+ryr5r�r	rv)rorr%r�r�rBrBrFr}|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�rr+ryr5r�r	rv)rorr%r�r�rBrBrF�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�rr+ryr5r�r	rv)rorr%r�r�rBrBrF�visit_notilike_op_binary�sz$SQLCompiler.visit_notilike_op_binarycKs&|j�dd�}|j||rdndf|�S)Nr9Fz BETWEEN SYMMETRIC z	 BETWEEN )r�rrm)rorr%r�r9rBrBrF�visit_between_op_binary�sz#SQLCompiler.visit_between_op_binarycKs&|j�dd�}|j||rdndf|�S)Nr9Fz NOT BETWEEN SYMMETRIC z
 NOT BETWEEN )r�rrm)rorr%r�r9rBrBrF�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�rkz@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_implreZ_has_bind_expression�bind_expressionrmrlr�r�rr�r��render_literal_bindparam�_truncate_bindparamr�r>r��intersectionZ_is_crudr
r�)
ror�r�rkr�r{�implr�r�ZexistingrBrBrF�visit_bindparam�sB	




zSQLCompiler.visit_bindparamcKs|j}|�||j�S)N)r�r�r�)ror�r�r�rBrBrFr��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_processorrerw)ror�r�Z	processorrBrBrFr��s
z SQLCompiler.render_literal_valuecCs@||jkr|j|S|j}t|tj�r2|�d|�}||j|<|S)Nr�)r�r�r�rr�r�)ror�Z	bind_namerBrBrFr��s


zSQLCompiler._truncate_bindparamcCs�||f|jkr|j||fS|�|j�}t|�|jdkr�|j�|d�}|dt|jdd��dt|�dd�}|d|j|<n|}||j||f<|S)N�rrrUr)r�Z	apply_mapr�r�r�r�max�hex)roZident_classr�ZanonnameZcounterZ	truncnamerBrBrFr�s,z!SQLCompiler._truncated_identifiercCs
||jS)N)r�)ror�rBrBrF�
_anonymizeszSQLCompiler._anonymizecCs<|�dd�\}}|j�|d�}|d|j|<|dt|�S)Nr#rrU)�splitr�rrC)ror��identZderivedZanonymous_counterrBrBrFr�"szSQLCompiler._process_anoncKsJ|jr&|dk	r|�|�n|j�|�|r8d|_d|S|jd|iSdS)NTz([EXPANDING_%s])r�)r�rIr��contains_expanding_parametersr�)ror��positional_namesr�r�rBrBrFr
(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)NrB)rDrrBrBrFr1�sz)SQLCompiler.visit_cte.<locals>.<listcomp>z(%s)z, c3s|]}�j�|�VqdS)N)rg�
format_column)rDr�)rorBrFr��sz(SQLCompiler.visit_cte.<locals>.<genexpr>r�z AS 
r�r#)'r�r�r�rr�r�r�Z	_restatesr�rr�Z
_cte_aliasr�rkrlr=�	visit_cte�	recursiver�rg�format_alias�originalr�Select�CompoundSelectrM�AssertionErrorr
Zunique_list�
inner_columnsr*r�r�ry�	_suffixes�_generate_prefixes�_requires_quotesr��get_render_as_alias_suffix)ro�cter��ashint�	fromhintsr�r{Zcte_nameZ
is_new_cteZembedded_in_current_named_cteZexisting_cteZ
pre_alias_cteZcte_pre_alias_namerZ
col_sourceZ
recur_colsrB)rorFr�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�rgr�r�ryr��format_from_hint_text)	ror�r�r��iscrudr�r{Z
alias_name�retrBrBrF�visit_alias�s 	zSQLCompiler.visit_aliascKsd|d<d|j|f|�S)NT�lateralz
LATERAL %s)r�)ror�r�rBrBrF�
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_methodryZseed)roZtablesampler�r�rrBrBrF�visit_tablesample�s
zSQLCompiler.visit_tablesamplecCsd|S)Nz AS rB)roZalias_name_textrBrBrFr��sz&SQLCompiler.get_render_as_alias_suffixcCs|j�||||f�dS)N)r�rI)ro�keynamer��objectsr�rBrBrFr�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�)rrorBrFr��sz;SQLCompiler._label_select_column.<locals>.add_to_result_mapN)r�r�)r�r�)r�r�reZ_has_column_expressionZcolumn_expressionrr�rZLabelr�r�r��
_key_labelZColumnClauser�r:rr�Z
_as_truncatedr�Z
TextClauseZUnaryExpressionZwraps_column_expression�hasattrrZFunctionZ
anon_label�updatery)ror6rrr��column_clause_argsr�r�r�Zcol_exprr�Zresult_exprrB)rrorF�_label_select_column�sV





z SQLCompiler._label_select_columncCs |�||�}|r|d|7}|S)Nr#)�get_from_hint_text)ro�sqltextr:Zhintr��hinttextrBrBrFr�;sz!SQLCompiler.format_from_hint_textcCsdS)NrB)roZbyfromsrBrBrF�get_select_hint_textAsz SQLCompiler.get_select_hint_textcCsdS)NrB)ror:rrBrBrFr�DszSQLCompiler.get_from_hint_textcCsdS)NrB)ror:rrBrBrF�get_crud_hint_textGszSQLCompiler.get_crud_hint_textcCs
d�|�S)Nr#)r*)roZ
hint_textsrBrBrF�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_clueZcloneZ
inside_select)rxZ
is_selectableZ_is_joinr�r5rZFromGroupingZ_reset_exportedr+r�r�r�rr�r�r�Z_labelr��zipr��itemsr��onclauseZ_is_from_containerZ_copy_internalsZ
_is_selectrrI)
r�r�Znewelemr5Zselectable_rZtranslate_dict�k�vZbarrier_select)�cloned�column_translate�visitrBrFr�WsR

z=SQLCompiler._transform_select_for_nested_joins.<locals>.visitrB)ror6rB)r�r�r�rF�"_transform_select_for_nested_joinsMsQz.SQLCompiler._transform_select_for_nested_joinscsFtdd�|jD���t�fdd�|jD����fdd�|jD�|_dS)Ncss|]}|j|fVqdS)N)r�)rDrrBrBrFr��szESQLCompiler._transform_result_map_for_nested_joins.<locals>.<genexpr>c3s|]}�|j|fVqdS)N)r�)rDr)�	inner_colrBrFr��scs2g|]*\}}}}||t�fdd�|D��|f�qS)csg|]}��||��qSrB)r)rDr�)�drBrFr1�szQSQLCompiler._transform_result_map_for_nested_joins.<locals>.<listcomp>.<listcomp>)�tuple)rDr�r�Zobjs�typ)r�rBrFr1�szFSQLCompiler._transform_result_map_for_nested_joins.<locals>.<listcomp>)r�r�r�)ror6�transformed_selectrB)r�r�rF�&_transform_result_map_for_nested_joins�s

z2SQLCompiler._transform_result_map_for_nested_joinsrFrGc	Cs\|j}|r|jn|jd}|d}|d}|rJ|sJ|j|�|�dd�}n|j||d�}|S)Nr�rFrGrB)�explicit_correlate_froms�implicit_correlate_froms)r�r�_get_display_froms�
difference)	ror6r�r�rr�rFrG�fromsrBrBrF�_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�rr�r�nested_join_translationr�rrFr�r�)r�r�zSELECT r#cSsg|]}|dk	r|�qS)NrB)rDrrBrBrFr1&sz,SQLCompiler.visit_select.<locals>.<listcomp>c
s&g|]\}}�j�|���|d��qS))r�)r�)rDr�r)r�r�rr6rorBrFr1(scSsg|]\}}|�qSrBrB)rDr�r�rBrBrFr1;scSsg|]\}}|�qSrBrB)rDr�r�rBrBrFr1=scs2g|]*\}}}}||t�fdd�|D��|f�qS)c3s|]}��||�VqdS)N)r)rD�o)�	translaterBrFr�Dsz6SQLCompiler.visit_select.<locals>.<listcomp>.<genexpr>)r�)rDr�r�rzr�)r�rBrFr1Dscs$g|]\}}|d�jjfkr|�qS)�*)rer�)rD�dialect_nameZht)rorBrFr1Nsr�r�)r�r�reZsupports_right_nested_joinsr��visit_selectrrr��_setup_select_stack�copyr��_hints�_setup_select_hints�	_prefixesr��get_select_precolumnsZ_columns_plus_namesr�r�r��_compose_select_bodyZ_statement_hintsr�r�rSr�r�)ror6r�rr�rr�Zselect_wraps_forr�r{Zneeds_nested_translationr�rrr�r��	hint_text�byfromr�Zper_dialectrB)r�r�rr6ror�rFr��s�



zSQLCompiler.visit_selectcs.t�fdd�|j��D��}��|�}||fS)Nc	s>g|]6\\}}}|d�jjfkr||d|j�dd�if�qS)r�r�T)r�)rer�ry)rD�from_rer�)rorBrFr1gs
z3SQLCompiler._setup_select_hints.<locals>.<listcomp>)r�r�r�r�)ror6r�r�rB)rorFr�ds


zSQLCompiler._setup_select_hintscCsp|d}|d}|r.|s.|j|�|�dd�}n|j||d�}ttj|��}|�|�}	||	|d�}
|j�|
�|S)NrFrGrB)r�r�)rGrFr)r�r�r8r�
_from_objectsr=r�rI)ror6r�r�r�rFrGr�Znew_correlate_fromsZall_correlate_fromsZ	new_entryrBrBrFr�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�)ry)rD�f)r�r{rorBrFr1�sz4SQLCompiler._compose_select_body.<locals>.<listcomp>cs"g|]}|j�fddi����qS)r�T)ry)rDr�)r{rorBrFr1�sz 
WHERE z	 
HAVING )r*r�r��_whereclausery�_group_by_clauser&rNZ_having�_order_by_clauserOrPrQrRZ_for_update_arg�for_update_clause)rorr6r�r�r�r{�trB)r�r{rorFr��s:

z SQLCompiler._compose_select_bodycs*d���fdd�|D��}|r&|d7}|S)Nr#c3s4|],\}}|dks|�jjkr|j�f��VqdS)N)rer�ry)rD�prefixr�)r�rorBrFr��sz1SQLCompiler._generate_prefixes.<locals>.<genexpr>)r*)ro�stmt�prefixesr�r)rB)r�rorFr��s
zSQLCompiler._generate_prefixescsb�jr(t�fdd��jD�g��j�_���j�d}|d�dd��j��D��7}|d7}|S)Ncsg|]}�j|�qSrB)r�)rDr�)rorBrFr1�sz2SQLCompiler._render_cte_clause.<locals>.<listcomp>r#z, 
cSsg|]}|�qSrBrB)rDZtxtrBrBrFr1�sz
 )r��sumr�r��get_cte_preambler�r*�values)roZcte_textrB)rorFrS�s
zSQLCompiler._render_cte_clausecCs|rdSdSdS)NzWITH RECURSIVEZWITHrB)ror�rBrBrFr��szSQLCompiler.get_cte_preamblecKs|jr
dpdS)zcCalled when building a ``SELECT`` statement, position is just
        before column list.

        z	DISTINCT r|)Z	_distinct)ror6r�rBrBrFr��sz!SQLCompiler.get_select_precolumnscKs$|jj|f|�}|rd|SdSdS)z5allow dialects to customize how GROUP BY is rendered.z
 GROUP BY r|N)r�ry)ror6r�Zgroup_byrBrBrFrN�szSQLCompiler.group_by_clausecKs$|jj|f|�}|rd|SdSdS)z5allow dialects to customize how ORDER BY is rendered.z
 ORDER BY r|N)r�ry)ror6r�r2rBrBrFrO�szSQLCompiler.order_by_clausecKsdS)Nz FOR UPDATErB)ror6r�rBrBrFr��szSQLCompiler.for_update_clausecCst�d��dS)Nz@RETURNING is not supported by this dialect's statement compiler.)rr�)ror��returning_colsrBrBrF�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 )rPrmrQ)ror6r�rrBrBrFrR	s


zSQLCompiler.limit_clausec
Ksv|s|rn|j�|�}|r<|r<|j�|�d|j�|j�}	n|j�|j�}	|rj||krj|�|	||||�}	|	SdSdS)Nr�r|)rgr�r�r�r�r�)
ror:r�r�r�r��
use_schemar{r�r�rBrBrF�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+ryr5r�)ror*r�r{Z	join_typerBrBrF�
visit_join*	szSQLCompiler.visit_joincsFt�fdd�|j��D��}|j|kr>��||j||jd�}||fS)Ncs,g|]$\\}}}|d�jjfkr||f�qS)r�)rer�)rDr:rer�)rorBrFr1<	s
z1SQLCompiler._setup_crud_hints.<locals>.<listcomp>T)r�r�r�r:r�)ror��
table_text�
dialect_hintsrB)rorF�_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)rFrGrzWThe '%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�)rDr)rgrBrFr1�	sz,SQLCompiler.visit_insert.<locals>.<listcomp>r#z %s%sz %sz DEFAULT VALUESz
 VALUES %scss&|]}dd�dd�|D��VqdS)z(%s)z, css|]}|dVqdS)rNrB)rDrrBrBrFr��	sz5SQLCompiler.visit_insert.<locals>.<genexpr>.<genexpr>N)r*)rDZcrud_param_setrBrBrFr��	sz+SQLCompiler.visit_insert.<locals>.<genexpr>z VALUES (%s)cSsg|]}|d�qS)rrB)rDrrBrBrFr1�	sr�r�r�)"r�rIr8r�_setup_crud_paramsZISINSERTre�supports_default_valuesZsupports_empty_insertrr�r�Z_has_multi_parametersZsupports_multivalues_insertrgr�r��format_tabler:r�r�r*r�r�r��returning_precedes_valuesr6rmZ_insert_from_selectr�Zcte_follows_insertrSZ_post_values_clauser�)roZinsert_stmtr�r�r�crud_paramsZcrud_params_singler�rr�rUr�Zselect_textZpost_values_clauserB)rgrF�visit_insertG	s�



zSQLCompiler.visit_insertcCsdS)z3Provide a hook for MySQL to add LIMIT to the UPDATENrB)ro�update_stmtrBrBrF�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�)ry)ror�
from_table�extra_fromsr�rBrBrF�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)rw)rorrr�
from_hintsr�rBrBrF�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|�qSrBrB)rDr�)�
main_fromsrBrFr1�	sz,SQLCompiler.visit_update.<locals>.<listcomp>)rFrGrzUPDATE z SET z, c3s,|]$}|dj��d�d|dVqdS)r)r��=rN)ry)rDr)r�rorBrFr�
sz+SQLCompiler.visit_update.<locals>.<genexpr>r#z WHERE r�r�r�)r��_extra_froms�boolr8rr�r:r=rIr�r�rrr�ZISUPDATEr�r��'render_table_with_column_in_update_fromr*r�r�r�r�rr�rmrr�rSr�)rorr�r�rrZ
is_multitableZrender_extra_fromsrFrr�rr��extra_from_textr�rRrB)r�r	rorF�visit_update�	sz


zSQLCompiler.visit_updatecCst�||j�S)N)r�_key_getters_for_crud_columnri)rorBrBrFr6
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)rw)rorrrrr�rBrBrF�delete_extra_from_clause:
sz$SQLCompiler.delete_extra_from_clausecCs|j|ddd�S)NT)r�r�)ry)ro�delete_stmtrrrBrBrF�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)rFrGrzDELETE zFROM r#z WHERE r�r�r�)r�rr�ZISDELETErr:r=rIr�r�rr�r�r�r�r�rr�ryr�rSr�)rorr�r�rrrFrr�r�rr�rBrBrF�visit_deleteM
s\
zSQLCompiler.visit_deletecCsd|j�|�S)NzSAVEPOINT %s)rg�format_savepoint)ro�savepoint_stmtrBrBrF�visit_savepoint�
szSQLCompiler.visit_savepointcCsd|j�|�S)NzROLLBACK TO SAVEPOINT %s)rgr)rorrBrBrF�visit_rollback_to_savepoint�
sz'SQLCompiler.visit_rollback_to_savepointcCsd|j�|�S)NzRELEASE SAVEPOINT %s)rgr)rorrBrBrF�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_MAPr7�COMPOUND_KEYWORDSrJr�r�r�r
r�r�r
r�rlrr�r�r�r�rqr�r�r
Zmemoized_instancemethodr��
contextlib�contextmanagerr�r��memoized_propertyr�r�rxr~ru�dependenciesr�r�r�r�r�r�r�r�r�r�rrr	r�rrrr r"r(r*r+r,r0r3r4r6r:rBrErCr@rTrWr\r^r_rcrerhrirjrarprqrrrsrtrmrZr[rwr|r~r�r�r�r�rzr}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��	frozensetrr�r�r�r�r�r�rSr�r�rNrOr�r�rRr�r�r�rrrrrrrrrrrrrBrBrBrFr��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>rB)rorrBrBrFr��
sz$StrSQLCompiler._fallback_column_namecKs$d|j|jf|�|j|jf|�fS)Nz%s[%s])rmr+r5)rorr%r�rBrBrF�visit_getitem_binary�
sz#StrSQLCompiler.visit_getitem_binarycKs|j||f|�S)N)r")rorr%r�rBrBrF�visit_json_getitem_op_binary�
sz+StrSQLCompiler.visit_json_getitem_op_binarycKs|j||f|�S)N)r")rorr%r�rBrBrF�!visit_json_path_getitem_op_binary�
sz0StrSQLCompiler.visit_json_path_getitem_op_binarycKsd|j�|�S)Nz<next sequence value: %s>)rg�format_sequence)ro�seqr�rBrBrFrC�
szStrSQLCompiler.visit_sequencecs&�fdd�t�|�D�}dd�|�S)Nc	sg|]}��d|ddi��qS)NTF)r�)rDr)rorBrFr1�
sz3StrSQLCompiler.returning_clause.<locals>.<listcomp>z
RETURNING z, )rZ_select_iterablesr*)ror�r��columnsrB)rorFr��
s
zStrSQLCompiler.returning_clausecs dd����fdd�|D��S)NzFROM z, c3s&|]}|j�fd�d����VqdS)T)r�r�N)ry)rDr�)rr�rorBrFr��
sz4StrSQLCompiler.update_from_clause.<locals>.<genexpr>)r*)rorrrrr�rB)rr�rorFr�
sz!StrSQLCompiler.update_from_clausecs dd����fdd�|D��S)Nz, c3s&|]}|j�fd�d����VqdS)T)r�r�N)ry)rDr�)rr�rorBrFr��
sz:StrSQLCompiler.delete_extra_from_clause.<locals>.<genexpr>)r*)rorrrrr�rB)rr�rorFr�
sz'StrSQLCompiler.delete_extra_from_clauseN)r�r�r�r�r�r"r#r$rCr�rrrBrBrBrFr!�
sr!c@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)reZstatement_compiler)rorBrBrFrx�
szDDLCompiler.sql_compilercCs|jjS)N)rer)rorBrBrFr�
szDDLCompiler.type_compilerNcCsdS)NrB)rorurBrBrFr~�
szDDLCompiler.construct_paramscKs�|j}t|jtj�r�|��}|j}|�|j�}t|�dkrJ|dd}}n|d|d}}|�	d|�|�	d|�|�	d|�
|j��|j�|j
|�S)Nrrr|r�r:r�fullname)�contextr��targetrZTabler�rg�format_table_seqr��
setdefaultr�rxr	ri)roZddlr{r*rg�pathr:ZschrBrBrF�	visit_ddl�
szDDLCompiler.visit_ddlcCs|j�|j�}d|S)NzCREATE SCHEMA )rg�
format_schemar�)rorrrBrBrF�visit_create_schemaszDDLCompiler.visit_create_schemacCs(|j�|j�}d|}|jr$|d7}|S)NzDROP SCHEMA z CASCADE)rgr0r��cascade)ro�droprrrBrBrF�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 r#zTABLE r��
F)�first_pkz, 
�	Tz (in table '%s', column '%s'): %sr)� _include_foreign_key_constraintsz
)%s

)r�rgr�r*r��create_table_suffixr'rm�primary_keyrr�r
Zraise_from_cause�u�descriptionr��args�create_table_constraintsZinclude_foreign_key_constraints�post_create_table)
rorr:rgrr9Z	separatorr6Z
create_columnrZ	processedZce�constrBrBrF�visit_create_tablesF
0
zDDLCompiler.visit_create_tableFcsL|j}|jrdS�j||d�}d��fdd�|jD��}|rH|d|7}|S)N)r6r#c3s|]}��|�VqdS)N)rm)rDr)rorBrFr�Esz2DDLCompiler.visit_create_column.<locals>.<genexpr>)r��system�get_column_specificationr*�constraints)rorr6rrr@rB)rorF�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|�qSrB)r:)rDr)�	omit_fkcsr:rBrFr1^sz8DDLCompiler.create_table_constraints.<locals>.<listcomp>z, 
	css|]}|dk	r|VqdS)NrB)rD�prBrBrFr�esz7DDLCompiler.create_table_constraints.<locals>.<genexpr>c3s@|]8}|jdks|���r�jjr.t|dd�s��|�VqdS)NZ	use_alterF)Z_create_rulereZsupports_alterr�rm)rDr)rorBrFr�gs


)r:rIZforeign_key_constraintsr�r8�extendZ_sorted_constraintsr*)ror:r8rDZall_fkcsrB)rFror:rFr>Ls
z$DDLCompiler.create_table_constraintscCsd|j�|j�S)Nz
DROP TABLE )rgr�r�)ror3rBrBrF�visit_drop_tableuszDDLCompiler.visit_drop_tablecCsd|j�|j�S)Nz
DROP VIEW )rgr�r�)ror3rBrBrF�visit_drop_viewxszDDLCompiler.visit_drop_viewcCs|jdkrt�d|j��dS)Nz,Index '%s' is not associated with any table.)r:rr�r�)ror�rBrBrF�_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)r�z, c3s |]}�jj|ddd�VqdS)FT)r�rkN)rxrm)rDr)rorBrFr��sz1DDLCompiler.visit_create_index.<locals>.<genexpr>)	r�rKrgr>�_prepared_index_namer�r:r*Zexpressions)rorrLZinclude_table_schemar�rgrrB)rorF�visit_create_index�s


zDDLCompiler.visit_create_indexcCs|j}d|j|dd�S)Nz
DROP INDEX T)rL)r�rM)ror3r�rBrBrF�visit_drop_index�szDDLCompiler.visit_drop_indexcCsX|jdk	r|j�|j�}nd}|r4|r4|j�|�}nd}|j�|�}|rT|d|}|S)Nr�)r:rgr�r��format_index)ror�rLr�Zschema_nameZ
index_namerBrBrFrM�s
z DDLCompiler._prepared_index_namecCs d|j�|jj�|�|j�fS)NzALTER TABLE %s ADD %s)rgr�r�r:rm)rorrBrBrF�visit_add_constraint�sz DDLCompiler.visit_add_constraintcCs(d|j�|j�|j�|jjt���fS)NzCOMMENT ON TABLE %s IS %s)rgr�r�rxr��commentr	�String)rorrBrBrF�visit_set_table_comment�sz#DDLCompiler.visit_set_table_commentcCsd|j�|j�S)NzCOMMENT ON TABLE %s IS NULL)rgr�r�)ror3rBrBrF�visit_drop_table_comment�sz$DDLCompiler.visit_drop_table_commentcCs.d|jj|jddd�|j�|jjt���fS)NzCOMMENT ON COLUMN %s IS %sT)�	use_tabler�)rgr�r�rxr�rRr	rS)rorrBrBrF�visit_set_column_comment�s
z$DDLCompiler.visit_set_column_commentcCsd|jj|jdd�S)NzCOMMENT ON COLUMN %s IS NULLT)rV)rgr�r�)ror3rBrBrF�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)rgr%r�Z	increment�startZminvalueZmaxvalueZ
nominvalueZ
nomaxvalue�cacher4�cycle)rorrrBrBrF�visit_create_sequence�s*
z!DDLCompiler.visit_create_sequencecCsd|j�|j�S)NzDROP SEQUENCE %s)rgr%r�)ror3rBrBrF�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�rg�format_constraintrr�r�r:r2)ror3r�formatted_namerBrBrF�visit_drop_constraint�s

z!DDLCompiler.visit_drop_constraintcKsT|j�|�d|jjj|j|d�}|�|�}|dk	rB|d|7}|jsP|d7}|S)Nr#)rz	 DEFAULT z	 NOT NULL)rgr�rerrmr��get_column_default_stringZnullable)rorr{ZcolspecrrBrBrFrC�s
z$DDLCompiler.get_column_specificationcCsdS)Nr|rB)ror:rBrBrFr9
szDDLCompiler.create_table_suffixcCsdS)Nr|rB)ror:rBrBrFr?szDDLCompiler.post_create_tablecCsPt|jtj�rHt|jjtj�r2|j�|jjt	j
�S|jj|jjdd�SndSdS)NT)rk)r�Zserver_defaultrZ
DefaultClause�argr
Zstring_typesrxr�r	rvrm)rorrBrBrFra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)r�rk)r�rgr^rxrmr��define_constraint_deferrability)rorrr_rBrBrF�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)r�rk)r�rgr^rxrmr�rc)rorrr_rBrBrF�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)rgr�r�)rDr)rorBrFr�Bsz;DDLCompiler.visit_primary_key_constraint.<locals>.<genexpr>)	r�r�rgr^r*Z_implicit_generatedZcolumns_autoinc_firstr'rc)rorrr_rB)rorF�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�)rDr�)rgrBrFr�Vsz;DDLCompiler.visit_foreign_key_constraint.<locals>.<genexpr>c3s|]}��|jj�VqdS)N)r�rr�)rDr�)rgrBrFr�\s)rgr�r^r�rrr:r*�define_constraint_remote_table�define_constraint_match�define_constraint_cascadesrc)rorrr_Zremote_tablerB)rgrF�visit_foreign_key_constraintLs$
z(DDLCompiler.visit_foreign_key_constraintcCs
|�|�S)z=Format the remote table clause of a CREATE CONSTRAINT clause.)r�)rorr:rgrBrBrFrhd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)rgr�r�)rDr)rorBrFr�qsz6DDLCompiler.visit_unique_constraint.<locals>.<genexpr>)r�r�rgr^r*rc)rorrr_rB)rorF�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)Zondeleterg�validate_sql_phrase�FK_ON_DELETEZonupdate�FK_ON_UPDATE)rorrrBrBrFrjv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)rr'rgrm�FK_INITIALLY)rorrrBrBrFrc�s



z+DDLCompiler.define_constraint_deferrabilitycCs d}|jdk	r|d|j7}|S)Nr|z	 MATCH %s)�match)rorrrBrBrFri�s
z#DDLCompiler.define_constraint_match)N)F)N)FT)F))r�r�r�r
rrxrr~r/r1r4rArEr>rIrJrKrNrOrMrQrTrUrWrXr\r]r`rCr9r?rardrerfrkrhrlrjrcrirBrBrBrFr(�
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)NZFLOATrB)ror�r�rBrBrF�visit_FLOAT�szGenericTypeCompiler.visit_FLOATcKsdS)NZREALrB)ror�r�rBrBrF�
visit_REAL�szGenericTypeCompiler.visit_REALcKs<|jdkrdS|jdkr&dd|jiSd|j|jd�SdS)NZNUMERICzNUMERIC(%(precision)s)�	precisionz!NUMERIC(%(precision)s, %(scale)s))ru�scale)rurv)ror�r�rBrBrF�
visit_NUMERIC�s

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

z!GenericTypeCompiler.visit_DECIMALcKsdS)NZINTEGERrB)ror�r�rBrBrF�
visit_INTEGER�sz!GenericTypeCompiler.visit_INTEGERcKsdS)NZSMALLINTrB)ror�r�rBrBrF�visit_SMALLINT�sz"GenericTypeCompiler.visit_SMALLINTcKsdS)NZBIGINTrB)ror�r�rBrBrF�visit_BIGINT�sz GenericTypeCompiler.visit_BIGINTcKsdS)N�	TIMESTAMPrB)ror�r�rBrBrF�visit_TIMESTAMP�sz#GenericTypeCompiler.visit_TIMESTAMPcKsdS)NZDATETIMErB)ror�r�rBrBrF�visit_DATETIME�sz"GenericTypeCompiler.visit_DATETIMEcKsdS)NZDATErB)ror�r�rBrBrF�
visit_DATE�szGenericTypeCompiler.visit_DATEcKsdS)NZTIMErB)ror�r�rBrBrF�
visit_TIME�szGenericTypeCompiler.visit_TIMEcKsdS)NZCLOBrB)ror�r�rBrBrF�
visit_CLOB�szGenericTypeCompiler.visit_CLOBcKsdS)NZNCLOBrB)ror�r�rBrBrF�visit_NCLOB�szGenericTypeCompiler.visit_NCLOBcCs0|}|jr|d|j7}|jr,|d|j7}|S)Nz(%d)z
 COLLATE "%s")�lengthr�)ror�r�rrBrBrF�_render_string_type�sz'GenericTypeCompiler._render_string_typecKs|�|d�S)NZCHAR)r�)ror�r�rBrBrF�
visit_CHAR�szGenericTypeCompiler.visit_CHARcKs|�|d�S)NZNCHAR)r�)ror�r�rBrBrF�visit_NCHAR�szGenericTypeCompiler.visit_NCHARcKs|�|d�S)NZVARCHAR)r�)ror�r�rBrBrF�
visit_VARCHAR�sz!GenericTypeCompiler.visit_VARCHARcKs|�|d�S)NZNVARCHAR)r�)ror�r�rBrBrF�visit_NVARCHAR�sz"GenericTypeCompiler.visit_NVARCHARcKs|�|d�S)NZTEXT)r�)ror�r�rBrBrF�
visit_TEXT�szGenericTypeCompiler.visit_TEXTcKsdS)NZBLOBrB)ror�r�rBrBrF�
visit_BLOB�szGenericTypeCompiler.visit_BLOBcKsd|jrd|jpdS)NZBINARYz(%d)r|)r�)ror�r�rBrBrF�visit_BINARY�sz GenericTypeCompiler.visit_BINARYcKsd|jrd|jpdS)NZ	VARBINARYz(%d)r|)r�)ror�r�rBrBrF�visit_VARBINARY�sz#GenericTypeCompiler.visit_VARBINARYcKsdS)NZBOOLEANrB)ror�r�rBrBrF�
visit_BOOLEAN�sz!GenericTypeCompiler.visit_BOOLEANcKs|j|f|�S)N)r�)ror�r�rBrBrF�visit_large_binary�sz&GenericTypeCompiler.visit_large_binarycKs|j|f|�S)N)r�)ror�r�rBrBrF�
visit_boolean�sz!GenericTypeCompiler.visit_booleancKs|j|f|�S)N)r�)ror�r�rBrBrF�
visit_time�szGenericTypeCompiler.visit_timecKs|j|f|�S)N)r~)ror�r�rBrBrF�visit_datetime�sz"GenericTypeCompiler.visit_datetimecKs|j|f|�S)N)r)ror�r�rBrBrF�
visit_date�szGenericTypeCompiler.visit_datecKs|j|f|�S)N)r{)ror�r�rBrBrF�visit_big_integer
sz%GenericTypeCompiler.visit_big_integercKs|j|f|�S)N)rz)ror�r�rBrBrF�visit_small_integer
sz'GenericTypeCompiler.visit_small_integercKs|j|f|�S)N)ry)ror�r�rBrBrF�
visit_integer
sz!GenericTypeCompiler.visit_integercKs|j|f|�S)N)rt)ror�r�rBrBrF�
visit_real

szGenericTypeCompiler.visit_realcKs|j|f|�S)N)rs)ror�r�rBrBrF�visit_float

szGenericTypeCompiler.visit_floatcKs|j|f|�S)N)rw)ror�r�rBrBrF�
visit_numeric
sz!GenericTypeCompiler.visit_numericcKs|j|f|�S)N)r�)ror�r�rBrBrF�visit_string
sz GenericTypeCompiler.visit_stringcKs|j|f|�S)N)r�)ror�r�rBrBrF�
visit_unicode
sz!GenericTypeCompiler.visit_unicodecKs|j|f|�S)N)r�)ror�r�rBrBrF�
visit_text
szGenericTypeCompiler.visit_textcKs|j|f|�S)N)r�)ror�r�rBrBrF�visit_unicode_text
sz&GenericTypeCompiler.visit_unicode_textcKs|j|f|�S)N)r�)ror�r�rBrBrF�
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�)ror�r�rBrBrFr"
szGenericTypeCompiler.visit_nullcKs|j|�|j�f|�S)N)rmZtype_enginere)ror�r�rBrBrF�visit_type_decorator)
sz(GenericTypeCompiler.visit_type_decoratorcKs|jf|�S)N)Zget_col_spec)ror�r�rBrBrF�visit_user_defined,
sz&GenericTypeCompiler.visit_user_definedN)-r�r�r�rsrtrwrxryrzr{r}r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�rBrBrBrFrr�sT	rrc@seZdZdd�Zdd�ZdS)�StrSQLTypeCompilercCs|�d�r|jSt|��dS)NZvisit_)�
startswith�_visit_unknown�AttributeError)ror�rBrBrF�__getattr__1
s
zStrSQLTypeCompiler.__getattr__cKsd|jjS)Nz%s)r?r�)ror�r�rBrBrFr�7
sz!StrSQLTypeCompiler._visit_unknownN)r�r�r�r�r�rBrBrBrFr�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)rLrKN)
re�
initial_quote�final_quote�escape_quote�escape_to_quote�omit_schema�quote_case_sensitive_collations�_stringsr�r)rorer�r�r�r�r�rBrBrFrqG
szIdentifierPreparer.__init__cCs,|j�|j�}|j�|j�t�|�|_|S)N)r?�__new__�__dict__r�r�_schema_getterr�)rorpZpreprBrBrFrhk
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)ror�rBrBrF�_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�)ror�rBrBrF�_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))rqrr��pattern)ror�ZregrBrBrFrm�
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�)ror�rBrBrF�quote_identifier�
s
z#IdentifierPreparer.quote_identifiercCs<|��}||jkp:|d|jkp:|j�t�|��p:||kS)z5Return True if the given identifier requires quoting.r)r=�reserved_words�illegal_initial_characters�legal_charactersrqr
�	text_type)ror�Zlc_valuerBrBrFr��
s

z#IdentifierPreparer._requires_quotescCs|j�t�|��S)zjReturn True if the given identifier requires quoting, but
        not taking case convention into account.)r�rqr
r�)ror�rBrBrFr;�
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�)ror�forcerBrBrFr��
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�)ror�r�rBrBrFr��
s




zIdentifierPreparer.quotecCs|jr|�|�S|SdS)N)r�r�)roZcollation_namerBrBrFr�s
z#IdentifierPreparer.format_collationcCs>|�|j�}|�|�}|js:|r:|dk	r:|�|�d|}|S)Nr�)r�r�r�r�r�)rorDr�r�r�rBrBrFr%s
z"IdentifierPreparer.format_sequencecCs|�|p|j�S)N)r�r�)ror�r�rBrBrFr�szIdentifierPreparer.format_labelcCs|�|p|j�S)N)r�r�)ror�r�rBrBrFr�!szIdentifierPreparer.format_aliascCs"|p|j}|�|�r|�|�}|S)N)r�r�r�)roZ	savepointr�r�rBrBrFr$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�rU���)r�r�rZ_defer_nameZ_constraint_name_for_tabler:Z_defer_none_namer�r�reZmax_index_name_lengthr�r�r
Zmd5_hexZvalidate_identifierr�)roZnamingrr�Zmax_rBrBrFr^-s"


(z$IdentifierPreparer.format_constraintcCs
|�|�S)N)r^)ror�rBrBrFrPKszIdentifierPreparer.format_indexcCsF|dkr|j}|�|�}|�|�}|jsB|rB|rB|�|�d|}|S)z'Prepare a quoted table and schema name.Nr�)r�r�r�r�r�)ror:r�r�r�r�rBrBrFr�Ns

zIdentifierPreparer.format_tablecCs
|�|�S)zPrepare a quoted schema name.)r�)ror�rBrBrFr0[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)r�r�r�)r�r�r�r:r�)rorrVr�Z
table_namer�rBrBrFr�`s
 z IdentifierPreparer.format_columncCsD|�|�}|js0|r0|r0|�|�|j|dd�fS|j|dd�fSdS)z(Format table name and schema as a tuple.F)r�N)r�r�r�r�)ror:r�r�rBrBrFr,�s

z#IdentifierPreparer.format_table_seqcCs@dd�|j|j|�|j�fD�\}}}t�d|||d��}|S)NcSsg|]}t�|��qSrB)r�r�)rDr$rBrBrFr1�sz5IdentifierPreparer._r_identifiers.<locals>.<listcomp>zM(?:(?:%(initial)s((?:%(escaped)s|[^%(final)s])+)%(final)s|([^\.]+))(?=\.|$))+)�initial�finalZescaped)r�r�r�r�rr)ror�r�Z
escaped_final�rrBrBrF�_r_identifiers�sz!IdentifierPreparer._r_identifierscs(�j}�fdd�dd�|�|�D�D�S)z:Unpack 'schema.table.column'-like strings into components.csg|]}��|��qSrB)r�)rDrH)rorBrFr1�sz;IdentifierPreparer.unformat_identifiers.<locals>.<listcomp>cSsg|]\}}|p|�qSrBrB)rD�a�brBrBrFr1�s)r��findall)roZidentifiersr�rB)rorF�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�r�rqrhr�r�rmr�r�r;r�r�r�r%r�r�rr
rr^rPr�r0r�r,rr�r�rBrBrBrFr�;
sF

	


%
2



	


 
r�)jr�rr�r�r|rrrrrrr	r
rr
r8r�rr�Ir�ZLEGAL_CHARACTERS_PLUS_SPACE�ranger=r�rnrorp�UNICODErrr��and_�or_�add�mulr�Zdiv�mod�truediv�neg�lt�le�ne�gt�ge�eqZis_distinct_fromZisnot_distinct_fromZ	concat_oprbZnotmatch_opZin_opZnotin_opZcomma_opr�r��is_Zisnotr�existsZdistinct_op�invZany_opZall_opZdesc_opZasc_opZ
nullsfirst_opZnullslast_opr�rOrrrrr-r.rPrQr7r?ZcubeZrollupZ
grouping_setsr>rr�raZ	UNION_ALLrbZ
EXCEPT_ALLrcZ
INTERSECT_ALLr�objectrdZwith_metaclassZEnsureKWArgTyper�Z	Visitabler�r�r!r(rrr�r�rBrBrBrF�<module>s�



=7

Zerion Mini Shell 1.0