Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-UDSF
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
Operations
Operations
Metrics
Environments
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
OpenXG
OpenXG-UDSF
Commits
ae3736e8
Commit
ae3736e8
authored
Dec 03, 2021
by
yangjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add mysql function: clear data
parent
4583f5fe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
0 deletions
+69
-0
src/common/custom_mysql.cpp
src/common/custom_mysql.cpp
+44
-0
src/common/custom_mysql.hpp
src/common/custom_mysql.hpp
+15
-0
src/udsf_app/main.cpp
src/udsf_app/main.cpp
+10
-0
No files found.
src/common/custom_mysql.cpp
0 → 100644
View file @
ae3736e8
#include "custom_mysql.hpp"
#include "logger.hpp"
#include "udsf_config.hpp"
#include <mysql/mysql.h>
using
namespace
config
;
extern
udsf_config
udsf_cfg
;
CustomMysql
::
CustomMysql
(){}
CustomMysql
::~
CustomMysql
(){}
bool
CustomMysql
::
clearing_tables_of_db
(
std
::
vector
<
std
::
string
>
&
tables
)
{
MYSQL
mysql
;
mysql_init
(
&
mysql
);
if
(
!
mysql_real_connect
(
&
mysql
,
udsf_cfg
.
mysql
.
mysql_server
.
c_str
(),
udsf_cfg
.
mysql
.
mysql_user
.
c_str
(),
udsf_cfg
.
mysql
.
mysql_pass
.
c_str
(),
udsf_cfg
.
mysql
.
mysql_db
.
c_str
(),
udsf_cfg
.
mysql
.
mysql_port
,
0
,
0
))
{
Logger
::
udsf_app
().
error
(
"An error occurred while connecting to db: %s"
,
mysql_error
(
&
mysql
));
return
false
;
}
std
::
string
query
=
""
;
for
(
int
i
=
0
;
i
<
tables
.
size
();
i
++
)
{
query
=
"TRUNCATE TABLE `"
+
tables
[
i
]
+
"`"
;
if
(
mysql_query
(
&
mysql
,
query
.
c_str
()))
{
Logger
::
udsf_app
().
error
(
"mysql_query failure!SQL(%s)"
,
query
.
c_str
());
Logger
::
udsf_app
().
error
(
"mysql error(%s)"
,
mysql_error
(
&
mysql
));
mysql_close
(
&
mysql
);
return
false
;
}
}
mysql_close
(
&
mysql
);
return
true
;
}
src/common/custom_mysql.hpp
0 → 100644
View file @
ae3736e8
#ifndef _CUSTOM_MYSQL_H_
#define _CUSTOM_MYSQL_H_
#include <vector>
#include <string>
class
CustomMysql
{
public:
CustomMysql
();
~
CustomMysql
();
static
bool
clearing_tables_of_db
(
std
::
vector
<
std
::
string
>
&
tables
);
};
#endif
src/udsf_app/main.cpp
View file @
ae3736e8
...
...
@@ -21,10 +21,13 @@
#include "Connection.h"
#include "ConnectionPool.h"
#include "custom_mysql.hpp"
using
namespace
config
;
udsf_config
udsf_cfg
;
int
main
(
int
argc
,
char
**
argv
)
{
std
::
vector
<
std
::
string
>
db_tables
;
if
(
!
Options
::
parse
(
argc
,
argv
))
{
std
::
cout
<<
"Options::parse() failed"
<<
std
::
endl
;
return
1
;
...
...
@@ -35,6 +38,13 @@ int main(int argc, char **argv) {
if
(
udsf_cfg
.
load
(
Options
::
getlibconfigConfig
())
<
0
)
return
0
;
udsf_cfg
.
display
();
db_tables
.
push_back
(
"gnb_context"
);
db_tables
.
push_back
(
"nas_context"
);
db_tables
.
push_back
(
"pdu_session_context"
);
db_tables
.
push_back
(
"ue_context"
);
db_tables
.
push_back
(
"ue_ngap_context"
);
CustomMysql
::
clearing_tables_of_db
(
db_tables
);
Logger
::
udsf_app
().
debug
(
"Initiating UDSF server endpoints"
);
Pistache
::
Address
addr
(
udsf_cfg
.
sbi
.
addr4
,
Pistache
::
Port
(
udsf_cfg
.
sbi
.
port
));
...
...
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