New command stickernamestypes
Lists sticker names with their types and optionally filters by type
This commit is contained in:
@@ -46,6 +46,8 @@ enum sticker_sql {
|
||||
STICKER_SQL_TRANSACTION_COMMIT,
|
||||
STICKER_SQL_TRANSACTION_ROLLBACK,
|
||||
STICKER_SQL_NAMES,
|
||||
STICKER_SQL_NAMES_TYPES,
|
||||
STICKER_SQL_NAMES_TYPES_BY_TYPE,
|
||||
|
||||
STICKER_SQL_COUNT
|
||||
};
|
||||
@@ -106,7 +108,13 @@ static constexpr auto sticker_sql = std::array {
|
||||
"ROLLBACK",
|
||||
|
||||
//[STICKER_SQL_NAMES]
|
||||
"SELECT DISTINCT name FROM sticker order by name",
|
||||
"SELECT DISTINCT name FROM sticker ORDER BY name",
|
||||
|
||||
//[STICKER_SQL_NAMES_TYPES]
|
||||
"SELECT name,type FROM sticker GROUP BY name,type ORDER BY name",
|
||||
|
||||
//[STICKER_SQL_NAMES_TYPES_BY_TYPE]
|
||||
"SELECT name,type FROM sticker WHERE type = ? GROUP BY name,type ORDER BY name",
|
||||
};
|
||||
|
||||
static constexpr const char sticker_sql_create[] =
|
||||
@@ -478,6 +486,29 @@ StickerDatabase::Names(void (*func)(const char *value, void *user_data), void *u
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
StickerDatabase::NamesTypes(const char *type, void (*func)(const char *value, const char *type, void *user_data), void *user_data)
|
||||
{
|
||||
assert(func != nullptr);
|
||||
|
||||
sqlite3_stmt *const s = type == nullptr
|
||||
? stmt[STICKER_SQL_NAMES_TYPES]
|
||||
: stmt[STICKER_SQL_NAMES_TYPES_BY_TYPE];
|
||||
assert(s != nullptr);
|
||||
|
||||
if (type != nullptr)
|
||||
BindAll(s, type);
|
||||
|
||||
AtScopeExit(s) {
|
||||
sqlite3_reset(s);
|
||||
};
|
||||
|
||||
ExecuteForEach(s, [s, func, user_data](){
|
||||
func((const char*)sqlite3_column_text(s, 0),
|
||||
(const char*)sqlite3_column_text(s, 1), user_data);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
StickerDatabase::BatchDeleteNoIdle(const std::list<StickerTypeUriPair> &stickers)
|
||||
{
|
||||
|
||||
@@ -52,6 +52,8 @@ class StickerDatabase {
|
||||
SQL_TRANSACTION_COMMIT,
|
||||
SQL_TRANSACTION_ROLLBACK,
|
||||
SQL_NAMES,
|
||||
SQL_NAMES_TYPES,
|
||||
SQL_NAMES_TYPES_BY_TYPE,
|
||||
|
||||
SQL_COUNT
|
||||
};
|
||||
@@ -166,6 +168,11 @@ public:
|
||||
*/
|
||||
void Names(void (*func)(const char *value, void *user_data), void *user_data);
|
||||
|
||||
/**
|
||||
* Uniq and sorted list of all sticker names by type
|
||||
*/
|
||||
void NamesTypes(const char *type, void (*func)(const char *value, const char *type, void *user_data), void *user_data);
|
||||
|
||||
using StickerTypeUriPair = std::pair<std::string, std::string>;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user