sticker/Database: return Sticker by value

This commit is contained in:
Max Kellermann
2019-04-24 15:05:05 +02:00
parent 7b48ae4f85
commit 5a915eb0e6
5 changed files with 13 additions and 32 deletions

View File

@@ -21,6 +21,7 @@
#include "Request.hxx" #include "Request.hxx"
#include "SongPrint.hxx" #include "SongPrint.hxx"
#include "db/Interface.hxx" #include "db/Interface.hxx"
#include "sticker/Sticker.hxx"
#include "sticker/SongSticker.hxx" #include "sticker/SongSticker.hxx"
#include "sticker/StickerPrint.hxx" #include "sticker/StickerPrint.hxx"
#include "sticker/StickerDatabase.hxx" #include "sticker/StickerDatabase.hxx"
@@ -76,11 +77,8 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
assert(song != nullptr); assert(song != nullptr);
AtScopeExit(&db, song) { db.ReturnSong(song); }; AtScopeExit(&db, song) { db.ReturnSong(song); };
Sticker *sticker = sticker_song_get(*song); const auto sticker = sticker_song_get(*song);
if (sticker) { sticker_print(r, sticker);
sticker_print(r, *sticker);
sticker_free(sticker);
}
return CommandResult::OK; return CommandResult::OK;
/* set song song_id id key */ /* set song song_id id key */

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2018 The Music Player Daemon Project * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@@ -18,6 +18,7 @@
*/ */
#include "SongSticker.hxx" #include "SongSticker.hxx"
#include "Sticker.hxx"
#include "StickerDatabase.hxx" #include "StickerDatabase.hxx"
#include "song/LightSong.hxx" #include "song/LightSong.hxx"
#include "db/Interface.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); return sticker_delete_value("song", uri.c_str(), name);
} }
Sticker * Sticker
sticker_song_get(const LightSong &song) sticker_song_get(const LightSong &song)
{ {
const auto uri = song.GetURI(); const auto uri = song.GetURI();

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2018 The Music Player Daemon Project * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * 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. * Throws #SqliteError on error.
* *
* @param song the song object * @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); sticker_song_get(const LightSong &song);
/** /**

View File

@@ -314,12 +314,6 @@ sticker_delete_value(const char *type, const char *uri, const char *name)
return modified; return modified;
} }
void
sticker_free(Sticker *sticker) noexcept
{
delete sticker;
}
const char * const char *
sticker_get_value(const Sticker &sticker, const char *name) noexcept 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); func(i.first.c_str(), i.second.c_str(), user_data);
} }
Sticker * Sticker
sticker_load(const char *type, const char *uri) sticker_load(const char *type, const char *uri)
{ {
Sticker s; Sticker s;
sticker_list_values(s.table, type, uri); sticker_list_values(s.table, type, uri);
if (s.table.empty()) return s;
/* don't return empty sticker objects */
return nullptr;
return new Sticker(std::move(s));
} }
static sqlite3_stmt * static sqlite3_stmt *

View File

@@ -108,14 +108,6 @@ sticker_delete(const char *type, const char *uri);
bool bool
sticker_delete_value(const char *type, const char *uri, const char *name); 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. * Determines a single value in a sticker.
* *
@@ -147,9 +139,9 @@ sticker_foreach(const Sticker &sticker,
* *
* @param type the resource type, e.g. "song" * @param type the resource type, e.g. "song"
* @param uri the URI of the resource, e.g. the song path * @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); sticker_load(const char *type, const char *uri);
/** /**