fix sqlite3 sink

This commit is contained in:
gabime 2016-03-30 19:11:32 +03:00
parent 12f6fd07e0
commit a2061e3780
1 changed files with 13 additions and 16 deletions

View File

@ -1,15 +1,19 @@
//
// Copyright(c) 2015 spdlog.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
#pragma once #pragma once
#include "spdlog\sinks\sink.h" #include <spdlog/sinks/sink.h>
#include "spdlog/details/log_msg.h" #include <spdlog/details/log_msg.h>
#include "spdlog/common.h" #include <spdlog/common.h>
#include <sqlite3.h> #include <sqlite3.h>
namespace spdlog namespace spdlog
{ {
namespace sinks namespace sinks
{ {
class sqlite_sink : class sqlite_sink: public sink
public sink
{ {
public: public:
@ -24,17 +28,12 @@ namespace spdlog
~sqlite_sink() ~sqlite_sink()
{ {
sqlite_sink::flush(); sqlite3_finalize(_query_stmt);
sqlite3_close(_database);
} }
void flush() override void flush() override
{ {
sqlite3_close(_database);
sqlite3_finalize(_query_stmt);
_database = nullptr;
_query_stmt = nullptr;
} }
void bind_to_statement(const details::log_msg& msg) const void bind_to_statement(const details::log_msg& msg) const
@ -57,8 +56,7 @@ namespace spdlog
{ {
bind_to_statement(msg); bind_to_statement(msg);
if (sqlite3_step(_query_stmt) != SQLITE_DONE) if (sqlite3_step(_query_stmt) != SQLITE_DONE) {
{
throw spdlog_ex(sqlite3_errmsg(_database)); throw spdlog_ex(sqlite3_errmsg(_database));
} }
@ -68,7 +66,6 @@ namespace spdlog
private: private:
sqlite3 *_database; sqlite3 *_database;
sqlite3_stmt * _query_stmt; sqlite3_stmt * _query_stmt;
}; };
} }