sqlalchemy :: sql :: compiler :: SQLCompiler :: Class SQLCompiler
[hide private]
[frames] | no frames]

Class SQLCompiler


Default implementation of Compiled.

Compiles ClauseElements into SQL strings. Uses a similar visit paradigm as visitors.ClauseVisitor but implements its own traversal.

Instance Methods [hide private]
 
__init__(self, dialect, statement, column_keys=None, inline=False, **kwargs)
Construct a new ``DefaultCompiler`` object.
 
_add_to_result_map(self, keyname, name, objects, type_)
 
_anonymize(self, name)
 
_apply_numbered_params(self)
 
_bind_processors(...)
 
_compose_select_body(self, text, select, inner_columns, froms, byfrom, kwargs)
 
_create_result_map(self)
utility method used for unit tests only.
 
_display_froms_for_select(self, select, asfrom)
 
_generate_generic_binary(self, binary, opstring, **kw)
 
_generate_generic_unary_modifier(self, unary, opstring, **kw)
 
_generate_generic_unary_operator(self, unary, opstring, **kw)
 
_generate_prefixes(self, stmt, prefixes, **kw)
 
_init_cte_state(self, *args, **kw)
Initialize collections related to CTEs only if a CTE is located, to save on the overhead of these collections otherwise.
 
_is_toplevel_select(self, select)
Return True if the stack is placed at the given select, and is also the outermost SELECT, meaning there is either no stack before this one, or the enclosing stack is a topmost INSERT.
 
_key_getters_for_crud_column(...)
 
_label_select_column(self, select, column, populate_result_map, asfrom, column_clause_args, name=None, within_columns_clause=True)
produce labeled columns present in a select().
 
_like_percent_literal(...)
 
_nested_result(*args, **kwds)
special API to support the use case of 'nested result sets'
 
_process_anon(self, key)
 
_render_cte_clause(self)
 
_setup_select_hints(self, select)
 
_setup_select_stack(self, select, entry, asfrom)
 
_transform_result_map_for_nested_joins(self, select, transformed_select)
 
_transform_select_for_nested_joins(self, select)
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.
 
_truncate_bindparam(self, bindparam)
 
_truncated_identifier(self, ident_class, name)
 
bindparam_string(self, name, positional_names=None, **kw)
 
construct_params(self, params=None, _group_number=None, _check=True)
return a dictionary of bind parameter keys and values
 
default_from(self)
Called when a SELECT statement has no froms, and no FROM clause is to be appended.
 
escape_literal_column(self, text)
provide escaping for the literal_column() construct.
 
for_update_clause(self, select, **kw)
 
format_from_hint_text(self, sqltext, table, hint, iscrud)
 
function_argspec(self, func, **kwargs)
 
get_crud_hint_text(self, table, text)
 
get_cte_preamble(self, recursive)
 
get_from_hint_text(self, table, text)
 
get_render_as_alias_suffix(self, alias_name_text)
 
get_select_hint_text(self, byfroms)
 
get_select_precolumns(self, select, **kw)
Called when building a ``SELECT`` statement, position is just before column list.
 
get_statement_hint_text(self, hint_texts)
 
is_subquery(self)
 
limit_clause(self, select, **kw)
 
order_by_clause(self, select, **kw)
 
post_process_text(self, text)
 
render_literal_bindparam(self, bindparam, **kw)
 
render_literal_value(self, value, type_)
Render the value of a bind parameter as a quoted literal.
 
returning_clause(self, stmt, returning_cols)
 
update_from_clause(self, update_stmt, from_table, extra_froms, from_hints, **kw)
Provide a hook to override the generation of an UPDATE..FROM clause.
 
update_limit_clause(self, update_stmt)
Provide a hook for MySQL to add LIMIT to the UPDATE
 
update_tables_clause(self, update_stmt, from_table, extra_froms, **kw)
Provide a hook to override the initial table clause in an UPDATE statement.
 
visit_alias(self, alias, asfrom=False, ashint=False, iscrud=False, fromhints=None, **kwargs)
 
visit_between_op_binary(self, binary, operator, **kw)
 
visit_binary(self, binary, override_operator=None, **kw)
 
visit_bindparam(self, bindparam, within_columns_clause=False, literal_binds=False, skip_bind_expression=False, **kwargs)
 
visit_case(self, clause, **kwargs)
 
visit_cast(self, cast, **kwargs)
 
visit_clauselist(self, clauselist, **kw)
 
visit_column(self, column, add_to_result_map=None, include_table=True, **kwargs)
 
visit_compound_select(self, cs, asfrom=False, parens=True, compound_index=0, **kwargs)
 
visit_contains_op_binary(self, binary, operator, **kw)
 
visit_cte(self, cte, asfrom=False, ashint=False, fromhints=None, **kwargs)
 
visit_custom_op_binary(self, element, operator, **kw)
 
visit_custom_op_unary_modifier(self, element, operator, **kw)
 
visit_custom_op_unary_operator(self, element, operator, **kw)
 
visit_delete(self, delete_stmt, **kw)
 
visit_endswith_op_binary(self, binary, operator, **kw)
 
visit_extract(self, extract, **kwargs)
 
visit_false(self, expr, **kw)
 
visit_fromclause(self, fromclause, **kwargs)
 
visit_funcfilter(self, funcfilter, **kwargs)
 
visit_function(self, func, add_to_result_map=None, **kwargs)
 
