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
052d350b
Commit
052d350b
authored
Dec 12, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sticker/Database: move SQLite helpers to lib/sqlite/Util.hxx
parent
2ca18a7e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
45 deletions
+82
-45
Makefile.am
Makefile.am
+1
-0
Util.hxx
src/lib/sqlite/Util.hxx
+80
-0
StickerDatabase.cxx
src/sticker/StickerDatabase.cxx
+1
-45
No files found.
Makefile.am
View file @
052d350b
...
...
@@ -355,6 +355,7 @@ if ENABLE_SQLITE
libmpd_a_SOURCES
+=
\
src/command/StickerCommands.cxx src/command/StickerCommands.hxx
\
src/lib/sqlite/Domain.cxx src/lib/sqlite/Domain.hxx
\
src/lib/sqlite/Util.hxx
\
src/sticker/StickerDatabase.cxx src/sticker/StickerDatabase.hxx
\
src/sticker/StickerPrint.cxx src/sticker/StickerPrint.hxx
\
src/sticker/SongSticker.cxx src/sticker/SongSticker.hxx
...
...
src/lib/sqlite/Util.hxx
0 → 100644
View file @
052d350b
/*
* Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_SQLITE_UTIL_HXX
#define MPD_SQLITE_UTIL_HXX
#include "Domain.hxx"
#include "Log.hxx"
#include <sqlite3.h>
#include <assert.h>
static
void
LogError
(
sqlite3
*
db
,
const
char
*
msg
)
{
FormatError
(
sqlite_domain
,
"%s: %s"
,
msg
,
sqlite3_errmsg
(
db
));
}
static
void
LogError
(
sqlite3_stmt
*
stmt
,
const
char
*
msg
)
{
LogError
(
sqlite3_db_handle
(
stmt
),
msg
);
}
static
bool
Bind
(
sqlite3_stmt
*
stmt
,
unsigned
i
,
const
char
*
value
)
{
int
result
=
sqlite3_bind_text
(
stmt
,
i
,
value
,
-
1
,
nullptr
);
if
(
result
!=
SQLITE_OK
)
{
LogError
(
stmt
,
"sqlite3_bind_text() failed"
);
return
false
;
}
return
true
;
}
template
<
typename
...
Args
>
static
bool
BindAll2
(
gcc_unused
sqlite3_stmt
*
stmt
,
gcc_unused
unsigned
i
)
{
assert
(
int
(
i
-
1
)
==
sqlite3_bind_parameter_count
(
stmt
));
return
true
;
}
template
<
typename
...
Args
>
static
bool
BindAll2
(
sqlite3_stmt
*
stmt
,
unsigned
i
,
const
char
*
value
,
Args
&&
...
args
)
{
return
Bind
(
stmt
,
i
,
value
)
&&
BindAll2
(
stmt
,
i
+
1
,
std
::
forward
<
Args
>
(
args
)...);
}
template
<
typename
...
Args
>
static
bool
BindAll
(
sqlite3_stmt
*
stmt
,
Args
&&
...
args
)
{
assert
(
int
(
sizeof
...(
args
))
==
sqlite3_bind_parameter_count
(
stmt
));
return
BindAll2
(
stmt
,
1
,
std
::
forward
<
Args
>
(
args
)...);
}
#endif
src/sticker/StickerDatabase.cxx
View file @
052d350b
...
...
@@ -20,17 +20,16 @@
#include "config.h"
#include "StickerDatabase.hxx"
#include "lib/sqlite/Domain.hxx"
#include "lib/sqlite/Util.hxx"
#include "fs/Path.hxx"
#include "Idle.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/Macros.hxx"
#include "Log.hxx"
#include <string>
#include <map>
#include <sqlite3.h>
#include <assert.h>
struct
sticker
{
...
...
@@ -78,14 +77,6 @@ static const char sticker_sql_create[] =
static
sqlite3
*
sticker_db
;
static
sqlite3_stmt
*
sticker_stmt
[
ARRAY_SIZE
(
sticker_sql
)];
static
constexpr
Domain
sticker_domain
(
"sticker"
);
static
void
LogError
(
sqlite3
*
db
,
const
char
*
msg
)
{
FormatError
(
sticker_domain
,
"%s: %s"
,
msg
,
sqlite3_errmsg
(
db
));
}
static
sqlite3_stmt
*
sticker_prepare
(
const
char
*
sql
,
Error
&
error
)
{
...
...
@@ -165,41 +156,6 @@ sticker_enabled()
return
sticker_db
!=
nullptr
;
}
static
bool
Bind
(
sqlite3_stmt
*
stmt
,
unsigned
i
,
const
char
*
value
)
{
int
result
=
sqlite3_bind_text
(
stmt
,
i
,
value
,
-
1
,
nullptr
);
if
(
result
!=
SQLITE_OK
)
{
LogError
(
sticker_db
,
"sqlite3_bind_text() failed"
);
return
false
;
}
return
true
;
}
template
<
typename
...
Args
>
static
bool
BindAll2
(
gcc_unused
sqlite3_stmt
*
stmt
,
gcc_unused
unsigned
i
)
{
assert
(
int
(
i
-
1
)
==
sqlite3_bind_parameter_count
(
stmt
));
return
true
;
}
template
<
typename
...
Args
>
static
bool
BindAll2
(
sqlite3_stmt
*
stmt
,
unsigned
i
,
const
char
*
value
,
Args
&&
...
args
)
{
return
Bind
(
stmt
,
i
,
value
)
&&
BindAll2
(
stmt
,
i
+
1
,
std
::
forward
<
Args
>
(
args
)...);
}
template
<
typename
...
Args
>
static
bool
BindAll
(
sqlite3_stmt
*
stmt
,
Args
&&
...
args
)
{
return
BindAll2
(
stmt
,
1
,
std
::
forward
<
Args
>
(
args
)...);
}
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