Commit f74a9eb1 authored by yangjian's avatar yangjian

add mysql reconnection

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