@@ -483,8 +483,6 @@ def year_lookup_bounds(self, connection, year):
483483 bounds = connection .ops .year_lookup_bounds_for_date_field (year )
484484 return bounds
485485
486-
487- class YearComparisonLookup (YearLookup ):
488486 def as_sql (self , compiler , connection ):
489487 # Avoid the extract operation if the rhs is a direct value to allow
490488 # indexes to be used.
@@ -493,53 +491,44 @@ def as_sql(self, compiler, connection):
493491 # that is self.lhs.lhs.
494492 lhs_sql , params = self .process_lhs (compiler , connection , self .lhs .lhs )
495493 rhs_sql , _ = self .process_rhs (compiler , connection )
496- rhs_sql = self .get_rhs_op (connection , rhs_sql )
494+ rhs_sql = self .get_direct_rhs_sql (connection , rhs_sql )
497495 start , finish = self .year_lookup_bounds (connection , self .rhs )
498- params .append (self .get_bound (start , finish ))
496+ params .extend (self .get_bound_params (start , finish ))
499497 return '%s %s' % (lhs_sql , rhs_sql ), params
500498 return super ().as_sql (compiler , connection )
501499
502- def get_rhs_op (self , connection , rhs ):
500+ def get_direct_rhs_sql (self , connection , rhs ):
503501 return connection .operators [self .lookup_name ] % rhs
504502
505- def get_bound (self , start , finish ):
503+ def get_bound_params (self , start , finish ):
506504 raise NotImplementedError (
507- 'subclasses of YearComparisonLookup must provide a get_bound () method'
505+ 'subclasses of YearLookup must provide a get_bound_params () method'
508506 )
509507
510508
511509class YearExact (YearLookup , Exact ):
512- lookup_name = 'exact'
513-
514- def as_sql (self , compiler , connection ):
515- # Avoid the extract operation if the rhs is a direct value to allow
516- # indexes to be used.
517- if self .rhs_is_direct_value ():
518- # Skip the extract part by directly using the originating field,
519- # that is self.lhs.lhs.
520- lhs_sql , params = self .process_lhs (compiler , connection , self .lhs .lhs )
521- bounds = self .year_lookup_bounds (connection , self .rhs )
522- params .extend (bounds )
523- return '%s BETWEEN %%s AND %%s' % lhs_sql , params
524- return super ().as_sql (compiler , connection )
510+ def get_direct_rhs_sql (self , connection , rhs ):
511+ return 'BETWEEN %s AND %s'
525512
513+ def get_bound_params (self , start , finish ):
514+ return (start , finish )
526515
527516
528- class YearGt (YearComparisonLookup , GreaterThan ):
529- def get_bound (self , start , finish ):
530- return finish
517+ class YearGt (YearLookup , GreaterThan ):
518+ def get_bound_params (self , start , finish ):
519+ return ( finish ,)
531520
532521
533- class YearGte (YearComparisonLookup , GreaterThanOrEqual ):
534- def get_bound (self , start , finish ):
535- return start
522+ class YearGte (YearLookup , GreaterThanOrEqual ):
523+ def get_bound_params (self , start , finish ):
524+ return ( start ,)
536525
537526
538- class YearLt (YearComparisonLookup , LessThan ):
539- def get_bound (self , start , finish ):
540- return start
527+ class YearLt (YearLookup , LessThan ):
528+ def get_bound_params (self , start , finish ):
529+ return ( start ,)
541530
542531
543- class YearLte (YearComparisonLookup , LessThanOrEqual ):
544- def get_bound (self , start , finish ):
545- return finish
532+ class YearLte (YearLookup , LessThanOrEqual ):
533+ def get_bound_params (self , start , finish ):
534+ return ( finish ,)
0 commit comments