summaryrefslogtreecommitdiff
path: root/django/db/models/sql/where.py
AgeCommit message (Collapse)Author
2013-11-28Fixed E125 pep8 warningsChristopher Medrela
2013-07-29Removed most of absolute_import importsClaude Paroz
Should be unneeded with Python 2.7 and up. Added some unicode_literals along the way.
2013-07-14Fixed #20746 -- Removed Python 2.6 specific code/docsTim Graham
2013-07-08A large number of stylistic cleanups across django/db/Alex Gaynor
2013-05-27Fixed #20507 -- SubqueryConstraint alias relabelingAnssi Kääriäinen
The SubqueryConstraint defined relabeled_clone(), but that was never called. Instead there is now clone() and relabel_aliases() methods for SubqueryConstraint. A related problem was that SubqueryConstraint didn't correctly use quote_name_unless_alias() of the outer query. This resulted in failures when running under PostgreSQL.
2013-05-20Fixed qs.values() regression when used in subqueryAnssi Kääriäinen
2013-05-19Fixed #11442 -- Postgresql backend casts all inet types to textErik Romijn
2013-03-24Fixed Oracle specific failures in multicolumn joinsAnssi Kääriäinen
Refs #19385
2013-03-24Fixed #19385 again, now with real code changesAnssi Kääriäinen
The commit of 266de5f9ae9e9f2fbfaec3b7e4b5fb9941967801 included only tests, this time also code changes included...
2013-03-22Fixed #20094 - Be more careful when checking for IteratorMarc Tamlyn
Python 2.6 has some different behaviour when checking isinstance(foo, collections.Iterator).
2013-03-17Fixed #19635 -- Made fields pickleableAnssi Kääriäinen
2013-03-13Refactored qs.add_q() and utils/tree.pyAnssi Kääriäinen
The sql/query.py add_q method did a lot of where/having tree hacking to get complex queries to work correctly. The logic was refactored so that it should be simpler to understand. The new logic should also produce leaner WHERE conditions. The changes cascade somewhat, as some other parts of Django (like add_filter() and WhereNode) expect boolean trees in certain format or they fail to work. So to fix the add_q() one must fix utils/tree.py, some things in add_filter(), WhereNode and so on. This commit also fixed add_filter to see negate clauses up the path. A query like .exclude(Q(reversefk__in=a_list)) didn't work similarly to .filter(~Q(reversefk__in=a_list)). The reason for this is that only the immediate parent negate clauses were seen by add_filter, and thus a tree like AND: (NOT AND: (AND: condition)) will not be handled correctly, as there is one intermediary AND node in the tree. The example tree is generated by .exclude(~Q(reversefk__in=a_list)). Still, aggregation lost connectors in OR cases, and F() objects and aggregates in same filter clause caused GROUP BY problems on some databases. Fixed #17600, fixed #13198, fixed #17025, fixed #17000, fixed #11293.
2013-03-12Fixed #19964 -- Removed relabel_aliases from some structsAnssi Kääriäinen
Before there was need to have both .relabel_aliases() and .clone() for many structs. Now there is only relabeled_clone() for those structs where alias is the only mutable attribute.
2013-02-24Revert "fixes #19263" - Fails if not SQLiteHonza Kral
This reverts commit 2b76f19f2b89ac96bae2a169d71b23553c8101c7.
2013-02-23fixes #19263Marcin Biernat
2013-02-16Fixed #17260 -- Added time zone aware aggregation and lookups.Aymeric Augustin
Thanks Carl Meyer for the review. Squashed commit of the following: commit 4f290bdb60b7d8534abf4ca901bd0844612dcbda Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Wed Feb 13 21:21:30 2013 +0100 Used '0:00' instead of 'UTC' which doesn't always exist in Oracle. Thanks Ian Kelly for the suggestion. commit 01b6366f3ce67d57a58ca8f25e5be77911748638 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Wed Feb 13 13:38:43 2013 +0100 Made tzname a parameter of datetime_extract/trunc_sql. This is required to work around a bug in Oracle. commit 924a144ef8a80ba4daeeafbe9efaa826566e9d02 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Wed Feb 13 14:47:44 2013 +0100 Added support for parameters in SELECT clauses. commit b4351d2890cd1090d3ff2d203fe148937324c935 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 22:30:22 2013 +0100 Documented backwards incompatibilities in the two previous commits. commit 91ef84713c81bd455f559dacf790e586d08cacb9 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 09:42:31 2013 +0100 Used QuerySet.datetimes for the admin's date_hierarchy. commit 0d0de288a5210fa106cd4350961eb2006535cc5c Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 09:29:38 2013 +0100 Used QuerySet.datetimes in date-based generic views. commit 9c0859ff7c0b00734afe7fc15609d43d83215072 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:43:25 2013 +0100 Implemented QuerySet.datetimes on Oracle. commit 68ab511a4ffbd2b811bf5da174d47e4dd90f28fc Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:43:14 2013 +0100 Implemented QuerySet.datetimes on MySQL. commit 22d52681d347a8cdf568dc31ed032cbc61d049ef Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:42:29 2013 +0100 Implemented QuerySet.datetimes on SQLite. commit f6800fd04c93722b45f9236976389e0b2fe436f5 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:43:03 2013 +0100 Implemented QuerySet.datetimes on PostgreSQL. commit 0c829c23f4cf4d6804cadcc93032dd4c26b8c65e Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:41:08 2013 +0100 Added datetime-handling infrastructure in the ORM layers. commit 104d82a7778cf3f0f5d03dfa53709c26df45daad Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Mon Feb 11 10:05:55 2013 +0100 Updated null_queries tests to avoid clashing with the __second lookup. commit c01bbb32358201b3ac8cb4291ef87b7612a2b8e6 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 23:07:41 2013 +0100 Updated tests of .dates(). Replaced .dates() by .datetimes() for DateTimeFields. Replaced dates with datetimes in the expected output for DateFields. commit 50fb7a52462fecf0127b38e7f3df322aeb287c43 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 21:40:09 2013 +0100 Updated and added tests for QuerySet.datetimes. commit a8451a5004c437190e264667b1e6fb8acc3c1eeb Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 22:34:46 2013 +0100 Documented the new time lookups and updated the date lookups. commit 29413eab2bd1d5e004598900c0dadc0521bbf4d3 Author: Aymeric Augustin <aymeric.augustin@m4x.org> Date: Sun Feb 10 16:15:49 2013 +0100 Documented QuerySet.datetimes and updated QuerySet.dates.
2013-02-11Added a check in the creation of IS NULL clauses.Aymeric Augustin
value_annotation isn't very well defined. Before this change, setting it to datetime.datetime could silently reverse the behavior of isnull lookups. This commit doesn't have any consequences on the current code. It's just a safeguard for future ORM hackers.
2013-01-08Fixed #16759 -- Remove use of __deepcopy__ in qs.clone()Anssi Kääriäinen
The original problem was that queryset cloning was really expensive when filtering with F() clauses. The __deepcopy__ went too deep copying _meta attributes of the models used. To fix this the use of __deepcopy__ in qs cloning was removed. This commit results in some speed improvements across the djangobench benchmark suite. Most query_* tests are 20-30% faster, save() is 50% faster and finally complex filtering situations can see 2x to order of magnitude improvments. Thanks to Suor, Alex and lrekucki for valuable feedback.
2013-01-06Fixed #19173 -- Made EmptyQuerySet a marker class onlyAnssi Kääriäinen
The guarantee that no queries will be made when accessing results is done by new EmptyWhere class which is used for query.where and having. Thanks to Simon Charette for reviewing and valuable suggestions.
2012-07-22[py3] Added Python 3 compatibility for xrange.Aymeric Augustin
2012-07-03Fixed comment wording in sql/where.pyAnssi Kääriäinen
Thanks to Simon Charette for noticing this.
2012-07-01Fixed a regression introduced in where.as_sql() refactorAnssi Kääriäinen
At least Oracle needs parentheses in negated where conditions, even if there is only single condition negated. Fixed this by reverting to old logic in that part of as_sql() and adding a comment about this. I did not investigate why the parentheses are needed. The original offending commit was bd283aa844b04651b7c8b4e85f48c6dced1678f0.
2012-07-01Refactored the empty/full result logic in WhereNode.as_sql()Anssi Kääriäinen
Made sure the WhereNode.as_sql() handles various EmptyResultSet and FullResultSet conditions correctly. Also, got rid of the FullResultSet exception class. It is now represented by '', [] return value in the as_sql() methods.
2012-05-22Replaced 'next' testing by collections.Iterator testing.Claude Paroz
The new construct is also Python 3 compatible (where 'next' has been renamed to '__next__').
2012-04-09Fixed #17877 -- Ensured that extra WHERE clauses get correctly ANDed when ↵Julien Phalip
they contain OR operations. Thanks to Marek Brzóska for the report, to eleather for the test case and to Adrien Lemaire for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17880 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-02-22Fixed #17728 -- When filtering an annotation, ensured the values used in the ↵Aymeric Augustin
filter are properly converted to their database representation. This bug was particularly visible with timezone-aware DateTimeFields. Thanks gg for the report and Carl for the review. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17576 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-10-17Remove several more relative imports.Alex Gaynor
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17007 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-07-13Fixed #16225 -- Removed unused imports. Many thanks to Aymeric Augustin for ↵Jannis Leidel
the work on the patch and Alex for reviewing. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16539 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-09-16Fixed #14244: Allow lists of more than 1000 items to be used with the 'in' ↵Ian Kelly
lookup in Oracle, by breaking them up into groups of 1000 items and ORing them together. Thanks to rlynch for the report and initial patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@13859 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-09-13Fixed #11594 - Inaccurate docstring for WhereNode.add()Luke Plant
Thanks to garrison for report, dwillis for patch git-svn-id: http://code.djangoproject.com/svn/django/trunk@13843 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-04-21Fixed #13328 -- Ensured that querysets on models with callable defaults can ↵Russell Keith-Magee
be pickled. No, really this time. Thanks to Alex for his help brainstorming the solution. git-svn-id: http://code.djangoproject.com/svn/django/trunk@13013 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-02-23Fixed #12855 -- QuerySets with `extra` where parameters now combine ↵Justin Bronn
correctly. Thanks, Alex Gaynor. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12502 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-12-22Fixed #1142 -- Added multiple database support.Russell Keith-Magee
This monster of a patch is the result of Alex Gaynor's 2009 Google Summer of Code project. Congratulations to Alex for a job well done. Big thanks also go to: * Justin Bronn for keeping GIS in line with the changes, * Karen Tracey and Jani Tiainen for their help testing Oracle support * Brett Hoerner, Jon Loyens, and Craig Kimmerer for their feedback. * Malcolm Treddinick for his guidance during the GSoC submission process. * Simon Willison for driving the original design process * Cal Henderson for complaining about ponies he wanted. ... and everyone else too numerous to mention that helped to bring this feature into fruition. git-svn-id: http://code.djangoproject.com/svn/django/trunk@11952 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-08Fixed #10432 -- Handle all kinds of iterators in queryset filters.Malcolm Tredinnick
Only consumes the iterators once and works with Python 2.3. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9986 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-02Fixed #10181 -- Handle an EmptyResultSet exception case properly in nested ↵Malcolm Tredinnick
querysets. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9951 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-08Fixed #10160 -- Modified evaluation of F() expressions to protect against ↵Russell Keith-Magee
potential SQL injection attacks. Thanks to Ian Kelly for the suggestion and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9820 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-08Fixed #7672 -- Added a 'week_day' lookup type. Many thanks to Ross Poulton ↵Karen Tracey
for the proposal and implementation on all built-in database backends.. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9818 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-08Using querysets as an rvalue in filter() calls was causing an unnecessaryMalcolm Tredinnick
database query, due to a bool() call. This change stops that behaviour. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9715 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-07-23Allow for matches against unsaved objects in querysets (which will thereforeMalcolm Tredinnick
match nothing). This allows for some more straightforward code in the admin interface. Fixed #7488 (all the debugging there was done by Brian Rosner, who narrowed it down to the item in this patch). git-svn-id: http://code.djangoproject.com/svn/django/trunk@8061 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-06-27Removed a dead line that was left in [7773] by accident.Malcolm Tredinnick
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7774 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-12Negligible comment typo fixesAdrian Holovaty
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7620 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-29Fixed an Oracle error on double negations in where conditions. Fixed #7111Ian Kelly
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7509 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