visit_grouping(self, grouping, asfrom=False, **kwargs)
 
visit_ilike_op_binary(self, binary, operator, **kw)
 
visit_index(self, index, **kwargs)
 
visit_insert(self, insert_stmt, **kw)
 
visit_isfalse_unary_operator(self, element, operator, **kw)
 
visit_istrue_unary_operator(self, element, operator, **kw)
 
visit_join(self, join, asfrom=False, **kwargs)
 
visit_label(self, label, add_to_result_map=None, within_label_clause=False, within_columns_clause=False, render_label_as_label=None, **kw)
 
visit_label_reference(self, element, within_columns_clause=False, **kwargs)
 
visit_like_op_binary(self, binary, operator, **kw)
 
visit_next_value_func(self, next_value, **kw)
 
visit_notbetween_op_binary(self, binary, operator, **kw)
 
visit_notcontains_op_binary(self, binary, operator, **kw)
 
visit_notendswith_op_binary(self, binary, operator, **kw)
 
visit_notilike_op_binary(self, binary, operator, **kw)
 
visit_notlike_op_binary(self, binary, operator, **kw)
 
visit_notmatch_op_binary(self, binary, operator, **kw)
 
visit_notstartswith_op_binary(self, binary, operator, **kw)
 
visit_null(self, expr, **kw)
 
visit_over(self, over, **kwargs)
 
visit_release_savepoint(self, savepoint_stmt)
 
visit_rollback_to_savepoint(self, savepoint_stmt)
 
visit_savepoint(self, savepoint_stmt)
 
visit_select(self, select, asfrom=False, parens=True, fromhints=None, compound_index=0, nested_join_translation=False, select_wraps_for=None, **kwargs)
 
visit_sequence(self, sequence)
 
visit_startswith_op_binary(self, binary, operator, **kw)
 
visit_table(self, table, asfrom=False, iscrud=False, ashint=False, fromhints=None, use_schema=True, **kwargs)
 
visit_text_as_from(self, taf, compound_index=None, asfrom=False, parens=True, **kw)
 
visit_textclause(self, textclause, **kw)
 
visit_textual_label_reference(self, element, within_columns_clause=False, **kwargs)
 
visit_true(self, expr, **kw)
 
visit_typeclause(self, typeclause, **kw)
 
visit_unary(self, unary, **kw)
 
visit_update(self, update_stmt, **kw)

Inherited from Compiled: __str__, compile, execute, process, scalar

Inherited from Compiled (private): _execute_on_connection

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Variables [hide private]
  _default_stack_entry = immutabledict({'asfrom_froms': frozense...
  ansi_bind_rules = False
  compound_keywords = {symbol('UNION'): 'UNION', symbol('INTERSE...
  extract_map = {'day': 'day', 'dow': 'dow', 'doy': 'doy', 'epoc...
  isdelete = False
  isinsert = False
  isplaintext = False
  isupdate = False
  render_table_with_column_in_update_from = False
  returning = None
hash(x)
  returning_precedes_values = False

Inherited from Compiled (private): _cached_metadata

Properties [hide private]
  params
Return the bind param dictionary embedded into this compiled object, for those values that are present.
  sql_compiler
Return a Compiled that is capable of processing SQL expressions.

Inherited from object: __class__

Method Details [hide private]

__init__(self, dialect, statement, column_keys=None, inline=False, **kwargs)
(Constructor)

 
Construct a new ``DefaultCompiler`` object.

dialect
  Dialect to be used

statement
  ClauseElement to be compiled

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

Overrides: object.__init__

_transform_select_for_nested_joins(self, select)

 

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 the main one).

construct_params(self, params=None, _group_number=None, _check=True)

 

return a dictionary of bind parameter keys and values

Overrides: Compiled.construct_params

default_from(self)

 

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.

render_literal_value(self, value, type_)

 

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.

update_from_clause(self, update_stmt, from_table, extra_froms, from_hints, **kw)

 

Provide a hook to override the generation of an UPDATE..FROM clause.

MySQL and MSSQL override this.

update_tables_clause(self, update_stmt, from_table, extra_froms, **kw)

 

Provide a hook to override the initial table clause in an UPDATE statement.

MySQL overrides this.


Class Variable Details [hide private]

_default_stack_entry

Value:
immutabledict({'asfrom_froms': frozenset([]), 'correlate_froms': froze\
nset([])})

compound_keywords

Value:
{symbol('UNION'): 'UNION',
 symbol('INTERSECT'): 'INTERSECT',
 symbol('UNION ALL'): 'UNION ALL',
 symbol('EXCEPT ALL'): 'EXCEPT ALL',
 symbol('EXCEPT'): 'EXCEPT',
 symbol('INTERSECT ALL'): 'INTERSECT ALL'}

extract_map

Value:
{'day': 'day',
 'dow': 'dow',
 'doy': 'doy',
 'epoch': 'epoch',
 'hour': 'hour',
 'microseconds': 'microseconds',
 'milliseconds': 'milliseconds',
 'minute': 'minute',
...

Property Details [hide private]

params

Return the bind param dictionary embedded into this compiled object, for those values that are present.

Get Method:
unreachable.params(self) - Return the bind param dictionary embedded into this compiled object, for those values that are present.

sql_compiler

Return a Compiled that is capable of processing SQL expressions.

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

Get Method:
unreachable.sql_compiler(self)