added logger
This commit is contained in:
@@ -10,6 +10,7 @@ namespace matador::sql {
|
||||
|
||||
connection::connection(connection_info info)
|
||||
: connection_info_(std::move(info))
|
||||
, logger_(stdout, "SQL")
|
||||
{
|
||||
connection_.reset(backend_provider::instance().create_connection(connection_info_.type, connection_info_));
|
||||
}
|
||||
@@ -20,6 +21,7 @@ connection::connection(const std::string& dns)
|
||||
|
||||
connection::connection(const connection &x)
|
||||
: connection_info_(x.connection_info_)
|
||||
, logger_(x.logger_)
|
||||
{
|
||||
if (x.connection_) {
|
||||
throw std::runtime_error("couldn't copy connection with valid connection impl");
|
||||
@@ -28,6 +30,7 @@ connection::connection(const connection &x)
|
||||
|
||||
connection &connection::operator=(const connection &x) {
|
||||
connection_info_ = x.connection_info_;
|
||||
logger_ = x.logger_;
|
||||
if (x.connection_) {
|
||||
throw std::runtime_error("couldn't copy connection with valid connection impl");
|
||||
}
|
||||
@@ -75,11 +78,13 @@ bool connection::exists(const std::string &table_name) const
|
||||
|
||||
std::pair<size_t, std::string> connection::execute(const std::string &sql) const
|
||||
{
|
||||
logger_.debug(sql);
|
||||
return {connection_->execute(sql), sql};
|
||||
}
|
||||
|
||||
std::unique_ptr<query_result_impl> connection::call_fetch(const std::string &sql) const
|
||||
std::unique_ptr<query_result_impl> connection::fetch(const std::string &sql) const
|
||||
{
|
||||
logger_.debug(sql);
|
||||
return connection_->fetch(sql);
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -37,11 +37,14 @@ const std::string &dialect::data_type_at(data_type_t type) const
|
||||
std::string dialect::prepare_identifier(const column &col) const
|
||||
{
|
||||
std::string result(col.name());
|
||||
escape_quotes_in_identifier(result);
|
||||
if (!col.is_function()) {
|
||||
escape_quotes_in_identifier(result);
|
||||
quote_identifier(result);
|
||||
} else {
|
||||
return sql_func_map_.at(col.function()) + "(" + result + ")";
|
||||
result = sql_func_map_.at(col.function()) + "(" + result + ")";
|
||||
}
|
||||
if (!col.alias().empty()) {
|
||||
result += " AS " + col.alias();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -460,4 +460,9 @@ column count(const std::string &column)
|
||||
return {sql_function_t::COUNT, column};
|
||||
}
|
||||
|
||||
column count_all()
|
||||
{
|
||||
return count("*");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ record query_select_finish::fetch_one()
|
||||
|
||||
std::unique_ptr<query_result_impl> query_select_finish::fetch()
|
||||
{
|
||||
return session_.call_fetch(builder_.compile().sql);
|
||||
return session_.fetch(builder_.compile().sql);
|
||||
}
|
||||
|
||||
query_intermediate::query_intermediate(session &db, query_builder &query)
|
||||
|
||||
+3
-3
@@ -56,7 +56,7 @@ query_result<record> session::fetch(const query &q) const
|
||||
const_cast<column&>(col).type(rit->type());
|
||||
}
|
||||
}
|
||||
auto res = c->call_fetch(q.sql);
|
||||
auto res = c->fetch(q.sql);
|
||||
return query_result<record>{std::move(res), q.prototype};
|
||||
}
|
||||
|
||||
@@ -83,13 +83,13 @@ const class dialect &session::dialect() const
|
||||
return dialect_;
|
||||
}
|
||||
|
||||
std::unique_ptr<query_result_impl> session::call_fetch(const std::string &sql) const
|
||||
std::unique_ptr<query_result_impl> session::fetch(const std::string &sql) const
|
||||
{
|
||||
auto c = pool_.acquire();
|
||||
if (!c.valid()) {
|
||||
throw std::logic_error("no database connection available");
|
||||
}
|
||||
return c->call_fetch(sql);
|
||||
return c->fetch(sql);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user