Commit Graph

75 Commits

Author SHA1 Message Date
Mike Bayer bb5f4392a4 - update the flake8 rules again
- apply autopep8 + manual fixes to most of test/sql/
2014-07-18 17:40:58 -04:00
Mike Bayer e6cbd88fe1 - Fixed bug in SQLite join rewriting where anonymized column names
due to repeats would not correctly be rewritten in subqueries.
This would affect SELECT queries with any kind of subquery + join.
fixes #3057
2014-05-25 11:32:07 -04:00
Alex Gaynor 1caa7fafbd Fix many typos throughout the codebase
Found using: https://github.com/intgr/topy
2014-04-26 13:13:13 -07:00
Mike Bayer 9c731b2ebf - add further coverage for join_condition to make sure we get this case where
there are multiple, equivalent foreign keys
2014-03-28 16:41:08 -04:00
Mike Bayer 302ad6228a - Some changes to how the :attr:.FromClause.c collection behaves
when presented with duplicate columns.  The behavior of emitting a
warning and replacing the old column with the same name still
remains to some degree; the replacement in particular is to maintain
backwards compatibility.  However, the replaced column still remains
associated with the ``c`` collection now in a collection ``._all_columns``,
which is used by constructs such as aliases and unions, to deal with
the set of columns in ``c`` more towards what is actually in the
list of columns rather than the unique set of key names.  This helps
with situations where SELECT statements with same-named columns
are used in unions and such, so that the union can match the columns
up positionally and also there's some chance of :meth:`.FromClause.corresponding_column`
still being usable here (it can now return a column that is only
in selectable.c._all_columns and not otherwise named).
The new collection is underscored as we still need to decide where this
list might end up.   Theoretically it
would become the result of iter(selectable.c), however this would mean
that the length of the iteration would no longer match the length of
keys(), and that behavior needs to be checked out.
fixes #2974
- add a bunch more tests for ColumnCollection
2014-02-26 15:34:49 -05:00
Mike Bayer bf67069d26 - Fixed issue in new :meth:.TextClause.columns method where the ordering
of columns given positionally would not be preserved.   This could
have potential impact in positional situations such as applying the
resulting :class:`.TextAsFrom` object to a union.
2014-02-26 13:28:14 -05:00
Mike Bayer bf934018a5 - for TextAsFrom, put the "inner" columns in the result map directly.
Have also considered linking column.label() to the "column" itself being
in the result map but this reveals some naming collision problems (that
also seem to be very poorly tested...).   This should be as far as
we want to go right now with [ticket:2932].
2014-02-10 19:17:00 -05:00
Mike Bayer 15b23c7f71 - Fixed an 0.9 regression where the automatic aliasing applied by
:class:`.Query` and in other situations where selects or joins
were aliased (such as joined table inheritance) could fail if a
user-defined :class:`.Column` subclass were used in the expression.
In this case, the subclass would fail to propagate ORM-specific
"annotations" along needed by the adaptation.  The "expression
annotations" system has been corrected to account for this case.
[ticket:2918]
2014-01-23 14:49:04 -05:00
Mike Bayer 31cecebd48 - add support for specifying tables or entities for "of"
- implement Query with_for_update()
- rework docs and tests
2013-11-28 23:23:27 -05:00
Mike Bayer 4aaf3753d7 - fix up rendering of "of"
- move out tests, dialect specific out of compiler, compiler tests use new API,
legacy API tests in test_selecatble
- add support for adaptation of ForUpdateArg, alias support in compilers
2013-11-28 22:25:09 -05:00
Mike Bayer e74627f827 A :func:.select that is made to refer to itself in its FROM clause,
typically via in-place mutation, will raise an informative error
message rather than causing a recursion overflow.
[ticket:2815]
2013-10-08 20:06:58 -04:00
Mike Bayer 9df4651fba Fixed bug where using an annotation such as :func:.remote or
:func:`.foreign` on a :class:`.Column` before association with a parent
:class:`.Table` could produce issues related to the parent table not
rendering within joins, due to the inherent copy operation performed
by an annotation. [ticket:2813]
2013-10-08 19:47:13 -04:00
Mike Bayer 0ca7b53b42 Fixed bug where the expression system relied upon the `str()`
form of a some expressions when referring to the ``.c`` collection
on a ``select()`` construct, but the ``str()`` form isn't available
since the element relies on dialect-specific compilation constructs,
notably the ``__getitem__()`` operator as used with a Postgresql
``ARRAY`` element.  The fix also adds a new exception class
:class:`.UnsupportedCompilationError` which is raised in those cases
where a compiler is asked to compile something it doesn't know
how to.  Also in 0.8.3.
[ticket:2780]
2013-07-12 11:32:34 -04:00
Mike Bayer f76cae4bc9 - rework of correlation, continuing on #2668, #2746
- add support for correlations to propagate all the way in; because
correlations require context now, need to make sure a select enclosure
of any level takes effect any number of levels deep.
- fix what we said correlate_except() was supposed to do when we first
released #2668 - "the FROM clause is left intact if the correlated SELECT
is not used in the context of an enclosing SELECT..." - it was not
considering the "existing_froms" collection at all, and prohibited
additional FROMs from being placed in an any() or has().
- add test for multilevel any()
- lots of docs, including glossary entries as we really need to define
"WHERE clause", "columns clause" etc. so that we can explain correlation better
- based on the insight that a SELECT can correlate anything that ultimately
came from an enclosing SELECT that links to this one via WHERE/columns/HAVING/ORDER BY,
have the compiler keep track of the FROM lists that correspond in this way,
link it to the asfrom flag, so that we send to _get_display_froms() the exact
list of candidate FROMs to correlate.  no longer need any asfrom logic in the
Select() itself
- preserve 0.8.1's behavior for correlation when no correlate options are given, not
to mention 0.7 and prior's behavior of not propagating implicit correlation more than one level..
this is to reduce surprises/hard-to-debug situations when a user isn't trying
to correlate anything.
2013-06-26 13:19:45 -04:00
Mike Bayer e288aff8ea The resolution of :class:.ForeignKey objects to their
target :class:`.Column` has been reworked to be as
immediate as possible, based on the moment that the
target :class:`.Column` is associated with the same
:class:`.MetaData` as this :class:`.ForeignKey`, rather
than waiting for the first time a join is constructed,
or similar. This along with other improvements allows
earlier detection of some foreign key configuration
issues.  Also included here is a rework of the
type-propagation system, so that
it should be reliable now to set the type as ``None``
on any :class:`.Column` that refers to another via
:class:`.ForeignKey` - the type will be copied from the
target column as soon as that other column is associated,
and now works for composite foreign keys as well.
[ticket:1765]
2013-06-23 15:58:07 -04:00
Mike Bayer 31063d16f2 - tests for the alias() API
- docs docs docs
2013-06-08 18:41:59 -04:00
Mike Bayer 1188edccf6 fix test 2013-06-06 18:53:44 -04:00
Mike Bayer 26ec0507be Merge branch 'ticket_2587'
Conflicts:
	test/profiles.txt
	test/sql/test_selectable.py
2013-06-04 21:38:56 -04:00
Mike Bayer 66b8ed40c3 repair these tests now that we allow join from selectable to fromgrouping 2013-06-04 18:58:24 -04:00
Mike Bayer 8a865a4d1f Fixed bug whereby joining a select() of a table "A" with multiple
foreign key paths to a table "B", to that table "B", would fail
to produce the "ambiguous join condition" error that would be
reported if you join table "A" directly to "B"; it would instead
produce a join condition with multiple criteria.
[ticket:2738]
2013-06-03 17:03:15 -04:00
Mike Bayer 2ddcd20267 Merge branch 'master' into rel_0_9 2013-05-26 17:18:27 -04:00
Mike Bayer e2b8c893ca fix this test 2013-05-26 17:18:04 -04:00
Mike Bayer 4b614b9b35 - the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
2013-04-27 19:53:57 -04:00
Mike Bayer a5ede47f12 A major fix to the way in which a select() object produces
labeled columns when apply_labels() is used; this mode
produces a SELECT where each column is labeled as in
<tablename>_<columnname>, to remove column name collisions
for a multiple table select.   The fix is that if two labels
collide when combined with the table name, i.e.
"foo.bar_id" and "foo_bar.id", anonymous aliasing will be
applied to one of the dupes.  This allows the ORM to handle
both columns independently; previously, 0.7
would in some cases silently emit a second SELECT for the
column that was "duped", and in 0.8 an ambiguous column error
would be emitted.   The "keys" applied to the .c. collection
of the select() will also be deduped, so that the "column
being replaced" warning will no longer emit for any select()
that specifies use_labels, though the dupe key will be given
an anonymous label which isn't generally user-friendly.
[ticket:2702]
2013-04-11 16:14:23 -04:00
Mike Bayer af44efe26e Fixed a bug regarding column annotations which in particular
could impact some usages of the new :func:`.orm.remote` and
:func:`.orm.local` annotation functions, where annotations
could be lost when the column were used in a subsequent
expression.
[ticket:2660]
2013-02-02 20:06:31 -05:00
Mike Bayer eea0ca9fb4 cleanup and pep8 2013-02-02 19:57:45 -05:00
Mike Bayer 4950b85e83 - BinaryExpression now keeps track of "left" and "right" as passed in,
so that they can be compared in ``__nonzero__`` prior to their
self_group() step.  [ticket:2621]
2012-12-02 12:37:52 -05:00
Mike Bayer 6397a4ff4b Fixed bug in type_coerce() whereby typing information
could be lost if the statement were used as a subquery
inside of another statement, as well as other similar
situations.  Among other things, would cause
typing information to be lost when the Oracle/mssql dialects
would apply limit/offset wrappings. [ticket:2603]
2012-11-12 15:48:40 -05:00
Mike Bayer d30ab8495c Fixed bug whereby the ".key" of a Column wasn't being
used when producing a "proxy" of the column against
a selectable.   This probably didn't occur in 0.7
since 0.7 doesn't respect the ".key" in a wider
range of scenarios. [ticket:2597]
2012-10-31 14:30:47 -04:00
Mike Bayer a13812606c - remove remote_foreign annotation
- support annotations on Column where name isn't immediately present
2012-10-28 18:23:57 -04:00
Mike Bayer c307df6596 - [feature] "scalar" selects now have a WHERE method
to help with generative building.  Also slight adjustment
    regarding how SS "correlates" columns; the new methodology
    no longer applies meaning to the underlying
    Table column being selected.  This improves
    some fairly esoteric situations, and the logic
    that was there didn't seem to have any purpose.
  - [feature] Some support for auto-rendering of a
    relationship join condition based on the mapped
    attribute, with usage of core SQL constructs.
    E.g. select([SomeClass]).where(SomeClass.somerelationship)
    would render SELECT from "someclass" and use the
    primaryjoin of "somerelationship" as the WHERE
    clause.   This changes the previous meaning
    of "SomeClass.somerelationship" when used in a
    core SQL context; previously, it would "resolve"
    to the parent selectable, which wasn't generally
    useful.  Related to [ticket:2245].
2012-10-15 17:21:38 -04:00
Mike Bayer 20cdc64588 trying different approaches to test layout. in this one, the testing modules
become an externally usable package but still remains within the main sqlalchemy parent package.
in this system, we use kind of an ugly hack to get the noseplugin imported outside of the
"sqlalchemy" package, while still making it available within sqlalchemy for usage by
third party libraries.
2012-09-27 02:37:33 -04:00
Mike Bayer 824bd66158 - aaaaand fix one more glitch I just thought of 2012-08-18 01:03:31 -04:00
Mike Bayer 54808ecccd - [bug] Declarative can now propagate a column
declared on a single-table inheritance subclass
up to the parent class' table, when the parent
class is itself mapped to a join() or select()
statement, directly or via joined inheritane,
and not just a Table.   [ticket:2549]
2012-08-15 18:42:59 -04:00
Mike Bayer f839b89270 - [feature] Added reduce_columns() method
to select() construct, replaces columns inline
    using the util.reduce_columns utility function
    to remove equivalent columns.  reduce_columns()
    also adds "with_only_synonyms" to limit the
    reduction just to those columns which have the same
    name.  The deprecated fold_equivalents() feature is
    removed [ticket:1729].
  - [feature] Added with_labels and
    reduce_columns keyword arguments to
    Query.subquery(), to provide two alternate
    strategies for producing queries with uniquely-
    named columns.  [ticket:1729].
2012-07-28 17:12:09 -04:00
Mike Bayer 27913554a8 trailing whitespace bonanza 2012-07-28 15:50:05 -04:00
Mike Bayer de115ae406 - a big renaming of all the _Underscore classes to have
plain names.  The old names are still defined for
backwards compatibility.
- _BindParamClause renamed to BindParameter
2012-07-17 20:04:22 -04:00
Mike Bayer 81eefb2f13 - [bug] Fixed regression introduced in 0.7.6
whereby the FROM list of a SELECT statement
could be incorrect in certain "clone+replace"
scenarios.  [ticket:2518]
2012-06-21 14:55:04 -04:00
Mike Bayer 6a48ce44f4 - [bug] Fixed bug whereby append_column()
wouldn't function correctly on a cloned
select() construct, courtesy
Gunnlaugur Por Briem.  [ticket:2482]
Also in 0.7.8.
2012-06-16 19:02:48 -04:00
Mike Bayer 503bddc879 - [bug] column.label(None) now produces an
anonymous label, instead of returning the
column object itself, consistent with the behavior
of label(column, None).  [ticket:2168]
2012-04-24 13:04:38 -04:00
Mike Bayer 9b73e997b2 - [bug] The names of the columns on the
.c. attribute of a select().apply_labels()
is now based on <tablename>_<colkey> instead
of <tablename>_<colname>, for those columns
that have a distinctly named .key.
[ticket:2397]
2012-04-24 11:24:23 -04:00
Mike Bayer 713a4e19fa - merged #1401 branch from bitbucket
- resolved some serious speed hits I missed, we need to ensure
only deannotated columns are used in the local/remote collections and soforth
so that hash lookups against mapped columns don't dig into __eq__()
- fix some other parity mismatches regarding stuff from [ticket:2453],
including finding another case where _deep_annotate() was doing the wrong thing,
new tests.
- [feature] Major rewrite of relationship()
internals now allow join conditions which
include columns pointing to themselves
within composite foreign keys.   A new
API for very specialized primaryjoin conditions
is added, allowing conditions based on
SQL functions, CAST, etc. to be handled
by placing the annotation functions
remote() and foreign() inline within the
expression when necessary.  Previous recipes
using the semi-private _local_remote_pairs
approach can be upgraded to this new
approach. [ticket:1401]
2012-04-22 19:43:31 -04:00
Mike Bayer 1378bf0d25 - reopened #2453, needed to put in the original patch as well to cover the case
of column_property() objs building off each other
2012-04-03 09:59:22 -04:00
Mike Bayer 45046367f3 - [bug] Fixed bug in expression annotation
mechanics which could lead to incorrect
rendering of SELECT statements with aliases
and joins, particularly when using
column_property().  [ticket:2453]
2012-03-31 13:35:05 -04:00
Mike Bayer 57868f587e - [bug] Fixed bug whereby a primaryjoin
condition with a "literal" in it would
raise an error on compile with certain
kinds of deeply nested expressions
which also needed to render the same
bound parameter name more than once.
[ticket:2425]
2012-03-12 13:35:27 -07:00
Mike Bayer d934ea23e2 - figured out again why deannotate must clone()
- got everything working.  just need to update
error strings
2012-02-11 20:33:56 -05:00
Mike Bayer bc45fa350a - got m2m, local_remote_pairs, etc. working
- using new traversal that returns the product of both sides
of a binary, starting to work with (a+b) == (c+d) types of joins.
primaryjoins on functions working
- annotations working, including reversing local/remote when
doing backref
2012-02-09 21:16:53 -05:00
Mike Bayer 73f734bf80 initial annotations approach to join conditions. all tests pass, plus additional tests in #1401 pass.
would now like to reorganize RelationshipProperty more around the annotations concept.
2012-02-06 12:20:15 -05:00
Mike Bayer 2dbeeff50b - [bug] Added support for using the .key
of a Column as a string identifier in a
result set row.   The .key is currently
listed as an "alternate" name for a column,
and is superseded by the name of a column
which has that key value as its regular name.
For the next major release
of SQLAlchemy we may reverse this precedence
so that .key takes precedence, but this
is not decided on yet.  [ticket:2392]
2012-02-05 16:58:32 -05:00
Mike Bayer 699146086d - [bug] Fixed bug whereby column_property() created
against ORM-level column could be treated as
a distinct entity when producing certain
kinds of joined-inh joins.  [ticket:2316]

- [bug] related to [ticket:2316], made some
adjustments to the change from [ticket:2261]
regarding the "from" list on a select(). The
_froms collection is no longer memoized, as this
simplifies various use cases and removes the
need for a "warning" if a column is attached
to a table after it was already used in an
expression - the select() construct will now
always produce the correct expression.
There's probably no real-world
performance hit here; select() objects are
almost always made ad-hoc, and systems that
wish to optimize the re-use of a select()
would be using the "compiled_cache" feature.
A hit which would occur when calling select.bind
has been reduced, but the vast majority
of users shouldn't be using "bound metadata"
anyway :).
2011-12-03 19:50:01 -05:00