Skip to content

Commit

Permalink
correct sqlite statements
Browse files Browse the repository at this point in the history
Signed-off-by: Karsten Knese <karsten@openrobotics.org>
  • Loading branch information
Karsten1987 committed Apr 1, 2020
1 parent 21b2c80 commit 83042cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class ROSBAG2_STORAGE_DEFAULT_PLUGINS_PUBLIC SqliteStorage
std::vector<rosbag2_storage::TopicMetadata> all_topics_and_types_;
std::string relative_path_;
std::atomic_bool active_transaction_ {false};
uint64_t no_of_inserts_;
};

} // namespace rosbag2_storage_plugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,10 @@ void SqliteStorage::activate_transaction()
return;
}

if (!write_statement_) {
prepare_for_writing();
}
ROSBAG2_STORAGE_DEFAULT_PLUGINS_LOG_DEBUG_STREAM("begin transaction");
database_->prepare_statement("BEGIN TRANSACTION;")->execute_and_reset();

write_statement_->bind("BEGIN TRANSACTION;");
write_statement_->execute_and_reset();

active_transaction_.store(true, std::memory_order_relaxed);
active_transaction_ = true;
}

void SqliteStorage::commit_transaction()
Expand All @@ -134,16 +130,10 @@ void SqliteStorage::commit_transaction()
return;
}

if (!write_statement_) {
prepare_for_writing();
}

write_statement_->bind("COMMIT;");
write_statement_->execute_and_reset();
ROSBAG2_STORAGE_DEFAULT_PLUGINS_LOG_DEBUG_STREAM("commit transaction");
database_->prepare_statement("COMMIT;")->execute_and_reset();

active_transaction_.store(false, std::memory_order_relaxed);
// Reset batch insert counter
no_of_inserts_ = 0;
active_transaction_ = false;
}

void SqliteStorage::write(std::shared_ptr<const rosbag2_storage::SerializedBagMessage> message)
Expand Down Expand Up @@ -172,15 +162,7 @@ void SqliteStorage::write(
activate_transaction();

for (auto & message : messages) {
auto topic_entry = topics_.find(message->topic_name);
if (topic_entry == end(topics_)) {
throw SqliteException(
"Topic '" + message->topic_name +
"' has not been created yet! Call 'create_topic' first.");
}

write_statement_->bind(message->time_stamp, topic_entry->second, message->serialized_data);
write_statement_->execute_and_reset();
write(message);
}

commit_transaction();
Expand Down

0 comments on commit 83042cc

Please sign in to comment.