sticker/Match: add inequality operators

This commit is contained in:
Max Kellermann 2014-12-12 22:26:04 +01:00
parent cc143105b8
commit 49968541fd
4 changed files with 39 additions and 0 deletions

View File

@ -2155,6 +2155,11 @@ OK
<para> <para>
Searches for stickers with the given value. Searches for stickers with the given value.
</para> </para>
<para>
Other supported operators are:
"<function>&lt;</function>", "<function>&gt;</function>"
</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
</variablelist> </variablelist>

View File

@ -155,6 +155,10 @@ handle_sticker_song(Client &client, ConstBuffer<const char *> args)
if (strcmp(op_s, "=") == 0) if (strcmp(op_s, "=") == 0)
op = StickerOperator::EQUALS; op = StickerOperator::EQUALS;
else if (strcmp(op_s, "<") == 0)
op = StickerOperator::LESS_THAN;
else if (strcmp(op_s, ">") == 0)
op = StickerOperator::GREATER_THAN;
else { else {
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
"bad operator"); "bad operator");

View File

@ -32,6 +32,18 @@ enum class StickerOperator {
* exists. * exists.
*/ */
EQUALS, EQUALS,
/**
* Matches if a sticker with the specified name exists with a
* value smaller than the specified one.
*/
LESS_THAN,
/**
* Matches if a sticker with the specified name exists with a
* value bigger than the specified one.
*/
GREATER_THAN,
}; };
#endif #endif

View File

@ -44,6 +44,8 @@ enum sticker_sql {
STICKER_SQL_DELETE_VALUE, STICKER_SQL_DELETE_VALUE,
STICKER_SQL_FIND, STICKER_SQL_FIND,
STICKER_SQL_FIND_VALUE, STICKER_SQL_FIND_VALUE,
STICKER_SQL_FIND_LT,
STICKER_SQL_FIND_GT,
}; };
static const char *const sticker_sql[] = { static const char *const sticker_sql[] = {
@ -64,6 +66,12 @@ static const char *const sticker_sql[] = {
//[STICKER_SQL_FIND_VALUE] = //[STICKER_SQL_FIND_VALUE] =
"SELECT uri,value FROM sticker WHERE type=? AND uri LIKE (? || '%') AND name=? AND value=?", "SELECT uri,value FROM sticker WHERE type=? AND uri LIKE (? || '%') AND name=? AND value=?",
//[STICKER_SQL_FIND_LT] =
"SELECT uri,value FROM sticker WHERE type=? AND uri LIKE (? || '%') AND name=? AND value<?",
//[STICKER_SQL_FIND_GT] =
"SELECT uri,value FROM sticker WHERE type=? AND uri LIKE (? || '%') AND name=? AND value>?",
}; };
static const char sticker_sql_create[] = static const char sticker_sql_create[] =
@ -392,6 +400,16 @@ BindFind(const char *type, const char *base_uri, const char *name,
return BindAllOrNull(error, return BindAllOrNull(error,
sticker_stmt[STICKER_SQL_FIND_VALUE], sticker_stmt[STICKER_SQL_FIND_VALUE],
type, base_uri, name, value); type, base_uri, name, value);
case StickerOperator::LESS_THAN:
return BindAllOrNull(error,
sticker_stmt[STICKER_SQL_FIND_LT],
type, base_uri, name, value);
case StickerOperator::GREATER_THAN:
return BindAllOrNull(error,
sticker_stmt[STICKER_SQL_FIND_GT],
type, base_uri, name, value);
} }
assert(false); assert(false);