Commit f74a9eb1 authored by yangjian's avatar yangjian

add mysql reconnection

parent e29e19ce
......@@ -38,6 +38,8 @@ AuthenticationStatusDocumentApiImpl::AuthenticationStatusDocumentApiImpl(
Logger::udr_server().error("An error occurred while connecting to db: %s", mysql_error(mysql_WitcommUDRDB));
return ;
}
reconnect = 1;
mysql_options(mysql_WitcommUDRDB,MYSQL_OPT_RECONNECT,&reconnect);
}
AuthenticationStatusDocumentApiImpl::~AuthenticationStatusDocumentApiImpl()
......
......@@ -53,6 +53,8 @@ public:
private:
MYSQL *mysql_WitcommUDRDB;
char reconnect;
};
}
......
......@@ -44,7 +44,9 @@ AuthenticationSubscriptionDocumentApiImpl::
Logger::udr_server().error("An error occurred while connecting to db: %s", mysql_error(mysql_WitcommUDRDB));
return ;
}
// mysql_WitcommUDRDB = &mysqldb;
reconnect = 1;
mysql_options(mysql_WitcommUDRDB,MYSQL_OPT_RECONNECT,&reconnect);
Logger::udr_server().debug("****** AuthenticationSubscription: mysql init pointer(%p) ******",mysql_WitcommUDRDB);
}
AuthenticationSubscriptionDocumentApiImpl::
......@@ -78,6 +80,7 @@ void AuthenticationSubscriptionDocumentApiImpl::
MYSQL_RES *res = NULL;
MYSQL_ROW row;
int ret;
const std::string select_Authenticationsubscription =
"select * from AuthenticationSubscription WHERE ueid='" + ueId + "'";
......@@ -92,20 +95,20 @@ void AuthenticationSubscriptionDocumentApiImpl::
nlohmann::json::parse(patchItem[i].getValue().c_str())
.get_to(sequencenumber);
if (mysql_real_query(
mysql_WitcommUDRDB, select_Authenticationsubscription.c_str(),
(unsigned long)select_Authenticationsubscription.size())) {
Logger::udr_server().error("mysql_real_query failure!SQL(%s)",
select_Authenticationsubscription.c_str());
ret = mysql_real_query(mysql_WitcommUDRDB, select_Authenticationsubscription.c_str(),(unsigned long)select_Authenticationsubscription.size());
if (ret) {
Logger::udr_server().error("mysql_real_query failure!SQL(%s), mysql_error(%d): %s",
select_Authenticationsubscription.c_str(),ret,mysql_error(mysql_WitcommUDRDB));
Logger::udr_server().error("****** AuthenticationSubscription: mysql_real_query pointer(%p) ******",mysql_WitcommUDRDB);
// mysql_close(&mysqldb);
return;
}
res = mysql_store_result(mysql_WitcommUDRDB);
if (res == NULL) {
Logger::udr_server().error("mysql_store_result failure!SQL(%s)",
select_Authenticationsubscription.c_str());
// mysql_close(&mysqldb);
Logger::udr_server().error("mysql_store_result failure!SQL(%s), mysql_error: %s",
select_Authenticationsubscription.c_str(),mysql_error(mysql_WitcommUDRDB));
Logger::udr_server().error("****** AuthenticationSubscription: mysql_store_result pointer(%p) ******",mysql_WitcommUDRDB);
return;
}
if (mysql_num_rows(res)) {
......@@ -125,10 +128,11 @@ void AuthenticationSubscriptionDocumentApiImpl::
// Logger::udr_server().debug("modify content:
// %s",query.c_str());
if (mysql_real_query(mysql_WitcommUDRDB, query.c_str(),
(unsigned long)query.size())) {
Logger::udr_server().error("update mysql failure!SQL(%s)",
query.c_str());
ret = mysql_real_query(mysql_WitcommUDRDB, query.c_str(),
(unsigned long)query.size());
if (ret) {
Logger::udr_server().error("update mysql failure!SQL(%s), mysql_error(%d): %s",
query.c_str(),ret,mysql_error(mysql_WitcommUDRDB));
// mysql_close(&mysqldb);
return;
}
......@@ -156,6 +160,7 @@ void AuthenticationSubscriptionDocumentApiImpl::
MYSQL_RES *res = NULL;
MYSQL_ROW row;
MYSQL_FIELD *field = nullptr;
int ret;
nlohmann::json j;
......@@ -176,18 +181,19 @@ void AuthenticationSubscriptionDocumentApiImpl::
const std::string query =
"select * from AuthenticationSubscription WHERE ueid='" + ueId + "'";
if (mysql_real_query(mysql_WitcommUDRDB, query.c_str(),
(unsigned long)query.size())) {
Logger::udr_server().error("mysql_real_query failure!SQL(%s)",
query.c_str());
ret = mysql_real_query(mysql_WitcommUDRDB, query.c_str(),
(unsigned long)query.size());
if (ret) {
Logger::udr_server().error("mysql_real_query failure!SQL(%s), mysql_error(%d): %s",
query.c_str(),ret,mysql_error(mysql_WitcommUDRDB));
// mysql_close(&mysqldb);
return;
}
res = mysql_store_result(mysql_WitcommUDRDB);
if (res == NULL) {
Logger::udr_server().error("mysql_store_result failure!SQL(%s)",
query.c_str());
Logger::udr_server().error("mysql_store_result failure!SQL(%s), mysql_error: %s",
query.c_str(),mysql_error(mysql_WitcommUDRDB));
// mysql_close(&mysqldb);
return;
}
......
......@@ -55,6 +55,7 @@ public:
private:
MYSQL *mysql_WitcommUDRDB;
char reconnect;
};
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment