Skip to content

Commit

Permalink
Rename is_filed_exist(..) to field_exists(..)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
  • Loading branch information
MichaelOrlov committed Sep 19, 2022
1 parent bafa9e5 commit 3eaaf4d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ROSBAG2_STORAGE_DEFAULT_PLUGINS_PUBLIC SqliteWrapper
SqliteWrapper();
~SqliteWrapper();

bool is_field_exist(const std::string & table_name, const std::string & field_name);
bool field_exists(const std::string & table_name, const std::string & field_name);
SqliteStatement prepare_statement(const std::string & query);
std::string query_pragma_value(const std::string & key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ rosbag2_storage::BagMetadata SqliteStorage::get_metadata()
rcutils_time_point_value_t min_time = INT64_MAX;
rcutils_time_point_value_t max_time = 0;

if (database_->is_field_exist("topics", "offered_qos_profiles")) {
if (database_->field_exists("topics", "offered_qos_profiles")) {
std::string query =
"SELECT name, type, serialization_format, COUNT(messages.id), MIN(messages.timestamp), "
"MAX(messages.timestamp), offered_qos_profiles "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ std::string SqliteWrapper::query_pragma_value(const std::string & key)
return std::get<0>(pragma_value);
}

bool SqliteWrapper::is_field_exist(const std::string & table_name, const std::string & field_name)
bool SqliteWrapper::field_exists(const std::string & table_name, const std::string & field_name)
{
auto query = "SELECT INSTR(sql, '" + field_name + "') FROM sqlite_master WHERE type='table' AND "
"name='" + table_name + "';";
auto query_result = prepare_statement(query)->execute_query<int>();
auto query_result_begin = query_result.begin();
if (query_result_begin == query_result.end()) {
std::stringstream errmsg;
errmsg << "is_field_exist(..) failed. Table `" << table_name << "` doesn't exist!";
errmsg << "field_exists(..) failed. Table `" << table_name << "` doesn't exist!";
throw SqliteException{errmsg.str()};
}
auto position = *(query_result_begin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ TEST_F(SqliteWrapperTestFixture, get_single_line_handles_empty_result_set) {
EXPECT_THROW(result.get_single_line(), rosbag2_storage_plugins::SqliteException);
}

TEST_F(SqliteWrapperTestFixture, is_field_exist) {
TEST_F(SqliteWrapperTestFixture, field_exists) {
db_.prepare_statement("CREATE TABLE test_table (timestamp INTEGER, data BLOB);")
->execute_and_reset();
rcutils_time_point_value_t time = 1099511627783;
Expand All @@ -158,8 +158,8 @@ TEST_F(SqliteWrapperTestFixture, is_field_exist) {
db_.prepare_statement("INSERT INTO test_table (timestamp, data) VALUES (?, ?);")
->bind(time, message)->execute_and_reset();

EXPECT_TRUE(db_.is_field_exist("test_table", "data"));
EXPECT_FALSE(db_.is_field_exist("test_table", "non_existent_field"));
EXPECT_TRUE(db_.field_exists("test_table", "data"));
EXPECT_FALSE(db_.field_exists("test_table", "non_existent_field"));
EXPECT_THROW(
db_.is_field_exist("non_existent_table", "data"), rosbag2_storage_plugins::SqliteException);
db_.field_exists("non_existent_table", "data"), rosbag2_storage_plugins::SqliteException);
}

0 comments on commit 3eaaf4d

Please sign in to comment.