Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
a3542482
Commit
a3542482
authored
Dec 26, 2020
by
Olivier Bertrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Continue BSON implementation + fix create modified ha_connect.cc
parent
2113cab7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
125 deletions
+132
-125
storage/connect/bson.cpp
storage/connect/bson.cpp
+90
-84
storage/connect/bson.h
storage/connect/bson.h
+15
-13
storage/connect/bsonudf.cpp
storage/connect/bsonudf.cpp
+4
-4
storage/connect/ha_connect.cc
storage/connect/ha_connect.cc
+4
-4
storage/connect/tabbson.cpp
storage/connect/tabbson.cpp
+19
-20
No files found.
storage/connect/bson.cpp
View file @
a3542482
...
@@ -59,38 +59,6 @@ void trans_func(unsigned int u, _EXCEPTION_POINTERS* pExp) {
...
@@ -59,38 +59,6 @@ void trans_func(unsigned int u, _EXCEPTION_POINTERS* pExp) {
char
*
GetExceptionDesc
(
PGLOBAL
g
,
unsigned
int
e
);
char
*
GetExceptionDesc
(
PGLOBAL
g
,
unsigned
int
e
);
#endif // SE_CATCH
#endif // SE_CATCH
#if 0
char* GetJsonNull(void);
/***********************************************************************/
/* IsNum: check whether this string is all digits. */
/***********************************************************************/
bool IsNum(PSZ s) {
for (char* p = s; *p; p++)
if (*p == ']')
break;
else if (!isdigit(*p) || *p == '-')
return false;
return true;
} // end of IsNum
/***********************************************************************/
/* NextChr: return the first found '[' or Sep pointer. */
/***********************************************************************/
char* NextChr(PSZ s, char sep) {
char* p1 = strchr(s, '[');
char* p2 = strchr(s, sep);
if (!p2)
return p1;
else if (p1)
return MY_MIN(p1, p2);
return p2;
} // end of NextChr
#endif // 0
/* --------------------------- Class BDOC ---------------------------- */
/* --------------------------- Class BDOC ---------------------------- */
/***********************************************************************/
/***********************************************************************/
...
@@ -180,7 +148,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng)
...
@@ -180,7 +148,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng)
if
(
bvp
->
Type
!=
TYPE_UNKNOWN
)
{
if
(
bvp
->
Type
!=
TYPE_UNKNOWN
)
{
bvp
->
To_Val
=
ParseAsArray
(
i
);
bvp
->
To_Val
=
ParseAsArray
(
i
);
bvp
->
Type
=
TYPE_JAR
;
bvp
->
Type
=
TYPE_JAR
;
}
else
if
((
bvp
->
To_Val
=
MOF
(
ParseValue
(
i
))))
}
else
if
((
bvp
->
To_Val
=
MOF
(
ParseValue
(
i
,
NewVal
()
))))
bvp
->
Type
=
TYPE_JVAL
;
bvp
->
Type
=
TYPE_JVAL
;
else
else
throw
4
;
throw
4
;
...
@@ -269,11 +237,11 @@ OFFSET BDOC::ParseArray(int& i)
...
@@ -269,11 +237,11 @@ OFFSET BDOC::ParseArray(int& i)
sprintf
(
G
->
Message
,
"Unexpected value near %.*s"
,
ARGS
);
sprintf
(
G
->
Message
,
"Unexpected value near %.*s"
,
ARGS
);
throw
1
;
throw
1
;
}
else
if
(
lastvlp
)
{
}
else
if
(
lastvlp
)
{
vlp
=
ParseValue
(
i
);
vlp
=
ParseValue
(
i
,
NewVal
()
);
lastvlp
->
Next
=
MOF
(
vlp
);
lastvlp
->
Next
=
MOF
(
vlp
);
lastvlp
=
vlp
;
lastvlp
=
vlp
;
}
else
}
else
firstvlp
=
lastvlp
=
ParseValue
(
i
);
firstvlp
=
lastvlp
=
ParseValue
(
i
,
NewVal
()
);
level
=
(
b
)
?
1
:
2
;
level
=
(
b
)
?
1
:
2
;
break
;
break
;
...
@@ -303,10 +271,10 @@ OFFSET BDOC::ParseObject(int& i)
...
@@ -303,10 +271,10 @@ OFFSET BDOC::ParseObject(int& i)
case
'"'
:
case
'"'
:
if
(
level
<
2
)
{
if
(
level
<
2
)
{
key
=
ParseString
(
++
i
);
key
=
ParseString
(
++
i
);
bpp
=
SubAlloc
Pair
(
key
);
bpp
=
New
Pair
(
key
);
if
(
lastbpp
)
{
if
(
lastbpp
)
{
lastbpp
->
Next
=
MOF
(
bpp
);
lastbpp
->
Vlp
.
Next
=
MOF
(
bpp
);
lastbpp
=
bpp
;
lastbpp
=
bpp
;
}
else
}
else
firstbpp
=
lastbpp
=
bpp
;
firstbpp
=
lastbpp
=
bpp
;
...
@@ -320,7 +288,7 @@ OFFSET BDOC::ParseObject(int& i)
...
@@ -320,7 +288,7 @@ OFFSET BDOC::ParseObject(int& i)
break
;
break
;
case
':'
:
case
':'
:
if
(
level
==
2
)
{
if
(
level
==
2
)
{
lastbpp
->
Vlp
=
MOF
(
ParseValue
(
++
i
));
ParseValue
(
++
i
,
GetVlp
(
lastbpp
));
level
=
3
;
level
=
3
;
}
else
{
}
else
{
sprintf
(
G
->
Message
,
"Unexpected ':' near %.*s"
,
ARGS
);
sprintf
(
G
->
Message
,
"Unexpected ':' near %.*s"
,
ARGS
);
...
@@ -362,10 +330,8 @@ OFFSET BDOC::ParseObject(int& i)
...
@@ -362,10 +330,8 @@ OFFSET BDOC::ParseObject(int& i)
/***********************************************************************/
/***********************************************************************/
/* Parse a JSON Value. */
/* Parse a JSON Value. */
/***********************************************************************/
/***********************************************************************/
PBVAL
BDOC
::
ParseValue
(
int
&
i
)
PBVAL
BDOC
::
ParseValue
(
int
&
i
,
PBVAL
bvp
)
{
{
PBVAL
bvp
=
NewVal
();
for
(;
i
<
len
;
i
++
)
for
(;
i
<
len
;
i
++
)
switch
(
s
[
i
])
{
switch
(
s
[
i
])
{
case
'\n'
:
case
'\n'
:
...
@@ -750,7 +716,7 @@ bool BDOC::SerializeObject(OFFSET obp)
...
@@ -750,7 +716,7 @@ bool BDOC::SerializeObject(OFFSET obp)
if
(
jp
->
WriteChr
(
'{'
))
if
(
jp
->
WriteChr
(
'{'
))
return
true
;
return
true
;
for
(
prp
;
prp
;
prp
=
MPP
(
prp
->
Next
))
{
for
(
prp
;
prp
;
prp
=
GetNext
(
prp
))
{
if
(
first
)
if
(
first
)
first
=
false
;
first
=
false
;
else
if
(
jp
->
WriteChr
(
','
))
else
if
(
jp
->
WriteChr
(
','
))
...
@@ -760,7 +726,7 @@ bool BDOC::SerializeObject(OFFSET obp)
...
@@ -760,7 +726,7 @@ bool BDOC::SerializeObject(OFFSET obp)
jp
->
WriteStr
(
MZP
(
prp
->
Key
))
||
jp
->
WriteStr
(
MZP
(
prp
->
Key
))
||
jp
->
WriteChr
(
'"'
)
||
jp
->
WriteChr
(
'"'
)
||
jp
->
WriteChr
(
':'
)
||
jp
->
WriteChr
(
':'
)
||
SerializeValue
(
MVP
(
prp
->
Vl
p
)))
SerializeValue
(
GetVlp
(
pr
p
)))
return
true
;
return
true
;
}
// endfor i
}
// endfor i
...
@@ -883,15 +849,35 @@ void BJSON::MemSet(size_t size)
...
@@ -883,15 +849,35 @@ void BJSON::MemSet(size_t size)
/* ------------------------ Bobject functions ------------------------ */
/* ------------------------ Bobject functions ------------------------ */
/***********************************************************************/
/***********************************************************************/
/* Set a pair vlp to some PVAL values. */
/***********************************************************************/
void
BJSON
::
SetPairValue
(
PBPR
brp
,
PBVAL
bvp
)
{
if
(
bvp
)
{
brp
->
Vlp
.
To_Val
=
bvp
->
To_Val
;
brp
->
Vlp
.
Nd
=
bvp
->
Nd
;
brp
->
Vlp
.
Type
=
bvp
->
Type
;
}
else
{
brp
->
Vlp
.
To_Val
=
0
;
brp
->
Vlp
.
Nd
=
0
;
brp
->
Vlp
.
Type
=
TYPE_NULL
;
}
// endif bvp
}
// end of SetPairValue
/***********************************************************************/
/* Sub-allocate and initialize a BPAIR. */
/* Sub-allocate and initialize a BPAIR. */
/***********************************************************************/
/***********************************************************************/
PBPR
BJSON
::
SubAllocPair
(
OFFSET
key
,
OFFSET
val
)
PBPR
BJSON
::
NewPair
(
OFFSET
key
,
int
type
)
{
{
PBPR
bpp
=
(
PBPR
)
BsonSubAlloc
(
sizeof
(
BPAIR
));
PBPR
bpp
=
(
PBPR
)
BsonSubAlloc
(
sizeof
(
BPAIR
));
bpp
->
Key
=
key
;
bpp
->
Key
=
key
;
bpp
->
Vlp
=
val
;
bpp
->
Vlp
.
Ktp
=
TYPE_STRG
;
bpp
->
Next
=
0
;
bpp
->
Vlp
.
Type
=
type
;
bpp
->
Vlp
.
To_Val
=
0
;
bpp
->
Vlp
.
Nd
=
0
;
bpp
->
Vlp
.
Next
=
0
;
return
bpp
;
return
bpp
;
}
// end of SubAllocPair
}
// end of SubAllocPair
...
@@ -905,7 +891,7 @@ int BJSON::GetObjectSize(PBVAL bop, bool b)
...
@@ -905,7 +891,7 @@ int BJSON::GetObjectSize(PBVAL bop, bool b)
for
(
PBPR
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
for
(
PBPR
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
// If b return only non null pairs
// If b return only non null pairs
if
(
!
b
||
(
brp
->
Vlp
&&
GetVal
(
brp
)
->
Type
!=
TYPE_NULL
))
if
(
!
b
||
(
brp
->
Vlp
.
To_Val
&&
brp
->
Vlp
.
Type
!=
TYPE_NULL
))
n
++
;
n
++
;
return
n
;
return
n
;
...
@@ -914,20 +900,21 @@ int BJSON::GetObjectSize(PBVAL bop, bool b)
...
@@ -914,20 +900,21 @@ int BJSON::GetObjectSize(PBVAL bop, bool b)
/***********************************************************************/
/***********************************************************************/
/* Add a new pair to an Object and return it. */
/* Add a new pair to an Object and return it. */
/***********************************************************************/
/***********************************************************************/
void
BJSON
::
AddPair
(
PBVAL
bop
,
PSZ
key
,
OFFSET
val
)
PBVAL
BJSON
::
AddPair
(
PBVAL
bop
,
PSZ
key
,
int
type
)
{
{
CheckType
(
bop
,
TYPE_JOB
);
CheckType
(
bop
,
TYPE_JOB
);
PBPR
brp
;
PBPR
brp
;
OFFSET
nrp
=
NewPair
(
key
,
val
);
OFFSET
nrp
=
NewPair
(
key
,
type
);
if
(
bop
->
To_Val
)
{
if
(
bop
->
To_Val
)
{
for
(
brp
=
GetObject
(
bop
);
brp
->
Next
;
brp
=
GetNext
(
brp
));
for
(
brp
=
GetObject
(
bop
);
brp
->
Vlp
.
Next
;
brp
=
GetNext
(
brp
));
brp
->
Next
=
nrp
;
brp
->
Vlp
.
Next
=
nrp
;
}
else
}
else
bop
->
To_Val
=
nrp
;
bop
->
To_Val
=
nrp
;
bop
->
Nd
++
;
bop
->
Nd
++
;
return
GetVlp
(
MPP
(
nrp
));
}
// end of AddPair
}
// end of AddPair
/***********************************************************************/
/***********************************************************************/
...
@@ -953,7 +940,7 @@ PBVAL BJSON::GetObjectValList(PBVAL bop)
...
@@ -953,7 +940,7 @@ PBVAL BJSON::GetObjectValList(PBVAL bop)
PBVAL
arp
=
NewVal
(
TYPE_JAR
);
PBVAL
arp
=
NewVal
(
TYPE_JAR
);
for
(
PBPR
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
for
(
PBPR
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
AddArrayValue
(
arp
,
brp
->
Vlp
);
AddArrayValue
(
arp
,
GetVlp
(
brp
)
);
return
arp
;
return
arp
;
}
// end of GetObjectValList
}
// end of GetObjectValList
...
@@ -967,7 +954,7 @@ PBVAL BJSON::GetKeyValue(PBVAL bop, PSZ key)
...
@@ -967,7 +954,7 @@ PBVAL BJSON::GetKeyValue(PBVAL bop, PSZ key)
for
(
PBPR
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
for
(
PBPR
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
if
(
!
strcmp
(
GetKey
(
brp
),
key
))
if
(
!
strcmp
(
GetKey
(
brp
),
key
))
return
GetV
al
(
brp
);
return
GetV
lp
(
brp
);
return
NULL
;
return
NULL
;
}
// end of GetKeyValue;
}
// end of GetKeyValue;
...
@@ -993,11 +980,11 @@ PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text)
...
@@ -993,11 +980,11 @@ PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text)
b
=
false
;
b
=
false
;
}
// endif text
}
// endif text
if
(
b
&&
!
brp
->
Next
&&
!
strcmp
(
MZP
(
brp
->
Key
),
"$date"
))
{
if
(
b
&&
!
brp
->
Vlp
.
Next
&&
!
strcmp
(
MZP
(
brp
->
Key
),
"$date"
))
{
int
i
;
int
i
;
PSZ
s
;
PSZ
s
;
GetValueText
(
g
,
MVP
(
brp
->
Vl
p
),
text
);
GetValueText
(
g
,
GetVlp
(
br
p
),
text
);
s
=
text
->
GetStr
();
s
=
text
->
GetStr
();
i
=
(
s
[
1
]
==
'-'
?
2
:
1
);
i
=
(
s
[
1
]
==
'-'
?
2
:
1
);
...
@@ -1013,10 +1000,10 @@ PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text)
...
@@ -1013,10 +1000,10 @@ PSZ BJSON::GetObjectText(PGLOBAL g, PBVAL bop, PSTRG text)
}
// endif text
}
// endif text
}
else
for
(
PBPR
brp
=
GetObject
(
bop
)
;
brp
;
brp
=
GetNext
(
brp
))
{
}
else
for
(;
brp
;
brp
=
GetNext
(
brp
))
{
GetValueText
(
g
,
GetV
al
(
brp
),
text
);
GetValueText
(
g
,
GetV
lp
(
brp
),
text
);
if
(
brp
->
Next
)
if
(
brp
->
Vlp
.
Next
)
text
->
Append
(
' '
);
text
->
Append
(
' '
);
}
// endfor brp
}
// endfor brp
...
@@ -1041,18 +1028,18 @@ void BJSON::SetKeyValue(PBVAL bop, OFFSET bvp, PSZ key)
...
@@ -1041,18 +1028,18 @@ void BJSON::SetKeyValue(PBVAL bop, OFFSET bvp, PSZ key)
if
(
bop
->
To_Val
)
{
if
(
bop
->
To_Val
)
{
for
(
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
for
(
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
if
(
!
strcmp
(
GetKey
(
brp
),
key
))
{
if
(
!
strcmp
(
GetKey
(
brp
),
key
))
brp
->
Vlp
=
bvp
;
break
;
return
;
else
}
else
prp
=
brp
;
prp
=
brp
;
if
(
!
brp
)
if
(
!
brp
)
prp
->
Next
=
NewPair
(
key
,
bvp
);
brp
=
MPP
(
prp
->
Vlp
.
Next
=
NewPair
(
key
)
);
}
else
}
else
b
op
->
To_Val
=
NewPair
(
key
,
bvp
);
b
rp
=
MPP
(
bop
->
To_Val
=
NewPair
(
key
)
);
SetPairValue
(
brp
,
MVP
(
bvp
));
bop
->
Nd
++
;
bop
->
Nd
++
;
}
// end of SetKeyValue
}
// end of SetKeyValue
...
@@ -1066,7 +1053,7 @@ PBVAL BJSON::MergeObject(PBVAL bop1, PBVAL bop2)
...
@@ -1066,7 +1053,7 @@ PBVAL BJSON::MergeObject(PBVAL bop1, PBVAL bop2)
if
(
bop1
->
To_Val
)
if
(
bop1
->
To_Val
)
for
(
PBPR
brp
=
GetObject
(
bop2
);
brp
;
brp
=
GetNext
(
brp
))
for
(
PBPR
brp
=
GetObject
(
bop2
);
brp
;
brp
=
GetNext
(
brp
))
SetKeyValue
(
bop1
,
brp
->
Vlp
,
GetKey
(
brp
));
SetKeyValue
(
bop1
,
GetVlp
(
brp
)
,
GetKey
(
brp
));
else
{
else
{
bop1
->
To_Val
=
bop2
->
To_Val
;
bop1
->
To_Val
=
bop2
->
To_Val
;
...
@@ -1087,9 +1074,9 @@ void BJSON::DeleteKey(PBVAL bop, PCSZ key)
...
@@ -1087,9 +1074,9 @@ void BJSON::DeleteKey(PBVAL bop, PCSZ key)
for
(
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
for
(
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
if
(
!
strcmp
(
MZP
(
brp
->
Key
),
key
))
{
if
(
!
strcmp
(
MZP
(
brp
->
Key
),
key
))
{
if
(
pbrp
)
{
if
(
pbrp
)
{
pbrp
->
Next
=
brp
->
Next
;
pbrp
->
Vlp
.
Next
=
brp
->
Vlp
.
Next
;
}
else
}
else
bop
->
To_Val
=
brp
->
Next
;
bop
->
To_Val
=
brp
->
Vlp
.
Next
;
bop
->
Nd
--
;
bop
->
Nd
--
;
break
;
break
;
...
@@ -1106,7 +1093,7 @@ bool BJSON::IsObjectNull(PBVAL bop)
...
@@ -1106,7 +1093,7 @@ bool BJSON::IsObjectNull(PBVAL bop)
CheckType
(
bop
,
TYPE_JOB
);
CheckType
(
bop
,
TYPE_JOB
);
for
(
PBPR
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
for
(
PBPR
brp
=
GetObject
(
bop
);
brp
;
brp
=
GetNext
(
brp
))
if
(
brp
->
Vlp
&&
(
MVP
(
brp
->
Vlp
))
->
Type
!=
TYPE_NULL
)
if
(
brp
->
Vlp
.
To_Val
&&
brp
->
Vlp
.
Type
!=
TYPE_NULL
)
return
false
;
return
false
;
return
true
;
return
true
;
...
@@ -1368,6 +1355,25 @@ int BJSON::GetSize(PBVAL vlp, bool b)
...
@@ -1368,6 +1355,25 @@ int BJSON::GetSize(PBVAL vlp, bool b)
}
// end of GetSize
}
// end of GetSize
PBVAL
BJSON
::
GetBson
(
PBVAL
bvp
)
{
PBVAL
bp
=
NULL
;
switch
(
bvp
->
Type
)
{
case
TYPE_JAR
:
bp
=
MVP
(
bvp
->
To_Val
);
break
;
case
TYPE_JOB
:
bp
=
GetVlp
(
MPP
(
bvp
->
To_Val
));
break
;
default:
bp
=
bvp
;
break
;
}
// endswitch Type
return
bp
;
}
// end of GetBson
/***********************************************************************/
/***********************************************************************/
/* Return the Value's as a Value struct. */
/* Return the Value's as a Value struct. */
/***********************************************************************/
/***********************************************************************/
...
...
storage/connect/bson.h
View file @
a3542482
...
@@ -37,7 +37,8 @@ typedef struct _jvalue {
...
@@ -37,7 +37,8 @@ typedef struct _jvalue {
bool
B
;
// A boolean value True or false (0)
bool
B
;
// A boolean value True or false (0)
};
};
short
Nd
;
// Number of decimals
short
Nd
;
// Number of decimals
short
Type
;
// The value type
char
Type
;
// The value type
char
Ktp
;
// The key type
OFFSET
Next
;
// Offset to the next value in array
OFFSET
Next
;
// Offset to the next value in array
}
BVAL
,
*
PBVAL
;
// end of struct BVALUE
}
BVAL
,
*
PBVAL
;
// end of struct BVALUE
...
@@ -46,8 +47,7 @@ typedef struct _jvalue {
...
@@ -46,8 +47,7 @@ typedef struct _jvalue {
/***********************************************************************/
/***********************************************************************/
typedef
struct
_jpair
{
typedef
struct
_jpair
{
OFFSET
Key
;
// Offset to this pair key name
OFFSET
Key
;
// Offset to this pair key name
OFFSET
Vlp
;
// To the value of the pair
BVAL
Vlp
;
// The value of the pair
OFFSET
Next
;
// Offset to the next pair in object
}
BPAIR
,
*
PBPR
;
// end of struct BPAIR
}
BPAIR
,
*
PBPR
;
// end of struct BPAIR
char
*
NextChr
(
PSZ
s
,
char
sep
);
char
*
NextChr
(
PSZ
s
,
char
sep
);
...
@@ -81,9 +81,9 @@ class BJSON : public BLOCK {
...
@@ -81,9 +81,9 @@ class BJSON : public BLOCK {
// SubAlloc functions
// SubAlloc functions
void
*
BsonSubAlloc
(
size_t
size
);
void
*
BsonSubAlloc
(
size_t
size
);
PBPR
SubAllocPair
(
OFFSET
key
,
OFFSET
val
=
0
);
PBPR
NewPair
(
OFFSET
key
,
int
type
=
TYPE_NULL
);
OFFSET
NewPair
(
PSZ
key
,
OFFSET
val
=
0
)
OFFSET
NewPair
(
PSZ
key
,
int
type
=
TYPE_NULL
)
{
return
MOF
(
SubAllocPair
(
DupStr
(
key
),
val
));}
{
return
MOF
(
NewPair
(
DupStr
(
key
),
type
));}
PBVAL
NewVal
(
int
type
=
TYPE_NULL
);
PBVAL
NewVal
(
int
type
=
TYPE_NULL
);
PBVAL
NewVal
(
PVAL
valp
);
PBVAL
NewVal
(
PVAL
valp
);
PBVAL
SubAllocVal
(
OFFSET
toval
,
int
type
=
TYPE_NULL
,
short
nd
=
0
);
PBVAL
SubAllocVal
(
OFFSET
toval
,
int
type
=
TYPE_NULL
,
short
nd
=
0
);
...
@@ -110,13 +110,15 @@ class BJSON : public BLOCK {
...
@@ -110,13 +110,15 @@ class BJSON : public BLOCK {
// Object functions
// Object functions
inline
PBPR
GetObject
(
PBVAL
bop
)
{
return
MPP
(
bop
->
To_Val
);}
inline
PBPR
GetObject
(
PBVAL
bop
)
{
return
MPP
(
bop
->
To_Val
);}
inline
PBPR
GetNext
(
PBPR
brp
)
{
return
MPP
(
brp
->
Next
);
}
inline
PBPR
GetNext
(
PBPR
brp
)
{
return
MPP
(
brp
->
Vlp
.
Next
);
}
void
SetPairValue
(
PBPR
brp
,
PBVAL
bvp
);
int
GetObjectSize
(
PBVAL
bop
,
bool
b
=
false
);
int
GetObjectSize
(
PBVAL
bop
,
bool
b
=
false
);
PSZ
GetObjectText
(
PGLOBAL
g
,
PBVAL
bop
,
PSTRG
text
);
PSZ
GetObjectText
(
PGLOBAL
g
,
PBVAL
bop
,
PSTRG
text
);
PBVAL
MergeObject
(
PBVAL
bop1
,
PBVAL
bop2
);
PBVAL
MergeObject
(
PBVAL
bop1
,
PBVAL
bop2
);
void
AddPair
(
PBVAL
bop
,
PSZ
key
,
OFFSET
val
=
0
);
PBVAL
AddPair
(
PBVAL
bop
,
PSZ
key
,
int
type
=
TYPE_NULL
);
PSZ
GetKey
(
PBPR
prp
)
{
return
MZP
(
prp
->
Key
);}
PSZ
GetKey
(
PBPR
prp
)
{
return
prp
?
MZP
(
prp
->
Key
)
:
NULL
;}
PBVAL
GetVal
(
PBPR
prp
)
{
return
MVP
(
prp
->
Vlp
);}
PBVAL
GetTo_Val
(
PBPR
prp
)
{
return
prp
?
MVP
(
prp
->
Vlp
.
To_Val
)
:
NULL
;}
PBVAL
GetVlp
(
PBPR
prp
)
{
return
prp
?
(
PBVAL
)
&
prp
->
Vlp
:
NULL
;}
PBVAL
GetKeyValue
(
PBVAL
bop
,
PSZ
key
);
PBVAL
GetKeyValue
(
PBVAL
bop
,
PSZ
key
);
PBVAL
GetKeyList
(
PBVAL
bop
);
PBVAL
GetKeyList
(
PBVAL
bop
);
PBVAL
GetObjectValList
(
PBVAL
bop
);
PBVAL
GetObjectValList
(
PBVAL
bop
);
...
@@ -131,7 +133,7 @@ class BJSON : public BLOCK {
...
@@ -131,7 +133,7 @@ class BJSON : public BLOCK {
PBVAL
GetNext
(
PBVAL
vlp
)
{
return
MVP
(
vlp
->
Next
);}
PBVAL
GetNext
(
PBVAL
vlp
)
{
return
MVP
(
vlp
->
Next
);}
//PJSON GetJsp(void) { return (DataType == TYPE_JSON ? Jsp : NULL); }
//PJSON GetJsp(void) { return (DataType == TYPE_JSON ? Jsp : NULL); }
PSZ
GetValueText
(
PGLOBAL
g
,
PBVAL
vlp
,
PSTRG
text
);
PSZ
GetValueText
(
PGLOBAL
g
,
PBVAL
vlp
,
PSTRG
text
);
inline
PBVAL
GetBson
(
PBVAL
bvp
)
{
return
IsJson
(
bvp
)
?
MVP
(
bvp
->
To_Val
)
:
bvp
;
}
PBVAL
GetBson
(
PBVAL
bvp
);
PSZ
GetString
(
PBVAL
vp
,
char
*
buff
=
NULL
);
PSZ
GetString
(
PBVAL
vp
,
char
*
buff
=
NULL
);
int
GetInteger
(
PBVAL
vp
);
int
GetInteger
(
PBVAL
vp
);
long
long
GetBigint
(
PBVAL
vp
);
long
long
GetBigint
(
PBVAL
vp
);
...
@@ -178,7 +180,7 @@ class BDOC : public BJSON {
...
@@ -178,7 +180,7 @@ class BDOC : public BJSON {
protected:
protected:
OFFSET
ParseArray
(
int
&
i
);
OFFSET
ParseArray
(
int
&
i
);
OFFSET
ParseObject
(
int
&
i
);
OFFSET
ParseObject
(
int
&
i
);
PBVAL
ParseValue
(
int
&
i
);
PBVAL
ParseValue
(
int
&
i
,
PBVAL
bvp
);
OFFSET
ParseString
(
int
&
i
);
OFFSET
ParseString
(
int
&
i
);
void
ParseNumeric
(
int
&
i
,
PBVAL
bvp
);
void
ParseNumeric
(
int
&
i
,
PBVAL
bvp
);
OFFSET
ParseAsArray
(
int
&
i
);
OFFSET
ParseAsArray
(
int
&
i
);
...
...
storage/connect/bsonudf.cpp
View file @
a3542482
...
@@ -856,7 +856,7 @@ my_bool BJNX::LocateObject(PGLOBAL g, PBVAL jobp)
...
@@ -856,7 +856,7 @@ my_bool BJNX::LocateObject(PGLOBAL g, PBVAL jobp)
if
(
Jp
->
WriteStr
(
MZP
(
pair
->
Key
)))
if
(
Jp
->
WriteStr
(
MZP
(
pair
->
Key
)))
return
true
;
return
true
;
if
(
LocateValue
(
g
,
MVP
(
pair
->
Vlp
)))
if
(
LocateValue
(
g
,
GetVlp
(
pair
)))
return
true
;
return
true
;
}
// endfor i
}
// endfor i
...
@@ -976,7 +976,7 @@ my_bool BJNX::LocateObjectAll(PGLOBAL g, PBVAL jobp)
...
@@ -976,7 +976,7 @@ my_bool BJNX::LocateObjectAll(PGLOBAL g, PBVAL jobp)
for
(
PBPR
pair
=
GetObject
(
jobp
);
pair
;
pair
=
GetNext
(
pair
))
{
for
(
PBPR
pair
=
GetObject
(
jobp
);
pair
;
pair
=
GetNext
(
pair
))
{
Jpnp
[
I
].
Key
=
MZP
(
pair
->
Key
);
Jpnp
[
I
].
Key
=
MZP
(
pair
->
Key
);
if
(
LocateValueAll
(
g
,
MVP
(
pair
->
Vlp
)))
if
(
LocateValueAll
(
g
,
GetVlp
(
pair
)))
return
true
;
return
true
;
}
// endfor i
}
// endfor i
...
@@ -1020,8 +1020,8 @@ my_bool BJNX::CompareTree(PGLOBAL g, PBVAL jp1, PBVAL jp2)
...
@@ -1020,8 +1020,8 @@ my_bool BJNX::CompareTree(PGLOBAL g, PBVAL jp1, PBVAL jp2)
PBPR
p1
=
GetObject
(
jp1
),
p2
=
GetObject
(
jp2
);
PBPR
p1
=
GetObject
(
jp1
),
p2
=
GetObject
(
jp2
);
// Keys can be differently ordered
// Keys can be differently ordered
for
(;
found
&&
p1
&&
p2
;
p1
=
MPP
(
p1
->
Next
))
for
(;
found
&&
p1
&&
p2
;
p1
=
GetNext
(
p1
))
found
=
CompareValues
(
g
,
MVP
(
p1
->
Vlp
),
GetKeyValue
(
jp2
,
MZP
(
p1
->
Key
)));
found
=
CompareValues
(
g
,
GetVlp
(
p1
),
GetKeyValue
(
jp2
,
GetKey
(
p1
)));
}
else
if
(
jp1
->
Type
==
TYPE_JVAL
)
{
}
else
if
(
jp1
->
Type
==
TYPE_JVAL
)
{
found
=
CompareTree
(
g
,
MVP
(
jp1
->
To_Val
),
(
MVP
(
jp2
->
To_Val
)));
found
=
CompareTree
(
g
,
MVP
(
jp1
->
To_Val
),
(
MVP
(
jp2
->
To_Val
)));
...
...
storage/connect/ha_connect.cc
View file @
a3542482
...
@@ -170,7 +170,7 @@
...
@@ -170,7 +170,7 @@
#define JSONMAX 10 // JSON Default max grp size
#define JSONMAX 10 // JSON Default max grp size
extern
"C"
{
extern
"C"
{
char
version
[]
=
"Version 1.07.0002 December
19
, 2020"
;
char
version
[]
=
"Version 1.07.0002 December
25
, 2020"
;
#if defined(__WIN__)
#if defined(__WIN__)
char
compver
[]
=
"Version 1.07.0002 "
__DATE__
" "
__TIME__
;
char
compver
[]
=
"Version 1.07.0002 "
__DATE__
" "
__TIME__
;
char
slash
=
'\\'
;
char
slash
=
'\\'
;
...
@@ -6440,9 +6440,9 @@ int ha_connect::create(const char *name, TABLE *table_arg,
...
@@ -6440,9 +6440,9 @@ int ha_connect::create(const char *name, TABLE *table_arg,
// Check table type
// Check table type
if
(
type
==
TAB_UNDEF
)
{
if
(
type
==
TAB_UNDEF
)
{
options
->
type
=
(
options
->
srcdef
)
?
"MYSQL"
:
options
->
type
=
(
options
->
srcdef
)
?
"MYSQL"
:
#if defined(
BSON
_SUPPORT)
#if defined(
REST
_SUPPORT)
(
options
->
http
)
?
"JSON"
:
(
options
->
http
)
?
"JSON"
:
#endif //
BSON
_SUPPORT
#endif //
REST
_SUPPORT
(
options
->
tabname
)
?
"PROXY"
:
"DOS"
;
(
options
->
tabname
)
?
"PROXY"
:
"DOS"
;
type
=
GetTypeID
(
options
->
type
);
type
=
GetTypeID
(
options
->
type
);
sprintf
(
g
->
Message
,
"No table_type. Will be set to %s"
,
options
->
type
);
sprintf
(
g
->
Message
,
"No table_type. Will be set to %s"
,
options
->
type
);
...
@@ -6460,7 +6460,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
...
@@ -6460,7 +6460,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
DBUG_RETURN
(
HA_ERR_INTERNAL_ERROR
);
DBUG_RETURN
(
HA_ERR_INTERNAL_ERROR
);
inward
=
IsFileType
(
type
)
&&
!
options
->
filename
&&
inward
=
IsFileType
(
type
)
&&
!
options
->
filename
&&
(
type
!=
TAB_JSON
||
!
cnc
.
length
);
(
(
type
!=
TAB_JSON
&&
type
!=
TAB_BSON
)
||
!
cnc
.
length
);
if
(
options
->
data_charset
)
{
if
(
options
->
data_charset
)
{
const
CHARSET_INFO
*
data_charset
;
const
CHARSET_INFO
*
data_charset
;
...
...
storage/connect/tabbson.cpp
View file @
a3542482
...
@@ -342,7 +342,7 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
...
@@ -342,7 +342,7 @@ int BSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
strncpy
(
colname
,
bp
->
GetKey
(
jpp
),
64
);
strncpy
(
colname
,
bp
->
GetKey
(
jpp
),
64
);
fmt
[
bf
]
=
0
;
fmt
[
bf
]
=
0
;
if
(
Find
(
g
,
bp
->
GetV
al
(
jpp
),
colname
,
MY_MIN
(
lvl
,
0
)))
if
(
Find
(
g
,
bp
->
GetV
lp
(
jpp
),
colname
,
MY_MIN
(
lvl
,
0
)))
goto
err
;
goto
err
;
}
// endfor jpp
}
// endfor jpp
...
@@ -444,7 +444,7 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j)
...
@@ -444,7 +444,7 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j)
strncat
(
strncat
(
colname
,
"_"
,
n
),
k
,
n
-
1
);
strncat
(
strncat
(
colname
,
"_"
,
n
),
k
,
n
-
1
);
}
// endif Key
}
// endif Key
if
(
Find
(
g
,
bp
->
GetV
al
(
jrp
),
k
,
j
+
1
))
if
(
Find
(
g
,
bp
->
GetV
lp
(
jrp
),
k
,
j
+
1
))
return
true
;
return
true
;
*
p
=
*
pc
=
0
;
*
p
=
*
pc
=
0
;
...
@@ -691,7 +691,7 @@ PBVAL BTUTIL::MakeTopTree(PGLOBAL g, int type)
...
@@ -691,7 +691,7 @@ PBVAL BTUTIL::MakeTopTree(PGLOBAL g, int type)
}
// endif Val
}
// endif Val
Tp
->
Row
=
val
;
Tp
->
Row
=
val
;
Tp
->
Row
->
Type
=
type
;
if
(
Tp
->
Row
)
Tp
->
Row
->
Type
=
type
;
}
else
}
else
top
=
Tp
->
Row
=
NewVal
(
type
);
top
=
Tp
->
Row
=
NewVal
(
type
);
...
@@ -1052,18 +1052,20 @@ PBVAL BCUTIL::GetRow(PGLOBAL g)
...
@@ -1052,18 +1052,20 @@ PBVAL BCUTIL::GetRow(PGLOBAL g)
}
else
{
}
else
{
// Construct missing objects
// Construct missing objects
for
(
i
++
;
row
&&
i
<
nod
;
i
++
)
{
for
(
i
++
;
row
&&
i
<
nod
;
i
++
)
{
int
type
;
if
(
nodes
[
i
].
Op
==
OP_XX
)
if
(
nodes
[
i
].
Op
==
OP_XX
)
break
;
break
;
else
if
(
!
nodes
[
i
].
Key
)
else
if
(
!
nodes
[
i
].
Key
)
// Construct intermediate array
// Construct intermediate array
nwr
=
NewVal
(
TYPE_JAR
)
;
type
=
TYPE_JAR
;
else
else
nwr
=
NewVal
(
TYPE_JOB
)
;
type
=
TYPE_JOB
;
if
(
row
->
Type
==
TYPE_JOB
)
{
if
(
row
->
Type
==
TYPE_JOB
)
{
SetKeyValue
(
row
,
MOF
(
nwr
),
nodes
[
i
-
1
].
Key
);
nwr
=
AddPair
(
row
,
nodes
[
i
-
1
].
Key
,
type
);
}
else
if
(
row
->
Type
==
TYPE_JAR
)
{
}
else
if
(
row
->
Type
==
TYPE_JAR
)
{
AddArrayValue
(
row
,
nwr
);
AddArrayValue
(
row
,
(
nwr
=
NewVal
(
type
))
);
}
else
{
}
else
{
strcpy
(
g
->
Message
,
"Wrong type when writing new row"
);
strcpy
(
g
->
Message
,
"Wrong type when writing new row"
);
nwr
=
NULL
;
nwr
=
NULL
;
...
@@ -2258,19 +2260,16 @@ int TDBBSON::MakeDocument(PGLOBAL g)
...
@@ -2258,19 +2260,16 @@ int TDBBSON::MakeDocument(PGLOBAL g)
Docp
=
jsp
;
Docp
=
jsp
;
else
{
else
{
// The table is void or is just one object or one value
// The table is void or is just one object or one value
if
(
objp
)
{
Docp
=
Bp
->
GetKeyValue
(
objp
,
key
);
Docp
->
To_Val
=
Bp
->
MOF
(
Bp
->
DupVal
(
Docp
));
Docp
->
Type
=
TYPE_JAR
;
}
else
if
(
arp
)
{
Docp
=
Bp
->
NewVal
(
TYPE_JAR
);
Docp
=
Bp
->
NewVal
(
TYPE_JAR
);
Bp
->
AddArrayValue
(
Docp
,
jsp
);
if
(
val
)
Bp
->
SetArrayValue
(
arp
,
Docp
,
i
);
Bp
->
AddArrayValue
(
Docp
,
val
);
}
else
else
if
(
jsp
)
Top
=
Docp
=
Bp
->
NewVal
(
TYPE_JAR
);
Bp
->
AddArrayValue
(
Docp
,
Bp
->
DupVal
(
jsp
));
if
(
objp
)
Bp
->
SetKeyValue
(
objp
,
Bp
->
DupVal
(
Docp
),
key
);
else
if
(
arp
)
Bp
->
SetArrayValue
(
arp
,
Bp
->
DupVal
(
Docp
),
i
);
else
Top
=
Docp
;
}
// endif jsp
}
// endif jsp
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment