KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: A utility method that tests for a NIL UUID
PRODUCT: 4D | VERSION: 13.5 | PLATFORM: Mac & Win
Published On: April 10, 2015

A common coding statement is to test the state of a field" before executing follow-on code; e.g. [myTable]myField = "". As simple as such a test is, it is not so simple when a the intention of a field is for it to contain a UUID. From the 4D design reference...

If you try to store a string that does not comply with the UUID format in this field, 4D converts it automatically. The same operation is also applied to the contents of existing non-Alpha fields that are transformed into UUID fields: when loading the records, the values are reformatted and then stored once again.

Notes: An UUID field that is initialized (generated) and that has the NULL value returns an empty string. An UUID field that is not generated is not NULL and returns "000..." (the number of 0s is equal to the number of characters). The property is not taken into account by non-generated UUID fields (display of "000...").


So it is possible for three different UUID representations to be considered NIL values.

  • An empty string

  • A string of thirty-two zeros

  • A string containing one or more character pairs of "20"


In the image below the first, third, fourth and fifth values represent a NIL UUID.


The utility show below tests for all three conditions and returns true if any one of the conditions are met. To fully understand the test, please review Tech Tip Understanding the display of UUIDs

Utility method UTIL_IsNilUUID


If (True)
   If (False)
      Begin SQL
         /*
          Name: UTIL_IsNilUUID
          Path: UTIL_IsNilUUID

          Purpose: Test a string for NIl UUID format

          $0 - C_BOOLEAN
          $1 -C_TEXT
         */
      End SQL
   End if
   C_TEXT($MethodName_T)
   $MethodName_T:=Current method name
    //===================== Declare Variables ==================================
    //method_parameters_declarations
   C_BOOLEAN($0)
   C_TEXT($UID_T;$1)
    //--------------------------------------------------------------------------
    //method_wide_constants_declarations
    //--------------------------------------------------------------------------
    //local_variable_declarations
   C_LONGINT($Ndx;$SOA;$RIS;$Params_L)

End if
//====================== Initialize and Setup ================================

$UID_T:=$1

//======================== Method Actions ==================================

$0:=($UID_T="") | ($UID_T=("0"*32)) | (Position("20";$UID_T)>0)


Commented by Keith Culotta on April 17, 2015 at 7:51 AM
It seems that (Position("20";$UID_T)>0) can be true for a valid UUID. The 7th value in the series above contains two "20".