I've thought about this a little bit. I think we could first create a
class called SQLEscaper that takes a Connection * and provides the
escape_string( ) methods*.
1. We could just stick those methods in a class called SQLEscaper from
which Query and SQLStream are derived.
2. Query is derived from std::ostream and SQLEscaper and otherwise
remains the exactly the same (conn_ is now a protected member of
3. SQLStream is derived from SQLEscaper and std::ostringstream.
4. The stuff in manip.cpp is changed to recognize SQLEscaper instead of
Query, which both of our classes are derived from.
* I have to wonder why those methods aren't in Connection to begin
with. I realize Connection isn't intended for dealing with SQL, but
those methods in Query don't actually use any aspect of Query! I tried
making them static (and conn_ public so I could) just to verify that.
It might be possible (and reasonable) to dispense with the need for the
SQLEscaper if those methods could go in the Connection class where they
seem to belong. Of course, SQLEscaper gives us a common base class for
Query and SQLStream which is convenient for the manipulators.