Skip to content

Commit

Permalink
Merge pull request #10553 from simularis/dev-sqliteprocedures-errors
Browse files Browse the repository at this point in the history
Improve error checking in SQLite database connection (again)
  • Loading branch information
Myoldmopar authored Jun 17, 2024
2 parents 2d5e061 + 1d6293b commit 3c8844f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/EnergyPlus/SQLiteProcedures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2597,16 +2597,17 @@ SQLite::SQLiteData::SQLiteData(std::shared_ptr<std::ostream> const &errorStream,
}

SQLiteProcedures::SQLiteProcedures(std::shared_ptr<std::ostream> const &errorStream, std::shared_ptr<sqlite3> const &db)
: m_writeOutputToSQLite(true), m_errorStream(errorStream), m_connection(nullptr), m_db(db)
: m_writeOutputToSQLite(true), m_errorStream(errorStream), m_db(db)
{
}

SQLiteProcedures::SQLiteProcedures(std::shared_ptr<std::ostream> const &errorStream,
bool writeOutputToSQLite,
fs::path const &dbName,
fs::path const &errorFilePath)
: m_writeOutputToSQLite(writeOutputToSQLite), m_errorStream(errorStream), m_connection(nullptr)
: m_writeOutputToSQLite(writeOutputToSQLite), m_errorStream(errorStream)
{
sqlite3 *m_connection = nullptr;
if (m_writeOutputToSQLite) {
int rc = -1;
bool ok = true;
Expand Down Expand Up @@ -2641,10 +2642,14 @@ SQLiteProcedures::SQLiteProcedures(std::shared_ptr<std::ostream> const &errorStr
}
if (ok) {
char *zErrMsg = nullptr;
rc = sqlite3_exec(m_connection, "CREATE TABLE Test(x INTEGER PRIMARY KEY)", nullptr, 0, &zErrMsg);
// Set journal_mode OFF to avoid creating the file dbName + "-journal" (when dbName is a regular file)
rc = sqlite3_exec(m_connection, "PRAGMA journal_mode = OFF;", nullptr, 0, &zErrMsg);
if (!rc) {
rc = sqlite3_exec(m_connection, "CREATE TABLE Test(x INTEGER PRIMARY KEY)", nullptr, 0, &zErrMsg);
}
sqlite3_close(m_connection);
if (rc) {
*m_errorStream << "SQLite3 message, can't get exclusive lock to edit database: " << sqlite3_errmsg(m_connection) << std::endl;
*m_errorStream << "SQLite3 message, can't get exclusive lock to edit database: " << zErrMsg << std::endl;
ok = false;
} else {
if (dbName != ":memory:") {
Expand Down Expand Up @@ -2803,7 +2808,7 @@ int SQLiteProcedures::sqliteResetCommand(sqlite3_stmt *stmt)

bool SQLiteProcedures::sqliteWithinTransaction()
{
return (sqlite3_get_autocommit(m_connection) == 0);
return (sqlite3_get_autocommit(m_db.get()) == 0);
}

// int SQLiteProcedures::sqliteClearBindings(sqlite3_stmt * stmt)
Expand Down
1 change: 0 additions & 1 deletion src/EnergyPlus/SQLiteProcedures.hh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ protected:

bool m_writeOutputToSQLite;
std::shared_ptr<std::ostream> m_errorStream;
sqlite3 *m_connection;
std::shared_ptr<sqlite3> m_db;
};

Expand Down

15 comments on commit 3c8844f

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4: OK (2830 of 2830 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-MacOS-10.18-clang-15.0.0: OK (2809 of 2809 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - Win64-Windows-10-VisualStudio-16: OK (2808 of 2808 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-UnitTestsCoverage-Debug: OK (2019 of 2019 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-IntegrationCoverage-Debug: OK (792 of 792 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10509feiUseStdDensityAtSeaLevel (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4: OK (3638 of 3638 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10509feiUseStdDensityAtSeaLevel (Myoldmopar) - Win64-Windows-10-VisualStudio-16: OK (2808 of 2808 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10509feiUseStdDensityAtSeaLevel (Myoldmopar) - x86_64-MacOS-10.18-clang-15.0.0: OK (3597 of 3597 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10509feiUseStdDensityAtSeaLevel (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-IntegrationCoverage-Debug: OK (792 of 792 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10509feiUseStdDensityAtSeaLevel (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-UnitTestsCoverage-Debug: OK (2019 of 2019 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10508HybridModelThermalMassCalculationIssue (Myoldmopar) - Win64-Windows-10-VisualStudio-16: OK (2808 of 2808 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10508HybridModelThermalMassCalculationIssue (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4: OK (3638 of 3638 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10508HybridModelThermalMassCalculationIssue (Myoldmopar) - x86_64-MacOS-10.18-clang-15.0.0: OK (3597 of 3597 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10508HybridModelThermalMassCalculationIssue (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-UnitTestsCoverage-Debug: OK (2019 of 2019 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10508HybridModelThermalMassCalculationIssue (Myoldmopar) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-IntegrationCoverage-Debug: OK (792 of 792 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.