Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
c85af12d
Commit
c85af12d
authored
Oct 17, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
StickerDatabase: return std::string
parent
e452d1f5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
23 deletions
+26
-23
SongSticker.cxx
src/SongSticker.cxx
+1
-1
SongSticker.hxx
src/SongSticker.hxx
+6
-1
StickerCommands.cxx
src/StickerCommands.cxx
+3
-4
StickerDatabase.cxx
src/StickerDatabase.cxx
+11
-14
StickerDatabase.hxx
src/StickerDatabase.hxx
+5
-3
No files found.
src/SongSticker.cxx
View file @
c85af12d
...
...
@@ -28,7 +28,7 @@
#include <assert.h>
#include <string.h>
char
*
std
::
string
sticker_song_get_value
(
const
Song
*
song
,
const
char
*
name
)
{
assert
(
song
!=
NULL
);
...
...
src/SongSticker.hxx
View file @
c85af12d
...
...
@@ -20,6 +20,10 @@
#ifndef MPD_SONG_STICKER_HXX
#define MPD_SONG_STICKER_HXX
#include "Compiler.h"
#include <string>
struct
Song
;
struct
Directory
;
struct
sticker
;
...
...
@@ -28,7 +32,8 @@ struct sticker;
* Returns one value from a song's sticker record. The caller must
* free the return value with g_free().
*/
char
*
gcc_pure
std
::
string
sticker_song_get_value
(
const
Song
*
song
,
const
char
*
name
);
/**
...
...
src/StickerCommands.cxx
View file @
c85af12d
...
...
@@ -65,16 +65,15 @@ handle_sticker_song(Client *client, int argc, char *argv[])
if
(
song
==
nullptr
)
return
print_error
(
client
,
error
);
c
har
*
value
=
sticker_song_get_value
(
song
,
argv
[
4
]);
c
onst
auto
value
=
sticker_song_get_value
(
song
,
argv
[
4
]);
db
->
ReturnSong
(
song
);
if
(
value
==
NULL
)
{
if
(
value
.
empty
()
)
{
command_error
(
client
,
ACK_ERROR_NO_EXIST
,
"no such sticker"
);
return
COMMAND_RETURN_ERROR
;
}
sticker_print_value
(
client
,
argv
[
4
],
value
);
g_free
(
value
);
sticker_print_value
(
client
,
argv
[
4
],
value
.
c_str
());
return
COMMAND_RETURN_OK
;
/* list song song_id */
...
...
src/StickerDatabase.cxx
View file @
c85af12d
...
...
@@ -29,7 +29,6 @@
#include <string>
#include <map>
#include <glib.h>
#include <sqlite3.h>
#include <assert.h>
...
...
@@ -172,12 +171,11 @@ sticker_enabled(void)
return
sticker_db
!=
NULL
;
}
char
*
std
::
string
sticker_load_value
(
const
char
*
type
,
const
char
*
uri
,
const
char
*
name
)
{
sqlite3_stmt
*
const
stmt
=
sticker_stmt
[
STICKER_SQL_GET
];
int
ret
;
char
*
value
;
assert
(
sticker_enabled
());
assert
(
type
!=
NULL
);
...
...
@@ -185,42 +183,41 @@ sticker_load_value(const char *type, const char *uri, const char *name)
assert
(
name
!=
NULL
);
if
(
*
name
==
0
)
return
NULL
;
return
std
::
string
()
;
sqlite3_reset
(
stmt
);
ret
=
sqlite3_bind_text
(
stmt
,
1
,
type
,
-
1
,
NULL
);
if
(
ret
!=
SQLITE_OK
)
{
LogError
(
sticker_db
,
"sqlite3_bind_text() failed"
);
return
NULL
;
return
std
::
string
()
;
}
ret
=
sqlite3_bind_text
(
stmt
,
2
,
uri
,
-
1
,
NULL
);
if
(
ret
!=
SQLITE_OK
)
{
LogError
(
sticker_db
,
"sqlite3_bind_text() failed"
);
return
NULL
;
return
std
::
string
()
;
}
ret
=
sqlite3_bind_text
(
stmt
,
3
,
name
,
-
1
,
NULL
);
if
(
ret
!=
SQLITE_OK
)
{
LogError
(
sticker_db
,
"sqlite3_bind_text() failed"
);
return
NULL
;
return
std
::
string
()
;
}
do
{
ret
=
sqlite3_step
(
stmt
);
}
while
(
ret
==
SQLITE_BUSY
);
std
::
string
value
;
if
(
ret
==
SQLITE_ROW
)
{
/* record found */
value
=
g_strdup
((
const
char
*
)
sqlite3_column_text
(
stmt
,
0
)
);
value
=
(
const
char
*
)
sqlite3_column_text
(
stmt
,
0
);
}
else
if
(
ret
==
SQLITE_DONE
)
{
/* no record found */
value
=
NULL
;
}
else
{
/* error */
LogError
(
sticker_db
,
"sqlite3_step() failed"
);
return
NULL
;
}
sqlite3_reset
(
stmt
);
...
...
@@ -523,8 +520,8 @@ sticker_get_value(const struct sticker *sticker, const char *name)
void
sticker_foreach
(
const
struct
sticker
*
sticker
,
void
(
*
func
)(
const
char
*
name
,
const
char
*
value
,
gpointer
user_data
),
gpointer
user_data
)
void
*
user_data
),
void
*
user_data
)
{
for
(
const
auto
&
i
:
sticker
->
table
)
func
(
i
.
first
.
c_str
(),
i
.
second
.
c_str
(),
user_data
);
...
...
@@ -548,8 +545,8 @@ sticker_load(const char *type, const char *uri)
bool
sticker_find
(
const
char
*
type
,
const
char
*
base_uri
,
const
char
*
name
,
void
(
*
func
)(
const
char
*
uri
,
const
char
*
value
,
gpointer
user_data
),
gpointer
user_data
)
void
*
user_data
),
void
*
user_data
)
{
sqlite3_stmt
*
const
stmt
=
sticker_stmt
[
STICKER_SQL_FIND
];
int
ret
;
...
...
src/StickerDatabase.hxx
View file @
c85af12d
...
...
@@ -44,6 +44,8 @@
#include "Compiler.h"
#include <string>
class
Error
;
class
Path
;
struct
sticker
;
...
...
@@ -72,10 +74,10 @@ bool
sticker_enabled
(
void
);
/**
* Returns one value from an object's sticker record.
The caller must
*
free the return value with g_free()
.
* Returns one value from an object's sticker record.
Returns an
*
empty string if the value doesn't exist
.
*/
char
*
std
::
string
sticker_load_value
(
const
char
*
type
,
const
char
*
uri
,
const
char
*
name
);
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment