MySQL++  3.3.0
Public Types | Public Member Functions | Public Attributes | List of all members
mysqlpp::Null< Type, Behavior > Class Template Reference

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

#include <null.h>

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. More...
 
 Null (const Type &x)
 Initialize the object with a particular value. More...
 
 Null (const null_type &)
 Construct a Null equal to SQL null. More...
 
 operator Type () const
 Converts this object to Type. More...
 
Nulloperator= (const Type &x)
 Assign a value to the object. More...
 
Nulloperator= (const null_type &)
 Assign SQL null to this object. More...
 
bool operator== (const Null< Type > &rhs) const
 Do equality comparison of two nullable values. More...
 
bool operator== (const null_type &) const
 Do equality comparison against hard-coded SQL null. More...
 
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. More...
 
bool operator< (const null_type &) const
 Do less-than comparison against hard-coded SQL null. More...
 

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

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

◆ Null() [1/3]

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.

◆ Null() [2/3]

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.

◆ Null() [3/3]

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

Null<int> foo = null;

...to get a null int.

Member Function Documentation

◆ operator Type()

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.

References mysqlpp::Null< Type, Behavior >::data, and mysqlpp::Null< Type, Behavior >::is_null.

◆ operator<() [1/2]

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.

References mysqlpp::Null< Type, Behavior >::data, and mysqlpp::Null< Type, Behavior >::is_null.

◆ operator<() [2/2]

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.

◆ operator=() [1/2]

template<class Type , class Behavior = NullIsNull>
Null& mysqlpp::Null< Type, Behavior >::operator= ( const null_type )
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.

References mysqlpp::Null< Type, Behavior >::is_null.

◆ operator=() [2/2]

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.

References mysqlpp::Null< Type, Behavior >::data, and mysqlpp::Null< Type, Behavior >::is_null.

◆ operator==() [1/2]

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.

References mysqlpp::Null< Type, Behavior >::data, and mysqlpp::Null< Type, Behavior >::is_null.

◆ operator==() [2/2]

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.

References mysqlpp::Null< Type, Behavior >::is_null.

Member Data Documentation

◆ is_null

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.

Referenced by mysqlpp::Null< Type, Behavior >::operator Type(), mysqlpp::Null< Type, Behavior >::operator<(), mysqlpp::Null< Type, Behavior >::operator=(), and mysqlpp::Null< Type, Behavior >::operator==().


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