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
3a4d20fa
Commit
3a4d20fa
authored
Apr 01, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sticker: added sticker_find()
sticker_find() finds stickers with the specified name.
parent
7f38c3fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
0 deletions
+85
-0
sticker.c
src/sticker.c
+69
-0
sticker.h
src/sticker.h
+16
-0
No files found.
src/sticker.c
View file @
3a4d20fa
...
...
@@ -37,6 +37,7 @@ enum sticker_sql {
STICKER_SQL_UPDATE
,
STICKER_SQL_INSERT
,
STICKER_SQL_DELETE
,
STICKER_SQL_FIND
,
};
static
const
char
*
const
sticker_sql
[]
=
{
...
...
@@ -50,6 +51,8 @@ static const char *const sticker_sql[] = {
"INSERT INTO sticker(type,uri,name,value) VALUES(?, ?, ?, ?)"
,
[
STICKER_SQL_DELETE
]
=
"DELETE FROM sticker WHERE type=? AND uri=?"
,
[
STICKER_SQL_FIND
]
=
"SELECT uri,value FROM sticker WHERE type=? AND uri LIKE (? || '%') AND name=?"
,
};
static
const
char
sticker_sql_create
[]
=
...
...
@@ -508,3 +511,69 @@ sticker_load(const char *type, const char *uri)
return
sticker
;
}
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
)
{
sqlite3_stmt
*
const
stmt
=
sticker_stmt
[
STICKER_SQL_FIND
];
int
ret
;
assert
(
type
!=
NULL
);
assert
(
name
!=
NULL
);
assert
(
func
!=
NULL
);
assert
(
sticker_enabled
());
sqlite3_reset
(
stmt
);
ret
=
sqlite3_bind_text
(
stmt
,
1
,
type
,
-
1
,
NULL
);
if
(
ret
!=
SQLITE_OK
)
{
g_warning
(
"sqlite3_bind_text() failed: %s"
,
sqlite3_errmsg
(
sticker_db
));
return
false
;
}
if
(
base_uri
==
NULL
)
base_uri
=
""
;
ret
=
sqlite3_bind_text
(
stmt
,
2
,
base_uri
,
-
1
,
NULL
);
if
(
ret
!=
SQLITE_OK
)
{
g_warning
(
"sqlite3_bind_text() failed: %s"
,
sqlite3_errmsg
(
sticker_db
));
return
false
;
}
ret
=
sqlite3_bind_text
(
stmt
,
3
,
name
,
-
1
,
NULL
);
if
(
ret
!=
SQLITE_OK
)
{
g_warning
(
"sqlite3_bind_text() failed: %s"
,
sqlite3_errmsg
(
sticker_db
));
return
false
;
}
do
{
ret
=
sqlite3_step
(
stmt
);
switch
(
ret
)
{
case
SQLITE_ROW
:
func
((
const
char
*
)
sqlite3_column_text
(
stmt
,
0
),
(
const
char
*
)
sqlite3_column_text
(
stmt
,
1
),
user_data
);
break
;
case
SQLITE_DONE
:
break
;
case
SQLITE_BUSY
:
/* no op */
break
;
default:
g_warning
(
"sqlite3_step() failed: %s"
,
sqlite3_errmsg
(
sticker_db
));
return
false
;
}
}
while
(
ret
!=
SQLITE_DONE
);
sqlite3_reset
(
stmt
);
sqlite3_clear_bindings
(
stmt
);
return
true
;
}
src/sticker.h
View file @
3a4d20fa
...
...
@@ -129,4 +129,20 @@ sticker_foreach(const struct sticker *sticker,
struct
sticker
*
sticker_load
(
const
char
*
type
,
const
char
*
uri
);
/**
* Finds stickers with the specified name below the specified URI.
*
* @param type the resource type, e.g. "song"
* @param base_uri the URI prefix of the resources, or NULL if all
* resources should be searched
* @param name the name of the sticker
* @return true on success (even if no sticker was found), false on
* failure
*/
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
);
#endif
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