예제 #1
0
    def _mapper_for_dep(self):
        """return a dynamic mapping of (Mapper, DependencyProcessor) to 
        True or False, indicating if the DependencyProcessor operates 
        on objects of that Mapper.

        The result is stored in the dictionary persistently once
        calculated.

        """
        return util.PopulateDict(
            lambda tup: tup[0]._props.get(tup[1].key) is tup[1].prop)
예제 #2
0
    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.

        """
        engine.Compiled.__init__(self, dialect, statement, column_keys, **kwargs)

        # compile INSERT/UPDATE defaults/sequences inlined (no pre-execute)
        self.inline = inline or getattr(statement, 'inline', False)

        # a dictionary of bind parameter keys to _BindParamClause instances.
        self.binds = {}

        # a dictionary of _BindParamClause instances to "compiled" names that are
        # actually present in the generated SQL
        self.bind_names = util.column_dict()

        # stack which keeps track of nested SELECT statements
        self.stack = []

        # relates label names in the final SQL to
        # a tuple of local column/label name, ColumnElement object (if any) and TypeEngine.
        # ResultProxy uses this for type processing and column targeting
        self.result_map = {}

        # true if the paramstyle is positional
        self.positional = self.dialect.positional
        if self.positional:
            self.positiontup = []

        self.bindtemplate = BIND_TEMPLATES[self.dialect.paramstyle]

        # an IdentifierPreparer that formats the quoting of identifiers
        self.preparer = self.dialect.identifier_preparer

        self.label_length = self.dialect.label_length or self.dialect.max_identifier_length
        
        # a map which tracks "anonymous" identifiers that are
        # created on the fly here
        self.anon_map = util.PopulateDict(self._process_anon)

        # a map which tracks "truncated" names based on dialect.label_length
        # or dialect.max_identifier_length
        self.truncated_names = {}
예제 #3
0
def row_adapter(from_, equivalent_columns=None):
    """create a row adapter callable against a selectable."""

    if equivalent_columns is None:
        equivalent_columns = {}

    def locate_col(col):
        c = from_.corresponding_column(col)
        if c:
            return c
        elif col in equivalent_columns:
            for c2 in equivalent_columns[col]:
                corr = from_.corresponding_column(c2)
                if corr:
                    return corr
        return col

    map = util.PopulateDict(locate_col)

    def adapt(row):
        return AliasedRow(row, map)

    return adapt
예제 #4
0
    def resolve_arg(arg):
        import sqlalchemy
        
        def access_cls(key):
            try:
                return _GetColumns(cls._decl_class_registry[key])
            except KeyError:
                return sqlalchemy.__dict__[key]

        d = util.PopulateDict(access_cls)
        def return_cls():
            try:
                x = eval(arg, globals(), d)
                
                if isinstance(x, _GetColumns):
                    return x.cls
                else:
                    return x
            except NameError, n:
                raise exceptions.InvalidRequestError(
                    "When compiling mapper %s, expression %r failed to locate a name (%r). "
                    "If this is a class name, consider adding this relation() to the %r "
                    "class after both dependent classes have been defined." % (
                    prop.parent, arg, n.args[0], cls))
예제 #5
0
 def __setstate__(self, state):
     self.__dict__.update(state)
     self.columns = util.PopulateDict(self._locate_col)
예제 #6
0
def _cached_connection_dict(base_mapper):
    # dictionary of connection->connection_with_cache_options.
    return util.PopulateDict(
        lambda conn:conn.execution_options(
        compiled_cache=base_mapper._compiled_cache
    ))