Author: wyoung
Date: Sat Oct 7 05:54:00 2006
New Revision: 1328
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1328&view=rev
Log:
Classes ColData_Tmpl and const_string can now be instantiated with a C
string plus a length parameter, allowing them to hold binary data.
Modified:
trunk/Wishlist
trunk/lib/coldata.h
trunk/lib/const_string.h
Modified: trunk/Wishlist
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1328&r1=1327&r2=1328&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Sat Oct 7 05:54:00 2006
@@ -31,16 +31,11 @@
o Fix handling of /usr/local/mysql as base install dir.
- o ColData doesn't cope with nulls very well, such as storing
- BLOB column data. This manifests in things like Row::at()
- returning truncated data, because somewhere along the line
- a ColData object was created using only a char*; we need to
- be able to use a length as well. Update examples/cgi_image
- and examples/load_file to use this new mechanism.
-
- o A BLOB field containing a null will be truncated when using
- SSQLS with a std::string member. This is probably related
- to the previous item.
+ o Update examples/cgi_image and examples/load_file to use new
+ binary-aware ColData, const_string and Query classes.
+
+ o Check that SSQLS works with BLOB now that ColData, const_string
+ and Query classes cope with embedded nulls. If not, fix.
o Have resetdb create a second table containing a BLOB column
that load_file and cgi_image can use.
Modified: trunk/lib/coldata.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/coldata.h?rev=1328&r1=1327&r2=1328&view=diff
==============================================================================
--- trunk/lib/coldata.h (original)
+++ trunk/lib/coldata.h Sat Oct 7 05:54:00 2006
@@ -111,7 +111,7 @@
{
}
- /// \brief Full constructor.
+ /// \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
@@ -126,25 +126,32 @@
{
}
+ /// \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),
+ buf_(str),
+ null_(n)
+ {
+ }
+
/// \brief Get this object's current MySQL type.
- mysql_type_info type() const
- {
- return 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();
- }
+ 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();
- }
+ bool escape_q() const { return type_.escape_q(); }
/// \brief Template for converting data from one type to another.
template <class Type> Type conv(Type dummy) const;
@@ -311,7 +318,7 @@
{
std::string strbuf = buf_;
strip_all_blanks(strbuf);
- size_t len = strbuf.size();
+ std::string::size_type len = strbuf.size();
const char* str = strbuf.c_str();
const char* end = str;
Type num = mysql_convert<Type>(str, end);
Modified: trunk/lib/const_string.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/const_string.h?rev=1328&r1=1327&r2=1328&view=diff
==============================================================================
--- trunk/lib/const_string.h (original)
+++ trunk/lib/const_string.h Sat Oct 7 05:54:00 2006
@@ -31,9 +31,10 @@
#include "defs.h"
+#include <algorithm>
+#include <iostream>
#include <stdexcept>
#include <string>
-#include <iostream>
namespace mysqlpp {
@@ -77,13 +78,22 @@
/// \brief Create empty string
const_string() :
- str_data_("")
+ str_data_(""),
+ length_(0)
{
}
/// \brief Initialize string from existing C string
const_string(const char* str) :
- str_data_(str)
+ str_data_(str),
+ length_(strlen(str))
+ {
+ }
+
+ /// \brief Initialize string from existing C string of known length
+ const_string(const char* str, size_type len) :
+ str_data_(str),
+ length_(len)
{
}
@@ -91,53 +101,34 @@
const_string& operator=(const char* str)
{
str_data_ = str;
+ length_ = strlen(str);
return *this;
}
+ /// \brief Return number of characters in the string
+ size_type length() const { return length_; }
+
/// \brief Return number of characters in string
- size_type size() const
- {
- register int i = 0;
- while (str_data_[i])
- i++;
- return i;
- }
-
+ size_type size() const { return length(); }
+
/// \brief Return iterator pointing to the first character of
/// the string
- const_iterator begin() const
- {
- return str_data_;
- }
+ const_iterator begin() const { return str_data_; }
/// \brief Return iterator pointing to one past the last character
/// of the string.
- const_iterator end() const
- {
- return str_data_ + size();
- }
-
- /// \brief Return number of characters in the string
- size_type length() const
- {
- return size();
- }
+ const_iterator end() const { return str_data_ + size(); }
/// \brief Return the maximum number of characters in the string.
///
/// Because this is a \c const string, this is just an alias for
/// size(); its size is always equal to the amount of data currently
/// stored.
- size_type max_size() const
- {
- return size();
- }
+ size_type max_size() const { return size(); }
/// \brief Return a reference to a character within the string.
const_reference operator [](size_type pos) const
- {
- return str_data_[pos];
- }
+ { return str_data_[pos]; }
/// \brief Return a reference to a character within the string.
///
@@ -151,18 +142,12 @@
return str_data_[pos];
}
- /// \brief Return a const pointer to the string data,
- /// null-terminated.
- const char* c_str() const
- {
- return str_data_;
- }
-
- /// \brief Alias for c_str()
- const char* data() const
- {
- return str_data_;
- }
+ /// \brief Return a const pointer to the string data. Not
+ /// necessarily null-terminated!
+ const char* c_str() const { return str_data_; }
+
+ /// \brief Alias for \c c_str()
+ const char* data() const { return str_data_; }
/// \brief Lexically compare this string to another.
///
@@ -173,17 +158,16 @@
/// \retval >0 if str1 is lexically "greater than" str2
int compare(const const_string& str) const
{
- const char* str1 = str_data_;
- const char* str2 = str.str_data_;
- while (*str1 == *str2 && (*str1 && *str2)) {
- str1++;
- str2++;
+ size_type i = 0, short_len = std::min(length(), str.length());
+ while ((i < short_len) && (str_data_[i] != str.str_data_[i])) {
+ ++i;
}
- return *str1 - *str2;
+ return str_data_[i] - str.str_data_[i];
}
private:
const char* str_data_;
+ size_type length_;
};
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits