@@ -498,16 +498,19 @@ fn build_composite_clause(
498498 fn prepare_comparison (
499499 value : & MemberValue ,
500500 bind_values : & mut Vec < String > ,
501- historical : bool ,
501+ json_format : bool ,
502502 ) -> Result < String , Error > {
503503 match value {
504504 MemberValue :: String ( value) => {
505505 bind_values. push ( value. to_string ( ) ) ;
506506 Ok ( "?" . to_string ( ) )
507507 }
508508 MemberValue :: Primitive ( value) => {
509- let value = if historical {
510- Ty :: Primitive ( * value) . to_json_value ( ) ?. to_string ( )
509+ let value = if json_format {
510+ Ty :: Primitive ( * value)
511+ . to_json_value ( ) ?
512+ . to_string ( )
513+ . replace ( "\" " , "" )
511514 } else {
512515 value. to_sql_value ( )
513516 } ;
@@ -518,19 +521,33 @@ fn build_composite_clause(
518521 "({})" ,
519522 values
520523 . iter( )
521- . map( |v| prepare_comparison( v, bind_values, historical ) )
524+ . map( |v| prepare_comparison( v, bind_values, json_format ) )
522525 . collect:: <Result <Vec <String >, Error >>( ) ?
523526 . join( ", " )
524527 ) ) ,
525528 }
526529 }
527- let value = prepare_comparison ( & member. value , & mut bind_values, historical) ?;
528530
529531 let model = member. model . clone ( ) ;
530532 let operator = member. operator . clone ( ) ;
531533
534+ // Determine if we need JSON formatting for values
535+ let array_index = parse_array_index ( & member. member ) ;
536+ let is_array_operation = matches ! (
537+ operator,
538+ ComparisonOperator :: Contains
539+ | ComparisonOperator :: ContainsAll
540+ | ComparisonOperator :: ContainsAny
541+ | ComparisonOperator :: ArrayLengthEq
542+ | ComparisonOperator :: ArrayLengthGt
543+ | ComparisonOperator :: ArrayLengthLt
544+ ) || array_index. is_some ( ) ; // Array indexing also needs JSON formatting
545+
546+ let value =
547+ prepare_comparison ( & member. value , & mut bind_values, is_array_operation) ?;
548+
532549 // Check if this field has array indexing syntax like "field[0]"
533- if let Some ( ( field_name, index) ) = parse_array_index ( & member . member ) {
550+ if let Some ( ( field_name, index) ) = array_index {
534551 // Handle array element access
535552 let column_access = if historical {
536553 format ! ( "JSON_EXTRACT({table}.data, '$.{field_name}')" )
0 commit comments