Commit 5a915eb0 authored by Max Kellermann's avatar Max Kellermann

sticker/Database: return Sticker by value

parent 7b48ae4f
......@@ -21,6 +21,7 @@
#include "Request.hxx"
#include "SongPrint.hxx"
#include "db/Interface.hxx"
#include "sticker/Sticker.hxx"
#include "sticker/SongSticker.hxx"
#include "sticker/StickerPrint.hxx"
#include "sticker/StickerDatabase.hxx"
......@@ -76,11 +77,8 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
assert(song != nullptr);
AtScopeExit(&db, song) { db.ReturnSong(song); };
Sticker *sticker = sticker_song_get(*song);
if (sticker) {
sticker_print(r, *sticker);
sticker_free(sticker);
}
const auto sticker = sticker_song_get(*song);
sticker_print(r, sticker);
return CommandResult::OK;
/* set song song_id id key */
......
/*
* Copyright 2003-2018 The Music Player Daemon Project
* Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
......@@ -18,6 +18,7 @@
*/
#include "SongSticker.hxx"
#include "Sticker.hxx"
#include "StickerDatabase.hxx"
#include "song/LightSong.hxx"
#include "db/Interface.hxx"
......@@ -61,7 +62,7 @@ sticker_song_delete_value(const LightSong &song, const char *name)
return sticker_delete_value("song", uri.c_str(), name);
}
Sticker *
Sticker
sticker_song_get(const LightSong &song)
{
const auto uri = song.GetURI();
......
/*
* Copyright 2003-2018 The Music Player Daemon Project
* Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
......@@ -72,9 +72,9 @@ sticker_song_delete_value(const LightSong &song, const char *name);
* Throws #SqliteError on error.
*
* @param song the song object
* @return a sticker object, or nullptr if there is no sticker
* @return a sticker object
*/
Sticker *
Sticker
sticker_song_get(const LightSong &song);
/**
......
......@@ -314,12 +314,6 @@ sticker_delete_value(const char *type, const char *uri, const char *name)
return modified;
}
void
sticker_free(Sticker *sticker) noexcept
{
delete sticker;
}
const char *
sticker_get_value(const Sticker &sticker, const char *name) noexcept
{
......@@ -340,18 +334,14 @@ sticker_foreach(const Sticker &sticker,
func(i.first.c_str(), i.second.c_str(), user_data);
}
Sticker *
Sticker
sticker_load(const char *type, const char *uri)
{
Sticker s;
sticker_list_values(s.table, type, uri);
if (s.table.empty())
/* don't return empty sticker objects */
return nullptr;
return new Sticker(std::move(s));
return s;
}
static sqlite3_stmt *
......
......@@ -109,14 +109,6 @@ bool
sticker_delete_value(const char *type, const char *uri, const char *name);
/**
* Frees resources held by the sticker object.
*
* @param sticker the sticker object to be freed
*/
void
sticker_free(Sticker *sticker) noexcept;
/**
* Determines a single value in a sticker.
*
* @param sticker the sticker object
......@@ -147,9 +139,9 @@ sticker_foreach(const Sticker &sticker,
*
* @param type the resource type, e.g. "song"
* @param uri the URI of the resource, e.g. the song path
* @return a sticker object, or nullptr if there is no sticker
* @return a sticker object
*/
Sticker *
Sticker
sticker_load(const char *type, const char *uri);
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment