From 6c41354da565ae83c963c6518723c446c25e3231 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Mon, 6 May 2024 21:00:13 +0000 Subject: [PATCH] DbLib: Prevent uncaught exception creating statement Defer telling the statement about the connection until the try block, because otherwise it can connect immediately and potentially throw an exception if the connection fails. (cherry picked from commit ddd7c355865850a5df7fc801b791d53a7ea5e7fb) Co-authored-by: Jon Evans --- common/database/database_connection.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/database/database_connection.cpp b/common/database/database_connection.cpp index b597375e30..b2b80e2968 100644 --- a/common/database/database_connection.cpp +++ b/common/database/database_connection.cpp @@ -390,15 +390,14 @@ bool DATABASE_CONNECTION::SelectOne( const std::string& aTable, columnsFor( tableName ), m_quoteChar, tableName, m_quoteChar, m_quoteChar, columnName, m_quoteChar ); - - nanodbc::statement statement( *m_conn ); nanodbc::string query = fromUTF8( queryStr ); PROF_TIMER timer; + nanodbc::statement statement; try { - statement.prepare( query ); + statement.prepare( *m_conn, query ); statement.bind( 0, aWhere.second.c_str() ); } catch( nanodbc::database_error& e )