lib/sqlite/Domain: add Domain instance for SQLite

Replaces the sticker_domain for Error::domain.
This commit is contained in:
Max Kellermann 2014-12-12 20:49:00 +01:00
parent 7dbe5f4640
commit 2ca18a7ee5
4 changed files with 58 additions and 5 deletions

View File

@ -354,6 +354,7 @@ endif
if ENABLE_SQLITE if ENABLE_SQLITE
libmpd_a_SOURCES += \ libmpd_a_SOURCES += \
src/command/StickerCommands.cxx src/command/StickerCommands.hxx \ src/command/StickerCommands.cxx src/command/StickerCommands.hxx \
src/lib/sqlite/Domain.cxx src/lib/sqlite/Domain.hxx \
src/sticker/StickerDatabase.cxx src/sticker/StickerDatabase.hxx \ src/sticker/StickerDatabase.cxx src/sticker/StickerDatabase.hxx \
src/sticker/StickerPrint.cxx src/sticker/StickerPrint.hxx \ src/sticker/StickerPrint.cxx src/sticker/StickerPrint.hxx \
src/sticker/SongSticker.cxx src/sticker/SongSticker.hxx src/sticker/SongSticker.cxx src/sticker/SongSticker.hxx

24
src/lib/sqlite/Domain.cxx Normal file
View File

@ -0,0 +1,24 @@
/*
* 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.
*/
#include "config.h"
#include "Domain.hxx"
#include "util/Domain.hxx"
const Domain sqlite_domain("sqlite");

27
src/lib/sqlite/Domain.hxx Normal file
View File

@ -0,0 +1,27 @@
/*
* 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_DOMAIN_HXX
#define MPD_SQLITE_DOMAIN_HXX
class Domain;
extern const Domain sqlite_domain;
#endif

View File

@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include "StickerDatabase.hxx" #include "StickerDatabase.hxx"
#include "lib/sqlite/Domain.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "Idle.hxx" #include "Idle.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -91,7 +92,7 @@ sticker_prepare(const char *sql, Error &error)
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
int ret = sqlite3_prepare_v2(sticker_db, sql, -1, &stmt, nullptr); int ret = sqlite3_prepare_v2(sticker_db, sql, -1, &stmt, nullptr);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
error.Format(sticker_domain, ret, error.Format(sqlite_domain, ret,
"sqlite3_prepare_v2() failed: %s", "sqlite3_prepare_v2() failed: %s",
sqlite3_errmsg(sticker_db)); sqlite3_errmsg(sticker_db));
return nullptr; return nullptr;
@ -112,9 +113,9 @@ sticker_global_init(Path path, Error &error)
ret = sqlite3_open(path.c_str(), &sticker_db); ret = sqlite3_open(path.c_str(), &sticker_db);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
const std::string utf8 = path.ToUTF8(); const std::string utf8 = path.ToUTF8();
error.Format(sticker_domain, ret, error.Format(sqlite_domain, ret,
"Failed to open sqlite database '%s': %s", "Failed to open sqlite database '%s': %s",
utf8.c_str(), sqlite3_errmsg(sticker_db)); utf8.c_str(), sqlite3_errmsg(sticker_db));
return false; return false;
} }
@ -123,7 +124,7 @@ sticker_global_init(Path path, Error &error)
ret = sqlite3_exec(sticker_db, sticker_sql_create, ret = sqlite3_exec(sticker_db, sticker_sql_create,
nullptr, nullptr, nullptr); nullptr, nullptr, nullptr);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
error.Format(sticker_domain, ret, error.Format(sqlite_domain, ret,
"Failed to create sticker table: %s", "Failed to create sticker table: %s",
sqlite3_errmsg(sticker_db)); sqlite3_errmsg(sticker_db));
return false; return false;