Unofficial Content

The goal of this document is to explain how to work with -or avoid- null values in GeneXus-generated applications.

Attribute values

An attribute can have one of the following values:

  1. An actual value.
  2. Empty
    This is a special value, i.e. zero for numeric data, empty string for character data, etc.
  3. Null, if it is allowed to
    Null means that the value is not set, unspecified, does not apply or unknown.

It is important to understand the difference between these last two special values: Null is not the same as Empty.

Working with null values

To be able to accept null values, an Attribute must be declared as nullable by setting the Nullable property - Attribute to Yes.

Nullable attributes can be set as null in different ways.

Constraints

  • Variables cannot be null
  • Nullity is not copied on assignments

If X is an attribute and its value is null, the statement "Y = X" does _not_ set the value of Y to null. It's set to empty. You can change this behavior by writing the following code:

If Y.IsNull()
  X.SetNull()
Else
  X = Y
Endif
  • Nullity is not supported in parameter passing

Parameter passing protocol does not support nulls. The empty value is always received by the referenced object, even in the following situations:

  • In a transaction there is a object.call(attribute) where the attribute is on the form and the control has Empty As Null = Yes.
  • object.call(nullvalue(attribute)) and Generate null for nullvalue = Yes.
  • object.call(attribute.setnull()).
    In this case a specification error is displayed.

Avoiding null values

The best way to avoid null values in an attribute is to set it's Nullable property - Attribute to No.

In backward compatibility situations or, if you cannot reorganize the database (to avoid nulls), there are several programming considerations you may take into account:

This minimizes the risk of setting a value to null. Nullvalue function behavior may be affected by the value of Generate null for nullvalue() property.

See also

Empty value for each DBMS/Data type

 

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant