Author: wyoung
Date: Sat Aug 11 00:30:04 2007
New Revision: 1749

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1749&view=rev
Log:
Added operator=(const std::string&) and several assign() overloads to
ColData, to give more options for changing the value of an existing
ColData object.  This is most useful with SSQLS and BLOBs: the field
type is a ColData, and you will almost certainly have to do a 2-step
create with it, since the alternative is creating a temporary ColData
just to call the copy ctor...ick.

Modified:
    trunk/Wishlist
    trunk/lib/coldata.h

Modified: trunk/Wishlist
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1749&r1=1748&r2=1749&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Sat Aug 11 00:30:04 2007
@@ -61,12 +61,6 @@
         made into a base class that all SSQLSes derive from.  Some
         template functions like Query::insert<T> might become regular
         member functions, taking a reference to the SSQLS base class.
-
-    o Revamp ColData:
-
-      - Add operator =(const std::string&)
-
-      - Add assign() methods to parallel all ctors
 
     o Rework elment access in subscript_iterator derivatives:
 

Modified: trunk/lib/coldata.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/coldata.h?rev=1749&r1=1748&r2=1749&view=diff
==============================================================================
--- trunk/lib/coldata.h (original)
+++ trunk/lib/coldata.h Sat Aug 11 00:30:04 2007
@@ -174,6 +174,48 @@
        /// \brief Destroy string
        ~ColData();
 
+       /// \brief Assign raw data to this object
+       ///
+       /// This parallels the ctor with the same parameters, for when you
+       /// must do a 2-step create, or when you want to reassign the data 
+       /// without creating a ColData temporary to get around the fact
+       /// that operator=() can only take one parameter.
+       void assign(const char* str, size_type len,
+                       mysql_type_info type = mysql_type_info::string_type,
+                       bool is_null = false)
+       {
+               dec_ref_count();
+               buffer_ = new Buffer(str, len, type, is_null);
+       }
+
+       /// \brief Assign a C++ string to this object
+       ///
+       /// This parallels the ctor with the same parameters, for when you
+       /// must do a 2-step create, or when you want to reassign the data 
+       /// without creating a ColData temporary to get around the fact
+       /// that operator=() can only take one parameter.
+       void assign(const std::string& str,
+                       mysql_type_info type = mysql_type_info::string_type,
+                       bool is_null = false)
+       {
+               dec_ref_count();
+               buffer_ = new Buffer(str.data(), str.length(), type, is_null);
+       }
+
+       /// \brief Assign a C string to this object
+       ///
+       /// This parallels the ctor with the same parameters, for when you
+       /// must do a 2-step create, or when you want to reassign the data 
+       /// without creating a ColData temporary to get around the fact
+       /// that operator=() can only take one parameter.
+       void assign(const char* str,
+                       mysql_type_info type = mysql_type_info::string_type,
+                       bool is_null = false)
+       {
+               dec_ref_count();
+               buffer_ = new Buffer(str, strlen(str), type, is_null);
+       }
+
        /// \brief Return a character within the string.
        ///
        /// Unlike \c operator[](), this function throws an 
@@ -245,6 +287,17 @@
 
        /// \brief Get this object's current MySQL type.
        mysql_type_info type() const { return buffer_->type(); }
+
+       /// \brief Assignment operator, from C++ string
+       ColData& operator =(const std::string& rhs)
+       {
+               dec_ref_count();
+
+               buffer_ = new Buffer(rhs.data(), rhs.length(),
+                               mysql_type_info::string_type, false);
+
+               return *this;
+       }
 
        /// \brief Assignment operator, from C string
        ///


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to