class SQLCompiler(Compiled): (source)
Known subclasses: sqlalchemy.dialects.mssql.base.MSSQLCompiler
, sqlalchemy.dialects.mysql.base.MySQLCompiler
, sqlalchemy.dialects.oracle.base.OracleCompiler
, sqlalchemy.dialects.postgresql.base.PGCompiler
, sqlalchemy.dialects.sqlite.base.SQLiteCompiler
, sqlalchemy.sql.compiler.StrSQLCompiler
Default implementation of :class:`.Compiled`. Compiles :class:`_expression.ClauseElement` objects into SQL strings.
Method | __init__ |
Construct a new :class:`.SQLCompiler` object. |
Method | bindparam |
Undocumented |
Method | construct |
Return a new :class:`.ExpandedState` for a given parameter set. |
Method | construct |
return a dictionary of bind parameter keys and values |
Method | default |
Called when a SELECT statement has no froms, and no FROM clause is to be appended. |
Method | delete |
Provide a hook to override the generation of an DELETE..FROM clause. |
Method | delete |
Undocumented |
Method | escape |
Undocumented |
Method | fetch |
Undocumented |
Method | for |
Undocumented |
Method | format |
Undocumented |
Method | function |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | get |
Called when building a ``SELECT`` statement, position is just before column list. |
Method | get |
Undocumented |
Method | group |
allow dialects to customize how GROUP BY is rendered. |
Method | is |
Undocumented |
Method | limit |
Undocumented |
Method | order |
allow dialects to customize how ORDER BY is rendered. |
Method | post |
Undocumented |
Method | render |
Undocumented |
Method | render |
Undocumented |
Method | render |
Render the value of a bind parameter as a quoted literal. |
Method | returning |
Undocumented |
Method | update |
Provide a hook to override the generation of an UPDATE..FROM clause. |
Method | update |
Provide a hook for MySQL to add LIMIT to the UPDATE |
Method | update |
Provide a hook to override the initial table clause in an UPDATE statement. |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Method | visit |
Undocumented |
Class Variable | ansi |
SQL 92 doesn't allow bind parameters to be used in the columns clause of a SELECT, nor does it allow ambiguous expressions like "? = ?". A compiler subclass can set this flag to False if the target driver/DB enforces this... |
Class Variable | bindname |
A mapping (e.g. dict or similar) containing a lookup of characters keyed to replacement characters which will be applied to all 'bind names' used in SQL statements as a form of 'escaping'; the given characters are replaced entirely with the 'replacement' character when rendered in the SQL statement, and a similar translation is performed on the incoming names used in parameter dictionaries passed to methods like :meth:`_engine... |
Class Variable | implicit |
list of "implicit" returning columns for a toplevel INSERT or UPDATE statement, used to receive newly generated values of columns. |
Class Variable | insert |
list of columns for which default values should be evaluated before an INSERT takes place |
Class Variable | is |
Undocumented |
Class Variable | literal |
bindparameter objects that are rendered as literal values at statement execution time. |
Class Variable | post |
bindparameter objects that are rendered as bound parameter placeholders at statement execution time. |
Class Variable | postfetch |
list of columns that can be post-fetched after INSERT or UPDATE to receive server-updated values |
Class Variable | postfetch |
if True, and this in insert, use cursor.lastrowid to populate result.inserted_primary_key. |
Class Variable | render |
set to True classwide to indicate the SET clause in a multi-table UPDATE statement should qualify columns with the table name (i.e. MySQL only) |
Class Variable | returning |
set to True classwide to generate RETURNING clauses before the VALUES or WHERE clause (i.e. MSSQL) |
Class Variable | translate |
if not ``None``, should be a callable which accepts ``(select_stmt, **kw)`` and returns a select object. this is used for structural changes mostly to accommodate for LIMIT/OFFSET schemes |
Class Variable | update |
list of columns for which onupdate default values should be evaluated before an UPDATE takes place |
Instance Variable | anon |
Undocumented |
Instance Variable | bind |
a dictionary of BindParameter instances to "compiled" names that are actually present in the generated SQL |
Instance Variable | binds |
a dictionary of bind parameter keys to BindParameter instances. |
Instance Variable | bindtemplate |
template to render bound parameters based on paramstyle. |
Instance Variable | cache |
The :class:`.CacheKey` that was generated ahead of creating this :class:`.Compiled` object. |
Instance Variable | column |
Undocumented |
Instance Variable | compilation |
template used by compiler to render parameters before positional paramstyle application |
Instance Variable | compile |
Optional :class:`.CompileState` object that maintains additional state used by the compiler. |
Instance Variable | ctes |
Undocumented |
Instance Variable | ctes |
Undocumented |
Instance Variable | ctes |
Undocumented |
Instance Variable | dml |
Optional :class:`.CompileState` assigned at the same point that .isinsert, .isupdate, or .isdelete is assigned. |
Instance Variable | escaped |
Undocumented |
Instance Variable | for |
Undocumented |
Instance Variable | from |
Undocumented |
Instance Variable | has |
if True, there are bindparam() objects that have the isoutparam flag set. |
Instance Variable | inline |
Undocumented |
Instance Variable | isdelete |
Undocumented |
Instance Variable | isinsert |
Undocumented |
Instance Variable | isplaintext |
Undocumented |
Instance Variable | isupdate |
class-level defaults which can be set at the instance level to define if this Compiled instance represents INSERT/UPDATE/DELETE |
Instance Variable | label |
Undocumented |
Instance Variable | level |
Undocumented |
Instance Variable | linting |
Undocumented |
Instance Variable | next |
Undocumented |
Instance Variable | positional |
Undocumented |
Instance Variable | positiontup |
for a compiled construct that uses a positional paramstyle, will be a sequence of strings, indicating the names of bound parameters in order. |
Instance Variable | stack |
major statements such as SELECT, INSERT, UPDATE, DELETE are tracked in this stack using an entry format. |
Instance Variable | string |
The string representation of the ``statement`` |
Instance Variable | truncated |
Undocumented |
Property | current |
Return the current 'executable' that is being compiled. |
Property | effective |
The effective "returning" columns for INSERT, UPDATE or DELETE. |
Property | insert |
When an INSERT is compiled with a single set of parameters inside a VALUES expression, the string is assigned here, where it can be used for insert batching schemes to rewrite the VALUES expression. |
Property | params |
Return the bind param dictionary embedded into this compiled object, for those values that are present. |
Property | prefetch |
Undocumented |
Property | returning |
backwards compatibility; returns the effective_returning collection. |
Property | sql |
Return a Compiled that is capable of processing SQL expressions. |
Class Method | _init |
Undocumented |
Class Method | _init |
Undocumented |
Method | _add |
Undocumented |
Method | _anonymize |
Undocumented |
Method | _compose |
Undocumented |
Method | _create |
utility method used for unit tests only. |
Method | _deliver |
Undocumented |
Method | _dispatch |
Undocumented |
Method | _display |
Undocumented |
Method | _fallback |
Undocumented |
Method | _format |
Undocumented |
Method | _generate |
Undocumented |
Method | _generate |
Undocumented |
Method | _generate |
Undocumented |
Method | _generate |
Undocumented |
Method | _generate |
Undocumented |
Method | _generate |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _init |
Initialize collections related to CTEs only if a CTE is located, to save on the overhead of these collections otherwise. |
Method | _insert |
Undocumented |
Method | _label |
Render a column with necessary labels inside of a RETURNING clause. |
Method | _label |
produce labeled columns present in a select(). |
Method | _literal |
Undocumented |
Method | _literal |
Undocumented |
Method | _nested |
special API to support the use case of 'nested result sets' |
Method | _process |
Undocumented |
Method | _process |
handle special post compile parameters. |
Method | _process |
Undocumented |
Method | _render |
include_following_stack Also render the nesting CTEs on the next stack. Useful for SQL structures like UNION or INSERT that can wrap SELECT statements containing nesting CTEs. |
Method | _render |
Undocumented |
Method | _row |
Undocumented |
Method | _setup |
Undocumented |
Method | _setup |
Undocumented |
Method | _setup |
Undocumented |
Method | _truncate |
Undocumented |
Method | _truncated |
Undocumented |
Class Variable | _bind |
Undocumented |
Class Variable | _bind |
Undocumented |
Class Variable | _default |
Undocumented |
Class Variable | _get |
Undocumented |
Class Variable | _insert |
Undocumented |
Class Variable | _positional |
Undocumented |
Class Variable | _post |
Undocumented |
Class Variable | _pyformat |
Undocumented |
Class Variable | _values |
Undocumented |
Class Variable | _visited |
Undocumented |
Instance Variable | _ad |
tell the result that we encountered text() or '*' constructs in the middle of the result columns, but we also have compiled columns, so if the number of columns in cursor.description does not match how many expressions we have, that means we can't rely on positional at all and should match on name. |
Instance Variable | _cache |
a mapping that will relate the BindParameter object we compile to those that are part of the extracted collection of parameters in the cache key, if we were given a cache key. |
Instance Variable | _insertmanyvalues |
Undocumented |
Instance Variable | _loose |
tell the result object that the SQL statement is textual, wants to match up to Column objects, and may be using the ._tq_label in the SELECT rather than the base name. |
Instance Variable | _numeric |
True if paramstyle is "numeric". This paramstyle is trickier than all the others. |
Instance Variable | _numeric |
Character that's used to as the identifier of a numerical bind param. For example if this char is set to ``$``, numerical binds will be rendered in the form ``$1, $2, $3``. |
Instance Variable | _ordered |
if False, means we can't be sure the list of entries in _result_columns is actually the rendered order. Usually True unless using an unordered TextualSelect. |
Instance Variable | _post |
When render_postcompile is used, the ``ExpandedState`` used to create the "expanded" SQL is assigned here, and then used by the ``.params`` accessor and ``.construct_params()`` methods for their return values. |
Instance Variable | _pre |
Undocumented |
Instance Variable | _pre |
Stores the original string SQL before 'post_compile' is applied, for cases where 'post_compile' were used. |
Instance Variable | _render |
whether to render out POSTCOMPILE params during the compile phase. |
Instance Variable | _result |
relates label names in the final SQL to a tuple of local column/label name, ColumnElement object (if any) and TypeEngine. CursorResult uses this for type processing and column targeting |
Instance Variable | _textual |
tell the result object that the column names as rendered are important, but they are also "ordered" vs. what is in the compiled object here. |
Instance Variable | _truncated |
Undocumented |
Property | _bind |
Undocumented |
Property | _global |
Undocumented |
Property | _inserted |
Undocumented |
Property | _inserted |
Undocumented |
Property | _like |
Undocumented |
Property | _within |
Undocumented |
Inherited from Compiled
:
Method | __init |
Undocumented |
Method | __str__ |
Return the string text of the generated SQL or DDL. |
Method | process |
Undocumented |
Method | visit |
Undocumented |
Class Variable | is |
Undocumented |
Instance Variable | can |
Undocumented |
Instance Variable | dialect |
Undocumented |
Instance Variable | execution |
Undocumented |
Instance Variable | preparer |
Undocumented |
Instance Variable | schema |
Execution options propagated from the statement. In some cases, sub-elements of the statement can modify these. |
Instance Variable | state |
description of the compiler's state |
Instance Variable | statement |
The statement to compile. |
Method | _execute |
Undocumented |
Class Variable | _cached |
Undocumented |
Instance Variable | _annotations |
Undocumented |
Instance Variable | _gen |
Generation time of this :class:`.Compiled`, used for reporting cache stats. |
Dialect
, statement: Optional[ ClauseElement]
, cache_key: Optional[ CacheKey]
= None, column_keys: Optional[ Sequence[ str]]
= None, for_executemany: bool
= False, linting: Linting
= NO_LINTING, **kwargs: Any
):
(source)
¶
sqlalchemy.dialects.mssql.base.MSSQLCompiler
, sqlalchemy.dialects.oracle.base.OracleCompiler
Construct a new :class:`.SQLCompiler` object. :param dialect: :class:`.Dialect` to be used :param statement: :class:`_expression.ClauseElement` to be compiled :param column_keys: a list of column names to be compiled into an INSERT or UPDATE statement. :param for_executemany: whether INSERT / UPDATE statements should expect that they are to be invoked in an "executemany" style, which may impact how the statement will be expected to return the values of defaults and autoincrement / sequences and similar. Depending on the backend and driver in use, support for retrieving these values may be disabled which means SQL expressions may be rendered inline, RETURNING may not be rendered, etc. :param kwargs: additional keyword arguments to be consumed by the superclass.
str
, post_compile: bool
= False, expanding: bool
= False, escaped_from: Optional[ str]
= None, bindparam_type: Optional[ TypeEngine[ Any]]
= None, accumulate_bind_names: Optional[ Set[ str]]
= None, visited_bindparam: Optional[ List[ str]]
= None, **kw: Any
) -> str
:
(source)
¶
Undocumented
Optional[ _CoreSingleExecuteParams]
= None, escape_names: bool
= True) -> ExpandedState
:
(source)
¶
Return a new :class:`.ExpandedState` for a given parameter set. For queries that use "expanding" or other late-rendered parameters, this method will provide for both the finalized SQL string as well as the parameters that would be used for a particular parameter set. .. versionadded:: 2.0.0rc1
Optional[ _CoreSingleExecuteParams]
= None, extracted_parameters: Optional[ Sequence[ BindParameter[ Any]]]
= None, escape_names: bool
= True, _group_number: Optional[ int]
= None, _check: bool
= True, _no_postcompile: bool
= False) -> _MutableCoreSingleExecuteParams
:
(source)
¶
return a dictionary of bind parameter keys and values
sqlalchemy.dialects.mysql.base.MySQLCompiler
, sqlalchemy.dialects.oracle.base.OracleCompiler
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.
sqlalchemy.dialects.mssql.base.MSSQLCompiler
, sqlalchemy.dialects.mysql.base.MySQLCompiler
, sqlalchemy.dialects.postgresql.base.PGCompiler
, sqlalchemy.sql.compiler.StrSQLCompiler
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.
sqlalchemy.dialects.mssql.base.MSSQLCompiler
, sqlalchemy.dialects.mysql.base.MySQLCompiler
Undocumented
sqlalchemy.dialects.postgresql.base.PGCompiler
Undocumented
sqlalchemy.dialects.mssql.base.MSSQLCompiler
, sqlalchemy.dialects.oracle.base.OracleCompiler
Undocumented
sqlalchemy.dialects.mssql.base.MSSQLCompiler
, sqlalchemy.dialects.mysql.base.MySQLCompiler
, sqlalchemy.dialects.postgresql.base.PGCompiler
Called when building a ``SELECT`` statement, position is just before column list.
sqlalchemy.dialects.mssql.base.MSSQLCompiler
allow dialects to customize how ORDER BY is rendered.
Undocumented
sqlalchemy.dialects.mssql.base.MSSQLStrictCompiler
, sqlalchemy.dialects.mysql.base.MySQLCompiler
, sqlalchemy.dialects.postgresql.base.PGCompiler
Render the value of a bind parameter as a quoted literal. This is used for statement sections that do not accept bind parameters on the target driver/database. This should be implemented by subclasses using the quoting services of the DBAPI.
UpdateBase
, returning_cols: Sequence[ ColumnElement[ Any]]
, *, populate_result_map: bool
, **kw: Any
) -> str
:
(source)
¶
sqlalchemy.dialects.mssql.base.MSSQLCompiler
, sqlalchemy.dialects.mysql.base.MySQLCompiler
, sqlalchemy.dialects.postgresql.base.PGCompiler
, sqlalchemy.dialects.sqlite.base.SQLiteCompiler
, sqlalchemy.sql.compiler.StrSQLCompiler
Provide a hook to override the generation of an UPDATE..FROM clause. MySQL and MSSQL override this.
sqlalchemy.dialects.mysql.base.MySQLCompiler
Provide a hook for MySQL to add LIMIT to the UPDATE
sqlalchemy.dialects.mysql.base.MySQLCompiler
Provide a hook to override the initial table clause in an UPDATE statement. MySQL overrides this.
sqlalchemy.dialects.mssql.base.MSSQLCompiler
Undocumented
sqlalchemy.dialects.mssql.base.MSSQLCompiler
Undocumented
Undocumented
sqlalchemy.dialects.mysql.base.MySQLCompiler
, sqlalchemy.dialects.sqlite.base.SQLiteCompiler
Undocumented
ColumnClause[ Any]
, add_to_result_map: Optional[ _ResultMapAppender]
= None, include_table: bool
= True, result_map_targets: Tuple[ Any, ...]
= (), ambiguous_table_name_map: Optional[ _AmbiguousTableNameMap]
= None, **kwargs: Any
) -> str
:
(source)
¶
sqlalchemy.dialects.mssql.base.MSSQLCompiler
Undocumented
CTE
, asfrom: bool
= False, ashint: bool
= False, fromhints: Optional[ _FromHintsType]
= None, visiting_cte: Optional[ CTE]
= None, from_linter: Optional[ FromLinter]
= None, cte_opts: selectable._CTEOpts
= selectable._CTEOpts(Any
) -> Optional[ str]
:
(source)
¶
Undocumented
sqlalchemy.dialects.mssql.base.MSSQLCompiler
, sqlalchemy.dialects.mysql.base.MySQLCompiler
, sqlalchemy.dialects.oracle.base.OracleCompiler
, sqlalchemy.dialects.postgresql.base.PGCompiler
, sqlalchemy.dialects.sqlite.base.SQLiteCompiler
, sqlalchemy.sql.compiler.StrSQLCompiler
Undocumented
sqlalchemy.dialects.mssql.base.MSSQLCompiler
, sqlalchemy.dialects.sqlite.base.SQLiteCompiler
Undocumented
Function[ Any]
, add_to_result_map: Optional[ _ResultMapAppender]
= None, **kwargs: Any
) -> str
:
(source)
¶
sqlalchemy.dialects.oracle.base.OracleCompiler
Undocumented
sqlalchemy.dialects.mysql.base.MySQLCompiler
, sqlalchemy.dialects.oracle.base.OracleCompiler
Undocumented
Undocumented
Undocumented
sqlalchemy.dialects.mssql.base.MSSQLCompiler
Undocumented
sqlalchemy.dialects.mssql.base.MSSQLStrictCompiler
SQL 92 doesn't allow bind parameters to be used in the columns clause of a SELECT, nor does it allow ambiguous expressions like "? = ?". A compiler subclass can set this flag to False if the target driver/DB enforces this
A mapping (e.g. dict or similar) containing a lookup of characters keyed to replacement characters which will be applied to all 'bind names' used in SQL statements as a form of 'escaping'; the given characters are replaced entirely with the 'replacement' character when rendered in the SQL statement, and a similar translation is performed on the incoming names used in parameter dictionaries passed to methods like :meth:`_engine.Connection.execute`. This allows bound parameter names used in :func:`_sql.bindparam` and other constructs to have any arbitrary characters present without any concern for characters that aren't allowed at all on the target database. Third party dialects can establish their own dictionary here to replace the default mapping, which will ensure that the particular characters in the mapping will never appear in a bound parameter name. The dictionary is evaluated at **class creation time**, so cannot be modified at runtime; it must be present on the class when the class is first declared. Note that for dialects that have additional bound parameter rules such as additional restrictions on leading characters, the :meth:`_sql.SQLCompiler.bindparam_string` method may need to be augmented. See the cx_Oracle compiler for an example of this. .. versionadded:: 2.0.0rc1
list of "implicit" returning columns for a toplevel INSERT or UPDATE statement, used to receive newly generated values of columns. .. versionadded:: 2.0 ``implicit_returning`` replaces the previous ``returning`` collection, which was not a generalized RETURNING collection and instead was in fact specific to the "implicit returning" feature.
bindparameter objects that are rendered as bound parameter placeholders at statement execution time.
sqlalchemy.dialects.mysql.base.MySQLCompiler
set to True classwide to indicate the SET clause in a multi-table UPDATE statement should qualify columns with the table name (i.e. MySQL only)
sqlalchemy.dialects.mssql.base.MSSQLCompiler
set to True classwide to generate RETURNING clauses before the VALUES or WHERE clause (i.e. MSSQL)
sqlalchemy.dialects.mssql.base.MSSQLCompiler
, sqlalchemy.dialects.oracle.base.OracleCompiler
if not ``None``, should be a callable which accepts ``(select_stmt, **kw)`` and returns a select object. this is used for structural changes mostly to accommodate for LIMIT/OFFSET schemes
a dictionary of BindParameter instances to "compiled" names that are actually present in the generated SQL
The :class:`.CacheKey` that was generated ahead of creating this :class:`.Compiled` object. This is used for routines that need access to the original :class:`.CacheKey` instance generated when the :class:`.Compiled` instance was first cached, typically in order to reconcile the original list of :class:`.BindParameter` objects with a per-statement list that's generated on each call.
Optional :class:`.CompileState` object that maintains additional state used by the compiler. Major executable objects such as :class:`_expression.Insert`, :class:`_expression.Update`, :class:`_expression.Delete`, :class:`_expression.Select` will generate this state when compiled in order to calculate additional information about the object. For the top level object that is to be executed, the state can be stored here where it can also have applicability towards result set processing. .. versionadded:: 1.4
Optional :class:`.CompileState` assigned at the same point that .isinsert, .isupdate, or .isdelete is assigned. This will normally be the same object as .compile_state, with the exception of cases like the :class:`.ORMFromStatementCompileState` object. .. versionadded:: 1.4.40
class-level defaults which can be set at the instance level to define if this Compiled instance represents INSERT/UPDATE/DELETE
for a compiled construct that uses a positional paramstyle, will be a sequence of strings, indicating the names of bound parameters in order. This is used in order to render bound parameters in their correct order, and is combined with the :attr:`_sql.Compiled.params` dictionary to render parameters. This sequence always contains the unescaped name of the parameters. .. seealso:: :ref:`faq_sql_expression_string` - includes a usage example for debugging use cases.
major statements such as SELECT, INSERT, UPDATE, DELETE are tracked in this stack using an entry format.
Return the current 'executable' that is being compiled. This is currently the :class:`_sql.Select`, :class:`_sql.Insert`, :class:`_sql.Update`, :class:`_sql.Delete`, :class:`_sql.CompoundSelect` object that is being compiled. Specifically it's assigned to the ``self.stack`` list of elements. When a statement like the above is being compiled, it normally is also assigned to the ``.statement`` attribute of the :class:`_sql.Compiler` object. However, all SQL constructs are ultimately nestable, and this attribute should never be consulted by a ``visit_`` method, as it is not guaranteed to be assigned nor guaranteed to correspond to the current statement being compiled. .. versionadded:: 1.3.21 For compatibility with previous versions, use the following recipe:: statement = getattr(self, "current_executable", False) if statement is False: statement = self.stack[-1]["selectable"] For versions 1.4 and above, ensure only .current_executable is used; the format of "self.stack" may change.
The effective "returning" columns for INSERT, UPDATE or DELETE. This is either the so-called "implicit returning" columns which are calculated by the compiler on the fly, or those present based on what's present in ``self.statement._returning`` (expanded into individual columns using the ``._all_selected_columns`` attribute) i.e. those set explicitly using the :meth:`.UpdateBase.returning` method. .. versionadded:: 2.0
When an INSERT is compiled with a single set of parameters inside a VALUES expression, the string is assigned here, where it can be used for insert batching schemes to rewrite the VALUES expression. .. versionadded:: 1.3.8 .. versionchanged:: 2.0 This collection is no longer used by SQLAlchemy's built-in dialects, in favor of the currently internal ``_insertmanyvalues`` collection that is used only by :class:`.SQLCompiler`.
sqlalchemy.sql.compiler.Compiled.params
Return the bind param dictionary embedded into this compiled object, for those values that are present. .. seealso:: :ref:`faq_sql_expression_string` - includes a usage example for debugging use cases.
Return a Compiled that is capable of processing SQL expressions. If this compiler is one, it would likely just return 'self'.
str
, name: str
, objects: Tuple[ Any, ...]
, type_: TypeEngine[ Any]
):
(source)
¶
Undocumented
Undocumented
Undocumented
Initialize collections related to CTEs only if a CTE is located, to save on the overhead of these collections otherwise.
Render a column with necessary labels inside of a RETURNING clause. This method is provided for individual dialects in place of calling the _label_select_column method directly, so that the two use cases of RETURNING vs. SELECT can be disambiguated going forward. .. versionadded:: 1.4.21
produce labeled columns present in a select().
Undocumented
_MutableCoreSingleExecuteParams
, _populate_self: bool
= False) -> ExpandedState
:
(source)
¶
handle special post compile parameters. These include: * "expanding" parameters -typically IN tuples that are rendered on a per-parameter basis for an otherwise fixed SQL statement string. * literal_binds compiled with the literal_execute flag. Used for things like SQL Server "TOP N" where the driver does not accommodate N as a bound parameter.
include_following_stack Also render the nesting CTEs on the next stack. Useful for SQL structures like UNION or INSERT that can wrap SELECT statements containing nesting CTEs.
sqlalchemy.dialects.mssql.base.MSSQLCompiler
, sqlalchemy.dialects.oracle.base.OracleCompiler
Undocumented
Undocumented
tell the result that we encountered text() or '*' constructs in the middle of the result columns, but we also have compiled columns, so if the number of columns in cursor.description does not match how many expressions we have, that means we can't rely on positional at all and should match on name.
a mapping that will relate the BindParameter object we compile to those that are part of the extracted collection of parameters in the cache key, if we were given a cache key.
tell the result object that the SQL statement is textual, wants to match up to Column objects, and may be using the ._tq_label in the SELECT rather than the base name.
Character that's used to as the identifier of a numerical bind param. For example if this char is set to ``$``, numerical binds will be rendered in the form ``$1, $2, $3``.
if False, means we can't be sure the list of entries in _result_columns is actually the rendered order. Usually True unless using an unordered TextualSelect.
When render_postcompile is used, the ``ExpandedState`` used to create the "expanded" SQL is assigned here, and then used by the ``.params`` accessor and ``.construct_params()`` methods for their return values. .. versionadded:: 2.0.0rc1
Stores the original string SQL before 'post_compile' is applied, for cases where 'post_compile' were used.
whether to render out POSTCOMPILE params during the compile phase. This attribute is used only for end-user invocation of stmt.compile(); it's never used for actual statement execution, where instead the dialect internals access and render the internal postcompile structure directly.
relates label names in the final SQL to a tuple of local column/label name, ColumnElement object (if any) and TypeEngine. CursorResult uses this for type processing and column targeting
tell the result object that the column names as rendered are important, but they are also "ordered" vs. what is in the compiled object here. As of 1.4.42 this condition is only present when the statement is a TextualSelect, e.g. text("....").columns(...), where it is required that the columns are considered positionally and not by name.
_bind_processors:
MutableMapping[ str, Union[ _BindProcessorType[ Any], Sequence[ _BindProcessorType[ Any]]]]
=
(source)
¶
Undocumented
@util.preload_module(
_inserted_primary_key_from_lastrowid_getter = (source) ¶
Undocumented