summaryrefslogtreecommitdiff
path: root/storage/connect/bsonudf.h
blob: 1675d36cee533e06f958baf46dcd29ab211d59cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/******************** tabjson H Declares Source Code File (.H) *******************/
/*  Name: bsonudf.h   Version 1.0                                                */
/*                                                                               */
/*  (C) Copyright to the author Olivier BERTRAND          2020                   */
/*                                                                               */
/*  This file contains the BSON UDF function and class declares.                 */
/*********************************************************************************/
#pragma once
#include "jsonudf.h"
#include "bson.h"

/* --------------------------- New Testing BJSON Stuff --------------------------*/

typedef class BJNX* PBJNX;

/*********************************************************************************/
/*  Class BJNX: BJSON access methods.                                            */
/*********************************************************************************/
class BJNX : public BDOC {
public:
	// Constructors
	BJNX(PGLOBAL g, PBVAL row, int type, int len = 64, int prec = 0, my_bool wr = false);

	// Implementation
	int     GetPrecision(void) { return Prec; }
	PVAL    GetValue(void) { return Value; }

	// Methods
	my_bool SetJpath(PGLOBAL g, char* path, my_bool jb = false);
	my_bool ParseJpath(PGLOBAL g);
	void    ReadValue(PGLOBAL g);
	PBVAL   GetRowValue(PGLOBAL g, PBVAL row, int i, my_bool b = true);
	PBVAL   GetJson(PGLOBAL g);
	my_bool CheckPath(PGLOBAL g);
	my_bool WriteValue(PGLOBAL g, PBVAL jvalp);
	char* Locate(PGLOBAL g, PBVAL jsp, PBVAL jvp, int k = 1);
	char* LocateAll(PGLOBAL g, PBVAL jsp, PBVAL jvp, int mx = 10);

protected:
	my_bool SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm);
	PVAL    GetColumnValue(PGLOBAL g, PBVAL row, int i);
	PVAL    ExpandArray(PGLOBAL g, PBVAL arp, int n);
	PVAL    CalculateArray(PGLOBAL g, PBVAL arp, int n);
	PVAL    MakeJson(PGLOBAL g, PBVAL bvp);
	void    SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp);
	PBVAL   GetRow(PGLOBAL g);
	my_bool CompareValues(PGLOBAL g, PBVAL v1, PBVAL v2);
	my_bool LocateArray(PGLOBAL g, PBVAL jarp);
	my_bool LocateObject(PGLOBAL g, PBVAL jobp);
	my_bool LocateValue(PGLOBAL g, PBVAL jvp);
	my_bool LocateArrayAll(PGLOBAL g, PBVAL jarp);
	my_bool LocateObjectAll(PGLOBAL g, PBVAL jobp);
	my_bool LocateValueAll(PGLOBAL g, PBVAL jvp);
	my_bool CompareTree(PGLOBAL g, PBVAL jp1, PBVAL jp2);
	my_bool AddPath(void);

	// Default constructor not to be used
	BJNX(void) {}

	// Members
	PBVAL    Row;
	PBVAL    Bvalp;
	PJPN     Jpnp;
	JOUTSTR *Jp;
	JNODE   *Nodes;               // The intermediate objects
	PVAL     Value;
	PVAL     MulVal;              // To value used by multiple column
	char    *Jpath;               // The json path
	int      Buf_Type;
	int      Long;
	int      Prec;
	int      Nod;                 // The number of intermediate objects
	int      Xnod;                // Index of multiple values
	int      K;										// Kth item to locate
	int      I;										// Index of JPN
	int      Imax;								// Max number of JPN's
	int      B;										// Index base
	my_bool  Xpd;                 // True for expandable column
	my_bool  Parsed;              // True when parsed
	my_bool  Found;								// Item found by locate
	my_bool  Wr;			  					// Write mode
	my_bool  Jb;			  					// Must return json item
}; // end of class BJNX

extern "C" {
	DllExport my_bool bson_test_init(UDF_INIT*, UDF_ARGS*, char*);
	DllExport char* bson_test(UDF_EXEC_ARGS);
	DllExport void bson_test_deinit(UDF_INIT*);

	DllExport my_bool bsonvalue_init(UDF_INIT*, UDF_ARGS*, char*);
	DllExport char* bsonvalue(UDF_EXEC_ARGS);
	DllExport void bsonvalue_deinit(UDF_INIT*);

	DllExport my_bool bson_make_array_init(UDF_INIT*, UDF_ARGS*, char*);
	DllExport char* bson_make_array(UDF_EXEC_ARGS);
	DllExport void bson_make_array_deinit(UDF_INIT*);

	DllExport my_bool bson_array_add_values_init(UDF_INIT*, UDF_ARGS*, char*);
	DllExport char* bson_array_add_values(UDF_EXEC_ARGS);
	DllExport void bson_array_add_values_deinit(UDF_INIT*);

	DllExport my_bool bsonlocate_init(UDF_INIT*, UDF_ARGS*, char*);
	DllExport char* bsonlocate(UDF_EXEC_ARGS);
	DllExport void bsonlocate_deinit(UDF_INIT*);

	DllExport my_bool bson_locate_all_init(UDF_INIT*, UDF_ARGS*, char*);
	DllExport char* bson_locate_all(UDF_EXEC_ARGS);
	DllExport void bson_locate_all_deinit(UDF_INIT*);

	DllExport my_bool bfile_bjson_init(UDF_INIT*, UDF_ARGS*, char*);
	DllExport char* bfile_bjson(UDF_EXEC_ARGS);
	DllExport void bfile_bjson_deinit(UDF_INIT*);
} // extern "C"