[go: up one dir, main page]

File: logger.cpp

package info (click to toggle)
soci 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,944 kB
  • sloc: ansic: 169,887; cpp: 54,198; javascript: 12,258; ada: 1,973; sh: 36; makefile: 12; xml: 2
file content (119 lines) | stat: -rw-r--r-- 2,131 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// Copyright (C) 2014 Vadim Zeitlin
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
//

#define SOCI_SOURCE
#include "soci/logger.h"
#include "soci/error.h"

using namespace soci;

namespace // anonymous
{

// Helper to throw from not implemented logger_impl methods.
[[noreturn]] void throw_not_supported()
{
    throw soci_error("Legacy method not supported by this logger.");
}

} // namespace anonymous


void logger_impl::start_query(const std::string &)
{
    clear_query_parameters();
}

void logger_impl::add_query_parameter(std::string name, std::string value)
{
    queryParams_.emplace_back(std::move(name), std::move(value));
}

void logger_impl::clear_query_parameters()
{
    queryParams_.clear();
}

logger_impl * logger_impl::clone() const
{
    logger_impl * const impl = do_clone();
    if (!impl)
    {
        throw soci_error("Cloning a logger implementation must work.");
    }

    return impl;
}

logger_impl::~logger_impl()
{
}

void logger_impl::set_stream(std::ostream *)
{
    throw_not_supported();
}

std::ostream * logger_impl::get_stream() const
{
    throw_not_supported();
}

std::string logger_impl::get_last_query() const
{
    throw_not_supported();
}

std::string logger_impl::get_last_query_context() const
{
    std::string context;

    bool first = true;
    for (const query_parameter &param : queryParams_)
    {
        if (first)
        {
            first = false;
        }
        else
        {
            context += ", ";
        }

        context += ":" + param.name + "=" + param.value;
    }

    return context;
}

logger::logger(logger_impl * impl)
    : m_impl(impl)
{
    if (!m_impl)
    {
        throw soci_error("Null logger implementation not allowed.");
    }
}

logger::logger(logger const & other)
    : m_impl(other.m_impl->clone())
{
}

logger& logger::operator=(logger const & other)
{
    logger_impl * const implOld = m_impl;
    m_impl = other.m_impl->clone();
    delete implOld;

    return *this;
}

logger::~logger()
{
    delete m_impl;
}