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
a6dc1ab0
Commit
a6dc1ab0
authored
Apr 25, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/sqlite/Database: wrapper for `sqlite3*`
parent
77c9081f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
13 deletions
+97
-13
Database.cxx
src/lib/sqlite/Database.cxx
+35
-0
Database.hxx
src/lib/sqlite/Database.hxx
+58
-0
meson.build
src/lib/sqlite/meson.build
+1
-0
Database.cxx
src/sticker/Database.cxx
+1
-12
Database.hxx
src/sticker/Database.hxx
+2
-1
No files found.
src/lib/sqlite/Database.cxx
0 → 100644
View file @
a6dc1ab0
/*
* Copyright 2003-2019 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.
*/
#include "Database.hxx"
#include "Error.hxx"
#include "util/StringFormat.hxx"
namespace
Sqlite
{
Database
::
Database
(
const
char
*
path
)
{
int
result
=
sqlite3_open
(
path
,
&
db
);
if
(
result
!=
SQLITE_OK
)
throw
SqliteError
(
db
,
result
,
StringFormat
<
1024
>
(
"Failed to open sqlite database '%s'"
,
path
));
}
}
// namespace Sqlite
src/lib/sqlite/Database.hxx
0 → 100644
View file @
a6dc1ab0
/*
* Copyright 2003-2019 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_DATABASE_HXX
#define MPD_SQLITE_DATABASE_HXX
#include <sqlite3.h>
#include <utility>
namespace
Sqlite
{
class
Database
{
sqlite3
*
db
=
nullptr
;
public
:
Database
()
=
default
;
explicit
Database
(
const
char
*
path
);
~
Database
()
noexcept
{
if
(
db
!=
nullptr
)
sqlite3_close
(
db
);
}
Database
(
Database
&&
src
)
noexcept
:
db
(
std
::
exchange
(
src
.
db
,
nullptr
))
{}
Database
&
operator
=
(
Database
&&
src
)
noexcept
{
using
std
::
swap
;
swap
(
db
,
src
.
db
);
return
*
this
;
}
operator
sqlite3
*
()
const
noexcept
{
return
db
;
}
};
}
// namespace Sqlite
#endif
src/lib/sqlite/meson.build
View file @
a6dc1ab0
...
...
@@ -6,6 +6,7 @@ endif
sqlite = static_library(
'sqlite',
'Database.cxx',
'Error.cxx',
include_directories: inc,
dependencies: [
...
...
src/sticker/Database.cxx
View file @
a6dc1ab0
...
...
@@ -82,21 +82,12 @@ static const char sticker_sql_create[] =
""
;
StickerDatabase
::
StickerDatabase
(
Path
path
)
:
db
(
path
.
c_str
())
{
assert
(
!
path
.
IsNull
());
int
ret
;
/* open/create the sqlite database */
ret
=
sqlite3_open
(
path
.
c_str
(),
&
db
);
if
(
ret
!=
SQLITE_OK
)
{
const
std
::
string
utf8
=
path
.
ToUTF8
();
throw
SqliteError
(
db
,
ret
,
(
"Failed to open sqlite database '"
+
utf8
+
"'"
).
c_str
());
}
/* create the table and index */
ret
=
sqlite3_exec
(
db
,
sticker_sql_create
,
...
...
@@ -123,8 +114,6 @@ StickerDatabase::~StickerDatabase() noexcept
sqlite3_finalize
(
stmt
[
i
]);
}
sqlite3_close
(
db
);
}
std
::
string
...
...
src/sticker/Database.hxx
View file @
a6dc1ab0
...
...
@@ -43,6 +43,7 @@
#define MPD_STICKER_DATABASE_HXX
#include "Match.hxx"
#include "lib/sqlite/Database.hxx"
#include "util/Compiler.h"
#include <sqlite3.h>
...
...
@@ -69,7 +70,7 @@ class StickerDatabase {
SQL_COUNT
};
sqlite3
*
db
;
Sqlite
::
Database
db
;
sqlite3_stmt
*
stmt
[
SQL_COUNT
];
public
:
...
...
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