MySQL++ Reference Manual

- Main Page
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

# mysqlpp::Null< Type, Behavior > Class Template Reference

Class for holding data from a SQL column with the NULL attribute. More...

`#include <null.h>`

Collaboration diagram for mysqlpp::Null< Type, Behavior >:

[legend]
List of all members.

## Public Types
typedef Type | value_type
| Type of the data stored in this object, when it is not equal to SQL null.
## Public Member Functions
| Null ()
| Default constructor.
| Null (const Type &x)
| Initialize the object with a particular value.
| Null (const null_type &)
| Construct a Null equal to SQL null.
| operator Type () const
| Converts this object to Type.
Null & | operator= (const Type &x)
| Assign a value to the object.
Null & | operator= (const null_type &n)
| Assign SQL null to this object.
bool | operator== (const Null< Type > &rhs) const
| Do equality comparison of two nullable values.
bool | operator== (const null_type &) const
| Do equality comparison against hard-coded SQL null.
bool | operator!= (const Null< Type > &rhs) const
| Do inequality comparison of two nullable values.
bool | operator!= (const null_type &rhs) const
| Do inequality comparison against hard-coded SQL null.
bool | operator< (const Null< Type > &rhs) const
| Do less-than comparison of two nullable values.
bool | operator< (const null_type &) const
| Do less-than comparison against hard-coded SQL null.
## Public Attributes
Type | data
| The object's value, when it is not SQL null.
bool | is_null
| If set, this object is considered equal to SQL null.

## Detailed Description

### template<class Type, class Behavior = NullIsNull>
class mysqlpp::Null< Type, Behavior >

Class for holding data from a SQL column with the NULL attribute.

This template is necessary because there is nothing in the C++ type system with the same semantics as SQL's null. In SQL, a column can have the optional 'NULL' attribute, so there is a difference in type between, say an `int` column that can be null and one that cannot be. C++'s NULL constant does not have these features.

It's important to realize that this class doesn't hold nulls, it holds data that can be null. It can hold a non-null value, you can then assign null to it (using MySQL++'s global `null` object), and then assign a regular value to it again; the object will behave as you expect throughout this process.

Because one of the template parameters is a C++ type, the typeid() for a null `int` is different than for a null `string`, to pick two random examples. See type_info.cpp for the table SQL types that can be null.

## Constructor & Destructor Documentation

template<class Type, class Behavior = NullIsNull>

mysqlpp::Null< Type, Behavior >::Null | ( |  | ) | `[inline]`

Default constructor.

"data" member is left uninitialized by this ctor, because we don't know what to initialize it to.

template<class Type, class Behavior = NullIsNull>

mysqlpp::Null< Type, Behavior >::Null | ( | const Type & | x | ) | `[inline]`

Initialize the object with a particular value.

The object is marked as "not null" if you use this ctor. This behavior exists because the class doesn't encode nulls, but rather data which can be null. The distinction is necessary because 'NULL' is an optional attribute of SQL columns.

template<class Type, class Behavior = NullIsNull>

mysqlpp::Null< Type, Behavior >::Null | ( | const null_type & |  | ) | `[inline]`

Construct a Null equal to SQL null.

This is typically used with the global `null` object. (Not to be confused with C's NULL type.) You can say something like...

            ///

...to get a null `int`.

## Member Function Documentation

template<class Type, class Behavior = NullIsNull>

mysqlpp::Null< Type, Behavior >::operator Type | ( |  | ) | const`[inline]`

Converts this object to Type.

If is_null is set, returns whatever we consider that null "is", according to the Behavior parameter you used when instantiating this template. See NullIsNull, NullIsZero and NullIsBlank.

Otherwise, just returns the 'data' member.

template<class Type, class Behavior = NullIsNull>

bool mysqlpp::Null< Type, Behavior >::operator< | ( | const null_type & |  | ) | const`[inline]`

Do less-than comparison against hard-coded SQL null.

Always returns false because we can only be greater than or equal to a SQL null.

template<class Type, class Behavior = NullIsNull>

bool mysqlpp::Null< Type, Behavior >::operator< | ( | const Null< Type > & | rhs | ) | const`[inline]`

Do less-than comparison of two nullable values.

Two null objects are equal to each other, and null is less than not-null. If neither is null, we delegate to operator < for the base data type.

template<class Type, class Behavior = NullIsNull>

Null& mysqlpp::Null< Type, Behavior >::operator= | ( | const null_type & | n | ) | `[inline]`

Assign SQL null to this object.

This just sets the is_null flag; the data member is not affected until you call the Type() operator on it.

template<class Type, class Behavior = NullIsNull>

Null& mysqlpp::Null< Type, Behavior >::operator= | ( | const Type & | x | ) | `[inline]`

Assign a value to the object.

This marks the object as "not null" as a side effect.

template<class Type, class Behavior = NullIsNull>

bool mysqlpp::Null< Type, Behavior >::operator== | ( | const null_type & |  | ) | const`[inline]`

Do equality comparison against hard-coded SQL null.

This tells you the same thing as testing is_null member.

template<class Type, class Behavior = NullIsNull>

bool mysqlpp::Null< Type, Behavior >::operator== | ( | const Null< Type > & | rhs | ) | const`[inline]`

Do equality comparison of two nullable values.

Two null objects are equal, and null is not equal to not-null. If neither is null, we delegate to operator == for the base data type.

## Member Data Documentation

template<class Type, class Behavior = NullIsNull>

bool mysqlpp::Null< Type, Behavior >::is_null

If set, this object is considered equal to SQL null.

This flag affects how the Type() and << operators work.

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

- null.h