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
cf8e78a4
Commit
cf8e78a4
authored
Oct 16, 2021
by
Sergei Krivonos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented Json_writer_array & Json_writer_object subitems name presence control
parent
df383043
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
6 deletions
+35
-6
.gitignore
.gitignore
+3
-0
sql/my_json_writer.cc
sql/my_json_writer.cc
+2
-0
sql/my_json_writer.h
sql/my_json_writer.h
+30
-6
No files found.
.gitignore
View file @
cf8e78a4
...
@@ -10,8 +10,11 @@
...
@@ -10,8 +10,11 @@
.ninja_*
.ninja_*
*.mri
*.mri
*.mri.tpl
*.mri.tpl
/.cproject
/.project
.gdb_history
.gdb_history
.vs/
.vs/
/.settings/
errmsg.sys
errmsg.sys
typescript
typescript
_CPack_Packages
_CPack_Packages
...
...
sql/my_json_writer.cc
View file @
cf8e78a4
...
@@ -260,6 +260,8 @@ void Json_writer::add_str(const String &str)
...
@@ -260,6 +260,8 @@ void Json_writer::add_str(const String &str)
add_str
(
str
.
ptr
(),
str
.
length
());
add_str
(
str
.
ptr
(),
str
.
length
());
}
}
thread_local
std
::
vector
<
bool
>
Json_writer_struct
::
named_items_expectation
;
Json_writer_temp_disable
::
Json_writer_temp_disable
(
THD
*
thd_arg
)
Json_writer_temp_disable
::
Json_writer_temp_disable
(
THD
*
thd_arg
)
{
{
thd
=
thd_arg
;
thd
=
thd_arg
;
...
...
sql/my_json_writer.h
View file @
cf8e78a4
...
@@ -15,8 +15,12 @@
...
@@ -15,8 +15,12 @@
#ifndef JSON_WRITER_INCLUDED
#ifndef JSON_WRITER_INCLUDED
#define JSON_WRITER_INCLUDED
#define JSON_WRITER_INCLUDED
#include "my_base.h"
#include "my_base.h"
#include "sql_select.h"
#include "sql_select.h"
#include <vector>
class
Opt_trace_stmt
;
class
Opt_trace_stmt
;
class
Opt_trace_context
;
class
Opt_trace_context
;
class
Json_writer
;
class
Json_writer
;
...
@@ -308,6 +312,7 @@ class Json_value_helper
...
@@ -308,6 +312,7 @@ class Json_value_helper
/* A common base for Json_writer_object and Json_writer_array */
/* A common base for Json_writer_object and Json_writer_array */
class
Json_writer_struct
class
Json_writer_struct
{
{
static
thread_local
std
::
vector
<
bool
>
named_items_expectation
;
protected:
protected:
Json_writer
*
my_writer
;
Json_writer
*
my_writer
;
Json_value_helper
context
;
Json_value_helper
context
;
...
@@ -317,16 +322,29 @@ class Json_writer_struct
...
@@ -317,16 +322,29 @@ class Json_writer_struct
bool
closed
;
bool
closed
;
public:
public:
explicit
Json_writer_struct
(
THD
*
thd
)
explicit
Json_writer_struct
(
THD
*
thd
,
bool
expect_named_children
)
{
{
my_writer
=
thd
->
opt_trace
.
get_current_json
();
my_writer
=
thd
->
opt_trace
.
get_current_json
();
context
.
init
(
my_writer
);
context
.
init
(
my_writer
);
closed
=
false
;
closed
=
false
;
named_items_expectation
.
push_back
(
expect_named_children
);
}
virtual
~
Json_writer_struct
()
{
named_items_expectation
.
pop_back
();
}
}
bool
trace_started
()
bool
trace_started
()
const
{
{
return
my_writer
!=
0
;
return
my_writer
!=
0
;
}
}
bool
named_item_expected
()
const
{
return
named_items_expectation
.
size
()
>
1
&&
*
(
named_items_expectation
.
rbegin
()
+
1
);
}
};
};
...
@@ -347,15 +365,17 @@ class Json_writer_object : public Json_writer_struct
...
@@ -347,15 +365,17 @@ class Json_writer_object : public Json_writer_struct
}
}
public:
public:
explicit
Json_writer_object
(
THD
*
thd
)
explicit
Json_writer_object
(
THD
*
thd
)
:
Json_writer_struct
(
thd
)
:
Json_writer_struct
(
thd
,
true
)
{
{
DBUG_ASSERT
(
!
named_item_expected
());
if
(
unlikely
(
my_writer
))
if
(
unlikely
(
my_writer
))
my_writer
->
start_object
();
my_writer
->
start_object
();
}
}
explicit
Json_writer_object
(
THD
*
thd
,
const
char
*
str
)
explicit
Json_writer_object
(
THD
*
thd
,
const
char
*
str
)
:
Json_writer_struct
(
thd
)
:
Json_writer_struct
(
thd
,
true
)
{
{
DBUG_ASSERT
(
named_item_expected
());
if
(
unlikely
(
my_writer
))
if
(
unlikely
(
my_writer
))
my_writer
->
add_member
(
str
).
start_object
();
my_writer
->
add_member
(
str
).
start_object
();
}
}
...
@@ -519,14 +539,18 @@ class Json_writer_object : public Json_writer_struct
...
@@ -519,14 +539,18 @@ class Json_writer_object : public Json_writer_struct
class
Json_writer_array
:
public
Json_writer_struct
class
Json_writer_array
:
public
Json_writer_struct
{
{
public:
public:
Json_writer_array
(
THD
*
thd
)
:
Json_writer_struct
(
thd
)
Json_writer_array
(
THD
*
thd
)
:
Json_writer_struct
(
thd
,
false
)
{
{
DBUG_ASSERT
(
!
named_item_expected
());
if
(
unlikely
(
my_writer
))
if
(
unlikely
(
my_writer
))
my_writer
->
start_array
();
my_writer
->
start_array
();
}
}
Json_writer_array
(
THD
*
thd
,
const
char
*
str
)
:
Json_writer_struct
(
thd
)
Json_writer_array
(
THD
*
thd
,
const
char
*
str
)
:
Json_writer_struct
(
thd
,
false
)
{
{
DBUG_ASSERT
(
named_item_expected
());
if
(
unlikely
(
my_writer
))
if
(
unlikely
(
my_writer
))
my_writer
->
add_member
(
str
).
start_array
();
my_writer
->
add_member
(
str
).
start_array
();
}
}
...
...
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