@@ -3538,37 +3538,9 @@ void jsoncontains_path_deinit(UDF_INIT* initid)
3538
3538
} // end of jsoncontains_path_deinit
3539
3539
3540
3540
/* ********************************************************************************/
3541
- /* Set Json items of a Json document according to path. */
3541
+ /* This function is used by the json_set/insert/update_item functions. */
3542
3542
/* ********************************************************************************/
3543
- my_bool json_set_item_init (UDF_INIT *initid, UDF_ARGS *args, char *message)
3544
- {
3545
- unsigned long reslen, memlen;
3546
- int n = IsJson (args, 0 );
3547
-
3548
- if (!(args->arg_count % 2 )) {
3549
- strcpy (message, " This function must have an odd number of arguments" );
3550
- return true ;
3551
- } else if (!n && args->arg_type [0 ] != STRING_RESULT) {
3552
- strcpy (message, " First argument must be a json item" );
3553
- return true ;
3554
- } else
3555
- CalcLen (args, false , reslen, memlen);
3556
-
3557
- if (n == 2 && args->args [0 ]) {
3558
- char fn[_MAX_PATH];
3559
- long fl;
3560
-
3561
- memcpy (fn, args->args [0 ], args->lengths [0 ]);
3562
- fn[args->lengths [0 ]] = 0 ;
3563
- fl = GetFileLength (fn);
3564
- memlen += fl * 3 ;
3565
- } else if (n != 3 )
3566
- memlen += args->lengths [0 ] * 3 ;
3567
-
3568
- return JsonInit (initid, args, message, true , reslen, memlen);
3569
- } // end of json_set_item_init
3570
-
3571
- char *json_set_item (UDF_INIT *initid, UDF_ARGS *args, char *result,
3543
+ char *handle_item (UDF_INIT *initid, UDF_ARGS *args, char *result,
3572
3544
unsigned long *res_length, char *is_null, char *error)
3573
3545
{
3574
3546
char *p, *path, *str = NULL ;
@@ -3586,12 +3558,16 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
3586
3558
} else if (initid->const_item )
3587
3559
g->N = 1 ;
3588
3560
3589
- if (!strcmp (result, " $insert" ))
3561
+ if (!strcmp (result, " $set" ))
3562
+ w = 0 ;
3563
+ else if (!strcmp (result, " $insert" ))
3590
3564
w = 1 ;
3591
3565
else if (!strcmp (result, " $update" ))
3592
3566
w = 2 ;
3593
- else
3594
- w = 0 ;
3567
+ else {
3568
+ PUSH_WARNING (" Logical error, please contact CONNECT developer" );
3569
+ goto err;
3570
+ } // endelse
3595
3571
3596
3572
// Save stack and allocation environment and prepare error return
3597
3573
if (g->jump_level == MAX_JUMP) {
@@ -3660,17 +3636,55 @@ char *json_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
3660
3636
// Keep result of constant function
3661
3637
g->Activityp = (PACTIVITY)str;
3662
3638
3663
- err:
3639
+ err:
3664
3640
g->jump_level --;
3665
3641
3666
- fin:
3642
+ fin:
3667
3643
if (!str) {
3668
3644
*is_null = 1 ;
3669
3645
*res_length = 0 ;
3670
3646
} else
3671
3647
*res_length = strlen (str);
3672
3648
3673
3649
return str;
3650
+ } // end of handle_item
3651
+
3652
+ /* ********************************************************************************/
3653
+ /* Set Json items of a Json document according to path. */
3654
+ /* ********************************************************************************/
3655
+ my_bool json_set_item_init (UDF_INIT *initid, UDF_ARGS *args, char *message)
3656
+ {
3657
+ unsigned long reslen, memlen;
3658
+ int n = IsJson (args, 0 );
3659
+
3660
+ if (!(args->arg_count % 2 )) {
3661
+ strcpy (message, " This function must have an odd number of arguments" );
3662
+ return true ;
3663
+ } else if (!n && args->arg_type [0 ] != STRING_RESULT) {
3664
+ strcpy (message, " First argument must be a json item" );
3665
+ return true ;
3666
+ } else
3667
+ CalcLen (args, false , reslen, memlen);
3668
+
3669
+ if (n == 2 && args->args [0 ]) {
3670
+ char fn[_MAX_PATH];
3671
+ long fl;
3672
+
3673
+ memcpy (fn, args->args [0 ], args->lengths [0 ]);
3674
+ fn[args->lengths [0 ]] = 0 ;
3675
+ fl = GetFileLength (fn);
3676
+ memlen += fl * 3 ;
3677
+ } else if (n != 3 )
3678
+ memlen += args->lengths [0 ] * 3 ;
3679
+
3680
+ return JsonInit (initid, args, message, true , reslen, memlen);
3681
+ } // end of json_set_item_init
3682
+
3683
+ char *json_set_item (UDF_INIT *initid, UDF_ARGS *args, char *result,
3684
+ unsigned long *res_length, char *is_null, char *p)
3685
+ {
3686
+ strcpy (result, " $set" );
3687
+ return handle_item (initid, args, result, res_length, is_null, p);
3674
3688
} // end of json_set_item
3675
3689
3676
3690
void json_set_item_deinit (UDF_INIT* initid)
@@ -3690,7 +3704,7 @@ char *json_insert_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
3690
3704
unsigned long *res_length, char *is_null, char *p)
3691
3705
{
3692
3706
strcpy (result, " $insert" );
3693
- return json_set_item (initid, args, result, res_length, is_null, p);
3707
+ return handle_item (initid, args, result, res_length, is_null, p);
3694
3708
} // end of json_insert_item
3695
3709
3696
3710
void json_insert_item_deinit (UDF_INIT* initid)
@@ -3710,7 +3724,7 @@ char *json_update_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
3710
3724
unsigned long *res_length, char *is_null, char *p)
3711
3725
{
3712
3726
strcpy (result, " $update" );
3713
- return json_set_item (initid, args, result, res_length, is_null, p);
3727
+ return handle_item (initid, args, result, res_length, is_null, p);
3714
3728
} // end of json_update_item
3715
3729
3716
3730
void json_update_item_deinit (UDF_INIT* initid)
@@ -4706,14 +4720,9 @@ void jbin_item_merge_deinit(UDF_INIT* initid)
4706
4720
} // end of jbin_item_merge_deinit
4707
4721
4708
4722
/* ********************************************************************************/
4709
- /* Set Json items of a Json document according to path. */
4723
+ /* This function is used by the jbin_set/insert/update functions. */
4710
4724
/* ********************************************************************************/
4711
- my_bool jbin_set_item_init (UDF_INIT *initid, UDF_ARGS *args, char *message)
4712
- {
4713
- return json_set_item_init (initid, args, message);
4714
- } // end of jbin_set_item_init
4715
-
4716
- char *jbin_set_item (UDF_INIT *initid, UDF_ARGS *args, char *result,
4725
+ char *bin_handle_item (UDF_INIT *initid, UDF_ARGS *args, char *result,
4717
4726
unsigned long *res_length, char *is_null, char *error)
4718
4727
{
4719
4728
char *p, *path;
@@ -4732,12 +4741,16 @@ char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
4732
4741
} else if (initid->const_item )
4733
4742
g->N = 1 ;
4734
4743
4735
- if (!strcmp (result, " $insert" ))
4744
+ if (!strcmp (result, " $set" ))
4745
+ w = 0 ;
4746
+ else if (!strcmp (result, " $insert" ))
4736
4747
w = 1 ;
4737
4748
else if (!strcmp (result, " $update" ))
4738
4749
w = 2 ;
4739
- else
4740
- w = 0 ;
4750
+ else {
4751
+ PUSH_WARNING (" Logical error, please contact CONNECT developer" );
4752
+ goto fin;
4753
+ } // endelse
4741
4754
4742
4755
if (!g->Xchk ) {
4743
4756
if (CheckMemory (g, initid, args, 1 , true , false , true )) {
@@ -4791,14 +4804,29 @@ char *jbin_set_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
4791
4804
// Keep result of constant function
4792
4805
g->Activityp = (PACTIVITY)bsp;
4793
4806
4794
- fin:
4807
+ fin:
4795
4808
if (!bsp) {
4796
4809
*is_null = 1 ;
4797
4810
*res_length = 0 ;
4798
4811
} else
4799
4812
*res_length = sizeof (BSON);
4800
4813
4801
4814
return (char *)bsp;
4815
+ } // end of bin_handle_item
4816
+
4817
+ /* ********************************************************************************/
4818
+ /* Set Json items of a Json document according to path. */
4819
+ /* ********************************************************************************/
4820
+ my_bool jbin_set_item_init (UDF_INIT *initid, UDF_ARGS *args, char *message)
4821
+ {
4822
+ return json_set_item_init (initid, args, message);
4823
+ } // end of jbin_set_item_init
4824
+
4825
+ char *jbin_set_item (UDF_INIT *initid, UDF_ARGS *args, char *result,
4826
+ unsigned long *res_length, char *is_null, char *p)
4827
+ {
4828
+ strcpy (result, " $set" );
4829
+ return bin_handle_item (initid, args, result, res_length, is_null, p);
4802
4830
} // end of jbin_set_item
4803
4831
4804
4832
void jbin_set_item_deinit (UDF_INIT* initid)
@@ -4818,7 +4846,7 @@ char *jbin_insert_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
4818
4846
unsigned long *res_length, char *is_null, char *p)
4819
4847
{
4820
4848
strcpy (result, " $insert" );
4821
- return jbin_set_item (initid, args, result, res_length, is_null, p);
4849
+ return bin_handle_item (initid, args, result, res_length, is_null, p);
4822
4850
} // end of jbin_insert_item
4823
4851
4824
4852
void jbin_insert_item_deinit (UDF_INIT* initid)
@@ -4838,7 +4866,7 @@ char *jbin_update_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
4838
4866
unsigned long *res_length, char *is_null, char *p)
4839
4867
{
4840
4868
strcpy (result, " $update" );
4841
- return jbin_set_item (initid, args, result, res_length, is_null, p);
4869
+ return bin_handle_item (initid, args, result, res_length, is_null, p);
4842
4870
} // end of jbin_update_item
4843
4871
4844
4872
void jbin_update_item_deinit (UDF_INIT* initid)
0 commit comments