File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed
Expand file tree Collapse file tree 4 files changed +34
-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 << " 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 << " 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 << " 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 @@ -128,6 +128,7 @@ void Sqlite3Connection::init()
128128 else
129129 {
130130 sqlite3_extended_result_codes (tmp, true );
131+ status_ = ConnectStatus::Ok;
131132 okCallback_ (thisPtr);
132133 }
133134 });
@@ -167,6 +168,14 @@ void Sqlite3Connection::execSqlInQueue(
167168 const std::function<void (const std::exception_ptr &)> &exceptCallback)
168169{
169170 LOG_TRACE << " sql:" << sql;
171+ if (status_ != ConnectStatus::Ok)
172+ {
173+ LOG_ERROR << " Connection is not ready" ;
174+ auto exceptPtr =
175+ std::make_exception_ptr (drogon::orm::BrokenConnection ());
176+ exceptCallback (exceptPtr);
177+ return ;
178+ }
170179 std::shared_ptr<sqlite3_stmt> stmtPtr;
171180 bool newStmt = false ;
172181 if (paraNum > 0 )
@@ -375,6 +384,7 @@ void Sqlite3Connection::disconnect()
375384 auto thisPtr = weakPtr.lock ();
376385 if (!thisPtr)
377386 return ;
387+ thisPtr->status_ = ConnectStatus::Bad;
378388 thisPtr->connectionPtr_ .reset ();
379389 }
380390 pro.set_value (1 );
You can’t perform that action at this time.
0 commit comments