1- use crate :: query:: operators:: Operator ;
1+ use crate :: query:: operators:: { LikeKind , Operator } ;
22use crate :: query:: querybuilder:: syntax:: column:: ColumnRef ;
33use crate :: query:: querybuilder:: syntax:: dialect:: SqlDialect ;
44use crate :: query:: querybuilder:: syntax:: emitter:: types:: helpers:: Range ;
@@ -10,7 +10,7 @@ pub struct ConditionClause<'a> {
1010 pub ( crate ) kind : ConditionClauseKind ,
1111 pub ( crate ) column_name : ColumnRef < ' a > ,
1212 pub ( crate ) operator : Operator ,
13- pub ( crate ) value_indexes : Range ,
13+ pub ( crate ) value_indexes : Option < Range > ,
1414}
1515
1616#[ derive( Eq , PartialEq , Copy , Clone , Debug ) ]
@@ -51,25 +51,50 @@ impl<'a, D: SqlDialect> ToSqlTokens<'a, D> for ConditionClause<'a> {
5151 // Operator
5252 out. operator ( self . operator ) ;
5353
54- out. whitespace ( ) ;
55-
56- if self . value_indexes . is_range ( ) {
57- out. symbol ( Symbol :: LParen ) ;
58- let mut indexes = ( & self . value_indexes ) . into_iter ( ) . peekable ( ) ;
59- while indexes. next ( ) . is_some ( ) {
60- out. placeholder ( ) ;
61- if indexes. peek ( ) . is_some ( ) {
62- out. symbol ( Symbol :: Comma ) ;
54+ match self . operator {
55+ Operator :: Like ( kind) | Operator :: NotLike ( kind) => {
56+ let like_tokens = <LikeKind as ToSqlTokens < ' _ , D > >:: to_tokens ( & kind) ;
57+ out. extend ( like_tokens) ;
58+ }
59+ _ => {
60+ if let Some ( ref range) = self . value_indexes
61+ && range. is_range ( )
62+ {
63+ __impl:: output_range_of_placeholders :: < D > ( range, & mut out) ;
64+ } else {
6365 out. whitespace ( ) ;
66+ out. placeholder ( ) ;
6467 }
6568 }
66- out. symbol ( Symbol :: RParen ) ;
67- } else {
68- out. placeholder ( ) ;
6969 }
7070
7171 out. whitespace ( ) ;
7272
7373 out
7474 }
7575}
76+
77+ mod __impl {
78+ use crate :: query:: operators:: Operator ;
79+ use crate :: query:: querybuilder:: syntax:: dialect:: SqlDialect ;
80+ use crate :: query:: querybuilder:: syntax:: emitter:: types:: helpers:: Range ;
81+ use crate :: query:: querybuilder:: syntax:: symbol:: Symbol ;
82+ use crate :: query:: querybuilder:: syntax:: tokens:: { SqlTokens , ToSqlTokens } ;
83+
84+ pub ( crate ) fn output_range_of_placeholders < D : SqlDialect > (
85+ range : & Range ,
86+ out : & mut SqlTokens < ' _ > ,
87+ ) {
88+ out. whitespace ( ) ;
89+ out. symbol ( Symbol :: LParen ) ;
90+ let mut indexes = range. into_iter ( ) . peekable ( ) ;
91+ while indexes. next ( ) . is_some ( ) {
92+ out. placeholder ( ) ;
93+ if indexes. peek ( ) . is_some ( ) {
94+ out. symbol ( Symbol :: Comma ) ;
95+ out. whitespace ( ) ;
96+ }
97+ }
98+ out. symbol ( Symbol :: RParen ) ;
99+ }
100+ }
0 commit comments