diff options
author | Max Kellermann <max@duempel.org> | 2014-12-12 22:12:19 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-12-12 22:16:00 +0100 |
commit | cc143105b884bfcaa188c6e9f93babec5958ea87 (patch) | |
tree | 46d5022fc55999ca6ec69ea9a474b682ded4b3fd /src | |
parent | fed44e95b3c4bc74c8bd96eaf6f08bc6ad01ed55 (diff) | |
download | mpd-cc143105b884bfcaa188c6e9f93babec5958ea87.tar.gz mpd-cc143105b884bfcaa188c6e9f93babec5958ea87.tar.xz mpd-cc143105b884bfcaa188c6e9f93babec5958ea87.zip |
sticker/Match: add operator "EQUALS"
Mapped to "=" in the MPD protocol. This is the first operator,
initially supporting value matches in the MPD protocol.
Diffstat (limited to '')
-rw-r--r-- | src/command/StickerCommands.cxx | 18 | ||||
-rw-r--r-- | src/sticker/Match.hxx | 6 | ||||
-rw-r--r-- | src/sticker/StickerDatabase.cxx | 11 |
3 files changed, 32 insertions, 3 deletions
diff --git a/src/command/StickerCommands.cxx b/src/command/StickerCommands.cxx index b8eee55c5..07bed032e 100644 --- a/src/command/StickerCommands.cxx +++ b/src/command/StickerCommands.cxx @@ -138,7 +138,8 @@ handle_sticker_song(Client &client, ConstBuffer<const char *> args) return CommandResult::OK; /* find song dir key */ - } else if (args.size == 4 && strcmp(cmd, "find") == 0) { + } else if ((args.size == 4 || args.size == 6) && + strcmp(cmd, "find") == 0) { /* "sticker find song a/directory name" */ const char *const base_uri = args[2]; @@ -146,6 +147,21 @@ handle_sticker_song(Client &client, ConstBuffer<const char *> args) StickerOperator op = StickerOperator::EXISTS; const char *value = nullptr; + if (args.size == 6) { + /* match the value */ + + const char *op_s = args[4]; + value = args[5]; + + if (strcmp(op_s, "=") == 0) + op = StickerOperator::EQUALS; + else { + command_error(client, ACK_ERROR_ARG, + "bad operator"); + return CommandResult::ERROR; + } + } + bool success; struct sticker_song_find_data data = { client, diff --git a/src/sticker/Match.hxx b/src/sticker/Match.hxx index f91e70b40..6165ffb84 100644 --- a/src/sticker/Match.hxx +++ b/src/sticker/Match.hxx @@ -26,6 +26,12 @@ enum class StickerOperator { * "value" parameter is ignored (must be nullptr). */ EXISTS, + + /** + * Matches if a sticker with the specified name and value + * exists. + */ + EQUALS, }; #endif diff --git a/src/sticker/StickerDatabase.cxx b/src/sticker/StickerDatabase.cxx index 3c1245a6e..bd809c1d3 100644 --- a/src/sticker/StickerDatabase.cxx +++ b/src/sticker/StickerDatabase.cxx @@ -43,6 +43,7 @@ enum sticker_sql { STICKER_SQL_DELETE, STICKER_SQL_DELETE_VALUE, STICKER_SQL_FIND, + STICKER_SQL_FIND_VALUE, }; static const char *const sticker_sql[] = { @@ -60,6 +61,9 @@ static const char *const sticker_sql[] = { "DELETE FROM sticker WHERE type=? AND uri=? AND name=?", //[STICKER_SQL_FIND] = "SELECT uri,value FROM sticker WHERE type=? AND uri LIKE (? || '%') AND name=?", + + //[STICKER_SQL_FIND_VALUE] = + "SELECT uri,value FROM sticker WHERE type=? AND uri LIKE (? || '%') AND name=? AND value=?", }; static const char sticker_sql_create[] = @@ -383,9 +387,12 @@ BindFind(const char *type, const char *base_uri, const char *name, case StickerOperator::EXISTS: return BindAllOrNull(error, sticker_stmt[STICKER_SQL_FIND], type, base_uri, name); - } - (void)value; + case StickerOperator::EQUALS: + return BindAllOrNull(error, + sticker_stmt[STICKER_SQL_FIND_VALUE], + type, base_uri, name, value); + } assert(false); gcc_unreachable(); |