summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
AgeCommit message (Collapse)Author
2008-09-11A bug from queryset-refactor days: although the Query class has "group_by" andMalcolm Tredinnick
"having" attributes, only the former was included in the resulting SQL, meaning subclasses had to completely duplicate Query.as_sql() if they were using any kind of grouping filtering on the results. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9007 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-09-03Fixed #8819 -- Don't include two copies of extra-select columns in the query.Malcolm Tredinnick
This was triggered by r8794, but was, in fact, fairly fragile before then. The current fix is the correct way we should be doing this. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8898 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-09-02Fixed #8790 -- Multi-branch join trees that shared tables of the same name wereMalcolm Tredinnick
sometimes also sharing aliases, instead of creating their own. This was generating incorrect SQL. No representative test for this fix yet because I haven't had time to write one that fits in nicely with the test suite. But it works for the monstrous example in #8790 and a bunch of other complex examples I've created locally. Will write a test later. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8853 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-09-02Fixed #8439 -- Complex combinations of Q-objects (using both conjunctions andMalcolm Tredinnick
disjunctions) were producing incorrect SQL when nullable relations were involved. This fixes that. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8832 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-09-02A typo fix that fortunately wasn't creating invalid SQL, just slightly lessMalcolm Tredinnick
efficient than possible SQL in some odd cases (found via code inspection, not any particular failing example). git-svn-id: http://code.djangoproject.com/svn/django/trunk@8831 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-09-02Get the join promotion code (a bit more) correct when constructing joins for ↵Malcolm Tredinnick
ordering. Yes, this really is a commit that fixes an oversight in a commit that fixed an oversight. One day I'll get it right. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8829 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-09-01Replaced exact lookups of the empty string with isnull lookups in Oracle. ↵Ian Kelly
Fixes the testPreventDuplicateComments case. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8827 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-09-01Fixed #7302: Corrected quoting of columns in extra_group_by. Thanks to Ivan ↵Russell Keith-Magee
Sagalaev for the patch and initial test. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8794 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-09-01Fixed #7512 -- Fixed an oversight when I first fixed ordering on nullableMalcolm Tredinnick
foreign keys (r7761). Thanks to George Vilches for the test case here. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8783 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-08-28Improvements to [8608] to fix an infinite loop (for exclude(generic_relation)).Malcolm Tredinnick
Also comes with approximately 67% less stupidity in the table joins for filtering on generic relations. Fixed #5937, hopefully for good, this time. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8644 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-08-27Fixed #5937 -- When filtering on generic relations, restrict the target ↵Malcolm Tredinnick
objects to those with the right content type. This isn't a complete solution to this class of problem, but it will do for 1.0, which only has generic relations as a multicolumn type. A more general multicolumn solution will be available after that release. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8608 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-08-25Fixed #8106 -- Untangled some problems with complex select_related() queriesMalcolm Tredinnick
and models that have multiple paths to them from other models. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8559 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-08-22Fixed #8046 -- The first filter() call on a related manager for many-to-manyMalcolm Tredinnick
fields no longer creates duplicate copies of the join table(s). Basically, this means filters on the join table (for ManyToManyField(through=...)) and complex filters in the normal (non-through) case don't produce incorrect or duplicate results. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8472 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-08-17Fixed #8039 -- Make sure that extra(tables=...) tables are always included inMalcolm Tredinnick
the resulting SQL. Previously, an optimisation was removing them in some corner cases. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8429 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-08-17Changed the (internal) way extra(select=.., select_params=...) handling is doneMalcolm Tredinnick
so that parameters stay with their select items. This means that merging and trimming of those items is handled correctly. Refs #7957, #7961. Fixed #8191. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8426 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-08-06Major refactoring of django.dispatch with an eye towards speed. The net ↵Jacob Kaplan-Moss
result is that signals are up to 90% faster. Though some attempts and backwards-compatibility were made, speed trumped compatibility. Thus, as usual, check BackwardsIncompatibleChanges for the complete list of backwards-incompatible changes. Thanks to Jeremy Dunck and Keith Busell for the bulk of the work; some ideas from Brian Herring's previous work (refs #4561) were incorporated. Documentation is, sigh, still forthcoming. Fixes #6814 and #3951 (with the new dispatch_uid argument to connect). git-svn-id: http://code.djangoproject.com/svn/django/trunk@8223 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-27Fixed #7886 -- Reordered some code in Query.results_iter() to ensure that allMalcolm Tredinnick
the prequisites are correctly initialised prior to using them. Only affects Oracle and other db backends requiring resolve_columns() (e.g. MS SQL?) git-svn-id: http://code.djangoproject.com/svn/django/trunk@8112 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-27Fixed #7872 -- Fixed a missed case of promoting table joins when usingMalcolm Tredinnick
disjunctive filters. Thanks to Michael Radziej for the failing test case. problem. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8107 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-22Fixed #7813 -- Allow pickling of Query classes that use select_related().Malcolm Tredinnick
Based on a patch from Justin Bronn. The test in this patch most likely breaks on Oracle. That's another issue. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8053 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-22Fixed #7791 -- Fixed a really silly error I introduced in [7926]. :-(Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8052 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-22Fixed #7848 -- Removed a bunch of code that wasn't contributing to society. ↵Adrian Holovaty
Thanks, julien git-svn-id: http://code.djangoproject.com/svn/django/trunk@8047 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-22Fixed #7847 -- Removed a whole bunch of unused imports from throughout the ↵Adrian Holovaty
codebase. Thanks, julien git-svn-id: http://code.djangoproject.com/svn/django/trunk@8046 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-15Fixed #7411 -- worked around some possible transaction conflicts in SQLite.Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7926 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-12Fixed a bozo bug from [7885]. Fixed #7698.Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7901 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-11Removed a FIXME that isn't really a problem any longer.Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7886 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-11Fixed #7698 -- Handle '0' correctly when used as the upper bound of a slice.Malcolm Tredinnick
Based on a patch from enoksrd. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7885 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-04Redo the changes in [7773] in a better way.Malcolm Tredinnick
This removes some of the leaky abstraction problems (lifting WhereNode internals into the Query class) from that commit and makes it possible for extensions to WhereNode to have access to the field instances. It's also backwards-compatible with pre-[7773] code, which is also better. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7835 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-07-01Modified [7760] to not include a "col is not NULL" fragment for non-nullable ↵Malcolm Tredinnick
fields. This avoids any use of "pk is not NULL" fragment, which behave inconsistently in MySQL. Thanks to Russell Keith-Magee for diagnosing the problem and suggesting the easy fix. Refs #7076. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7812 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-30Fixed #7314 -- Changed the way extra() bits are handled when QuerySets are ↵Malcolm Tredinnick
merged. Also added a section to the documentation to indicate why it's probably not a good idea to rely on this feature for complex stuff. Garbage in, garbage out applies even to Django code. Thanks to erik for the test case for this one. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7791 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-29A way better fix for the count() issue in [7787].Malcolm Tredinnick
The first attempt was brain-damaged. Let's never speak of it again. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7788 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-29Fixed #7323 -- Fixed a count() edge-case.Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7787 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-29Fixed #7371 -- Fixed an edge case when ordering on related models.Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7786 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-29Factored out a semi-complex if-test that was used in two places.Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7782 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-29Fixed #7246 -- Pull in the all the necessary data when using ↵Malcolm Tredinnick
select_related() with multi-table inheritance. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7781 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-29Fixed handling of multiple fields in a model pointing to the same related model.Malcolm Tredinnick
Thanks to ElliotM, mk and oyvind for some excellent test cases for this. Fixed #7110, #7125. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7778 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-27Reorganised the internals of the Where node a bit to fix some copying problems.Malcolm Tredinnick
We no longer store any reference to Django field instances or models in the Where node. This should improve cloning speed, fix some pickling difficulties, reduce memory usage and remove some infinite loop possibilities in odd cases. Slightly backwards incompatible if you're writing custom filters. See the BackwardsIncompatibleChanges wiki page for details. Fixed #7128, #7204, #7506. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7773 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-26Fixed #7181 -- when ordering by a potentially NULL field, use a left-outer joinMalcolm Tredinnick
so that the ordering doesn't accidentally restrict the result set. (Ironically, one existing test actually showed this problem, but I was too dumb to notice the result was incorrect.) git-svn-id: http://code.djangoproject.com/svn/django/trunk@7761 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-26Fixed #7076 -- Include NULL values when excluding non-NULL items.Malcolm Tredinnick
Based on a patch from emulbreh. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7760 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-26Fixed a problem when constructing complex select_related() calls.Malcolm Tredinnick
Avoids joining with the wrong tables when connecting select_related() tables to the main query. This also leads to slightly more efficient (meaning less tables are joined) SQL queries in some other cases, too. Some unnecessary tables are now trimmed that were not previously. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7741 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-26Fixed a problem with values() and values_list() queries and nullable joins.Malcolm Tredinnick
Previously, if we were querying across a nullable join and then a non-nullable one, the second join would not be a LEFT OUTER join, which would exclude certain valid results from the result set. This is the same problem as [7597] but for values() field specifications, so this covers the second case where Django adds extra stuff to the select-clause. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7740 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-06-08Fixed #7369: fixed a corner-case involving select_related() following ↵Jacob Kaplan-Moss
non-null FKs after null ones. Thanks, George Vilches git-svn-id: http://code.djangoproject.com/svn/django/trunk@7597 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-28Changed Query.get_columns() to quote the 'AS' column names in an ↵Adrian Holovaty
extra_select situation, to match pre-queryset-refactor behavior. Added unit tests that verify this and provide an example git-svn-id: http://code.djangoproject.com/svn/django/trunk@7502 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-28Added the ability to pickle and unpickle QuerySets and Query classes.Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7499 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-28Fixed #7096 -- The simplifications in [7461] weren't complete. They brokeMalcolm Tredinnick
multi-component exclude() calls. Fixed that. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7493 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27Merged the queryset-refactor branch into trunk.Malcolm Tredinnick
This is a big internal change, but mostly backwards compatible with existing code. Also adds a couple of new features. Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658 git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37