Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File 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 Methods

| Null ()
| Default constructor.
| Null (const Type &x)
| Initialize the object with a particular value.
| Null (const null_type &n)
| Construct a Null equal to SQL null.
| operator Type & ()
| 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.

## 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 & | n | ) | `[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...

                Null<int> foo = null;

...to get a null `int`.

## Member Function Documentation

template<class Type, class Behavior = NullisNull>
mysqlpp::Null< Type, Behavior >::operator Type & | ( |  | ) | `[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>
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.

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