db/DatabasePrint: support descending sort

This commit is contained in:
Max Kellermann
2017-12-18 21:50:14 +01:00
parent 6246d36fe6
commit 7a55ab6acc
4 changed files with 25 additions and 9 deletions

View File

@@ -68,8 +68,15 @@ handle_match(Client &client, Request args, Response &r, bool fold_case)
window.SetAll();
TagType sort = TAG_NUM_OF_ITEM_TYPES;
bool descending = false;
if (args.size >= 2 && StringIsEqual(args[args.size - 2], "sort")) {
sort = tag_name_parse_i(args.back());
const char *s = args.back();
if (*s == '-') {
descending = true;
++s;
}
sort = tag_name_parse_i(s);
if (sort == TAG_NUM_OF_ITEM_TYPES)
throw ProtocolError(ACK_ERROR_ARG, "Unknown sort tag");
@@ -87,7 +94,7 @@ handle_match(Client &client, Request args, Response &r, bool fold_case)
db_selection_print(r, client.GetPartition(),
selection, true, false,
sort,
sort, descending,
window.start, window.end);
return CommandResult::OK;
}