SQLAlchemy 0.4 Documentation - module sqlalchemy.sql.compiler

# SQLAlchemy 0.4 Documentation

Multiple Pages | One Page
Version: 0.4.6 Last Updated: 05/14/08 14:36:43

### module sqlalchemy.sql.compiler

Base SQL and DDL compiler implementations.

Provides the DefaultCompiler class, which is responsible for generating all SQL query strings, as well as SchemaGenerator and SchemaDropper which issue CREATE and DROP DDL for tables, sequences, and indexes.

The elements in this module are used by public-facing constructs like ClauseElement and Engine. While dialect authors will want to be familiar with this module for the purpose of creating database-specific compilers and schema generators, the module is otherwise internal to SQLAlchemy.

### class DDLBase(SchemaIterator)

def find_alterables(self, tables)
back to section top

### class DefaultCompiler(Compiled)

Default implementation of Compiled.

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

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

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.

def bindparam_string(self, name)
def compile(self)
def construct_params(self, params=None)

return a dictionary of bind parameter keys and values

def 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.

def escape_literal_column(self, text)

provide escaping for the literal_column() construct.

def for_update_clause(self, select)
def function_argspec(self, func)
def function_string(self, func)
def get_select_precolumns(self, select)

Called when building a `SELECT` statement, position is just before column list.

def is_subquery(self, select)
def label_select_column(self, select, column, asfrom)

label columns present in a select().

def limit_clause(self, select)
def operator_string(self, operator)
def order_by_clause(self, select)
params = property()

return a dictionary of bind parameter keys and values

def process(self, obj, stack=None, **kwargs)
def visit_alias(self, alias, asfrom=False, **kwargs)
def visit_binary(self, binary, **kwargs)
def visit_bindparam(self, bindparam, **kwargs)
def visit_calculatedclause(self, clause, **kwargs)
def visit_cast(self, cast, **kwargs)
def visit_clauselist(self, clauselist, **kwargs)
def visit_column(self, column, result_map=None, **kwargs)
def visit_compound_select(self, cs, asfrom=False, parens=True, **kwargs)
def visit_delete(self, delete_stmt)
def visit_fromclause(self, fromclause, **kwargs)
def visit_function(self, func, result_map=None, **kwargs)
def visit_grouping(self, grouping, **kwargs)
def visit_index(self, index, **kwargs)
def visit_insert(self, insert_stmt)
def visit_join(self, join, asfrom=False, **kwargs)
def visit_label(self, label, result_map=None)
def visit_null(self, null, **kwargs)
def visit_release_savepoint(self, savepoint_stmt)
def visit_rollback_to_savepoint(self, savepoint_stmt)
def visit_savepoint(self, savepoint_stmt)
def visit_select(self, select, asfrom=False, parens=True, iswrapper=False, **kwargs)
def visit_sequence(self, seq)
def visit_table(self, table, asfrom=False, **kwargs)
def visit_textclause(self, textclause, **kwargs)
def visit_typeclause(self, typeclause, **kwargs)
def visit_unary(self, unary, **kwargs)
def visit_update(self, update_stmt)
back to section top

### class IdentifierPreparer(object)

Handle quoting and case-folding of identifiers based on options.

def __init__(self, dialect, initial_quote='"', final_quote=None, omit_schema=False)

Construct a new `IdentifierPreparer` object.

initial_quote
  Character that begins a delimited identifier.
final_quote
  Character that ends a delimited identifier. Defaults to initial_quote.
omit_schema
  Prevent prepending schema name. Useful for databases that do not support schemae.

def format_alias(self, alias, name=None)
def format_column(self, column, use_table=False, name=None, table_name=None)

Prepare a quoted column name.

deprecated. use preparer.quote(col, column.name) or combine with format_table()

def format_constraint(self, constraint)
def format_index(self, index)
def format_label(self, label, name=None)
def format_savepoint(self, savepoint, name=None)
def format_sequence(self, sequence, use_schema=True)
def format_table(self, table, use_schema=True, name=None)

Prepare a quoted table and schema name.

def format_table_seq(self, table, use_schema=True)

Format table name and schema as a tuple.

def quote(self, obj, ident)
def quote_identifier(self, value)

Quote an identifier.

Subclasses should override this to provide database-dependent quoting behavior.

def should_quote(self, object)
def unformat_identifiers(self, identifiers)

Unpack 'schema.table.column'-like strings into components.

back to section top

### class SchemaDropper(DDLBase)

def __init__(self, dialect, connection, checkfirst=False, tables=None, **kwargs)

Construct a new `SchemaDropper`.

def drop_foreignkey(self, constraint)
def visit_index(self, index)
def visit_metadata(self, metadata)
def visit_table(self, table)
back to section top

### class SchemaGenerator(DDLBase)

def __init__(self, dialect, connection, checkfirst=False, tables=None, **kwargs)

Construct a new `SchemaGenerator`.

def add_foreignkey(self, constraint)
def define_constraint_deferrability(self, constraint)
def define_foreign_key(self, constraint)
def get_column_default_string(self, column)
def get_column_specification(self, column, first_pk=False)
def post_create_table(self, table)
def visit_check_constraint(self, constraint)
def visit_column(self, column)
def visit_column_check_constraint(self, constraint)
def visit_foreign_key_constraint(self, constraint)
def visit_index(self, index)
def visit_metadata(self, metadata)
def visit_primary_key_constraint(self, constraint)
def visit_table(self, table)
def visit_unique_constraint(self, constraint)
back to section top