File tree Expand file tree Collapse file tree 4 files changed +33
-1
lines changed
Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -433,7 +433,14 @@ void MysqlConnection::execSqlInLoop(
433433 assert (rcb);
434434 assert (!isWorking_);
435435 assert (!sql.empty ());
436-
436+ if (status_ != ConnectStatus::Ok)
437+ {
438+ LOG_ERROR << " MySQL connection is not ready" ;
439+ auto exceptPtr =
440+ std::make_exception_ptr (drogon::orm::BrokenConnection ());
441+ exceptCallback (exceptPtr);
442+ return ;
443+ }
437444 callback_ = std::move (rcb);
438445 isWorking_ = true ;
439446 exceptionCallback_ = std::move (exceptCallback);
Original file line number Diff line number Diff line change @@ -241,6 +241,14 @@ void PgConnection::execSqlInLoop(
241241 std::function<void (const std::exception_ptr &)> &&exceptCallback)
242242{
243243 LOG_TRACE << sql;
244+ if (status_ != ConnectStatus::Ok)
245+ {
246+ LOG_ERROR << " MySQL connection is not ready" ;
247+ auto exceptPtr =
248+ std::make_exception_ptr (drogon::orm::BrokenConnection ());
249+ exceptCallback (exceptPtr);
250+ return ;
251+ }
244252 isWorking_ = true ;
245253 batchSqlCommands_.emplace_back (
246254 std::make_shared<SqlCmd>(std::move (sql),
Original file line number Diff line number Diff line change @@ -230,6 +230,14 @@ void PgConnection::execSqlInLoop(
230230 assert (rcb);
231231 assert (!isWorking_);
232232 assert (!sql.empty ());
233+ if (status_ != ConnectStatus::Ok)
234+ {
235+ LOG_ERROR << " MySQL connection is not ready" ;
236+ auto exceptPtr =
237+ std::make_exception_ptr (drogon::orm::BrokenConnection ());
238+ exceptCallback (exceptPtr);
239+ return ;
240+ }
233241 sql_ = std::move (sql);
234242 callback_ = std::move (rcb);
235243 isWorking_ = true ;
Original file line number Diff line number Diff line change @@ -167,6 +167,14 @@ void Sqlite3Connection::execSqlInQueue(
167167 const std::function<void (const std::exception_ptr &)> &exceptCallback)
168168{
169169 LOG_TRACE << " sql:" << sql;
170+ if (status_ != ConnectStatus::Ok)
171+ {
172+ LOG_ERROR << " MySQL connection is not ready" ;
173+ auto exceptPtr =
174+ std::make_exception_ptr (drogon::orm::BrokenConnection ());
175+ exceptCallback (exceptPtr);
176+ return ;
177+ }
170178 std::shared_ptr<sqlite3_stmt> stmtPtr;
171179 bool newStmt = false ;
172180 if (paraNum > 0 )
@@ -375,6 +383,7 @@ void Sqlite3Connection::disconnect()
375383 auto thisPtr = weakPtr.lock ();
376384 if (!thisPtr)
377385 return ;
386+ thisPtr->status_ = ConnectStatus::Bad;
378387 thisPtr->connectionPtr_ .reset ();
379388 }
380389 pro.set_value (1 );
You can’t perform that action at this time.
0 commit comments