Better handling of empty query's.

This commit is contained in:
eelke 2019-12-18 19:35:17 +01:00
parent 47b3ea83e9
commit 23165d77c8

View file

@ -310,21 +310,19 @@ void ASyncDBConnectionThread::doNewCommand()
// get command from top of queue (but leave it in the queue, we need the callback) // get command from top of queue (but leave it in the queue, we need the callback)
if (! m_commandQueue.m_queue.empty()) { if (! m_commandQueue.m_queue.empty()) {
const Command &command = m_commandQueue.m_queue.front(); const Command &command = m_commandQueue.m_queue.front();
if (!command.command.empty()) { bool query_send = false;
bool query_send = false; if (command.params.empty())
if (command.params.empty()) query_send = m_connection.sendQuery(command.command.c_str());
query_send = m_connection.sendQuery(command.command.c_str()); else
else query_send = m_connection.sendQueryParams(command.command.c_str(), command.params);
query_send = m_connection.sendQueryParams(command.command.c_str(), command.params);
if (query_send) { if (query_send) {
m_timer.start(); m_timer.start();
doStateCallback(ASyncDBConnection::State::QuerySend); doStateCallback(ASyncDBConnection::State::QuerySend);
} }
else { else {
std::string error = m_connection.getErrorMessage(); std::string error = m_connection.getErrorMessage();
// todo: need to report the error // 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) bool ASyncDBConnection::send(const std::string &command, on_result_callback on_result)
{ {
if (command.empty())
return false;
{ {
std::lock_guard<std::mutex> lg(m_threadData->m_commandQueue.m_mutex); std::lock_guard<std::mutex> lg(m_threadData->m_commandQueue.m_mutex);
m_threadData->m_commandQueue.m_queue.emplace(command, on_result); m_threadData->m_commandQueue.m_queue.emplace(command, on_result);