Skip to content

Commit 16fff40

Browse files
committed
extern driver
1 parent 9b28311 commit 16fff40

File tree

3 files changed

+5
-18
lines changed

3 files changed

+5
-18
lines changed

jwt_controller.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ std::string jwtDecrypt(const std::string &token)
3434
}
3535
catch (const std::exception &e)
3636
{
37-
// std::cout << "Failed to decrypt JWT: " + std::string(e.what()) << std::endl;
38-
// throw std::runtime_error("Failed to decrypt JWT");
37+
std::cout << "Failed to decrypt JWT: " + std::string(e.what()) << std::endl;
38+
throw std::runtime_error("Failed to decrypt JWT");
3939
}
4040
}
4141

main.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#include "msg_controller.h"
33
#include "user_controller.h"
44
#include "file_controller.h"
5-
5+
#include<mysql.h>
66
using namespace drogon;
7+
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
78
int main()
89
{
910
drogon::app().addListener("0.0.0.0", 8081);

mysql.cc

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
#include "jdbc/mysql_connection.h"
44
#include "jdbc/mysql_driver.h"
55
#include "json/json.h"
6-
6+
extern sql::mysql::MySQL_Driver *driver;
77
void sql_unlocked(const std::string& DeleteName)
88
{
9-
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
109
sql::Connection *con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
1110
con->setSchema("flypen");
1211
sql::Statement *stmt = con->createStatement();
@@ -26,7 +25,6 @@ void sql_unlocked(const std::string& DeleteName)
2625

2726
int sql_findexist(const std::string& receiver)
2827
{
29-
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
3028
sql::Connection *con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
3129
con->setSchema("flypen");
3230
std::string readdata = "SELECT username FROM users";
@@ -42,7 +40,6 @@ int sql_findexist(const std::string& receiver)
4240
}
4341
int lockcheck(const std::string& filename)
4442
{
45-
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
4643
sql::Connection *con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
4744
con->setSchema("flypen");
4845
std::string readData = "SELECT filename FROM file";
@@ -87,7 +84,6 @@ void process(sql::PreparedStatement *readDatament, std::vector<std::string> s, s
8784

8885
void sql_delete_operation(const std::string& sender, const std::string& receiver)
8986
{
90-
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
9187
sql::Connection *con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
9288

9389
con->setSchema("flypen");
@@ -103,7 +99,6 @@ void sql_delete_operation(const std::string& sender, const std::string& receiver
10399
void sql_process_request(const std::string& sender, const std::string& receiver, const std::string& attitude)
104100
{
105101
std::vector<std::string> usernamelist;
106-
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
107102
sql::Connection *con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
108103
con->setSchema("flypen");
109104

@@ -181,8 +176,6 @@ void sql_process_request(const std::string& sender, const std::string& receiver,
181176
void sql_addrequest(const std::string& sender, const std::string& receiver)
182177
{
183178
std::vector<std::string> usernamelist;
184-
185-
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
186179
sql::Connection *con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
187180
con->setSchema("flypen");
188181

@@ -230,7 +223,6 @@ void sql_addhistory(const std::string& sender, const std::string& receiver, cons
230223
{
231224
try
232225
{
233-
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
234226
sql::Connection *con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
235227
con->setSchema("flypen");
236228

@@ -258,7 +250,6 @@ void sql_add(const std::string& username, const std::string& passwd, int avatar)
258250
{
259251
try
260252
{
261-
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
262253
sql::Connection *con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
263254
con->setSchema("flypen");
264255

@@ -288,8 +279,6 @@ Json::Value get_my_info(const std::string& me)
288279

289280
try
290281
{
291-
sql::mysql::MySQL_Driver *driver;
292-
driver = sql::mysql::get_mysql_driver_instance();
293282
sql::Connection *con;
294283
con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
295284
con->setSchema("flypen");
@@ -368,7 +357,6 @@ bool sql_check(const std::string& user, const std::string& passwd)
368357
bool result = false;
369358
try
370359
{
371-
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
372360
sql::Connection *con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
373361
con->setSchema("flypen");
374362

@@ -410,7 +398,6 @@ Json::Value sql_find_my_msg(const std::string& me, const std::string& connect_ty
410398
// std::cout << "login user: " << me << std::endl;
411399
try
412400
{
413-
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
414401
sql::Connection *con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
415402
con->setSchema("flypen");
416403
sql::PreparedStatement *prepStmt;
@@ -511,7 +498,6 @@ Json::Value sql_find_my_msg(const std::string& me, const std::string& connect_ty
511498

512499
void set_avatar(const std::string& person, int avatar)
513500
{
514-
sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
515501
sql::Connection *con = driver->connect("tcp://8.130.48.157:3306", "root", "abc.123");
516502
con->setSchema("flypen");
517503
std::string update_sql = "UPDATE users SET avatar = ? WHERE username = ?";

0 commit comments

Comments
 (0)