Initialize thread_db within the loop

main
Simon Quigley 6 days ago
parent 9c7c91dac9
commit 9e6a0b0453

@ -36,10 +36,11 @@ static int get_delay(int attempt) {
QSqlDatabase get_thread_connection() { QSqlDatabase get_thread_connection() {
QString connection_name; QString connection_name;
QSqlDatabase thread_db;
bool passed = false; bool passed = false;
int attempt = 0; int attempt = 0;
while (!passed) { while (!passed) {
QSqlDatabase thread_db;
std::lock_guard<std::mutex> lock(connection_mutex_); std::lock_guard<std::mutex> lock(connection_mutex_);
thread_local unsigned int thread_unique_id = thread_id_counter.fetch_add(1); thread_local unsigned int thread_unique_id = thread_id_counter.fetch_add(1);
connection_name = QString("CIConn_%1").arg(thread_unique_id); connection_name = QString("CIConn_%1").arg(thread_unique_id);
@ -70,10 +71,8 @@ QSqlDatabase get_thread_connection() {
} }
if (!thread_db.open()) throw std::runtime_error("Failed to open new database connection for thread: " + thread_db.lastError().text().toStdString()); if (!thread_db.open()) throw std::runtime_error("Failed to open new database connection for thread: " + thread_db.lastError().text().toStdString());
passed = true;
}
return thread_db; return thread_db;
}
} }
bool ci_query_exec(QSqlQuery* query, const QString query_string) { bool ci_query_exec(QSqlQuery* query, const QString query_string) {

Loading…
Cancel
Save