MySQL++  3.3.0
Classes | Functions | Variables
null.h File Reference

Declares classes that implement SQL "null" semantics within C++'s type system. More...

#include "exceptions.h"
#include <iostream>
#include <string>

Go to the source code of this file.

Classes

class  mysqlpp::null_type
 The type of the global mysqlpp::null object. More...
 
struct  mysqlpp::NullIsNull
 Class for objects that define SQL null in terms of MySQL++'s null_type. More...
 
struct  mysqlpp::NullIsZero
 Class for objects that define SQL null as 0. More...
 
struct  mysqlpp::NullIsBlank
 Class for objects that define SQL null as a blank C string. More...
 
class  mysqlpp::Null< Type, Behavior >
 Class for holding data from a SQL column with the NULL attribute. More...
 

Functions

template<class Type , class Behavior >
std::ostream & mysqlpp::operator<< (std::ostream &o, const Null< Type, Behavior > &n)
 Inserts null-able data into a C++ stream if it is not actually null. Otherwise, insert something appropriate for null data.
 

Variables

const std::string mysqlpp::null_str
 "NULL" string constant
 
const null_type mysqlpp::null = null_type()
 Global 'null' instance. Use wherever you need a SQL null. More...
 

Detailed Description

Declares classes that implement SQL "null" semantics within C++'s type system.

This is required because C++'s own NULL type is not semantically the same as SQL nulls.

Variable Documentation

◆ null

const null_type mysqlpp::null = null_type()

Global 'null' instance. Use wherever you need a SQL null.

SQL null is equal to nothing else. It is not the same as C++'s NULL value, it is not a Boolean false....it is unique. As such, if you use this in some other type context, you will get a compiler error saying something about CannotConvertNullToAnyOtherDataType. The only thing you can assign this object instance to is a variable of type Null<T>, and then only directly. Code like this does not work:

int foo = return_some_value_for_foo();
Class for holding data from a SQL column with the NULL attribute.
Definition: null.h:171
const null_type null
Global 'null' instance. Use wherever you need a SQL null.
Definition: null.h:84

The compiler will try to convert mysqlpp::null to int to make all values in the conditional operation consistent, but this is not legal. Anyway, it's questionable code because it means you're using SQL null to mean the same thing as zero here. If zero is a special value, there's no reason to use SQL null. SQL null exists when every value for a particular column is legal and you need something that means "no legal value".