Author: wyoung
Date: Mon Aug  6 19:12:21 2007
New Revision: 1737

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1737&view=rev
Log:
Removed MutableColData altogether.  I thought it might be necessary to
extend ColData to support its uses, too, but there was only one within
the library and it was a crock, so it was better to just rewrite it.
We can extend ColData if someone complains, but I'd be surprised if
any one at all is using MutableColData directly; it was just never
"marketed" as a public class.

Modified:
    trunk/Wishlist
    trunk/lib/coldata.cpp
    trunk/lib/coldata.h
    trunk/lib/manip.cpp
    trunk/lib/manip.h
    trunk/lib/myset.h

Modified: trunk/Wishlist
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1737&r1=1736&r2=1737&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Mon Aug  6 19:12:21 2007
@@ -66,10 +66,6 @@
 
       - Change buffer management back to the v2.2 way, where ColData
         just held a copy of the pointer, not a copy of the data.
-
-      - Implement as much of the std::string interface as necessary
-        to allow replacing MutableColData in myset.h, adding CoW
-        semantics for any new function that can change the buffer.
 
       - Make Valgrind study all examples, especially load_jpeg
         with a large file.

Modified: trunk/lib/coldata.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/coldata.cpp?rev=1737&r1=1736&r2=1737&view=diff
==============================================================================
--- trunk/lib/coldata.cpp (original)
+++ trunk/lib/coldata.cpp Mon Aug  6 19:12:21 2007
@@ -1,10 +1,10 @@
 /***********************************************************************
- coldata.cpp - Implements the ColData_Tmpl template.
+ coldata.cpp - Implements the ColData class.
 
- Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
- Others may also hold copyrights on code in this file.  See the CREDITS
- file in the top directory of the distribution for details.
+ Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
+ (c) 2004-2007 by Educational Technology Resources, Inc.  Others may
+ also hold copyrights on code in this file.  See the CREDITS file in
+ the top directory of the distribution for details.
 
  This file is part of MySQL++.
 
@@ -30,6 +30,5 @@
 
 namespace mysqlpp {
 
-template class ColData_Tmpl<std::string>;
 
 } // end namespace mysqlpp

Modified: trunk/lib/coldata.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/coldata.h?rev=1737&r1=1736&r2=1737&view=diff
==============================================================================
--- trunk/lib/coldata.h (original)
+++ trunk/lib/coldata.h Mon Aug  6 19:12:21 2007
@@ -49,187 +49,34 @@
 
 namespace mysqlpp {
 
-/// \brief Template for string data that can convert itself to any
-/// standard C data type.
-///
-/// Do not use this class directly. Use the typedef ColData or
-/// MutableColData instead. ColData is a \c ColData_Tmpl<const
-/// \c std::string> and MutableColData is a
-/// \c ColData_Tmpl<std::string>.
-///
-/// The ColData types add to the C++ string type the ability to
-/// automatically convert the string data to any of the basic C types.
-/// This is important with SQL, because all data coming from the
-/// database is in string form.  MySQL++ uses this class internally
-/// to hold the data it receives from the server, so you can use it
-/// naturally, because it does the conversions implicitly:
+/// \brief A std::string work-alike that can convert itself from SQL
+/// text data formats to C++ data types.
+///
+/// This class is an intermediate form for a SQL field, normally
+/// converted to a more useful native C++ type.  It is not normally
+/// used directly by MySQL++ programs, but instead is the return type
+/// from several Row class members.
+///
+/// ColData's implicit conversion operators let you can use these
+/// objects naturally:
 ///
 /// \code ColData("12.86") + 2.0 \endcode
 ///
-/// That works fine, but be careful.  If you had said this instead:
+/// That will give you 14.86 (approximately) as you expect, but be
+/// careful not to get tripped up by C++'s type conversion rules.  If
+/// you had said this instead:
 /// 
 /// \code ColData("12.86") + 2 \endcode
 /// 
 /// the result would be 14 because 2 is an integer, and C++'s type
 /// conversion rules put the ColData object in an integer context.
 ///
-/// If these automatic conversions scare you, define the macro
-/// NO_BINARY_OPERS to disable this behavior.
+/// You can disable the operator overloads that allow these things by
+/// defining MYSQLPP_NO_BINARY_OPERS.
 ///
 /// This class also has some basic information about the type of data
 /// stored in it, to allow it to do the conversions more intelligently
 /// than a trivial implementation would allow.
-
-template <class Str>
-class MYSQLPP_EXPORT ColData_Tmpl : public Str
-{
-public:
-       /// \brief Default constructor
-       ///
-       /// Null flag is set to false, type data is not set, and string
-       /// data is left empty.
-       ///
-       /// It's probably a bad idea to use this ctor, becuase there's no
-       /// way to set the type data once the object's constructed.
-       ColData_Tmpl() :
-       null_(false)
-       {
-       }
-
-       /// \brief Copy ctor
-       ///
-       /// \param cd the other ColData_Tmpl object
-       ColData_Tmpl(const ColData_Tmpl<Str>& cd) :
-       Str(cd.data(), cd.length()),
-       type_(cd.type_),
-       null_(cd.null_)
-       {
-       }
-
-       /// \brief Constructor allowing you to set the null flag and the
-       /// type data.
-       ///
-       /// \param n if true, data is a SQL null
-       /// \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)
-       {
-       }
-
-       /// \brief Null-terminated 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 char* str,
-                       mysql_type_info t = mysql_type_info::string_type,
-                       bool n = false) :
-       Str(str),
-       type_(t),
-       null_(n)
-       {
-       }
-
-       /// \brief Full constructor.
-       ///
-       /// \param str the string this object represents
-       /// \param len the length of the string; embedded nulls are legal
-       /// \param t MySQL type information for data within str
-       /// \param n if true, str is a SQL null
-       explicit ColData_Tmpl(const char* str, typename Str::size_type len,
-                       mysql_type_info t = mysql_type_info::string_type,
-                       bool n = false) :
-       Str(str, len),
-       type_(t),
-       null_(n)
-       {
-       }
-
-       /// \brief Get this object's current MySQL type.
-       mysql_type_info type() const { return type_; }
-
-       /// \brief Returns true if data of this type should be quoted, false
-       /// otherwise.
-       bool quote_q() const { return type_.quote_q(); }
-
-       /// \brief Returns true if data of this type should be escaped, false
-       /// otherwise.
-       bool escape_q() const { return type_.escape_q(); }
-       
-       /// \brief Set a flag indicating that this object is a SQL null.
-       void it_is_null() { null_ = true; }
-
-       /// \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 assign 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(); }
-       
-       template <class T, class B> operator Null<T, B>() const;
-
-private:
-       mysql_type_info type_;
-       mutable std::string temp_buf_;  
-       bool null_;
-};
-
-/// \typedef ColData_Tmpl<std::string> MutableColData
-/// \brief The type that is returned by mutable rows
-typedef ColData_Tmpl<std::string> MutableColData;
-
-
-/// \brief Temporary implementation of ColData, being a merger of 
-/// ColData_Tmpl and const_string, instead of ColData_Tmpl<const_string>
-/// which amounts to the same thing.  ColData_Tmpl will be going away
-/// soon.
 
 class MYSQLPP_EXPORT ColData
 {
@@ -562,11 +409,11 @@
 
 
 
-#if !defined(NO_BINARY_OPERS) && !defined(DOXYGEN_IGNORE)
-// Ignore this section is NO_BINARY_OPERS is defined, or if this section
-// is being parsed by Doxygen.  In the latter case, it's ignored because
-// Doxygen doesn't understand it correctly, and we can't be bothered to
-// explain it to Doxygen.
+#if !defined(MYSQLPP_NO_BINARY_OPERS) && !defined(DOXYGEN_IGNORE)
+// Ignore this section is MYSQLPP_NO_BINARY_OPERS is defined, or if this
+// section is being parsed by Doxygen.  In the latter case, it's ignored
+// because Doxygen doesn't understand it correctly, and we can't be
+// bothered to explain it to Doxygen.
 
 #define oprsw(opr, other, conv) \
        inline other operator opr (ColData x, other y) \
@@ -606,7 +453,7 @@
 operator_binary_int(longlong, longlong)
 operator_binary_int(ulonglong, ulonglong)
 #endif
-#endif // NO_BINARY_OPERS
+#endif // MYSQLPP_NO_BINARY_OPERS
 
 /// \brief Converts this object to a SQL null
 ///

Modified: trunk/lib/manip.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/manip.cpp?rev=1737&r1=1736&r2=1737&view=diff
==============================================================================
--- trunk/lib/manip.cpp (original)
+++ trunk/lib/manip.cpp Mon Aug  6 19:12:21 2007
@@ -152,15 +152,6 @@
 }
 
 
-/// \brief Inserts a ColData_Tmpl<std::string> into a non-Query stream.
-
-ostream& operator <<(ostream& o, const ColData_Tmpl<string>& in)
-{
-       o.write(in.data(), in.length());
-       return o;
-}
-
-
 /// \brief Inserts a ColData into a non-Query stream.
 ///
 /// Although we know how to automatically quote and escape ColData
@@ -181,37 +172,6 @@
 }
 
 
-/// \brief Insert a ColData into a SQLQuery
-///
-/// This operator appears to be a workaround for a weakness in one
-/// compiler's implementation of the C++ type system.  See Wishlist for
-/// current plan on what to do about this.
-
-Query& operator <<(Query& o, const ColData_Tmpl<string>& in)
-{
-       if (dont_quote_auto) {
-               o.write(in.data(), in.length());
-       }
-       else if (in.escape_q()) {
-               char* s = new char[in.length() * 2 + 1];
-               size_t len = mysql_escape_string(s, in.data(), in.length());
-
-               if (in.quote_q()) o.write("'", 1);
-               o.write(s, len);
-               if (in.quote_q()) o.write("'", 1);
-
-               delete[] s;
-       }
-       else {
-               if (in.quote_q()) o.write("'", 1);
-               o.write(in.data(), in.length());
-               if (in.quote_q()) o.write("'", 1);
-       }
-
-       return o;
-}
-
-
 /// \brief Insert a ColData with const string into a SQLQuery
 ///
 /// This operator appears to be a workaround for a weakness in one
@@ -265,22 +225,6 @@
 }
 
 
-/// \brief Inserts a ColData into a stream, quoted
-///
-/// Because ColData was designed to contain MySQL type data, we may
-/// choose not to actually quote the data, if it is not needed.
-
-template <>
-ostream& operator <<(quote_only_type1 o, const ColData_Tmpl<string>& in)
-{
-       if (in.quote_q()) o.ostr->write("'", 1);
-       o.ostr->write(in.data(), in.length());
-       if (in.quote_q()) o.ostr->write("'", 1);
-
-       return *o.ostr;
-}
-
-
 /// \brief Inserts a ColData with const string into a stream, quoted
 ///
 /// Because ColData was designed to contain MySQL type data, we may
@@ -319,23 +263,6 @@
 }
 
 
-/// \brief Inserts a ColData into a stream, double-quoted (")
-///
-/// Because ColData was designed to contain MySQL type data, we may
-/// choose not to actually quote the data, if it is not needed.
-
-template <>
-ostream& operator <<(quote_double_only_type1 o,
-               const ColData_Tmpl<string>& in)
-{
-       if (in.quote_q()) o.ostr->write("\"", 1);
-       o.ostr->write(in.data(), in.length());
-       if (in.quote_q()) o.ostr->write("\"", 1);
-
-       return *o.ostr;
-}
-
-
 /// \brief Inserts a ColData with const string into a stream,
 /// double-quoted (")
 ///

Modified: trunk/lib/manip.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/manip.h?rev=1737&r1=1736&r2=1737&view=diff
==============================================================================
--- trunk/lib/manip.h (original)
+++ trunk/lib/manip.h Mon Aug  6 19:12:21 2007
@@ -3,23 +3,24 @@
 ///
 /// These manipulators let you automatically quote elements or escape
 /// characters that are special in SQL when inserting them into an
-/// \c std::ostream. Since mysqlpp::Query is an ostream, these
+/// \c std::ostream.  Since mysqlpp::Query is an ostream, these
 /// manipulators make it easier to build syntactically-correct SQL
 /// queries.
 ///
-/// This file also includes \c operator<< definitions for ColData_Tmpl,
-/// one of the MySQL++ string-like classes.  When inserting such items
-/// into a stream, they are automatically quoted and escaped as
-/// necessary unless the global variable dont_quote_auto is set to true.
-/// These operators are smart enough to turn this behavior off when
-/// the stream is \c cout or \c cerr, however, since quoting and
-/// escaping are surely not required in that instance.
+/// This file also includes special \c operator<< definitions for class
+/// \c ColData.  When inserting these objects into a Query using its
+/// stream interface, they are automatically quoted and escaped as
+/// necessary depending on data type unless the global variable
+/// dont_quote_auto is set to true.   Automatic quoting and escaping
+/// does not happen when inserting ColData objects into other stream
+/// types, but you can use the explicit quote and escape manipulators.
+/// See test/test_manip.cpp to see the expected behavior.
 
 /***********************************************************************
- Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
- Others may also hold copyrights on code in this file.  See the CREDITS
- file in the top directory of the distribution for details.
+ Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
+ (c) 2004-2007 by Educational Technology Resources, Inc.  Others may
+ also hold copyrights on code in this file.  See the CREDITS file in
+ the top directory of the distribution for details.
 
  This file is part of MySQL++.
 
@@ -126,15 +127,7 @@
 
 
 MYSQLPP_EXPORT std::ostream& operator <<(std::ostream& o,
-               const ColData_Tmpl<std::string>& in);
-
-
-MYSQLPP_EXPORT std::ostream& operator <<(std::ostream& o,
                const ColData& in);
-
-
-MYSQLPP_EXPORT Query& operator <<(Query& o,
-               const ColData_Tmpl<std::string>& in);
 
 
 MYSQLPP_EXPORT Query& operator <<(Query& o,
@@ -148,11 +141,6 @@
 template <>
 MYSQLPP_EXPORT std::ostream& operator <<(quote_type1 o,
                const char* const& in);
-
-
-template <>
-MYSQLPP_EXPORT std::ostream& operator <<(quote_type1 o,
-               const ColData_Tmpl<std::string>& in);
 
 
 template <>
@@ -284,11 +272,6 @@
 
 template <>
 MYSQLPP_EXPORT std::ostream& operator <<(quote_only_type1 o,
-               const ColData_Tmpl<std::string>& in);
-
-
-template <>
-MYSQLPP_EXPORT std::ostream& operator <<(quote_only_type1 o,
                const ColData& in);
 
 
@@ -393,11 +376,6 @@
 {
        return *o.ostr << '"' << in << '"';
 }
-
-
-template <>
-MYSQLPP_EXPORT std::ostream& operator <<(quote_double_only_type1 o,
-               const ColData_Tmpl<std::string>& in);
 
 
 template <>
@@ -527,11 +505,6 @@
 
 template <>
 MYSQLPP_EXPORT std::ostream& operator <<(escape_type1 o,
-               const ColData_Tmpl<std::string>& in);
-
-
-template <>
-MYSQLPP_EXPORT std::ostream& operator <<(escape_type1 o,
                const ColData& in);
 
 

Modified: trunk/lib/myset.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/myset.h?rev=1737&r1=1736&r2=1737&view=diff
==============================================================================
--- trunk/lib/myset.h (original)
+++ trunk/lib/myset.h Mon Aug  6 19:12:21 2007
@@ -132,20 +132,27 @@
 template <class Insert>
 void set2container(const char* str, Insert insert)
 {
-       while (1) {
-               MutableColData s("");
-               while (*str != ',' && *str) {
-                       s += *str;
-                       str++;
+       std::string temp;
+
+       // Break str up using comma separators
+       while (str && *str) {
+               if (*str == ',') {
+                       insert(temp);
+                       temp.clear();
+
+                       // Handle comma at end of string case
+                       if (*++str) {
+                               ++str;
+                       }
                }
+               else {
+                       temp += *str++;
+               }
+       }
 
-               insert(s);
-
-               if (!*str) {
-                       break; 
-               }
-
-               str++;
+       // Save final element of set, if any
+       if (temp.size()) {
+               insert(temp);
        }
 }
 


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

Reply via email to