diff --git a/pglablib/ASyncDBConnection.cpp b/pglablib/ASyncDBConnection.cpp index 66bb302..95d0181 100644 --- a/pglablib/ASyncDBConnection.cpp +++ b/pglablib/ASyncDBConnection.cpp @@ -310,21 +310,19 @@ void ASyncDBConnectionThread::doNewCommand() // get command from top of queue (but leave it in the queue, we need the callback) if (! m_commandQueue.m_queue.empty()) { const Command &command = m_commandQueue.m_queue.front(); - if (!command.command.empty()) { - bool query_send = false; - if (command.params.empty()) - query_send = m_connection.sendQuery(command.command.c_str()); - else - query_send = m_connection.sendQueryParams(command.command.c_str(), command.params); + bool query_send = false; + if (command.params.empty()) + query_send = m_connection.sendQuery(command.command.c_str()); + else + query_send = m_connection.sendQueryParams(command.command.c_str(), command.params); - if (query_send) { - m_timer.start(); - doStateCallback(ASyncDBConnection::State::QuerySend); - } - else { - std::string error = m_connection.getErrorMessage(); - // todo: need to report the error - } + if (query_send) { + m_timer.start(); + doStateCallback(ASyncDBConnection::State::QuerySend); + } + else { + std::string error = m_connection.getErrorMessage(); + // todo: need to report the error } } @@ -489,6 +487,9 @@ void ASyncDBConnection::closeConnection() bool ASyncDBConnection::send(const std::string &command, on_result_callback on_result) { + if (command.empty()) + return false; + { std::lock_guard lg(m_threadData->m_commandQueue.m_mutex); m_threadData->m_commandQueue.m_queue.emplace(command, on_result);