Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SQL column name escaping #44

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/warehouse_ros_sqlite/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ using escaped_columnname = std::string;
using escaped_tablename = std::string;
inline std::string escape_identifier(const std::string & s)
{
return "\"" + detail::escape<'"'>(s) + "\"";
return "`" + detail::escape<'`'>(s) + "`";
}
inline escaped_columnname escape_columnname_with_prefix(const std::string & c)
{
Expand Down
53 changes: 53 additions & 0 deletions test/DatabaseConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <gtest/gtest.h>

#include <geometry_msgs/msg/point.hpp>
#include <geometry_msgs/msg/pose.hpp>
#include <geometry_msgs/msg/vector3.hpp>
#include <warehouse_ros_sqlite/database_connection.hpp>
Expand Down Expand Up @@ -403,6 +404,58 @@ TEST_F(ConnectionTest, Sorting)
}
}

TEST_F(ConnectionTest, appendGTE)
{
auto coll = conn_->openCollection<geometry_msgs::msg::Point>("test_db", "test_collection");

auto metadata = coll.createMetadata();
metadata->append("test_metadata", 5.0);

geometry_msgs::msg::Point msg = {};
coll.insert(msg, metadata);

{
auto query = coll.createQuery();
query->appendGTE("unrelated", 4.0);
EXPECT_TRUE(coll.queryList(query).empty());
}

{
auto query = coll.createQuery();
query->appendGT("unrelated", 4.0);
EXPECT_TRUE(coll.queryList(query).empty());
}

{
auto query = coll.createQuery();
query->appendLTE("unrelated", 6.0);
EXPECT_TRUE(coll.queryList(query).empty());
}

{
auto query = coll.createQuery();
query->appendLT("unrelated", 6.0);
EXPECT_TRUE(coll.queryList(query).empty());
}
}

TEST_F(ConnectionTest, BacktickInMeta)
{
auto coll = conn_->openCollection<geometry_msgs::msg::Point>("test_db", "test_backtick");

auto metadata = coll.createMetadata();
metadata->append("test_`metadata", 5.0);

geometry_msgs::msg::Point msg = {};
coll.insert(msg, metadata);

{
auto query = coll.createQuery();
query->appendGTE("test_`metadata", 4.0);
EXPECT_EQ(coll.queryList(query).size(), 1);
}
}

TEST(Utils, Md5Validation)
{
const char * a = "4a842b65f413084dc2b10fb484ea7f17";
Expand Down
Loading