summaryrefslogtreecommitdiff
path: root/django/db/models/sql/query.py
AgeCommit message (Collapse)Author
2009-10-25Fixed #12079: Changed has_results to get a single result, thus preventing ↵Karen Tracey
exists() from always returning True on backends that support chunked reads. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11654 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-24Fixed #11402: added a `QuerySet.exists()` method. Thanks, Alex Gaynor.Jacob Kaplan-Moss
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11646 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-06-06Fixed #11082 -- Ensured that subqueries used in an exclude(X__in=) clause ↵Russell Keith-Magee
aren't pre-evaluated. Thanks to Henry Andrews for the report, and clement for the fix. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10929 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-06-06Fixed #10572 -- Corrected the operation of the defer() and only() clauses ↵Russell Keith-Magee
when used on inherited models. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10926 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-05-29Fixed #11216 and #11218 -- Corrected a few typos, thanks buriy.Gary Wilson Jr
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10861 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-05-11Fixed #10953, #10955: proxies of proxies now work correctly, though I still ↵Jacob Kaplan-Moss
don't quite understand why you'd want to do such a thing. Thanks, Armin Ronacher. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10738 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-30Fixed #10847 -- Modified handling of extra() to use a masking strategy, ↵Russell Keith-Magee
rather than last-minute trimming. Thanks to Tai Lee for the report, and Alex Gaynor for his work on the patch. This enables querysets with an extra clause to be used in an __in filter; as a side effect, it also means that as_sql() now returns the correct result for any query with an extra clause. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10648 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-11Fixed #10796 -- Corrected a pickling problem introduced by [10522]. Thanks ↵Russell Keith-Magee
to carljm for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10526 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-11Fixed #10197 -- Corrected pickling of querysets when a subset of fields was ↵Russell Keith-Magee
selected. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10522 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-11Fixed #10766 -- Raise an error when annotate() references another ↵Russell Keith-Magee
aggreagte(). Thanks to aseering@mit.edu for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10521 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-08Fixed #10666 -- Corrected the handling of inherited fields with aggregate() ↵Russell Keith-Magee
and annotate(). Thanks to julienb for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10446 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-04Fixed a problem when computing deferred fields on multiple related models.Malcolm Tredinnick
Fixed #10710, as this fixes the second bug reported there. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10384 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-02Fixed #10670: fixed reusing QuerySets previously used in a filter ↵Jacob Kaplan-Moss
expression. Thanks, Alex Gaynor. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10357 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-01Fixed #9871 -- Geometry objects are now returned in dictionaries and tuples ↵Justin Bronn
returned by `values()` and `values_list()`, respectively; updated `GeoQuery` methods to be compatible with `defer()` and `only`; removed defunct `GeomSQL` class; and removed redundant logic from `Query.get_default_columns`. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10326 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-24Fixed #9926 -- Fixes for some select_related() situations.Malcolm Tredinnick
Using select_related(...) across a nullable relation to a multi-table model inheritance situation no longer excludes results. Thanks to AdamG for a test demonstrating part of the problem. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10136 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-19Fixed #5420 -- Added support for delayed loading of model fields.Malcolm Tredinnick
In extreme cases, some fields are expensive to load from the database (e.g. GIS fields requiring conversion, or large text fields). This commit adds defer() and only() methods to querysets that allow the caller to specify which fields should not be loaded unless they are accessed. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10090 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-18Fixed #10356 -- Added pure-Python inheritance for models (a.k.a proxy models).Malcolm Tredinnick
Large portions of this are needed for #5420, so I implemented it fully. Thanks to Ryan Kelly for an initial patch to get this started. Refs #5420. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10083 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-14Fixed #10425 -- Corrected the interaction of .count() with .annotate() when ↵Russell Keith-Magee
.values() is also involved. Thanks to kmassey for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10053 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-13Fixed a case where column aliases weren't being quoted properly.Ian Kelly
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10048 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-06Improved table join handling for comparisons against NULL.Malcolm Tredinnick
This fixes a broad class of bugs involving filters that look for missing related models and fields. Most of them don't seem to have been reported (the added tests cover the root cause). The exception is that this has also fixed #9868. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9979 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-04Fixed #10251 -- Fixed model inheritance when there's also an explicit pk field.Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9970 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-04Fixed #10362 -- An update() that only affects a parent model no longer crashes.Malcolm Tredinnick
This includes a fairly large refactor of the update() query path (and the initial portions of constructing the SQL for any query). The previous code appears to have been only working more or less by accident and was very fragile. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9967 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-01Fixed insert/update handling when no database interaction is required.Malcolm Tredinnick
Fixed #10205 as part of this. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9926 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-01Fixed #10202 -- Fixed another couple of slicing edge-cases with querysets.Malcolm Tredinnick
Patch from Alex Gaynor and Ramiro Morales. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9924 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-28Fixed #10028 -- Fixed a problem when ordering by related models.Malcolm Tredinnick
Some results were inadvertently being excluded if we were ordering across a nullable relation which itself ordering by a non-nullable relation. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9916 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-25Fixed #10290: do not use aliases when adding extra_selects to the GROUP BY ↵Ian Kelly
clause, to generate compliant sql that will be accepted by Oracle. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9905 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-23Fixed #10182 -- Corrected realiasing and the process of evaluating values() ↵Russell Keith-Magee
for queries with aggregate clauses. This means that aggregate queries can now be used as subqueries (such as in an __in clause). Thanks to omat for the report. This involves a slight change to the interaction of annotate() and values() clauses that specify a list of columns. See the docs for details. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9888 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-16Fixed #10248 -- Corrected handling of the GROUP BY clause when using a ↵Russell Keith-Magee
DateQuerySet. Thanks to Alex Gaynor for the report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9839 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-16Fixed #10132 -- Corrected the interaction of extra() queries with the ↵Russell Keith-Magee
values() clause. Thanks to Glen Maynard for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9838 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-02Fixed #10127 -- Corrected handling of select_related() in annotate() calls. ↵Russell Keith-Magee
Thanks to Sylvain Pasche <sylvain.pasche@gmail.com> for the report and test case. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9805 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-29Fixed #7210 -- Added F() expressions to query language. See the ↵Russell Keith-Magee
documentation for details on usage. Many thanks to: * Nicolas Lara, who worked on this feature during the 2008 Google Summer of Code. * Alex Gaynor for his help debugging and fixing a number of issues. * Malcolm Tredinnick for his invaluable review notes. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9792 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-24Refs #10113 -- Modified the generated SQL to remove redundant GROUP BY ↵Russell Keith-Magee
elements, and modified the test added in [9788] to remove a test result that depended on a potentially ambiguous database ordering. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9791 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-24Fixed #10113 -- Ensured that joined fields mentioned in order_by() are ↵Russell Keith-Magee
included in the GROUP_BY clause on those backends that require it. Thanks to Koen Biermans <koen.biermans@werk.belgie.be> for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9788 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-23Fixed #10089 -- Corrected handling of aggregates when the query set contains ↵Russell Keith-Magee
no items (and the cursor returns None). Thanks to Kyle Fox for the report, and david for the initial patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9786 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-23Fixed #10100 -- Corrected handling of the negation required exclude() ↵Russell Keith-Magee
clauses that reference aggregate columns. Thanks to Anossov for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9785 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-20Fixed #10064 -- Corrected handling of aggregate queries that also use ↵Russell Keith-Magee
select_related(). Thanks to olivius for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9781 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-15Fixed #3566 -- Added support for aggregation to the ORM. See the ↵Russell Keith-Magee
documentation for details on usage. Many thanks to: * Nicolas Lara, who worked on this feature during the 2008 Google Summer of Code. * Alex Gaynor for his help debugging and fixing a number of issues. * Justin Bronn for his help integrating with contrib.gis. * Karen Tracey for her help with cross-platform testing. * Ian Kelly for his help testing and fixing Oracle support. * Malcolm Tredinnick for his invaluable review notes. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9742 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-08Fixed #9985 -- qs.values_list(...).values(...) was constructing incorrect SQL.Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9717 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-08Remove any ordering from a nested select query (in the where-clause).Malcolm Tredinnick
This fixes r9701 for Oracle (the test introduced there did its job and failed previously). git-svn-id: http://code.djangoproject.com/svn/django/trunk@9714 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-05Nested query support.Malcolm Tredinnick
This extends previous functionality that allowed passing Query objects as the rvals to filters. You can now pass QuerySets, which requires less poking at opaque attributes. See the documentation of the "__in" lookup type for the details. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9701 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-05Reconciling where- and having-clause behaviour.Malcolm Tredinnick
Extricated the code that works directly with SQL columns (standard "where" stuff) from the the code that takes SQL fragments and combines it with lookup types and values. The latter portion is now more generally reusable. Any existing code that was poking at Query.having will now break in very visible ways (no subtle miscalculations, which is a good thing). This patch, en passant, removes the existing "having" test, since the new implementation requires more setting up than previously. The aggregates support (currently in a separate codebase) has tests for this functionality that work as a replacement for the removed test. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9700 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-12-10If an SQL query doesn't specify any ordering, avoid the implicit sortMalcolm Tredinnick
that happens with MySQL when a "GROUP BY" clause is included. This is a backend-specific operation, so any other databases requiring similar encouragement can have a function added to their own backend code. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9637 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-12-09Fixed #9778 -- Added some special casing of the "Join on field 'abc'" errorMalcolm Tredinnick
message. It now gives an extra hint if there's a chance you just made a typo in the lookup type. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9620 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-12-08This fixes a group of problems in the SQL created by QuerySet.exclude() whenMalcolm Tredinnick
used in a few situations where NULL results can appear. Fixed #8921 (the only ticket I know of that noticed any of these). git-svn-id: http://code.djangoproject.com/svn/django/trunk@9590 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-12-07Fixed #9188 -- Fixed a case where we were generating syntactically invalid ↵Malcolm Tredinnick
SQL in some exclude() queries. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9588 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-10-24Fixed #9307 -- Added the ability to pickle the Query class used by the OracleMalcolm Tredinnick
backend. This allows Querysets to be cached for Oracle and should provide a model for adding pickling support to other (external) database backends that need a custom Query class. Thanks to Justin Bronn for some assistance with this patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9272 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-10-24Fixed #9406 -- Ensure that each database column is only represented once in theMalcolm Tredinnick
"ORDER BY" clause of an SQL statement. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9251 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-10-08A queryset that has had ordering removed (order_by()) can have ordering addedMalcolm Tredinnick
again later (order_by('foo')). Or, at least, it can now. Thanks to Ilya Novoselov for diagnosing the problem here. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9206 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-10-08Applying a limit to a queryset that already had an upper limit of 0 wasn'tMalcolm Tredinnick
working properly. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9201 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-09-22Fixed a missing variable initialisation deep in the Query bowels.Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9081 bcc190cf-cafb-0310-a4f2-bffc1f526a37