KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: ORDA query - Null and Undefined data types
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: November 14, 2022

When performing an ORDA query, this query will not automatically take null or undefined types into account. Null and Undefined are special data types that handle cases where the value of an expression is NOT known. To include these records in a query, the NULL keyword must be stated explicitly in the queryString.

The example below illustrates queries with null and undefined.
NOTE: The Records are created and saved to Table prior.
The Table contains two fields: ID(LongInt) and data(object).

// ID:1 -> data: undefined
// ID:2 -> data: {} empty object
// ID:3 -> data: {"value";True}
// ID:4 -> data: {"value";False}
// ID:5 -> data: {"value";Null}

$ob:=New object
$ob.all:=ds.Table.all()
$ob.q1:=ds.Table.query("Not(data.value=true)") // returns id:4
$ob.q2:=ds.Table.query("(data.value=null) OR Not(data.value=true)")//returns id:1,2,4,5

The first query (q1) only returns the record where value is NOT true. It only returns the entity where ID is equal to 4. The other records are not selected, because they have null/undefined/empty defined for value.

Notice with (q2) when the null keyword is explicitly stated in the queryString, you are able to receive all the records where value is NOT true and the records where value is null/undefined/empty.