Skip to content

Commit

Permalink
[humble] Fix for failing throws_on_invalid_pragma_in_config_file test…
Browse files Browse the repository at this point in the history
… on Windows (backport #1742) (#1748)

* Fix for failing throws_on_invalid_pragma_in_config_file on Windows (#1742)

- The failure was because database file was not properly closed after
throwing exception from the SqliteWrapper constructor and
std::filesystem::remove_all(..) failed to delete temporary folder in the
test fixture destructor.
- Added reset for prepared sql statement before throwing exception.
- Try to close database in constructor if we got exception after
opening it since destructor will not be called in this case.

Signed-off-by: Michael Orlov <[email protected]>
(cherry picked from commit 055935d)

# Conflicts:
#	rosbag2_storage_default_plugins/src/rosbag2_storage_default_plugins/sqlite/sqlite_wrapper.cpp

* Address merge conflicts

Signed-off-by: Michael Orlov <[email protected]>

---------

Signed-off-by: Michael Orlov <[email protected]>
Co-authored-by: Michael Orlov <[email protected]>
  • Loading branch information
mergify[bot] and MichaelOrlov authored Jul 16, 2024
1 parent 68d1190 commit 70434fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::shared_ptr<SqliteStatementWrapper> SqliteStatementWrapper::execute_and_rese
std::stringstream errmsg;
errmsg << "Error when processing SQL statement. SQLite error (" <<
return_code << "): " << sqlite3_errstr(return_code);

reset();
throw SqliteException{errmsg.str(), return_code};
}

Expand All @@ -72,7 +72,7 @@ std::shared_ptr<SqliteStatementWrapper> SqliteStatementWrapper::execute_and_rese
std::stringstream errmsg;
errmsg << "Statement returned empty value while result was expected: \'" <<
sqlite3_sql(statement_) << "\'";

reset();
throw SqliteException{errmsg.str(), return_code};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,18 @@ SqliteWrapper::SqliteWrapper(
}
}

apply_pragma_settings(pragmas, io_flag);
sqlite3_extended_result_codes(db_ptr, 1);
try {
apply_pragma_settings(pragmas, io_flag);
sqlite3_extended_result_codes(db_ptr, 1);
} catch (...) {
const int rc = sqlite3_close(db_ptr);
if (rc != SQLITE_OK) {
ROSBAG2_STORAGE_DEFAULT_PLUGINS_LOG_ERROR_STREAM(
"Could not close open database. Error code: " << rc <<
" Error message: " << sqlite3_errstr(rc));
}
throw;
}
}

SqliteWrapper::SqliteWrapper()
Expand Down

0 comments on commit 70434fc

Please sign in to comment.