Author: wyoung
Date: Wed Jul 11 00:28:40 2007
New Revision: 1657
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1657&view=rev
Log:
Restored ColData_Tmpl<T>::get_data(), removed in v2.3.0. It is indeed
pointless with MutableColData, but that's rarely used. There are better
alternatives to get_string() with plain ColData, so documented those,
but restored the method anyway to restore compatibility with existing
code.
Modified:
trunk/lib/coldata.h
Modified: trunk/lib/coldata.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/coldata.h?rev=1657&r1=1656&r2=1657&view=diff
==============================================================================
--- trunk/lib/coldata.h (original)
+++ trunk/lib/coldata.h Wed Jul 11 00:28:40 2007
@@ -181,6 +181,38 @@
/// \brief Returns true if this object is a SQL null.
inline const bool is_null() const { return null_; }
+ /// \brief Returns this object's data in C++ string form.
+ ///
+ /// This method is inefficient, and not recommended. It makes a
+ /// duplicate copy of the string that lives as long as the
+ /// \c ColData object itself.
+ ///
+ /// If you are using the \c MutableColData typedef for this
+ /// template, you can avoid the duplicate copy entirely. You can
+ /// pass a \c MutableColData object to anything expecting a
+ /// \c std::string and get the right result. (This didn't work
+ /// reliably prior to v2.3.)
+ ///
+ /// This method is arguably useful with plain \c ColData objects,
+ /// but there are more efficient alternatives. If you know your
+ /// data is a null-terminated C string, just cast this object to
+ /// a \c const \c char* or call the \c data() method. This gives
+ /// you a pointer to our internal buffer, so the copy isn't needed.
+ /// If the \c ColData can contain embedded null characters, you do
+ /// need to make a copy, but it's better to make your own copy of
+ /// the string, instead of calling get_string(), so you can better
+ /// control its lifetime:
+ ///
+ /// \code
+ /// ColData cd = ...;
+ /// std::string s(cd.data(), cd.length());
+ /// \endcode
+ inline const std::string& get_string() const
+ {
+ temp_buf_.assign(Str::data(), Str::length());
+ return temp_buf_;
+ }
+
/// \brief Returns a const char pointer to the object's raw data
operator cchar*() const { return Str::data(); }
@@ -245,11 +277,7 @@
private:
mysql_type_info type_;
-
- // 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_;
-
+ mutable std::string temp_buf_;
bool null_;
};
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits