void addQueryOp(aslmsg& query, const std::string& key, const std::string& value, ConstraintOperator op, ColumnType col_type) { if (key == kExtraColumnKey) { // ASL doesn't know about the 'Extra' column, so we can't do the matching // through the ASL query. Do nothing here, and later SQLite's engine will // do the match. return; } // Only some queries can be supported through ASL, those that are not will // just be performed later by the SQLite engine. if (kSupportedAslOps.count(op) > 0) { uint32_t asl_op = kSupportedAslOps.at(op); std::string modified_val = value; std::string modified_key = kColumnToAslKeyMap.at(key); switch (op) { case LIKE: // In the LIKE case, we need to convert the like string to a regex for // use in the ASL query modified_val = convertLikeRegex(value); break; default: if (isNumeric(col_type)) { asl_op |= ASL_QUERY_OP_NUMERIC; } } asl_set_query(query, modified_key.c_str(), modified_val.c_str(), asl_op); } }
TEST_F(AslTests, test_convert_like_regex) { EXPECT_EQ(".*", convertLikeRegex("%")); EXPECT_EQ("foo.*", convertLikeRegex("foo%")); EXPECT_EQ(".*foo.*", convertLikeRegex("%foo%")); EXPECT_EQ(".*.*", convertLikeRegex("%%")); EXPECT_EQ(".*.*", convertLikeRegex("%%")); EXPECT_EQ(".", convertLikeRegex("_")); EXPECT_EQ("foo.", convertLikeRegex("foo_")); EXPECT_EQ(".foo", convertLikeRegex("_foo")); EXPECT_EQ(".foo.", convertLikeRegex("_foo_")); EXPECT_EQ("..*", convertLikeRegex("_%")); EXPECT_EQ(".*foo..*", convertLikeRegex("%foo_%")); }