Commit 4d958285 authored by msobczak's avatar msobczak

Exposed the query formatting stream at the level of the session object.

parent 93bd3aa6
......@@ -8,6 +8,7 @@
#define SOCI_SOURCE
#include "once-temp-type.h"
#include "ref-counted-statement.h"
#include "session.h"
using namespace soci;
using namespace soci::details;
......@@ -15,6 +16,8 @@ using namespace soci::details;
once_temp_type::once_temp_type(session &s)
: rcst_(new ref_counted_statement(s))
{
// this is the beginning of new query
s.get_query_stream().str("");
}
once_temp_type::once_temp_type(once_temp_type const &o)
......
......@@ -8,6 +8,7 @@
#ifndef SOCI_ONCE_TEMP_TYPE_H_INCLUDED
#define SOCI_ONCE_TEMP_TYPE_H_INCLUDED
#include "ref-counted-statement.h"
#include "prepare-temp-type.h"
namespace soci
......
......@@ -8,6 +8,7 @@
#define SOCI_SOURCE
#include "prepare-temp-type.h"
#include "ref-counted-prepare-info.h"
#include "session.h"
using namespace soci;
using namespace soci::details;
......@@ -15,6 +16,8 @@ using namespace soci::details;
prepare_temp_type::prepare_temp_type(session &s)
: rcpi_(new ref_counted_prepare_info(s))
{
// this is the beginning of new query
s.get_query_stream().str("");
}
prepare_temp_type::prepare_temp_type(prepare_temp_type const &o)
......
......@@ -14,7 +14,7 @@ using namespace soci;
using namespace soci::details;
procedure_impl::procedure_impl(prepare_temp_type const &prep)
: statement_impl(*prep.get_prepare_info()->session_)
: statement_impl(prep.get_prepare_info()->session_)
{
ref_counted_prepare_info *prepInfo = prep.get_prepare_info();
......
......@@ -7,6 +7,7 @@
#define SOCI_SOURCE
#include "ref-counted-prepare-info.h"
#include "session.h"
using namespace soci;
using namespace soci::details;
......@@ -38,3 +39,8 @@ void ref_counted_prepare_info::final_action()
uses_.resize(i - 1);
}
}
std::string ref_counted_prepare_info::get_query() const
{
return session_.get_query_stream().str();
}
......@@ -29,7 +29,8 @@ class into_type_base;
class ref_counted_prepare_info : public ref_counted_statement_base
{
public:
ref_counted_prepare_info(session &s) : session_(&s) {}
ref_counted_prepare_info(session &s)
: ref_counted_statement_base(s), session_(s) {}
void exchange(into_type_ptr const &i);
void exchange(use_type_ptr const &u);
......@@ -40,12 +41,12 @@ private:
friend class statement_impl;
friend class procedure_impl;
session *session_;
session &session_;
std::vector<into_type_base*> intos_;
std::vector<use_type_base*> uses_;
std::string get_query() const { return query_.str(); }
std::string get_query() const;
};
} // namespace details
......
......@@ -7,7 +7,7 @@
#define SOCI_SOURCE
#include "ref-counted-statement.h"
#include "statement.h"
#include "session.h"
using namespace soci;
using namespace soci::details;
......@@ -17,7 +17,7 @@ void ref_counted_statement::final_action()
try
{
st_.alloc();
st_.prepare(query_.str(), eOneTimeQuery);
st_.prepare(session_.get_query_stream().str(), eOneTimeQuery);
st_.define_and_bind();
st_.execute(true);
}
......@@ -29,3 +29,8 @@ void ref_counted_statement::final_action()
st_.clean_up();
}
std::ostringstream & ref_counted_statement_base::get_query_stream()
{
return session_.get_query_stream();
}
......@@ -12,8 +12,6 @@
#include "into-type.h"
#include "use-type.h"
#include <sstream>
namespace soci
{
......@@ -24,7 +22,7 @@ namespace details
class ref_counted_statement_base
{
public:
ref_counted_statement_base() : refCount_(1) {}
ref_counted_statement_base(session &s) : refCount_(1), session_(s) {}
virtual ~ref_counted_statement_base() {}
virtual void final_action() = 0;
......@@ -50,14 +48,19 @@ public:
// TODO - mloskot: Consider to wrap conversion with try-catch
template <typename T>
void accumulate(T const &t) { query_ << t; }
void accumulate(T const &t) { get_query_stream() << t; }
protected:
ref_counted_statement_base(ref_counted_statement_base const &);
ref_counted_statement_base & operator=(ref_counted_statement_base const &);
// this function allows to break the circular dependenc
// between session and this class
std::ostringstream & get_query_stream();
int refCount_;
std::ostringstream query_;
session &session_;
};
// this class is supposed to be a vehicle for the "once" statements
......@@ -65,7 +68,8 @@ protected:
class ref_counted_statement : public ref_counted_statement_base
{
public:
ref_counted_statement(session &s) : st_(s) {}
ref_counted_statement(session &s)
: ref_counted_statement_base(s), st_(s) {}
void exchange(into_type_ptr const &i) { st_.exchange(i); }
void exchange(use_type_ptr const &u) { st_.exchange(u); }
......
......@@ -82,6 +82,11 @@ void session::reconnect()
backEnd_ = lastFactory_->make_session(lastConnectString_);
}
std::ostringstream & session::get_query_stream()
{
return query_stream_;
}
void session::set_log_stream(std::ostream *s)
{
logStream_ = s;
......
......@@ -11,6 +11,7 @@
#include "once-temp-type.h"
#include <ostream>
#include <sstream>
#include <string>
namespace soci
......@@ -48,6 +49,8 @@ public:
template <typename T>
details::once_temp_type operator<<(T const &t) { return once << t; }
std::ostringstream & get_query_stream();
// support for basic logging
void set_log_stream(std::ostream *s);
std::ostream * get_log_stream() const;
......@@ -67,6 +70,8 @@ private:
session(session const &);
session& operator=(session const &);
std::ostringstream query_stream_;
std::ostream *logStream_;
std::string lastQuery_;
......
......@@ -38,7 +38,7 @@ statement_impl::statement_impl(session &s)
}
statement_impl::statement_impl(prepare_temp_type const &prep)
: session_(*prep.get_prepare_info()->session_),
: session_(prep.get_prepare_info()->session_),
refCount_(1), row_(0), fetchSize_(1), alreadyDescribed_(false)
{
backEnd_ = session_.make_statement_backend();
......
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