MySQL++
3.3.0
|
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... | |
Null & | operator= (const Type &x) |
Assign a value to the object. More... | |
Null & | operator= (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... | |
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.
|
inline |
Default constructor.
"data" member is left uninitialized by this ctor, because we don't know what to initialize it to.
|
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.
|
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
.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
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==().