Author: wyoung
Date: Thu Nov 15 15:12:51 2007
New Revision: 1850
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1850&view=rev
Log:
SQLTypeAdapter now has-a std::string for its internal buffer instead of
deriving from std::string. There is no need for an is-a relationship.
Modified:
trunk/Wishlist
trunk/lib/stadapter.cpp
trunk/lib/stadapter.h
Modified: trunk/Wishlist
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1850&r1=1849&r2=1850&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Thu Nov 15 15:12:51 2007
@@ -17,21 +17,15 @@
formatting of the examples that dump tables. A setw(x) call
results in x spaces, not x - strlen(whatevercamebefore).
- o Change SQLTypeAdapter to no longer derive from std::string, but
- instead have a RefCountedBuffer data member like ColData.
- Shouldn't have to reimplement the entire std::string interface,
- due to SQLTypeAdapter's limited use.
-
o Rename ColData to String, reflecting its general-purpose nature.
+
+ o Change SQLTypeAdapter::buffer_'s type from std::string to
+ RefCountedBuffer, and add a copy ctor for String that can do
+ buffer sharing. Can then remove String specializations for
+ manipulators.
o Add String::compare(const char*, int), and anything else that
looks useful from the std::string interface.
-
- o Remove String specializations for manipulators, instead adding
- SQLTypeAdapter(const String&), which just copies the internal
- buffer pointer and bumps its refcount. Can probably also remove
- String::escape_q() and such. SQLTypeAdapter doesn't have these,
- and might not need to: is_string() might be sufficient.
o Add a userman section on String and SQLTypeAdapter.
Modified: trunk/lib/stadapter.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/stadapter.cpp?rev=1850&r1=1849&r2=1850&view=diff
==============================================================================
--- trunk/lib/stadapter.cpp (original)
+++ trunk/lib/stadapter.cpp Thu Nov 15 15:12:51 2007
@@ -42,7 +42,7 @@
}
SQLTypeAdapter::SQLTypeAdapter(const string& str, bool processed) :
-string(str),
+buffer_(str),
is_string_(true),
is_processed_(processed)
{
@@ -50,7 +50,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(const Null<string>& str, bool processed) :
-string(str.is_null ? null_str : str.data),
+buffer_(str.is_null ? null_str : str.data),
is_string_(!str.is_null),
is_processed_(processed)
{
@@ -58,21 +58,21 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(const char* str, bool processed) :
-string(str),
+buffer_(str),
is_string_(true),
is_processed_(processed)
{
}
SQLTypeAdapter::SQLTypeAdapter(const char* str, int len, bool processed) :
-string(str, len),
+buffer_(str, len),
is_string_(true),
is_processed_(processed)
{
}
SQLTypeAdapter::SQLTypeAdapter(char c) :
-string(stream2string(c)),
+buffer_(stream2string(c)),
is_string_(true),
is_processed_(false)
{
@@ -80,7 +80,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(Null<char> c) :
-string(c.is_null ? null_str : stream2string(c)),
+buffer_(c.is_null ? null_str : stream2string(c)),
is_string_(true),
is_processed_(false)
{
@@ -88,7 +88,7 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(sql_tinyint i) :
-string(stream2string(i)),
+buffer_(stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -96,7 +96,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(Null<sql_tinyint> i) :
-string(i.is_null ? null_str : stream2string(i)),
+buffer_(i.is_null ? null_str : stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -104,7 +104,7 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(sql_tinyint_unsigned i) :
-string(stream2string(i)),
+buffer_(stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -112,7 +112,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(Null<sql_tinyint_unsigned> i) :
-string(i.is_null ? null_str : stream2string(i)),
+buffer_(i.is_null ? null_str : stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -120,18 +120,18 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(short i) :
-string(stream2string(i)),
+buffer_(stream2string(i)),
is_string_(false),
is_processed_(false)
{
ostringstream outs;
outs << i;
- assign(outs.str());
+ buffer_.assign(outs.str());
}
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(Null<short> i) :
-string(i.is_null ? null_str : stream2string(i)),
+buffer_(i.is_null ? null_str : stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -139,7 +139,7 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(unsigned short i) :
-string(stream2string(i)),
+buffer_(stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -147,7 +147,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(Null<unsigned short> i) :
-string(i.is_null ? null_str : stream2string(i)),
+buffer_(i.is_null ? null_str : stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -155,7 +155,7 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(int i) :
-string(stream2string(i)),
+buffer_(stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -163,7 +163,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(Null<int> i) :
-string(i.is_null ? null_str : stream2string(i)),
+buffer_(i.is_null ? null_str : stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -171,7 +171,7 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(unsigned i) :
-string(stream2string(i)),
+buffer_(stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -179,7 +179,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(Null<unsigned> i) :
-string(i.is_null ? null_str : stream2string(i)),
+buffer_(i.is_null ? null_str : stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -187,7 +187,7 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(longlong i) :
-string(stream2string(i)),
+buffer_(stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -195,7 +195,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(Null<longlong> i) :
-string(i.is_null ? null_str : stream2string(i)),
+buffer_(i.is_null ? null_str : stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -203,7 +203,7 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(ulonglong i) :
-string(stream2string(i)),
+buffer_(stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -211,7 +211,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(Null<ulonglong> i) :
-string(i.is_null ? null_str : stream2string(i)),
+buffer_(i.is_null ? null_str : stream2string(i)),
is_string_(false),
is_processed_(false)
{
@@ -225,7 +225,7 @@
ostringstream outs;
outs.precision(7); // max digits in IEEE 754 single-prec float
outs << f;
- assign(outs.str());
+ buffer_.assign(outs.str());
}
#if !defined(DOXYGEN_IGNORE)
@@ -234,13 +234,13 @@
is_processed_(false)
{
if (f.is_null) {
- assign(null_str);
+ buffer_.assign(null_str);
}
else {
ostringstream outs;
outs.precision(7); // as above
outs << f;
- assign(outs.str());
+ buffer_.assign(outs.str());
}
}
#endif
@@ -252,7 +252,7 @@
ostringstream outs;
outs.precision(16); // max digits in IEEE 754 double-prec float
outs << f;
- assign(outs.str());
+ buffer_.assign(outs.str());
}
#if !defined(DOXYGEN_IGNORE)
@@ -261,19 +261,19 @@
is_processed_(false)
{
if (f.is_null) {
- assign(null_str);
+ buffer_.assign(null_str);
}
else {
ostringstream outs;
outs.precision(16); // as above
outs << f;
- assign(outs.str());
+ buffer_.assign(outs.str());
}
}
#endif
SQLTypeAdapter::SQLTypeAdapter(const Date& d) :
-string(stream2string(d)),
+buffer_(stream2string(d)),
is_string_(true),
is_processed_(false)
{
@@ -281,7 +281,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(const Null<Date>& d) :
-string(d.is_null ? null_str : stream2string(d)),
+buffer_(d.is_null ? null_str : stream2string(d)),
is_string_(true),
is_processed_(false)
{
@@ -289,7 +289,7 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(const DateTime& dt) :
-string(stream2string(dt)),
+buffer_(stream2string(dt)),
is_string_(true),
is_processed_(false)
{
@@ -297,7 +297,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(const Null<DateTime>& dt) :
-string(dt.is_null ? null_str : stream2string(dt)),
+buffer_(dt.is_null ? null_str : stream2string(dt)),
is_string_(true),
is_processed_(false)
{
@@ -305,7 +305,7 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(const Time& t) :
-string(stream2string(t)),
+buffer_(stream2string(t)),
is_string_(true),
is_processed_(false)
{
@@ -313,7 +313,7 @@
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(const Null<Time>& t) :
-string(t.is_null ? null_str : stream2string(t)),
+buffer_(t.is_null ? null_str : stream2string(t)),
is_string_(true),
is_processed_(false)
{
@@ -321,7 +321,7 @@
#endif
SQLTypeAdapter::SQLTypeAdapter(const null_type& i) :
-string(null_str),
+buffer_(null_str),
is_string_(false),
is_processed_(false)
{
Modified: trunk/lib/stadapter.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/stadapter.h?rev=1850&r1=1849&r2=1850&view=diff
==============================================================================
--- trunk/lib/stadapter.h (original)
+++ trunk/lib/stadapter.h Thu Nov 15 15:12:51 2007
@@ -1,19 +1,59 @@
/// \file stadapter.h
/// \brief Declares the SQLTypeAdapter class
+
+/***********************************************************************
+ 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++.
+
+ MySQL++ is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ MySQL++ is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with MySQL++; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA
+***********************************************************************/
+
+#if !defined(MYSQLPP_SQL_TYPE_ADAPTER_H)
+#define MYSQLPP_SQL_TYPE_ADAPTER_H
+
+#include "common.h"
+
+#include "datetime.h"
+#include "null.h"
+#include "sql_types.h"
+
+#include <string>
+
+namespace mysqlpp {
+
+/// \brief Converts many different data types to strings suitable for
+/// use in SQL queries.
///
/// This class provides implicit conversion between many C++ types and
-/// SQL-formatted string representations of that data while preserving
-/// some type information. End-users of MySQL++ are not expected to
-/// use this class directly. Rather, it exists for those interfaces in
-/// MySQL++ that need to accept any of several reasonable data types,
-/// particularly those involved in building query strings.
+/// SQL-formatted string representations of that data without losing
+/// important type information. This class is not for direct use
+/// outside MySQL++ itself. It exists for those interfaces in MySQL++
+/// that need to accept a value of any reasonable data type which it
+/// will use in building a query string.
///
-/// There are two main uses for this. One is in the Query class
-/// interfaces for building template queries: they have to be generic
-/// with respect to argument type, but because we know we want the data
-/// in some kind of string form eventually, we don't need to templatize
-/// it. The interface can just accept a SQLTypeAdapter, which lets it
-/// accept any reasonable data type.
+/// One major use for this is in the Query class interfaces for building
+/// template queries: they have to be generic with respect to argument
+/// type, but because we know we want the data in some kind of string
+/// form eventually, we don't need to templatize it. The interface can
+/// just use SQLTypeAdapter, which lets callers pass any reasonable data
+/// type. The adapter converts the passed value implicitly.
///
/// The other major use for this type is the quoting and escaping logic
/// in Query's stream interface: rather than overload the << operators
@@ -24,49 +64,11 @@
/// that the manipulator can decide whether to do automatic quoting
/// and/or escaping.
-/***********************************************************************
- 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++.
-
- MySQL++ is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- MySQL++ is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with MySQL++; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
- USA
-***********************************************************************/
-
-#if !defined(MYSQLPP_SQL_TYPE_ADAPTER_H)
-#define MYSQLPP_SQL_TYPE_ADAPTER_H
-
-#include "common.h"
-
-#include "datetime.h"
-#include "null.h"
-#include "sql_types.h"
-
-#include <string>
-
-namespace mysqlpp {
-
-/// \brief A specialized \c std::string that will convert from any
-/// valid MySQL type.
-
-class MYSQLPP_EXPORT SQLTypeAdapter : public std::string
+class MYSQLPP_EXPORT SQLTypeAdapter
{
public:
+ typedef size_t size_type; ///< size of length values
+
/// \brief Default constructor; empty string
SQLTypeAdapter();
@@ -136,7 +138,7 @@
/// \brief Copy a C string into this object
SQLTypeAdapter& operator =(const char* str)
{
- std::string::operator =(str);
+ buffer_.assign(str);
is_string_ = true;
is_processed_ = false;
return *this;
@@ -145,11 +147,18 @@
/// \brief Copy a C++ \c string into this object
SQLTypeAdapter& operator =(const std::string& str)
{
- std::string::operator =(str);
+ buffer_.assign(str);
is_string_ = true;
is_processed_ = false;
return *this;
}
+
+ /// \brief Return pointer to raw data buffer
+ const char* data() const { return buffer_.data(); }
+
+ /// \brief Return number of bytes in data buffer
+ size_type length() const { return buffer_.length(); }
+ size_type size() const { return length(); } ///< alias for length()
/// \brief Returns true if the object was initialized with a
/// stringish type
@@ -193,15 +202,18 @@
{ return operator =(str.data); }
SQLTypeAdapter& operator =(const null_type& n)
{
- assign(null_str);
+ buffer_.assign(null_str);
is_string_ = false;
is_processed_ = false;
}
#endif // !defined(DOXYGEN_IGNORE)
private:
- /// \brief If true, the object's string data is a copy of another
- /// string. Otherwise, it's the string form of an integral type.
+ /// \brief Our internal string buffer
+ std::string buffer_;
+
+ /// \brief If true, buffer_ holds a copy of another string, as
+ /// opposed to a string representation of a numeric value.
bool is_string_;
/// \brief If true, one of the MySQL++ manipulators has processed
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits