#include <coldata.h>
Collaboration diagram for mysqlpp::ColData_Tmpl< Str >:
Public Member Functions | |
ColData_Tmpl () | |
Default constructor. | |
ColData_Tmpl (const ColData_Tmpl< Str > &cd) | |
Copy ctor. | |
ColData_Tmpl (bool n, mysql_type_info t=mysql_type_info::string_type) | |
Constructor allowing you to set the null flag and the type data. | |
ColData_Tmpl (const std::string &str, mysql_type_info t=mysql_type_info::string_type, bool n=false) | |
C++ string version of full ctor. | |
ColData_Tmpl (const char *str, mysql_type_info t=mysql_type_info::string_type, bool n=false) | |
Null-terminated C string version of full ctor. | |
ColData_Tmpl (const char *str, typename Str::size_type len, mysql_type_info t=mysql_type_info::string_type, bool n=false) | |
Full constructor. | |
mysql_type_info | type () const |
Get this object's current MySQL type. | |
bool | quote_q () const |
Returns true if data of this type should be quoted, false otherwise. | |
bool | escape_q () const |
Returns true if data of this type should be escaped, false otherwise. | |
template<class Type> Type | conv (Type dummy) const |
Template for converting data from one type to another. | |
void | it_is_null () |
Set a flag indicating that this object is a SQL null. | |
const bool | is_null () const |
Returns true if this object is a SQL null. | |
const std::string & | get_string () const |
Returns this object's data in C++ string form. | |
operator cchar * () 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. | |
template<class T, class B> | operator Null () const |
Converts this object to a SQL null. |
Do not use this class directly. Use the typedef ColData or MutableColData instead. ColData is a ColData_Tmpl<const
std::string>
and MutableColData is a 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:
ColData("12.86") + 2.0
That works fine, but be careful. If you had said this instead:
ColData("12.86") + 2
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.
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.
|
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. |
|
Copy ctor.
|
|
Constructor allowing you to set the null flag and the type data.
|
|
C++ string version of full ctor.
|
|
Null-terminated C string version of full ctor.
|
|
Full constructor.
|
|
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
If you are using the
This method is arguably useful with plain
ColData cd = ...; std::string s(cd.data(), cd.length()); |
|
Converts this object to a SQL null. Returns a copy of the global null object if the string data held by the object is exactly equal to "NULL". Else, it constructs an empty object of type T and tries to convert it to Null<T, B>. |