Commit a2061e37 authored by gabime's avatar gabime

fix sqlite3 sink

parent 12f6fd07
//
// 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 ...@@ -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 ...@@ -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 ...@@ -68,7 +66,6 @@ namespace spdlog
private: private:
sqlite3 *_database; sqlite3 *_database;
sqlite3_stmt * _query_stmt; sqlite3_stmt * _query_stmt;
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment