Function DbSetNullValue() Foundation

Toggles NULL/NIL value support of a work area

Syntax
DbSetNullValue([<lNullAllowed>]) -> lNullAllowed
Parameters
<lNullAllowed>
<lNullAllowed> is a optional logical value. When .T. (true) is specified, NULL/NIL values are supported when accessing a database field. If .F., NULL values are automatically transformed to empty values.
Return

The function DbSetNullValue() returns the value of the function prior to this call of DbSetNullValue()

Description

DbSetNullValue() explicitly toggles NULL/NIL value support on a per work area basis. The default setting for handling null values is determined by the SET NULLVALUE command. For a more comprehensive explanation about null value hidding/transformation see SET NULLVALUE .

With DbSetNullValue(), NULL/NIL value support on the language level can be toggled at any time. This enables the programmer to disable NULL/NIL values for an XbpBrowse() object to automatically show empty values to the end user. In general enabling NULL/NIL values for business logic and disabling NULL/NIL values for displaying data is generally considered as a good practice.

Examples
DbSetNullValue()
// The sample illustrates how DbSetNullValue() 
// affects the Null value representation of a 
// field which is nullable. 
PROCEDURE Main() 
LOCAL aStructure := {} 

AAdd( aStructure , { "LASTNAME" , "C" , 20 , 0 } ) 
AAdd( aStructure , { "REVENUE"  , "N" ,  8 , 2 , "nullable" } ) 
AAdd( aStructure , { "CONTACT"  , "D" ,  8 , 0 , "nullable" } ) 

DbCreate("Customer",aStructure,"FOXCDX") 
USE Customer EXCLUSIVE VIA FOXCDX 

DbAppend() 
FIELD->LASTNAME := "Joe Doe" 

// result: "Joe Doe                       0   .  .  " 
// 
DbSetNullValue(.F.) 
? FIELD->LASTNAME, FIELD->REVENUE, FIELD->CONTACT 

// result: "Joe Doe              NIL NIL" 
// 
DbSetNullValue(.T.) 
? FIELD->LASTNAME, FIELD->REVENUE, FIELD->CONTACT 

FIELD->CONTACT := Date() 
FIELD->REVENUE := 1000 
DbCommit() 

// result: "Joe Doe               1000,00 04.08.2005" 
// 
? FIELD->LASTNAME, FIELD->REVENUE, FIELD->CONTACT 

DbSetNullValue(.F.) 
FIELD->CONTACT := NIL 
DbCommit() 

// result: "Joe Doe               1000,00   .  .  " 
// 
? FIELD->LASTNAME, FIELD->REVENUE, FIELD->CONTACT 

// result:  "Joe Doe               1000,00 NIL" 
// 
DbSetNullValue(.T.) 
? FIELD->LASTNAME, FIELD->REVENUE, FIELD->CONTACT 

CLOSE ALL 
RETURN 

PROCEDURE DbeSys() 
DbeLoad("FOXDBE") 
DbeLoad("CDXDBE") 
DbeBuild("FOXCDX","FOXDBE","CDXDBE") 
IF(DbeSetDefault()!="FOXCDX") 
  Alert("FOXCDX DatabaseEngine not loaded/or build") 
ENDIF 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.