Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File Members

# mysqlpp::ColData_Tmpl< Str > Class Template Reference

Template for string data that can convert itself to any standard C data type. More...

`#include <coldata.h>`

Collaboration diagram for mysqlpp::ColData_Tmpl< Str >:

[legend]
List of all members.

## Public Methods

| ColData_Tmpl ()
| Default constructor.
| 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 char *str, 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 the string form of this object's data.
| operator cchar * () const
| Returns a const char pointer to the string form of this object's 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.

## Detailed Description

### template<class Str>
class mysqlpp::ColData_Tmpl< Str >

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 `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 micro 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.

## Constructor & Destructor Documentation

template<class Str>
mysqlpp::ColData_Tmpl< Str >::ColData_Tmpl | ( |  | ) | `[inline]`

| 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.

template<class Str>
mysqlpp::ColData_Tmpl< Str >::ColData_Tmpl | ( | bool | n,
|  | mysql_type_info | t = mysql_type_info::string_type
| ) | `[inline, explicit]`

Constructor allowing you to set the null flag and the type data.

Parameters:

  n | if true, data is a SQL null
  t | MySQL type information for data being stored

template<class Str>
mysqlpp::ColData_Tmpl< Str >::ColData_Tmpl | ( | const char * | str,
|  | mysql_type_info | t = mysql_type_info::string_type,
|  | bool | n = false
| ) | `[inline, explicit]`

Full constructor.

Parameters:

  str | the string this object represents
  t | MySQL type information for data within str
  n | if true, str is a SQL null

## Member Function Documentation

template<class Str>
template<class T, class B>
mysqlpp::ColData_Tmpl< Str >::operator Null< T, B > | ( |  | ) | const

| 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>.

The documentation for this class was generated from the following file:

- coldata.h