o 3a*"@spdZddlmZddlmZddlmZdZdZGdddej Z Gd d d Z Gd d d Z Gd ddZ dS)zG Code to manage the creation and SQL rendering of 'where' constraints. EmptyResultSet)tree)cached_propertyANDORc@seZdZdZeZdZdZd'ddZddZ d(d d Z d d Z d dZ ddZ ddZddZddZeddZeddZeddZeddZedd Zed!d"Zed#d$Zd%d&ZdS)) WhereNodea An SQL WHERE clause. The class is tied to the Query class that created it (in order to create the correct SQL). A child is usually an expression producing boolean values. Most likely the expression is a Lookup instance. However, a child could also be any class with as_sql() and either relabeled_clone() method or relabel_aliases() and clone() methods and contains_aggregate attribute. FTc Cs|js|dfS||jA}|r|jtkp| o|jtk}|r$|jr$d|fSg}g}|jD]/}t|drL||\}}|durB|||durK||q+|jrU||q+||q+|rf| ||j|jnd} |rs| ||j|jnd} | | fS)z Return two possibly None nodes: one for those parts of self that should be included in the WHERE clause and one for those parts of self that must be included in the HAVING clause. N split_having) contains_aggregatenegated connectorrrchildrenhasattrr append __class__) selfr in_negatedmay_need_split where_parts having_partsc where_part having_part having_node where_noderz0WhereNode._contains_aggregate..) isinstancerNodeanyr r rGobjrrFrrC zWhereNode._contains_aggregatecC ||Sr1rBr5rrrr  zWhereNode.contains_aggregatecr@)Nc3rAr1_contains_over_clauserDrFrrrHrIz2WhereNode._contains_over_clause..)rJrrKrLr contains_over_clauserMrrFrrSrOzWhereNode._contains_over_clausecCrPr1rRr5rrrrTrQzWhereNode.contains_over_clausecCstdd|jDS)Ncss|]}|jVqdSr1) is_summary)rEr+rrrrHsz'WhereNode.is_summary..)rLr r5rrrrUszWhereNode.is_summarycOs&t|dr|j|g|Ri|}|S)Nresolve_expression)rrV)exprqueryargskwargsrrr _resolve_leafs zWhereNode._resolve_leafcOst|dr|jD]}|j||g|Ri|qt|dr,|j|j|g|Ri||_t|drB|j|j|g|Ri||_dSdS)Nr lhsrhs)rr _resolve_noder[r\r])rGnoderXrYrZr+rrrr^s    "zWhereNode._resolve_nodecOs*|}|j|g|Ri|d|_|S)NT)r=r^r$)rrYrZr=rrrrVszWhereNode.resolve_expression)Fr1)__name__ __module__ __qualname____doc__rdefaultr$ conditionalr r0r2r6r7r8r=r9r? classmethodrCrr rSrTpropertyrU staticmethodr[r^rVrrrrrs:  ! 4         rc@seZdZdZdZdddZdS) NothingNodezA node that matches nothing.FNcCstr1r)rr%r&rrrr0szNothingNode.as_sqlNN)r`rarbrcr r0rrrrrisric@s"eZdZdZddZdddZdS) ExtraWhereFcCs||_||_dSr1)sqlsr-)rrlr-rrr__init__s zExtraWhere.__init__NcCs(dd|jD}d|t|jpdfS)NcSsg|]}d|qS)rr)rEr,rrr sz%ExtraWhere.as_sql..z AND r)rlr#listr-)rr%r&rlrrrr0szExtraWhere.as_sqlrjr`rarbr rmr0rrrrrksrkc@s eZdZdZddZddZdS)SubqueryConstraintFcCs||_||_||_||_dSr1)r3columnstargets query_object)rr3rrrsrtrrrrms zSubqueryConstraint.__init__cCs0|j}||j|j|d}||j|j|S)N)r&)rt set_valuesrs get_compileras_subquery_conditionr3rr)rr%r&rXquery_compilerrrrr0s  zSubqueryConstraint.as_sqlNrprrrrrqs rqN)rcdjango.core.exceptionsr django.utilsrdjango.utils.functionalrrrrKrrirkrqrrrrs   G