A std::string work-alike that can convert itself from SQL text data formats to C++ data types.
More...
|
| String () |
| Default constructor. More...
|
|
| String (const String &other) |
| Copy ctor. More...
|
|
| String (const char *str, size_type len, mysql_type_info type=mysql_type_info::string_type, bool is_null=false) |
| Full constructor. More...
|
|
| String (const std::string &str, mysql_type_info type=mysql_type_info::string_type, bool is_null=false) |
| C++ string version of full ctor. More...
|
|
| String (const char *str, mysql_type_info type=mysql_type_info::string_type, bool is_null=false) |
| Null-terminated C string version of full ctor. More...
|
|
| ~String () |
| Destroy string.
|
|
void | assign (const char *str, size_type len, mysql_type_info type=mysql_type_info::string_type, bool is_null=false) |
| Assign raw data to this object. More...
|
|
void | assign (const std::string &str, mysql_type_info type=mysql_type_info::string_type, bool is_null=false) |
| Assign a C++ string to this object. More...
|
|
void | assign (const char *str, mysql_type_info type=mysql_type_info::string_type, bool is_null=false) |
| Assign a C string to this object. More...
|
|
char | at (size_type pos) const |
| Return a character within the string. More...
|
|
const_iterator | begin () const |
| Return iterator pointing to the first character of the string.
|
|
const char * | c_str () const |
| Return a const pointer to the string data.
|
|
template<class Type > |
Type | conv (Type) const |
| Template for converting the column data to most any numeric data type.
|
|
template<class T , class B > |
Null< T, B > | conv (Null< T, B >) const |
| Overload of conv() for types wrapped with Null<> More...
|
|
int | compare (const String &other) const |
| Lexically compare this string to another. More...
|
|
int | compare (const std::string &other) const |
| Lexically compare this string to another. More...
|
|
int | compare (size_type pos, size_type num, std::string &other) const |
| Lexically compare this string to another. More...
|
|
int | compare (const char *other) const |
| Lexically compare this string to another. More...
|
|
int | compare (size_type pos, size_type num, const char *other) const |
| Lexically compare this string to another. More...
|
|
const char * | data () const |
| Raw access to the underlying buffer, with no C string interpretation.
|
|
bool | empty () const |
| Returns true if size() == 0.
|
|
const_iterator | end () const |
| Return iterator pointing to one past the last character of the string.
|
|
bool | escape_q () const |
| Returns true if data of this type should be escaped, false otherwise.
|
|
bool | is_null () const |
| Returns true if this object is a SQL null.
|
|
void | it_is_null () |
| Set a flag indicating that this object is a SQL null.
|
|
size_type | length () const |
| Return number of bytes in the string. More...
|
|
size_type | max_size () const |
| Return the maximum number of characters in the string. More...
|
|
bool | quote_q () const |
| Returns true if data of this type should be quoted, false otherwise.
|
|
size_type | size () const |
| Return number of bytes in string. More...
|
|
void | strip_leading_blanks (std::string &s) const |
| Returns a copy of our internal string without leading blanks.
|
|
void | to_string (std::string &s) const |
| Copies this object's data into a C++ string. More...
|
|
mysql_type_info | type () const |
| Get this object's current MySQL type.
|
|
String & | operator= (const std::string &rhs) |
| Assignment operator, from C++ string.
|
|
String & | operator= (const char *str) |
| Assignment operator, from C string. More...
|
|
String & | operator= (const String &other) |
| Assignment operator, from other String. More...
|
|
template<typename T > |
bool | operator== (const T &rhs) const |
| Equality comparison operator. More...
|
|
bool | operator== (const mysqlpp::null_type &) const |
| Equality comparison operator. More...
|
|
template<typename T > |
bool | operator != (const T &rhs) const |
| Inequality comparison operator. More...
|
|
bool | operator != (const mysqlpp::null_type &) const |
| Inequality comparison operator. More...
|
|
char | operator [] (size_type pos) const |
| Return a character within the string. More...
|
|
| operator const char * () const |
| Returns a const char pointer to the object's raw data.
|
|
| operator signed char () const |
| Converts this object's string data to a signed char.
|
|
| operator unsigned char () const |
| Converts this object's string data to an unsigned char.
|
|
| operator int () const |
| Converts this object's string data to an int.
|
|
| operator unsigned int () const |
| Converts this object's string data to an unsigned int.
|
|
| operator short int () const |
| Converts this object's string data to a short int.
|
|
| operator unsigned short int () const |
| Converts this object's string data to an unsigned short int.
|
|
| operator long int () const |
| Converts this object's string data to a long int.
|
|
| operator unsigned long int () const |
| Converts this object's string data to an unsigned long int.
|
|
| operator longlong () const |
| Converts this object's string data to the platform- specific 'longlong' type, usually a 64-bit integer.
|
|
| operator ulonglong () const |
| Converts this object's string data to the platform- specific 'ulonglong' type, usually a 64-bit unsigned integer.
|
|
| operator float () const |
| Converts this object's string data to a float.
|
|
| operator double () const |
| Converts this object's string data to a double.
|
|
| operator bool () const |
| Converts this object's string data to a bool.
|
|
| operator Date () const |
| Converts this object's string data to a mysqlpp::Date.
|
|
| operator DateTime () const |
| Converts this object's string data to a mysqlpp::DateTime.
|
|
| operator Time () const |
| Converts this object's string data to a mysqlpp::Time.
|
|
template<class T , class B > |
| operator Null< T, B > () const |
| Converts the String to a nullable data type. More...
|
|
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, not used directly. The only exception is in dealing with BLOB data, which stays in String form for efficiency and to avoid corrupting the data with facile conversions. Even then, it's best to use it through the typedef aliases like sql_blob in sql_types.h, in case we later change this underlying representation.
String's implicit conversion operators let you can use these objects naturally:
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:
the result would be 14 because 2 is an integer, and C++'s type conversion rules put the String object in an integer context.
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.