Author: wyoung
Date: Fri Jun 22 20:15:16 2007
New Revision: 1590
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1590&view=rev
Log:
- No longer using ColData_Tmpl<T>::_buf member variable. The class
derives from std::string (or something like it) which has its own
buffer. The variable is still present, to preserve ABI compatibility.
- Removed ColData_Tmpl<T>::get_string(). This should only be used by
MySQL++ internals, which used to assume that the buf_ member was the
"real" buffer. Now that we're using our base class's buffer, we can
replace all instances of "coldata.get_string()" with just "coldata".
This should be documented as an API breakage.
- Added ColData_Tmpl<T>(const std::string& s,...) ctor, to avoid yet
another potential source of embedded null trouble.
- Added const_string::const_string(const std::string& s,...) ctor,
needed so ColData<const_string> can be instantiated, due to previous
change.
Modified:
trunk/Wishlist
trunk/lib/coldata.h
trunk/lib/const_string.h
trunk/lib/manip.cpp
Modified: trunk/Wishlist
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1590&r1=1589&r2=1590&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Fri Jun 22 20:15:16 2007
@@ -25,12 +25,6 @@
operator std::string to ColData_Tmpl to make this work right.
o That done, rework cgi_jpeg to use SSQLS as a test.
-
- o Stop using ColData_Tmpl<T>::buf_ member. It currently
- contains a duplicate (and, in the presence of nulls,
- truncated) copy of the data stored by the parent class when
- the template is instantiated with std::string. Removal will
- have to wait for v3.0.
o Define HAVE_MYSQL_SSL_SET by default on Windows? Make similar
decisions for other autoconf-only macros.
@@ -148,14 +142,12 @@
within myset.h, and that usage is inefficient to the point
of wanting replacement anyway.
- o Turn ColData_Tmpl<T> into a concrete class. Maybe it still
- derives from const std::string, but privately, or maybe
- it just has a string member. Either way, we don't need
- an is-a relationship here. All we need is an internal
- representation of the data, which we transform as required.
- This ties into the deprecation of the buf_ member in v2.3,
- because it either becomes the only buffer, or it goes away
- in favor of the parent class's buffer.
+ o Turn ColData_Tmpl<T> into a concrete class. Use private
+ std::string instance as buffer, and replicate the std::string
+ interface publically, delegating to that buffer.
+
+ o Use this new class in place of ColData_Tmpl<const_string>,
+ and remove const_string class.
o More robust fix for the Query stream base class init problem:
http://www.boost.org/libs/utility/base_from_member.html
Modified: trunk/lib/coldata.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/coldata.h?rev=1590&r1=1589&r2=1590&view=diff
==============================================================================
--- trunk/lib/coldata.h (original)
+++ trunk/lib/coldata.h Fri Jun 22 20:15:16 2007
@@ -105,6 +105,20 @@
/// \param t MySQL type information for data being stored
explicit ColData_Tmpl(bool n,
mysql_type_info t = mysql_type_info::string_type) :
+ type_(t),
+ null_(n)
+ {
+ }
+
+ /// \brief C++ string version of full ctor
+ ///
+ /// \param str the string this object represents
+ /// \param t MySQL type information for data within str
+ /// \param n if true, str is a SQL null
+ explicit ColData_Tmpl(const std::string& str,
+ mysql_type_info t = mysql_type_info::string_type,
+ bool n = false) :
+ Str(str),
type_(t),
null_(n)
{
@@ -120,7 +134,6 @@
bool n = false) :
Str(str),
type_(t),
- buf_(str),
null_(n)
{
}
@@ -136,7 +149,6 @@
bool n = false) :
Str(str, len),
type_(t),
- buf_(str),
null_(n)
{
}
@@ -161,12 +173,9 @@
/// \brief Returns true if this object is a SQL null.
inline const bool is_null() const { return null_; }
- /// \brief Returns the string form of this object's data.
- inline const std::string& get_string() const { return buf_; }
-
/// \brief Returns a const char pointer to the string form of
/// this object's data.
- operator cchar*() const { return buf_.c_str(); }
+ operator cchar*() const { return c_str(); }
/// \brief Converts this object's string data to a signed char
operator signed char() const
@@ -229,7 +238,11 @@
private:
mysql_type_info type_;
- std::string buf_;
+
+ // We will re-enable this field in v3.0 when we make ColData
+ // concrete, with no parent class. See the Wishlist for details.
+ std::string DISABLED_IN_V2_3_;
+
bool null_;
};
@@ -313,7 +326,7 @@
template <class Str> template <class Type>
Type ColData_Tmpl<Str>::conv(Type /* dummy */) const
{
- std::string strbuf = buf_;
+ std::string strbuf(*this);
strip_all_blanks(strbuf);
std::string::size_type len = strbuf.size();
const char* str = strbuf.c_str();
Modified: trunk/lib/const_string.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/const_string.h?rev=1590&r1=1589&r2=1590&view=diff
==============================================================================
--- trunk/lib/const_string.h (original)
+++ trunk/lib/const_string.h Fri Jun 22 20:15:16 2007
@@ -83,6 +83,13 @@
{
}
+ /// \brief Initialize string from existing C++ string
+ const_string(const std::string& str) :
+ str_data_(str.data()),
+ length_(str.length())
+ {
+ }
+
/// \brief Initialize string from existing C string
const_string(const char* str) :
str_data_(str),
Modified: trunk/lib/manip.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/manip.cpp?rev=1590&r1=1589&r2=1590&view=diff
==============================================================================
--- trunk/lib/manip.cpp (original)
+++ trunk/lib/manip.cpp Fri Jun 22 20:15:16 2007
@@ -177,7 +177,7 @@
{
if (dont_quote_auto || (o.rdbuf() == cout.rdbuf()) ||
(o.rdbuf() == cerr.rdbuf())) {
- return o << in.get_string();
+ return o << in;
}
if (in.escape_q()) {
@@ -191,10 +191,10 @@
delete[] s;
}
else if (in.quote_q()) {
- o << '\'' << in.get_string() << '\'';
- }
- else {
- o << in.get_string();
+ o << '\'' << in << '\'';
+ }
+ else {
+ o << in;
}
return o;
}
@@ -211,7 +211,7 @@
{
if (dont_quote_auto || (o.rdbuf() == cout.rdbuf()) ||
(o.rdbuf() == cerr.rdbuf())) {
- return o << in.get_string();
+ return o << in;
}
if (in.escape_q()) {
@@ -224,10 +224,10 @@
delete[] s;
}
else if (in.quote_q()) {
- o << '\'' << in.get_string() << '\'';
- }
- else {
- o << in.get_string();
+ o << '\'' << in << '\'';
+ }
+ else {
+ o << in;
}
return o;
}
@@ -242,7 +242,7 @@
Query& operator <<(Query& o, const ColData_Tmpl<string>& in)
{
if (dont_quote_auto) {
- o << in.get_string();
+ o << in;
return o;
}
if (in.escape_q()) {
@@ -256,10 +256,10 @@
delete[] s;
}
else if (in.quote_q()) {
- static_cast<ostream&>(o) << '\'' << in.get_string() << '\'';
- }
- else {
- static_cast<ostream&>(o) << in.get_string();
+ static_cast<ostream&>(o) << '\'' << in << '\'';
+ }
+ else {
+ static_cast<ostream&>(o) << in;
}
return o;
}
@@ -274,7 +274,7 @@
Query& operator <<(Query& o, const ColData_Tmpl<const_string>& in)
{
if (dont_quote_auto) {
- o << in.get_string();
+ o << in;
return o;
}
if (in.escape_q()) {
@@ -287,10 +287,10 @@
delete[] s;
}
else if (in.quote_q()) {
- static_cast<ostream&>(o) << '\'' << in.get_string() << '\'';
- }
- else {
- static_cast<ostream&>(o) << in.get_string();
+ static_cast<ostream&>(o) << '\'' << in << '\'';
+ }
+ else {
+ static_cast<ostream&>(o) << in;
}
return o;
}
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits