diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-12-08 18:58:03 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-12-08 18:58:03 +0000 |
commit | 8693d4b2876e9239cf48bbc42a7ffaa11c01b506 (patch) | |
tree | 6438a7f4a319c4e1f25376fb004de6fb73bfd7c0 /lib/sqlalchemy/sql/compiler.py | |
parent | 78bb82a44b7f382c6cfeab0cfc7f932e68c4de86 (diff) | |
download | sqlalchemy-8693d4b2876e9239cf48bbc42a7ffaa11c01b506.tar.gz |
- flush() refactor merged from uow_nontree branch r3871-r3885
- topological.py cleaned up, presents three public facing functions which
return list/tuple based structures, without exposing any internals. only
the third function returns the "hierarchical" structure. when results
include "cycles" or "child" items, 2- or 3- tuples are used to represent
results.
- unitofwork uses InstanceState almost exclusively now. new and deleted lists
are now dicts which ref the actual object to provide a strong ref for the
duration that they're in those lists. IdentitySet is only used for the public
facing versions of "new" and "deleted".
- unitofwork topological sort no longer uses the "hierarchical" version of the sort
for the base sort, only for the "per-object" secondary sort where it still
helps to group non-dependent operations together and provides expected insert
order. the default sort deals with UOWTasks in a straight list and is greatly
simplified. Tests all pass but need to see if svilen's stuff still works,
one block of code in _sort_cyclical_dependencies() seems to not be needed anywhere
but i definitely put it there for a reason at some point; if not hopefully we
can derive more test coverage from that.
- the UOWEventHandler is only applied to object-storing attributes, not
scalar (i.e. column-based) ones. cuts out a ton of overhead when setting
non-object based attributes.
- InstanceState also used throughout the flush process, i.e. dependency.py,
mapper.save_obj()/delete_obj(), sync.execute() all expect InstanceState objects
in most cases now.
- mapper/property cascade_iterator() takes InstanceState as its argument,
but still returns lists of object instances so that they are not dereferenced.
- a few tricks needed when dealing with InstanceState, i.e. when loading a list
of items that are possibly fresh from the DB, you *have* to get the actual objects
into a strong-referencing datastructure else they fall out of scope immediately.
dependency.py caches lists of dependent objects which it loads now (i.e. history
collections).
- AttributeHistory is gone, replaced by a function that returns a 3-tuple of
added, unchanged, deleted. these collections still reference the object
instances directly for the strong-referencing reasons mentiontioned, but
it uses less IdentitySet logic to generate.
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 94950b872..3af8f97ca 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -459,10 +459,7 @@ class DefaultCompiler(engine.Compiled): stack_entry = {'select':select} - if asfrom: - stack_entry['is_subquery'] = True - column_clause_args = {} - elif self.stack and 'select' in self.stack[-1]: + if asfrom or (self.stack and 'select' in self.stack[-1]): stack_entry['is_subquery'] = True column_clause_args = {} else: @@ -546,6 +543,7 @@ class DefaultCompiler(engine.Compiled): def get_select_precolumns(self, select): """Called when building a ``SELECT`` statement, position is just before column list.""" + return select._distinct and "DISTINCT " or "" def order_by_clause(self, select): @@ -624,8 +622,8 @@ class DefaultCompiler(engine.Compiled): self.binds[col.key] = bindparam return self.bindparam_string(self._truncate_bindparam(bindparam)) - self.postfetch = util.Set() - self.prefetch = util.Set() + self.postfetch = [] + self.prefetch = [] # no parameters in the statement, no parameters in the # compiled params - return binds for all columns @@ -651,7 +649,7 @@ class DefaultCompiler(engine.Compiled): if sql._is_literal(value): value = create_bind_param(c, value) else: - self.postfetch.add(c) + self.postfetch.append(c) value = self.process(value.self_group()) values.append((c, value)) elif isinstance(c, schema.Column): @@ -663,35 +661,35 @@ class DefaultCompiler(engine.Compiled): (c.default is not None and not isinstance(c.default, schema.Sequence))): values.append((c, create_bind_param(c, None))) - self.prefetch.add(c) + self.prefetch.append(c) elif isinstance(c.default, schema.ColumnDefault): if isinstance(c.default.arg, sql.ClauseElement): values.append((c, self.process(c.default.arg.self_group()))) if not c.primary_key: # dont add primary key column to postfetch - self.postfetch.add(c) + self.postfetch.append(c) else: values.append((c, create_bind_param(c, None))) - self.prefetch.add(c) + self.prefetch.append(c) elif isinstance(c.default, schema.PassiveDefault): if not c.primary_key: - self.postfetch.add(c) + self.postfetch.append(c) elif isinstance(c.default, schema.Sequence): proc = self.process(c.default) if proc is not None: values.append((c, proc)) if not c.primary_key: - self.postfetch.add(c) + self.postfetch.append(c) elif self.isupdate: if isinstance(c.onupdate, schema.ColumnDefault): if isinstance(c.onupdate.arg, sql.ClauseElement): values.append((c, self.process(c.onupdate.arg.self_group()))) - self.postfetch.add(c) + self.postfetch.append(c) else: values.append((c, create_bind_param(c, None))) - self.prefetch.add(c) + self.prefetch.append(c) elif isinstance(c.onupdate, schema.PassiveDefault): - self.postfetch.add(c) + self.postfetch.append(c) return values def visit_delete(self, delete_stmt): |