UUID Functions(4.3)

This section describes functions that facilitate creation and use of  immutable universally unique identifiers (UUID).

For general information about UUIDs, see https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html.

For information about the uuid type in , see Data Types(4.3).

uuidCreateFromHexString

This function takes a string representation of a UUID and converts it to the uuid type.

uuid uuidCreateFromHexString ( string aString )
ParameterDescription

uuidString

A string representation of a UUID

Returns

A UUID based on the input string

The format of the string is validated but not the content. The function returns null if the format of the string is incorrect.

Example - uuidCreateFromHexString

The following example converts a string to a UUID:

uuid getUuid (string s) {
 uuid u = uuidCreateFromHexString(s);
 if(u==null) {
  //Incorrect UUID format
 } 
 return u;
} 

uuidCreateRandom

This function generates a random UUID.

uuid uuidCreateRandom ( void )
ParameterDescription

Returns

A version 4 UUID (randomly generated UUID)

Example - uuidCreateRandom

The following example creates a random UUID:

uuid getUuid() {
    return uuidCreateRandom();   
}

uuidGetVersion

This function returns the version of a UUID. The version number describes the type of the UUID, e g time-based, DCE security, name-based, and randomly generated UUID. For instance, a UUID generated by the function uuidCreateRandom is 4 (randomly generated UUID).

int uuidGetVersion ( uuid aUuid )
ParameterDescription
aUuidThe UUID for which you want to retrieve the version.

Returns

The version of the UUID, or -1 if the UUID in the argument is null.

Example - uuidGetVersion

The following example retrieves the version from a UUID:

uuid getUuid (string s) {
    uuid u = uuidCreateFromHexString(s);
    if(u==null) {
        debug("Incorrect UUID format");
    } else if (uuidGetVersion(u)<0) {
        debug("Invalid UUID");
    }
    return u;
}

uuidString

This function converts a UUID to a string. 

string uuidString ( aUuid )
ParameterDescription
aUuidThe UUID that you want to convert

Returns

The UUID represented as a string

Example - uuidString

The result of the following two examples are identical:

uuid aUuid = uuidCreateRandom();
string s = (string) aUuid;
uuid aUuid = uuidCreateRandom();
string s = uuidString(aUuid);