Merge branch 'sticker_filters' of https://github.com/jcorporation/MPD
This commit is contained in:
commit
b3733ef32a
|
@ -1500,7 +1500,7 @@ the database for songs).
|
|||
Searches for stickers with the given value.
|
||||
|
||||
Other supported operators are:
|
||||
"``<``", "``>``" for strings and "``eq``", "``lt``", "``gt``" to cast the value to an integer.
|
||||
"``<``", "``>``", "``contains``", "``starts_with``" for strings and "``eq``", "``lt``", "``gt``" to cast the value to an integer.
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
|
@ -439,6 +439,10 @@ handle_sticker(Client &client, Request args, Response &r)
|
|||
op = StickerOperator::LESS_THAN_INT;
|
||||
else if (StringIsEqual(op_s, "gt"))
|
||||
op = StickerOperator::GREATER_THAN_INT;
|
||||
else if (StringIsEqual(op_s, "contains"))
|
||||
op = StickerOperator::CONTAINS;
|
||||
else if (StringIsEqual(op_s, "starts_with"))
|
||||
op = StickerOperator::STARTS_WITH;
|
||||
else {
|
||||
r.FmtError(ACK_ERROR_ARG, "bad operator \"{}\"", op_s);
|
||||
return CommandResult::ERROR;
|
||||
|
|
|
@ -28,6 +28,9 @@ enum sticker_sql_find {
|
|||
STICKER_SQL_FIND_LT_INT,
|
||||
STICKER_SQL_FIND_GT_INT,
|
||||
|
||||
STICKER_SQL_FIND_CONTAINS,
|
||||
STICKER_SQL_FIND_STARTS_WITH,
|
||||
|
||||
STICKER_SQL_FIND_COUNT
|
||||
};
|
||||
|
||||
|
@ -68,6 +71,12 @@ static constexpr auto sticker_sql_find = std::array {
|
|||
|
||||
//[STICKER_SQL_FIND_GT_INT] =
|
||||
"SELECT uri,value FROM sticker WHERE type=? AND uri LIKE (? || '%') AND name=? AND CAST(value AS INT)>?",
|
||||
|
||||
//[STICKER_SQL_FIND_CONTAINS] =
|
||||
"SELECT uri,value FROM sticker WHERE type=? AND uri LIKE (? || '%') AND name=? AND value LIKE ('%' || ? || '%')",
|
||||
|
||||
//[STICKER_SQL_FIND_STARTS_WITH] =
|
||||
"SELECT uri,value FROM sticker WHERE type=? AND uri LIKE (? || '%') AND name=? AND value LIKE (? || '%')",
|
||||
};
|
||||
|
||||
static constexpr auto sticker_sql = std::array {
|
||||
|
@ -392,6 +401,20 @@ StickerDatabase::BindFind(const char *type, const char *base_uri,
|
|||
sql = Prepare(db, sql_str.c_str());
|
||||
BindAll(sql, type, base_uri, name, value);
|
||||
return sql;
|
||||
|
||||
case StickerOperator::CONTAINS:
|
||||
sql_str = fmt::format("{} {} {}",
|
||||
sticker_sql_find[STICKER_SQL_FIND_CONTAINS], order_by, offset);
|
||||
sql = Prepare(db, sql_str.c_str());
|
||||
BindAll(sql, type, base_uri, name, value);
|
||||
return sql;
|
||||
|
||||
case StickerOperator::STARTS_WITH:
|
||||
sql_str = fmt::format("{} {} {}",
|
||||
sticker_sql_find[STICKER_SQL_FIND_STARTS_WITH], order_by, offset);
|
||||
sql = Prepare(db, sql_str.c_str());
|
||||
BindAll(sql, type, base_uri, name, value);
|
||||
return sql;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
|
|
|
@ -66,6 +66,9 @@ class StickerDatabase {
|
|||
SQL_FIND_LT_INT,
|
||||
SQL_FIND_GT_INT,
|
||||
|
||||
SQL_FIND_CONTAINS,
|
||||
SQL_FIND_STARTS_WITH,
|
||||
|
||||
SQL_FIND_COUNT
|
||||
};
|
||||
|
||||
|
|
|
@ -46,6 +46,18 @@ enum class StickerOperator {
|
|||
* integer value bigger than the specified one.
|
||||
*/
|
||||
GREATER_THAN_INT,
|
||||
|
||||
/**
|
||||
* Matches if a sticker with the specified name exists and value
|
||||
* contains given string.
|
||||
*/
|
||||
CONTAINS,
|
||||
|
||||
/**
|
||||
* Matches if a sticker with the specified name exits and value
|
||||
* starts with given string.
|
||||
*/
|
||||
STARTS_WITH,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue