Skip to content

Commit

Permalink
Fixup execAndThrowAndError
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Oct 29, 2024
1 parent 799d4d1 commit 834fa9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/utilities/sql/SqlFile_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ namespace detail {
initschema = true;
}

sqlite3_open_v2(fileName.c_str(), &m_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_EXCLUSIVE, nullptr);
int code = sqlite3_open_v2(fileName.c_str(), &m_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_EXCLUSIVE, nullptr);
m_connectionOpen = (code == 0);

if (initschema) {
execAndThrowOnError(
Expand Down
8 changes: 4 additions & 4 deletions src/utilities/sql/SqlFile_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,11 +1306,11 @@ namespace detail {
// Variadic arguments are the bind arguments if any, to replace '?' placeholders in the statement string
template <typename... Args>
void execAndThrowOnError(const std::string& bindingStatement, Args&&... args) {
if (m_db) {
PreparedStatement stmt(bindingStatement, m_db, false, args...);
stmt.execAndThrowOnError();
if (!m_connectionOpen) {
throw std::runtime_error("Error executing SQL statement as database connection is not open.");
}
throw std::runtime_error("Error executing SQL statement as database connection is not open.");
PreparedStatement stmt(bindingStatement, m_db, false, args...);
stmt.execAndThrowOnError();
}

void addSimulation(const openstudio::EpwFile& t_epwFile, const openstudio::DateTime& t_simulationTime, const openstudio::Calendar& t_calendar);
Expand Down

0 comments on commit 834fa9c

Please sign in to comment.