@@ -352,8 +352,9 @@ void FilterObjectGenerator::parse_orderby_asof_wmember(Object object) {
352
352
* 2) complexOperatorObject
353
353
* 3) columnObject
354
354
*/
355
- std::optional<std::string> FilterObjectGenerator::parse_complex_value (
356
- const std::string_view &column_name, Value *value) {
355
+ std::optional<mysqlrouter::sqlstring>
356
+ FilterObjectGenerator::parse_complex_value (const std::string_view &column_name,
357
+ Value *value) {
357
358
log_debug (" parse_complex_value %s" , column_name.data ());
358
359
if (!value->IsObject ()) return {};
359
360
if (value->MemberCount () != 1 ) return {};
@@ -378,7 +379,8 @@ std::optional<std::string> FilterObjectGenerator::parse_complex_value(
378
379
* 1) complexKey : [complexValues]
379
380
* 2) complexKey : simpleOperatorObject
380
381
*/
381
- std::optional<std::string> FilterObjectGenerator::parse_complex_operator_object (
382
+ std::optional<mysqlrouter::sqlstring>
383
+ FilterObjectGenerator::parse_complex_operator_object (
382
384
const std::string_view &column_name, Value *value,
383
385
const std::string_view &complex_key) {
384
386
log_debug (" parse_complex_operator_object, column=%s, operator=%s" ,
@@ -398,7 +400,8 @@ std::optional<std::string> FilterObjectGenerator::parse_complex_operator_object(
398
400
return {};
399
401
}
400
402
401
- std::optional<std::string> FilterObjectGenerator::parse_simple_operator_object (
403
+ std::optional<mysqlrouter::sqlstring>
404
+ FilterObjectGenerator::parse_simple_operator_object (
402
405
const std::string_view &column_name, Value *object) {
403
406
log_debug (" parse_simple_operator_object %s" , column_name.data ());
404
407
if (column_name.empty ()) return {};
@@ -503,10 +506,11 @@ std::optional<std::string> FilterObjectGenerator::parse_simple_operator_object(
503
506
return {};
504
507
}
505
508
506
- return result. str () ;
509
+ return result;
507
510
}
508
511
509
- std::optional<std::string> FilterObjectGenerator::parse_match (Value *value) {
512
+ std::optional<mysqlrouter::sqlstring> FilterObjectGenerator::parse_match (
513
+ Value *value) {
510
514
log_debug (" parse_complex_match" );
511
515
if (!value->IsObject ())
512
516
throw RestError (" Match operator, requires JSON object as value." );
@@ -557,7 +561,7 @@ std::optional<std::string> FilterObjectGenerator::parse_match(Value *value) {
557
561
mysqlrouter::sqlstring v{" MATCH (!) AGAINST(? ?) " };
558
562
v << fields << against_expr->value .GetString () << selected_modifier;
559
563
560
- return v. str () ;
564
+ return v;
561
565
}
562
566
563
567
/*
@@ -567,7 +571,7 @@ std::optional<std::string> FilterObjectGenerator::parse_match(Value *value) {
567
571
* columnName : date
568
572
* columnName : <other types>
569
573
*/
570
- std::optional<std::string > FilterObjectGenerator::parse_direct_value (
574
+ std::optional<mysqlrouter::sqlstring > FilterObjectGenerator::parse_direct_value (
571
575
const std::string_view &column_name, Value *value) {
572
576
log_debug (" parse_direct_value %s" , column_name.data ());
573
577
@@ -597,14 +601,15 @@ std::optional<std::string> FilterObjectGenerator::parse_direct_value(
597
601
throw ;
598
602
}
599
603
600
- return result. str () ;
604
+ return result;
601
605
}
602
606
603
607
/*
604
608
* complexValues
605
609
* complexValue , complexValues
606
610
<
1E0A
code class="diff-text syntax-highlighted-line"> */
607
- std::optional<std::string> FilterObjectGenerator::parse_complex_values (
611
+ std::optional<mysqlrouter::sqlstring>
612
+ FilterObjectGenerator::parse_complex_values (
608
613
const std::string_view &column_name, Value *value,
609
614
const std::string_view &complex_key) {
610
615
log_debug (" parse_complex_values %s" , column_name.data ());
@@ -620,7 +625,7 @@ std::optional<std::string> FilterObjectGenerator::parse_complex_values(
620
625
throw RestError (" parse_complex_values: array can't be empty" );
621
626
}
622
627
623
- std::string result_str ;
628
+ mysqlrouter::sqlstring output ;
624
629
bool first = true ;
625
630
for (auto &el : helper::json::array_iterator (arr)) {
626
631
auto result = parse_complex_value (column_name, &el);
@@ -629,15 +634,19 @@ std::optional<std::string> FilterObjectGenerator::parse_complex_values(
629
634
}
630
635
631
636
if (!first) {
632
- result_str += " " + sql_operator + " " ;
637
+ output.append_preformatted (" " );
638
+ output.append_preformatted (sql_operator.c_str ());
639
+ output.append_preformatted (" " );
633
640
} else {
634
641
first = false ;
635
642
}
636
643
637
- result_str += " (" + *result + " )" ;
644
+ output.append_preformatted (" (" );
645
+ output.append_preformatted (*result);
646
+ output.append_preformatted (" )" );
638
647
}
639
648
640
- return result_str ;
649
+ return output ;
641
650
}
642
651
643
652
namespace {
@@ -669,8 +678,9 @@ bool is_valid_column_name(const std::string_view &str) {
669
678
* 3) columnName : complexOperatorObject
670
679
* 4) columnName : [complexValues]
671
680
*/
672
- std::optional<std::string> FilterObjectGenerator::parse_column_object (
673
- const std::string_view &column_name, Value *value) {
681
+ std::optional<mysqlrouter::sqlstring>
682
+ FilterObjectGenerator::parse_column_object (const std::string_view &column_name,
683
+ Value *value) {
674
684
log_debug (" parse_column_object %s" , column_name.data ());
675
685
if (!is_valid_column_name (column_name)) return {};
676
686
@@ -725,7 +735,7 @@ bool FilterObjectGenerator::parse_wmember(const std::string_view &name,
725
735
726
736
if (result) {
727
737
where_.append_preformatted (" (" )
728
- .append_preformatted (( *result). c_str () )
738
+ .append_preformatted (*result)
729
739
.append_preformatted (" )" );
730
740
return true ;
731
741
}
0 commit comments